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; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 21 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 26 | 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] | 27 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 28 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 29 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 30 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 31 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 32 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 33 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 34 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 35 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 36 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 37 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 38 | import android.compat.annotation.ChangeId; |
| 39 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 40 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 41 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.content.Context; |
| 43 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 44 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 45 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 46 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 47 | import android.net.Uri; |
| 48 | import android.os.AsyncResult; |
| 49 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 50 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 51 | import android.os.Bundle; |
| 52 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 53 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 54 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Looper; |
| 56 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 57 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 58 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 59 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 60 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 61 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 62 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 63 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 64 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 65 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 66 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 67 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 68 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 69 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 70 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 71 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 72 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 73 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 74 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 75 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 76 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 77 | import android.telephony.AccessNetworkConstants; |
| 78 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 79 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 80 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 81 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 82 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 83 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 84 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 85 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 86 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 87 | import android.telephony.CellIdentityCdma; |
| 88 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 90 | import android.telephony.CellInfoGsm; |
| 91 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 92 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 93 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 94 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 95 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 96 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 97 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 98 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 99 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 100 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 101 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 102 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 103 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 104 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 105 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 106 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 107 | import android.telephony.SignalStrengthUpdateRequest; |
| 108 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 109 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 110 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 111 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 112 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 113 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 114 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 115 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 116 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 117 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 118 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 119 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 120 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 121 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 122 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 123 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 124 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 125 | import android.telephony.gba.GbaAuthRequest; |
| 126 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 127 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 128 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 129 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 130 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 131 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 139 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 140 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 141 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 143 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 144 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 146 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 147 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 148 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 149 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 150 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 151 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 166 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 186 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 190 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.data.DataUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 197 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 198 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 201 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.IccIoResult; |
| 204 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 209 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 211 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 212 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 213 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 214 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 215 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 216 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 217 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 218 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 219 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 220 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 221 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 222 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 223 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 224 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 225 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 226 | import com.android.services.telephony.TelecomAccountRegistry; |
| 227 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 228 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 229 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 230 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 231 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 232 | import java.io.IOException; |
| 233 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 234 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 235 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 236 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 237 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 238 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 239 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 240 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 241 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 242 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 243 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 244 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 245 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 246 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 247 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 248 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 249 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 250 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | |
| 252 | /** |
| 253 | * Implementation of the ITelephony interface. |
| 254 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 255 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 256 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 257 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 258 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 259 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 260 | |
| 261 | // Message codes used with mMainThreadHandler |
| 262 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 263 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 264 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 265 | private static final int CMD_OPEN_CHANNEL = 9; |
| 266 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 267 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 268 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 269 | private static final int CMD_NV_READ_ITEM = 13; |
| 270 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 271 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 272 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 273 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 274 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 275 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 276 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 277 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 278 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 279 | private static final int CMD_SEND_ENVELOPE = 25; |
| 280 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 281 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 282 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 283 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 284 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 285 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 286 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 287 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 288 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 289 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 290 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 291 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 292 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 293 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 294 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 295 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 296 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 297 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 298 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 299 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 300 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 301 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 302 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 303 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 304 | private static final int CMD_SWITCH_SLOTS = 50; |
| 305 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 306 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 307 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 308 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 309 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 310 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 311 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 312 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 313 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 314 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 315 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 316 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 317 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 318 | private static final int CMD_MODEM_REBOOT = 64; |
| 319 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 320 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 321 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 322 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 323 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 325 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 326 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 327 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 328 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 329 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 330 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 331 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 332 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 333 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 334 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 335 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 336 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 337 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 338 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 339 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 340 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 341 | private static final int CMD_GET_CALL_WAITING = 87; |
| 342 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 343 | private static final int CMD_SET_CALL_WAITING = 89; |
| 344 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 345 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 346 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 347 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 348 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 349 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 350 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 351 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 352 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 353 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 354 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 355 | private static final int CMD_SET_SIM_POWER = 101; |
| 356 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 357 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 358 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 359 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 360 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 361 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 362 | 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] | 363 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 364 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 365 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 366 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 367 | private static final int CMD_ENABLE_VONR = 113; |
| 368 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 369 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 370 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 371 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 372 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 374 | // Parameters of select command. |
| 375 | private static final int SELECT_COMMAND = 0xA4; |
| 376 | private static final int SELECT_P1 = 0x04; |
| 377 | private static final int SELECT_P2 = 0; |
| 378 | private static final int SELECT_P3 = 0x10; |
| 379 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 380 | /** The singleton instance. */ |
| 381 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 382 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 384 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 385 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 386 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 387 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 388 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 389 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 390 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 391 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 392 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 393 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 394 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 395 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 397 | /** User Activity */ |
| 398 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 399 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 400 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 401 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 402 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 403 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 404 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 405 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 406 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 407 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 408 | // String to store multi SIM allowed |
| 409 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 410 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 411 | // The AID of ISD-R. |
| 412 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 413 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 414 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 415 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 416 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 417 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 418 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 419 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 420 | 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] | 421 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 422 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 423 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 424 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 425 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 426 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 427 | */ |
| 428 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 429 | "reset_network_erase_modem_config_enabled"; |
| 430 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 431 | 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] | 432 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 433 | /** |
| 434 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 435 | * one ICCID active at the same time. |
| 436 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 437 | * |
| 438 | * @hide |
| 439 | */ |
| 440 | @ChangeId |
| 441 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 442 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 443 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 444 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 445 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 446 | * operation fails. |
| 447 | */ |
| 448 | @ChangeId |
| 449 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 450 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 451 | |
| 452 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 453 | * A request object to use for transmitting data to an ICC. |
| 454 | */ |
| 455 | private static final class IccAPDUArgument { |
| 456 | public int channel, cla, command, p1, p2, p3; |
| 457 | public String data; |
| 458 | |
| 459 | public IccAPDUArgument(int channel, int cla, int command, |
| 460 | int p1, int p2, int p3, String data) { |
| 461 | this.channel = channel; |
| 462 | this.cla = cla; |
| 463 | this.command = command; |
| 464 | this.p1 = p1; |
| 465 | this.p2 = p2; |
| 466 | this.p3 = p3; |
| 467 | this.data = data; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 472 | * A request object to use for transmitting data to an ICC. |
| 473 | */ |
| 474 | private static final class ManualNetworkSelectionArgument { |
| 475 | public OperatorInfo operatorInfo; |
| 476 | public boolean persistSelection; |
| 477 | |
| 478 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 479 | this.operatorInfo = operatorInfo; |
| 480 | this.persistSelection = persistSelection; |
| 481 | } |
| 482 | } |
| 483 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 484 | private static final class PurchasePremiumCapabilityArgument { |
| 485 | public @TelephonyManager.PremiumCapability int capability; |
| 486 | public @NonNull String appName; |
| 487 | public @NonNull IIntegerConsumer callback; |
| 488 | |
| 489 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 490 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 491 | this.capability = capability; |
| 492 | this.appName = appName; |
| 493 | this.callback = callback; |
| 494 | } |
| 495 | } |
| 496 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 497 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 498 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 499 | * request after sending. The main thread will notify the request when it is complete. |
| 500 | */ |
| 501 | private static final class MainThreadRequest { |
| 502 | /** The argument to use for the request */ |
| 503 | public Object argument; |
| 504 | /** The result of the request that is run on the main thread */ |
| 505 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 506 | // The subscriber id that this request applies to. Defaults to |
| 507 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 508 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 509 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 510 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 511 | public Phone phone; |
| 512 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 513 | public WorkSource workSource; |
| 514 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 515 | public MainThreadRequest(Object argument) { |
| 516 | this.argument = argument; |
| 517 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 518 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 519 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 520 | this.argument = argument; |
| 521 | if (phone != null) { |
| 522 | this.phone = phone; |
| 523 | } |
| 524 | this.workSource = workSource; |
| 525 | } |
| 526 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 527 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 528 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 529 | if (subId != null) { |
| 530 | this.subId = subId; |
| 531 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 532 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 536 | private static final class IncomingThirdPartyCallArgs { |
| 537 | public final ComponentName component; |
| 538 | public final String callId; |
| 539 | public final String callerDisplayName; |
| 540 | |
| 541 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 542 | String callerDisplayName) { |
| 543 | this.component = component; |
| 544 | this.callId = callId; |
| 545 | this.callerDisplayName = callerDisplayName; |
| 546 | } |
| 547 | } |
| 548 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 549 | /** |
| 550 | * A handler that processes messages on the main thread in the phone process. Since many |
| 551 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 552 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 553 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 554 | * on, which will be notified when the operation completes and will contain the result of the |
| 555 | * request. |
| 556 | * |
| 557 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 558 | * note that request.result must be set to something non-null for the calling thread to |
| 559 | * unblock. |
| 560 | */ |
| 561 | private final class MainThreadHandler extends Handler { |
| 562 | @Override |
| 563 | public void handleMessage(Message msg) { |
| 564 | MainThreadRequest request; |
| 565 | Message onCompleted; |
| 566 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 567 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 569 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | |
| 571 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | case CMD_HANDLE_USSD_REQUEST: { |
| 573 | request = (MainThreadRequest) msg.obj; |
| 574 | final Phone phone = getPhoneFromRequest(request); |
| 575 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 576 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 578 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | if (!isUssdApiAllowed(request.subId)) { |
| 580 | // Carrier does not support use of this API, return failure. |
| 581 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 582 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 583 | Bundle returnData = new Bundle(); |
| 584 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 585 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 588 | notifyRequester(request); |
| 589 | return; |
| 590 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 591 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | try { |
| 593 | request.result = phone != null |
| 594 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 595 | } catch (CallStateException cse) { |
| 596 | request.result = false; |
| 597 | } |
| 598 | // Wake up the requesting thread |
| 599 | notifyRequester(request); |
| 600 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 603 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 604 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 605 | final Phone phone = getPhoneFromRequest(request); |
| 606 | request.result = phone != null ? |
| 607 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 608 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 609 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 611 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 613 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 614 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 616 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 617 | uiccPort = getUiccPortFromRequest(request); |
| 618 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 619 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 620 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 622 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 624 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 625 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 626 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 627 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 628 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | break; |
| 631 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | ar = (AsyncResult) msg.obj; |
| 634 | request = (MainThreadRequest) ar.userObj; |
| 635 | if (ar.exception == null && ar.result != null) { |
| 636 | request.result = ar.result; |
| 637 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 638 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | if (ar.result == null) { |
| 640 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 641 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 642 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 643 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | } else { |
| 645 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 646 | } |
| 647 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 652 | request = (MainThreadRequest) msg.obj; |
| 653 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 654 | uiccPort = getUiccPortFromRequest(request); |
| 655 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 657 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 658 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | } else { |
| 660 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 661 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 662 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 663 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 664 | iccArgument.p2, |
| 665 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | } |
| 667 | break; |
| 668 | |
| 669 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 670 | ar = (AsyncResult) msg.obj; |
| 671 | request = (MainThreadRequest) ar.userObj; |
| 672 | if (ar.exception == null && ar.result != null) { |
| 673 | request.result = ar.result; |
| 674 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 675 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | if (ar.result == null) { |
| 677 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 678 | } else if (ar.exception instanceof CommandException) { |
| 679 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 680 | ar.exception); |
| 681 | } else { |
| 682 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 683 | } |
| 684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case CMD_EXCHANGE_SIM_IO: |
| 689 | request = (MainThreadRequest) msg.obj; |
| 690 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 691 | uiccPort = getUiccPortFromRequest(request); |
| 692 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 693 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 694 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 695 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 696 | } else { |
| 697 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 698 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 699 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 700 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 701 | iccArgument.data, onCompleted); |
| 702 | } |
| 703 | break; |
| 704 | |
| 705 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 706 | ar = (AsyncResult) msg.obj; |
| 707 | request = (MainThreadRequest) ar.userObj; |
| 708 | if (ar.exception == null && ar.result != null) { |
| 709 | request.result = ar.result; |
| 710 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 711 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 712 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 713 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 716 | case CMD_SEND_ENVELOPE: |
| 717 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 718 | uiccPort = getUiccPortFromRequest(request); |
| 719 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 720 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 721 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 722 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | } else { |
| 724 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 725 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 726 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case EVENT_SEND_ENVELOPE_DONE: |
| 730 | ar = (AsyncResult) msg.obj; |
| 731 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 732 | if (ar.exception == null && ar.result != null) { |
| 733 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 734 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 735 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 736 | if (ar.result == null) { |
| 737 | loge("sendEnvelopeWithStatus: Empty response"); |
| 738 | } else if (ar.exception instanceof CommandException) { |
| 739 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 740 | ar.exception); |
| 741 | } else { |
| 742 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 743 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 744 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 745 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 748 | case CMD_OPEN_CHANNEL: |
| 749 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 750 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 751 | IccLogicalChannelRequest openChannelRequest = |
| 752 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 753 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 754 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 755 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 756 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 758 | } else { |
| 759 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 760 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 761 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 762 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | break; |
| 764 | |
| 765 | case EVENT_OPEN_CHANNEL_DONE: |
| 766 | ar = (AsyncResult) msg.obj; |
| 767 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 768 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 770 | int[] result = (int[]) ar.result; |
| 771 | int channelId = result[0]; |
| 772 | byte[] selectResponse = null; |
| 773 | if (result.length > 1) { |
| 774 | selectResponse = new byte[result.length - 1]; |
| 775 | for (int i = 1; i < result.length; ++i) { |
| 776 | selectResponse[i - 1] = (byte) result[i]; |
| 777 | } |
| 778 | } |
| 779 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 780 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 781 | |
| 782 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 783 | if (uiccPort == null) { |
| 784 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 785 | } else { |
| 786 | IccLogicalChannelRequest channelRequest = |
| 787 | (IccLogicalChannelRequest) request.argument; |
| 788 | channelRequest.channel = channelId; |
| 789 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 790 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 791 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | if (ar.result == null) { |
| 793 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 794 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 795 | if (ar.exception != null) { |
| 796 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 797 | } |
| 798 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 799 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 800 | if (ar.exception instanceof CommandException) { |
| 801 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 802 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 803 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 804 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 805 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 806 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 810 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 811 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 812 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 813 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case CMD_CLOSE_CHANNEL: |
| 817 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 818 | uiccPort = getUiccPortFromRequest(request); |
| 819 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 820 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 821 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 822 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 823 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 824 | } else { |
| 825 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 826 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 827 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 831 | ar = (AsyncResult) msg.obj; |
| 832 | request = (MainThreadRequest) ar.userObj; |
| 833 | if (ar.exception == null) { |
| 834 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 835 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 836 | if (uiccPort == null) { |
| 837 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 838 | } else { |
| 839 | final int channelId = (Integer) request.argument; |
| 840 | uiccPort.onLogicalChannelClosed(channelId); |
| 841 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 842 | } else { |
| 843 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 844 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 845 | if (ar.exception instanceof CommandException) { |
| 846 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 847 | CommandException.Error error = |
| 848 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 849 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 850 | // should only throw exceptions from the binder threads. |
| 851 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 852 | "iccCloseLogicalChannel: invalid argument "); |
| 853 | } |
| 854 | } else { |
| 855 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 856 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 857 | request.result = (exception != null) ? exception : |
| 858 | new IllegalStateException( |
| 859 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 860 | } |
| 861 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case CMD_NV_READ_ITEM: |
| 865 | request = (MainThreadRequest) msg.obj; |
| 866 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 867 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 868 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 869 | break; |
| 870 | |
| 871 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 872 | ar = (AsyncResult) msg.obj; |
| 873 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 874 | if (ar.exception == null && ar.result != null) { |
| 875 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 876 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 877 | request.result = ""; |
| 878 | if (ar.result == null) { |
| 879 | loge("nvReadItem: Empty response"); |
| 880 | } else if (ar.exception instanceof CommandException) { |
| 881 | loge("nvReadItem: CommandException: " + |
| 882 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 883 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 884 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 887 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 888 | break; |
| 889 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | case CMD_NV_WRITE_ITEM: |
| 891 | request = (MainThreadRequest) msg.obj; |
| 892 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 893 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 894 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 895 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case EVENT_NV_WRITE_ITEM_DONE: |
| 899 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 900 | break; |
| 901 | |
| 902 | case CMD_NV_WRITE_CDMA_PRL: |
| 903 | request = (MainThreadRequest) msg.obj; |
| 904 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 905 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 909 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 910 | break; |
| 911 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 912 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 913 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 914 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 916 | break; |
| 917 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 918 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 919 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 920 | break; |
| 921 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 922 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 925 | request); |
| 926 | Phone phone = getPhoneFromRequest(request); |
| 927 | if (phone != null) { |
| 928 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 929 | } else { |
| 930 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 931 | request.result = false; |
| 932 | notifyRequester(request); |
| 933 | } |
| 934 | break; |
| 935 | } |
| 936 | |
| 937 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 938 | ar = (AsyncResult) msg.obj; |
| 939 | request = (MainThreadRequest) ar.userObj; |
| 940 | if (ar.exception == null && ar.result != null) { |
| 941 | request.result = ar.result; |
| 942 | } else { |
| 943 | // request.result must be set to something non-null |
| 944 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 945 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | request.result = false; |
| 949 | } |
| 950 | if (ar.result == null) { |
| 951 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 952 | } else if (ar.exception instanceof CommandException) { |
| 953 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 954 | + ar.exception); |
| 955 | } else { |
| 956 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 957 | } |
| 958 | } |
| 959 | notifyRequester(request); |
| 960 | break; |
| 961 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 962 | case CMD_IS_VONR_ENABLED: { |
| 963 | request = (MainThreadRequest) msg.obj; |
| 964 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 965 | request); |
| 966 | Phone phone = getPhoneFromRequest(request); |
| 967 | if (phone != null) { |
| 968 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 969 | } else { |
| 970 | loge("isVoNrEnabled: No phone object"); |
| 971 | request.result = false; |
| 972 | notifyRequester(request); |
| 973 | } |
| 974 | break; |
| 975 | } |
| 976 | |
| 977 | case EVENT_IS_VONR_ENABLED_DONE: |
| 978 | ar = (AsyncResult) msg.obj; |
| 979 | request = (MainThreadRequest) ar.userObj; |
| 980 | if (ar.exception == null && ar.result != null) { |
| 981 | request.result = ar.result; |
| 982 | } else { |
| 983 | // request.result must be set to something non-null |
| 984 | // for the calling thread to unblock |
| 985 | if (ar.result != null) { |
| 986 | request.result = ar.result; |
| 987 | } else { |
| 988 | request.result = false; |
| 989 | } |
| 990 | if (ar.result == null) { |
| 991 | loge("isVoNrEnabled: Empty response"); |
| 992 | } else if (ar.exception instanceof CommandException) { |
| 993 | loge("isVoNrEnabled: CommandException: " |
| 994 | + ar.exception); |
| 995 | } else { |
| 996 | loge("isVoNrEnabled: Unknown exception"); |
| 997 | } |
| 998 | } |
| 999 | notifyRequester(request); |
| 1000 | break; |
| 1001 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1002 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1003 | request = (MainThreadRequest) msg.obj; |
| 1004 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1005 | Phone phone = getPhoneFromRequest(request); |
| 1006 | if (phone != null) { |
| 1007 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1008 | request.workSource); |
| 1009 | } else { |
| 1010 | loge("enableNrDualConnectivity: No phone object"); |
| 1011 | request.result = |
| 1012 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1013 | notifyRequester(request); |
| 1014 | } |
| 1015 | break; |
| 1016 | } |
| 1017 | |
| 1018 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1019 | ar = (AsyncResult) msg.obj; |
| 1020 | request = (MainThreadRequest) ar.userObj; |
| 1021 | if (ar.exception == null) { |
| 1022 | request.result = |
| 1023 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1024 | } else { |
| 1025 | request.result = |
| 1026 | TelephonyManager |
| 1027 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1028 | if (ar.exception instanceof CommandException) { |
| 1029 | CommandException.Error error = |
| 1030 | ((CommandException) (ar.exception)).getCommandError(); |
| 1031 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1032 | request.result = |
| 1033 | TelephonyManager |
| 1034 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1035 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1036 | request.result = |
| 1037 | TelephonyManager |
| 1038 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1039 | } |
| 1040 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1041 | + ar.exception); |
| 1042 | } else { |
| 1043 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1044 | } |
| 1045 | } |
| 1046 | notifyRequester(request); |
| 1047 | break; |
| 1048 | } |
| 1049 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1050 | case CMD_ENABLE_VONR: { |
| 1051 | request = (MainThreadRequest) msg.obj; |
| 1052 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1053 | Phone phone = getPhoneFromRequest(request); |
| 1054 | if (phone != null) { |
| 1055 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1056 | request.workSource); |
| 1057 | } else { |
| 1058 | loge("setVoNrEnabled: No phone object"); |
| 1059 | request.result = |
| 1060 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1061 | notifyRequester(request); |
| 1062 | } |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | case EVENT_ENABLE_VONR_DONE: { |
| 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
| 1069 | if (ar.exception == null) { |
| 1070 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1071 | } else { |
| 1072 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1073 | if (ar.exception instanceof CommandException) { |
| 1074 | CommandException.Error error = |
| 1075 | ((CommandException) (ar.exception)).getCommandError(); |
| 1076 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1077 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1078 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1079 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1080 | } else { |
| 1081 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1082 | } |
| 1083 | loge("setVoNrEnabled" + ": CommandException: " |
| 1084 | + ar.exception); |
| 1085 | } else { |
| 1086 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1087 | } |
| 1088 | } |
| 1089 | notifyRequester(request); |
| 1090 | break; |
| 1091 | } |
| 1092 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1093 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1094 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1095 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1096 | request); |
| 1097 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1098 | break; |
| 1099 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1100 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1101 | ar = (AsyncResult) msg.obj; |
| 1102 | request = (MainThreadRequest) ar.userObj; |
| 1103 | if (ar.exception == null && ar.result != null) { |
| 1104 | request.result = ar.result; // Integer |
| 1105 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1106 | // request.result must be set to something non-null |
| 1107 | // for the calling thread to unblock |
| 1108 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1109 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1110 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1111 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1112 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1113 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1114 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1115 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | } |
| 1117 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1118 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | break; |
| 1120 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1121 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1122 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1123 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1124 | request); |
| 1125 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1126 | (Pair<Integer, Long>) request.argument; |
| 1127 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1128 | reasonWithNetworkTypes.first, |
| 1129 | reasonWithNetworkTypes.second, |
| 1130 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1131 | break; |
| 1132 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1134 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1135 | break; |
| 1136 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1137 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1138 | request = (MainThreadRequest)msg.obj; |
| 1139 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1140 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1141 | break; |
| 1142 | |
| 1143 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1144 | ar = (AsyncResult)msg.obj; |
| 1145 | request = (MainThreadRequest)ar.userObj; |
| 1146 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1147 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1148 | break; |
| 1149 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1150 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1151 | request = (MainThreadRequest) msg.obj; |
| 1152 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1153 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1154 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1155 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1156 | break; |
| 1157 | |
| 1158 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1159 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1160 | break; |
| 1161 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1162 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1163 | request = (MainThreadRequest) msg.obj; |
| 1164 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1165 | request); |
| 1166 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1167 | break; |
| 1168 | |
| 1169 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1170 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1171 | break; |
| 1172 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1173 | case CMD_PERFORM_NETWORK_SCAN: |
| 1174 | request = (MainThreadRequest) msg.obj; |
| 1175 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1176 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1177 | break; |
| 1178 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1179 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1180 | request = (MainThreadRequest) msg.obj; |
| 1181 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1182 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1183 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1184 | request.argument; |
| 1185 | int callForwardingReason = args.first; |
| 1186 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | } |
| 1189 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | ar = (AsyncResult) msg.obj; |
| 1191 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1192 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1193 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1194 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1195 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1196 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1198 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1199 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1200 | // any service for voice call. |
| 1201 | if ((callForwardInfo.serviceClass |
| 1202 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1203 | callForwardingInfo = new CallForwardingInfo( |
| 1204 | callForwardInfo.status |
| 1205 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | callForwardInfo.reason, |
| 1207 | callForwardInfo.number, |
| 1208 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | // Didn't find a call forward info for voice call. |
| 1213 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1215 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | } else { |
| 1219 | if (ar.result == null) { |
| 1220 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1221 | } |
| 1222 | if (ar.exception != null) { |
| 1223 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1224 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1225 | int errorCode = TelephonyManager |
| 1226 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1227 | if (ar.exception instanceof CommandException) { |
| 1228 | CommandException.Error error = |
| 1229 | ((CommandException) (ar.exception)).getCommandError(); |
| 1230 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1231 | errorCode = TelephonyManager |
| 1232 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1234 | errorCode = TelephonyManager |
| 1235 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | } |
| 1237 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1240 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1242 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1244 | request = (MainThreadRequest) msg.obj; |
| 1245 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1247 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1249 | request.argument).first; |
| 1250 | request.phone.setCallForwardingOption( |
| 1251 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1252 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | callForwardingInfoToSet.getReason(), |
| 1255 | callForwardingInfoToSet.getNumber(), |
| 1256 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | Consumer<Integer> callback = |
| 1264 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1265 | request.argument).second; |
| 1266 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1268 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1269 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | if (ar.exception instanceof CommandException) { |
| 1271 | CommandException.Error error = |
| 1272 | ((CommandException) (ar.exception)).getCommandError(); |
| 1273 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1274 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1275 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1277 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1278 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | callback.accept(errorCode); |
| 1282 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1283 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1285 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1287 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | request = (MainThreadRequest) msg.obj; |
| 1290 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1291 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1292 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1295 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | ar = (AsyncResult) msg.obj; |
| 1297 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1299 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1301 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | // Service Class is a bit mask per 3gpp 27.007. |
| 1303 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1304 | if (callForwardResults.length > 1 |
| 1305 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1307 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1308 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1309 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1311 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | } |
| 1313 | } else { |
| 1314 | if (ar.result == null) { |
| 1315 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1316 | } |
| 1317 | if (ar.exception != null) { |
| 1318 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1319 | } |
| 1320 | if (ar.exception instanceof CommandException) { |
| 1321 | CommandException.Error error = |
| 1322 | ((CommandException) (ar.exception)).getCommandError(); |
| 1323 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1324 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1326 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1327 | callWaitingStatus = |
| 1328 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | } |
| 1330 | } |
| 1331 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1332 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1336 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | request = (MainThreadRequest) msg.obj; |
| 1338 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1340 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
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 EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1345 | ar = (AsyncResult) msg.obj; |
| 1346 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1348 | Consumer<Integer> callback = |
| 1349 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1350 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | if (ar.exception instanceof CommandException) { |
| 1353 | CommandException.Error error = |
| 1354 | ((CommandException) (ar.exception)).getCommandError(); |
| 1355 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1356 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1357 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1358 | callback.accept( |
| 1359 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1360 | } else { |
| 1361 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1362 | } |
| 1363 | } else { |
| 1364 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1365 | } |
| 1366 | } else { |
| 1367 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1368 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1369 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1370 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1371 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1372 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1373 | ar = (AsyncResult) msg.obj; |
| 1374 | request = (MainThreadRequest) ar.userObj; |
| 1375 | CellNetworkScanResult cellScanResult; |
| 1376 | if (ar.exception == null && ar.result != null) { |
| 1377 | cellScanResult = new CellNetworkScanResult( |
| 1378 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1379 | (List<OperatorInfo>) ar.result); |
| 1380 | } else { |
| 1381 | if (ar.result == null) { |
| 1382 | loge("getCellNetworkScanResults: Empty response"); |
| 1383 | } |
| 1384 | if (ar.exception != null) { |
| 1385 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1386 | } |
| 1387 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1388 | if (ar.exception instanceof CommandException) { |
| 1389 | CommandException.Error error = |
| 1390 | ((CommandException) (ar.exception)).getCommandError(); |
| 1391 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1392 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1393 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1394 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1395 | } |
| 1396 | } |
| 1397 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1398 | } |
| 1399 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1400 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1401 | break; |
| 1402 | |
| 1403 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1404 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1405 | ManualNetworkSelectionArgument selArg = |
| 1406 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1407 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1408 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1409 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1410 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | |
| 1413 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1414 | ar = (AsyncResult) msg.obj; |
| 1415 | request = (MainThreadRequest) ar.userObj; |
| 1416 | if (ar.exception == null) { |
| 1417 | request.result = true; |
| 1418 | } else { |
| 1419 | request.result = false; |
| 1420 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1421 | } |
| 1422 | notifyRequester(request); |
| 1423 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1424 | break; |
| 1425 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1426 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1427 | request = (MainThreadRequest) msg.obj; |
| 1428 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1429 | if (defaultPhone != null) { |
| 1430 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1431 | } else { |
| 1432 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1433 | Bundle bundle = new Bundle(); |
| 1434 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1435 | new ModemActivityInfo(0, 0, 0, |
| 1436 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1437 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1438 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1439 | break; |
| 1440 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1441 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1442 | ar = (AsyncResult) msg.obj; |
| 1443 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1444 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1445 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1446 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1447 | if (mLastModemActivityInfo == null) { |
| 1448 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1449 | mLastModemActivitySpecificInfo[0] = |
| 1450 | new ActivityStatsTechSpecificInfo( |
| 1451 | 0, |
| 1452 | 0, |
| 1453 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1454 | 0); |
| 1455 | mLastModemActivityInfo = |
| 1456 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1457 | } |
| 1458 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1459 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1460 | // Update the last modem activity info and the result of the request. |
| 1461 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1462 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1463 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1464 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1465 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1466 | // We don't want to return mLastModemActivityInfo which is updated |
| 1467 | // inside mergeModemActivityInfo() |
| 1468 | ret = new ModemActivityInfo( |
| 1469 | mLastModemActivityInfo.getTimestampMillis(), |
| 1470 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1471 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1472 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1473 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1474 | } else { |
| 1475 | if (ar.result == null) { |
| 1476 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1477 | error = TelephonyManager.ModemActivityInfoException |
| 1478 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1480 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1481 | error = TelephonyManager.ModemActivityInfoException |
| 1482 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1483 | } else { |
| 1484 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1485 | error = TelephonyManager.ModemActivityInfoException |
| 1486 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1487 | } |
| 1488 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1489 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1490 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1491 | bundle.putParcelable( |
| 1492 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1493 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1494 | } else { |
| 1495 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1496 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1497 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1498 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1499 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1500 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1501 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1502 | case CMD_SET_ALLOWED_CARRIERS: |
| 1503 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1504 | CarrierRestrictionRules argument = |
| 1505 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1506 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1507 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1508 | break; |
| 1509 | |
| 1510 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1511 | ar = (AsyncResult) msg.obj; |
| 1512 | request = (MainThreadRequest) ar.userObj; |
| 1513 | if (ar.exception == null && ar.result != null) { |
| 1514 | request.result = ar.result; |
| 1515 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1516 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1517 | if (ar.exception instanceof CommandException) { |
| 1518 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1519 | CommandException.Error error = |
| 1520 | ((CommandException) (ar.exception)).getCommandError(); |
| 1521 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1522 | request.result = |
| 1523 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1524 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1525 | } else { |
| 1526 | loge("setAllowedCarriers: Unknown exception"); |
| 1527 | } |
| 1528 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1529 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1530 | break; |
| 1531 | |
| 1532 | case CMD_GET_ALLOWED_CARRIERS: |
| 1533 | request = (MainThreadRequest) msg.obj; |
| 1534 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1535 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1536 | break; |
| 1537 | |
| 1538 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1539 | ar = (AsyncResult) msg.obj; |
| 1540 | request = (MainThreadRequest) ar.userObj; |
| 1541 | if (ar.exception == null && ar.result != null) { |
| 1542 | request.result = ar.result; |
| 1543 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1544 | request.result = new IllegalStateException( |
| 1545 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1546 | if (ar.result == null) { |
| 1547 | loge("getAllowedCarriers: Empty response"); |
| 1548 | } else if (ar.exception instanceof CommandException) { |
| 1549 | loge("getAllowedCarriers: CommandException: " + |
| 1550 | ar.exception); |
| 1551 | } else { |
| 1552 | loge("getAllowedCarriers: Unknown exception"); |
| 1553 | } |
| 1554 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1555 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1556 | break; |
| 1557 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1558 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1559 | ar = (AsyncResult) msg.obj; |
| 1560 | request = (MainThreadRequest) ar.userObj; |
| 1561 | if (ar.exception == null && ar.result != null) { |
| 1562 | request.result = ar.result; |
| 1563 | } else { |
| 1564 | request.result = new IllegalArgumentException( |
| 1565 | "Failed to retrieve Forbidden Plmns"); |
| 1566 | if (ar.result == null) { |
| 1567 | loge("getForbiddenPlmns: Empty response"); |
| 1568 | } else { |
| 1569 | loge("getForbiddenPlmns: Unknown exception"); |
| 1570 | } |
| 1571 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1572 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1573 | break; |
| 1574 | |
| 1575 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1576 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1577 | uiccPort = getUiccPortFromRequest(request); |
| 1578 | if (uiccPort == null) { |
| 1579 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1580 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1581 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1582 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1583 | break; |
| 1584 | } |
| 1585 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1586 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1587 | if (uiccApp == null) { |
| 1588 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1589 | + appType); |
| 1590 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1591 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1592 | break; |
| 1593 | } else { |
| 1594 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1595 | + " specified type -- " + appType); |
| 1596 | } |
| 1597 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1598 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1599 | onCompleted); |
| 1600 | break; |
| 1601 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1602 | case CMD_SWITCH_SLOTS: |
| 1603 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1604 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1605 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1606 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1607 | break; |
| 1608 | |
| 1609 | case EVENT_SWITCH_SLOTS_DONE: |
| 1610 | ar = (AsyncResult) msg.obj; |
| 1611 | request = (MainThreadRequest) ar.userObj; |
| 1612 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1613 | notifyRequester(request); |
| 1614 | break; |
| 1615 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1616 | request = (MainThreadRequest) msg.obj; |
| 1617 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1618 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1619 | break; |
| 1620 | |
| 1621 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | if (ar.exception != null) { |
| 1625 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1626 | } else { |
| 1627 | int mode = ((int[]) ar.result)[0]; |
| 1628 | if (mode == 0) { |
| 1629 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1630 | } else { |
| 1631 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1632 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1633 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1634 | notifyRequester(request); |
| 1635 | break; |
| 1636 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1637 | request = (MainThreadRequest) msg.obj; |
| 1638 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1639 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1640 | break; |
| 1641 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1642 | ar = (AsyncResult) msg.obj; |
| 1643 | request = (MainThreadRequest) ar.userObj; |
| 1644 | if (ar.exception != null) { |
| 1645 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1646 | } else { |
| 1647 | request.result = ((int[]) ar.result)[0]; |
| 1648 | } |
| 1649 | notifyRequester(request); |
| 1650 | break; |
| 1651 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1652 | request = (MainThreadRequest) msg.obj; |
| 1653 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1654 | int mode = (int) request.argument; |
| 1655 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1656 | break; |
| 1657 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1658 | ar = (AsyncResult) msg.obj; |
| 1659 | request = (MainThreadRequest) ar.userObj; |
| 1660 | request.result = ar.exception == null; |
| 1661 | notifyRequester(request); |
| 1662 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1663 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1664 | request = (MainThreadRequest) msg.obj; |
| 1665 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1666 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1667 | break; |
| 1668 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1669 | ar = (AsyncResult) msg.obj; |
| 1670 | request = (MainThreadRequest) ar.userObj; |
| 1671 | if (ar.exception != null) { |
| 1672 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1673 | } else { |
| 1674 | request.result = ((int[]) ar.result)[0]; |
| 1675 | } |
| 1676 | notifyRequester(request); |
| 1677 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1678 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1679 | request = (MainThreadRequest) msg.obj; |
| 1680 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1681 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1682 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1683 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1684 | break; |
| 1685 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1686 | ar = (AsyncResult) msg.obj; |
| 1687 | request = (MainThreadRequest) ar.userObj; |
| 1688 | request.result = ar.exception == null; |
| 1689 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1690 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1691 | case CMD_GET_ALL_CELL_INFO: |
| 1692 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1693 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1694 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1695 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1696 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1697 | ar = (AsyncResult) msg.obj; |
| 1698 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1699 | // If a timeout occurs, the response will be null |
| 1700 | request.result = (ar.exception == null && ar.result != null) |
| 1701 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1702 | synchronized (request) { |
| 1703 | request.notifyAll(); |
| 1704 | } |
| 1705 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1706 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1707 | request = (MainThreadRequest) msg.obj; |
| 1708 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1709 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1710 | break; |
| 1711 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1712 | ar = (AsyncResult) msg.obj; |
| 1713 | request = (MainThreadRequest) ar.userObj; |
| 1714 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1715 | try { |
| 1716 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1717 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1718 | cb.onError( |
| 1719 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1720 | ar.exception.getClass().getName(), |
| 1721 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1722 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1723 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1724 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1725 | } else { |
| 1726 | // use the result as returned |
| 1727 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1728 | } |
| 1729 | } catch (RemoteException re) { |
| 1730 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1731 | } |
| 1732 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1733 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1734 | request = (MainThreadRequest) msg.obj; |
| 1735 | WorkSource ws = (WorkSource) request.argument; |
| 1736 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1737 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1738 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1739 | } |
| 1740 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1741 | ar = (AsyncResult) msg.obj; |
| 1742 | request = (MainThreadRequest) ar.userObj; |
| 1743 | if (ar.exception == null) { |
| 1744 | request.result = ar.result; |
| 1745 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1746 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1748 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | synchronized (request) { |
| 1752 | request.notifyAll(); |
| 1753 | } |
| 1754 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1755 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1756 | case CMD_MODEM_REBOOT: |
| 1757 | request = (MainThreadRequest) msg.obj; |
| 1758 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1759 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1760 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1761 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1762 | handleNullReturnEvent(msg, "rebootModem"); |
| 1763 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1764 | case CMD_REQUEST_ENABLE_MODEM: |
| 1765 | request = (MainThreadRequest) msg.obj; |
| 1766 | boolean enable = (boolean) request.argument; |
| 1767 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1768 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1769 | PhoneConfigurationManager.getInstance() |
| 1770 | .enablePhone(request.phone, enable, onCompleted); |
| 1771 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1772 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1773 | ar = (AsyncResult) msg.obj; |
| 1774 | request = (MainThreadRequest) ar.userObj; |
| 1775 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1776 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1777 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1778 | if ((boolean) request.result) { |
| 1779 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1780 | updateModemStateMetrics(); |
| 1781 | } else { |
| 1782 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1783 | + ar.exception); |
| 1784 | } |
| 1785 | notifyRequester(request); |
| 1786 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1787 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1788 | case CMD_GET_MODEM_STATUS: |
| 1789 | request = (MainThreadRequest) msg.obj; |
| 1790 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1791 | PhoneConfigurationManager.getInstance() |
| 1792 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1793 | break; |
| 1794 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1795 | ar = (AsyncResult) msg.obj; |
| 1796 | request = (MainThreadRequest) ar.userObj; |
| 1797 | int id = request.phone.getPhoneId(); |
| 1798 | if (ar.exception == null && ar.result != null) { |
| 1799 | request.result = ar.result; |
| 1800 | //update the cache as modem status has changed |
| 1801 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1802 | (boolean) request.result); |
| 1803 | } else { |
| 1804 | // Return true if modem status cannot be retrieved. For most cases, |
| 1805 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1806 | // and disable modem are not supported. Modem is always on. |
| 1807 | // TODO: this should be fixed in R to support a third |
| 1808 | // status UNKNOWN b/131631629 |
| 1809 | request.result = true; |
| 1810 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1811 | + ar.exception); |
| 1812 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1813 | notifyRequester(request); |
| 1814 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1815 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1816 | request = (MainThreadRequest) msg.obj; |
| 1817 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1818 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1819 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1820 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1821 | break; |
| 1822 | } |
| 1823 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1824 | ar = (AsyncResult) msg.obj; |
| 1825 | request = (MainThreadRequest) ar.userObj; |
| 1826 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1827 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1828 | args.second.accept(ar.exception == null); |
| 1829 | notifyRequester(request); |
| 1830 | break; |
| 1831 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1832 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1833 | request = (MainThreadRequest) msg.obj; |
| 1834 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1835 | Phone phone = getPhoneFromRequest(request); |
| 1836 | if (phone != null) { |
| 1837 | phone.getSystemSelectionChannels(onCompleted); |
| 1838 | } else { |
| 1839 | loge("getSystemSelectionChannels: No phone object"); |
| 1840 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1841 | notifyRequester(request); |
| 1842 | } |
| 1843 | break; |
| 1844 | } |
| 1845 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1846 | ar = (AsyncResult) msg.obj; |
| 1847 | request = (MainThreadRequest) ar.userObj; |
| 1848 | if (ar.exception == null && ar.result != null) { |
| 1849 | request.result = ar.result; |
| 1850 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1851 | request.result = new IllegalStateException( |
| 1852 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1853 | if (ar.result == null) { |
| 1854 | loge("getSystemSelectionChannels: Empty response"); |
| 1855 | } else { |
| 1856 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1857 | } |
| 1858 | } |
| 1859 | notifyRequester(request); |
| 1860 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1861 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1862 | ar = (AsyncResult) msg.obj; |
| 1863 | request = (MainThreadRequest) ar.userObj; |
| 1864 | if (ar.exception == null && ar.result != null) { |
| 1865 | request.result = ar.result; |
| 1866 | } else { |
| 1867 | request.result = -1; |
| 1868 | loge("Failed to set Forbidden Plmns"); |
| 1869 | if (ar.result == null) { |
| 1870 | loge("setForbidenPlmns: Empty response"); |
| 1871 | } else if (ar.exception != null) { |
| 1872 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1873 | request.result = -1; |
| 1874 | } else { |
| 1875 | loge("setForbiddenPlmns: Unknown exception"); |
| 1876 | } |
| 1877 | } |
| 1878 | notifyRequester(request); |
| 1879 | break; |
| 1880 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1881 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1882 | uiccPort = getUiccPortFromRequest(request); |
| 1883 | if (uiccPort == null) { |
| 1884 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1885 | request.result = -1; |
| 1886 | notifyRequester(request); |
| 1887 | break; |
| 1888 | } |
| 1889 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1890 | (Pair<Integer, List<String>>) request.argument; |
| 1891 | appType = setFplmnsArgs.first; |
| 1892 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1893 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1894 | if (uiccApp == null) { |
| 1895 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1896 | request.result = -1; |
| 1897 | loge("Failed to get UICC App"); |
| 1898 | notifyRequester(request); |
| 1899 | } else { |
| 1900 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1901 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1902 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1903 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1904 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1905 | case CMD_ERASE_MODEM_CONFIG: |
| 1906 | request = (MainThreadRequest) msg.obj; |
| 1907 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1908 | defaultPhone.eraseModemConfig(onCompleted); |
| 1909 | break; |
| 1910 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1911 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1912 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1913 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1914 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1915 | request = (MainThreadRequest) msg.obj; |
| 1916 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1917 | notifyRequester(request); |
| 1918 | break; |
| 1919 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1920 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1921 | request = (MainThreadRequest) msg.obj; |
| 1922 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1923 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1924 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1925 | changed.first, changed.second, onCompleted); |
| 1926 | break; |
| 1927 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1928 | ar = (AsyncResult) msg.obj; |
| 1929 | request = (MainThreadRequest) ar.userObj; |
| 1930 | if (ar.exception == null) { |
| 1931 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1932 | // If the operation is successful, update the PIN storage |
| 1933 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1934 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1935 | UiccController.getInstance().getPinStorage() |
| 1936 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1937 | } else { |
| 1938 | request.result = msg.arg1; |
| 1939 | } |
| 1940 | notifyRequester(request); |
| 1941 | break; |
| 1942 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1943 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1944 | request = (MainThreadRequest) msg.obj; |
| 1945 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1946 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1947 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1948 | enabled.first, enabled.second, onCompleted); |
| 1949 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1950 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1951 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1952 | ar = (AsyncResult) msg.obj; |
| 1953 | request = (MainThreadRequest) ar.userObj; |
| 1954 | if (ar.exception == null) { |
| 1955 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1956 | // If the operation is successful, update the PIN storage |
| 1957 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1958 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1959 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1960 | UiccController.getInstance().getPinStorage() |
| 1961 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1962 | } else { |
| 1963 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1964 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1965 | } else { |
| 1966 | request.result = msg.arg1; |
| 1967 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1968 | |
| 1969 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 | notifyRequester(request); |
| 1971 | break; |
| 1972 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1973 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1974 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1975 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1976 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1977 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1978 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1979 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1980 | |
| 1981 | case CMD_SET_DATA_THROTTLING: { |
| 1982 | request = (MainThreadRequest) msg.obj; |
| 1983 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1984 | DataThrottlingRequest dataThrottlingRequest = |
| 1985 | (DataThrottlingRequest) request.argument; |
| 1986 | Phone phone = getPhoneFromRequest(request); |
| 1987 | if (phone != null) { |
| 1988 | phone.setDataThrottling(onCompleted, |
| 1989 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1990 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1991 | } else { |
| 1992 | loge("setDataThrottling: No phone object"); |
| 1993 | request.result = |
| 1994 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1995 | notifyRequester(request); |
| 1996 | } |
| 1997 | |
| 1998 | break; |
| 1999 | } |
| 2000 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2001 | ar = (AsyncResult) msg.obj; |
| 2002 | request = (MainThreadRequest) ar.userObj; |
| 2003 | |
| 2004 | if (ar.exception == null) { |
| 2005 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2006 | } else if (ar.exception instanceof CommandException) { |
| 2007 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2008 | CommandException.Error error = |
| 2009 | ((CommandException) (ar.exception)).getCommandError(); |
| 2010 | |
| 2011 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2012 | request.result = TelephonyManager |
| 2013 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2014 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2015 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2016 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2017 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2018 | } else { |
| 2019 | request.result = |
| 2020 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2021 | } |
| 2022 | } else { |
| 2023 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2024 | } |
| 2025 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2026 | notifyRequester(request); |
| 2027 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2028 | |
| 2029 | case CMD_SET_SIM_POWER: { |
| 2030 | request = (MainThreadRequest) msg.obj; |
| 2031 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2032 | request = (MainThreadRequest) msg.obj; |
| 2033 | int stateToSet = |
| 2034 | ((Pair<Integer, IIntegerConsumer>) |
| 2035 | request.argument).first; |
| 2036 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2037 | break; |
| 2038 | } |
| 2039 | case EVENT_SET_SIM_POWER_DONE: { |
| 2040 | ar = (AsyncResult) msg.obj; |
| 2041 | request = (MainThreadRequest) ar.userObj; |
| 2042 | IIntegerConsumer callback = |
| 2043 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2044 | if (ar.exception != null) { |
| 2045 | loge("setSimPower exception: " + ar.exception); |
| 2046 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2047 | .RESULT_ERROR_UNKNOWN; |
| 2048 | if (ar.exception instanceof CommandException) { |
| 2049 | CommandException.Error error = |
| 2050 | ((CommandException) (ar.exception)).getCommandError(); |
| 2051 | if (error == CommandException.Error.SIM_ERR) { |
| 2052 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2053 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2054 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2055 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2056 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2057 | } else { |
| 2058 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2059 | } |
| 2060 | } |
| 2061 | try { |
| 2062 | callback.accept(errorCode); |
| 2063 | } catch (RemoteException e) { |
| 2064 | // Ignore if the remote process is no longer available to call back. |
| 2065 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2066 | } |
| 2067 | } else { |
| 2068 | try { |
| 2069 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2070 | } catch (RemoteException e) { |
| 2071 | // Ignore if the remote process is no longer available to call back. |
| 2072 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2073 | } |
| 2074 | } |
| 2075 | break; |
| 2076 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2077 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2078 | request = (MainThreadRequest) msg.obj; |
| 2079 | |
| 2080 | final Phone phone = getPhoneFromRequest(request); |
| 2081 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2082 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2083 | notifyRequester(request); |
| 2084 | break; |
| 2085 | } |
| 2086 | |
| 2087 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2088 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2089 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2090 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2091 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2092 | request.subId, pair.first /*callingUid*/, |
| 2093 | pair.second /*request*/, onCompleted); |
| 2094 | break; |
| 2095 | } |
| 2096 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2097 | ar = (AsyncResult) msg.obj; |
| 2098 | request = (MainThreadRequest) ar.userObj; |
| 2099 | // request.result will be the exception of ar if present, true otherwise. |
| 2100 | // Be cautious not to leave result null which will wait() forever |
| 2101 | request.result = ar.exception != null ? ar.exception : true; |
| 2102 | notifyRequester(request); |
| 2103 | break; |
| 2104 | } |
| 2105 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2106 | request = (MainThreadRequest) msg.obj; |
| 2107 | |
| 2108 | Phone phone = getPhoneFromRequest(request); |
| 2109 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2110 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2111 | notifyRequester(request); |
| 2112 | break; |
| 2113 | } |
| 2114 | |
| 2115 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2116 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2117 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2118 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2119 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2120 | request.subId, pair.first /*callingUid*/, |
| 2121 | pair.second /*request*/, onCompleted); |
| 2122 | break; |
| 2123 | } |
| 2124 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2125 | ar = (AsyncResult) msg.obj; |
| 2126 | request = (MainThreadRequest) ar.userObj; |
| 2127 | request.result = ar.exception != null ? ar.exception : true; |
| 2128 | notifyRequester(request); |
| 2129 | break; |
| 2130 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2131 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2132 | case CMD_GET_SLICING_CONFIG: { |
| 2133 | request = (MainThreadRequest) msg.obj; |
| 2134 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2135 | request.phone.getSlicingConfig(onCompleted); |
| 2136 | break; |
| 2137 | } |
| 2138 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2139 | ar = (AsyncResult) msg.obj; |
| 2140 | request = (MainThreadRequest) ar.userObj; |
| 2141 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2142 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2143 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2144 | Bundle bundle = new Bundle(); |
| 2145 | int resultCode = 0; |
| 2146 | if (ar.exception != null) { |
| 2147 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2148 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2149 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2150 | } else if (ar.result == null) { |
| 2151 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2152 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2153 | } else { |
| 2154 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2155 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2156 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2160 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2161 | } |
| 2162 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2163 | result.send(resultCode, bundle); |
| 2164 | notifyRequester(request); |
| 2165 | break; |
| 2166 | } |
| 2167 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2168 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2169 | request = (MainThreadRequest) msg.obj; |
| 2170 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2171 | PurchasePremiumCapabilityArgument arg = |
| 2172 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2173 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2174 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2175 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2176 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2177 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2178 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2179 | ar = (AsyncResult) msg.obj; |
| 2180 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2181 | PurchasePremiumCapabilityArgument arg = |
| 2182 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2183 | try { |
| 2184 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2185 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2186 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2187 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2188 | + ", result= " |
| 2189 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2190 | } catch (RemoteException e) { |
| 2191 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2192 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2193 | + " failed: " + e; |
| 2194 | if (DBG) log(logStr); |
| 2195 | AnomalyReporter.reportAnomaly( |
| 2196 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2197 | } |
| 2198 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2199 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2200 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2201 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2202 | request = (MainThreadRequest) msg.obj; |
| 2203 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2204 | UiccController.getInstance().getPinStorage() |
| 2205 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2206 | notifyRequester(request); |
| 2207 | break; |
| 2208 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2209 | default: |
| 2210 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2211 | break; |
| 2212 | } |
| 2213 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2214 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2215 | private void notifyRequester(MainThreadRequest request) { |
| 2216 | synchronized (request) { |
| 2217 | request.notifyAll(); |
| 2218 | } |
| 2219 | } |
| 2220 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2221 | private void handleNullReturnEvent(Message msg, String command) { |
| 2222 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2223 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2224 | if (ar.exception == null) { |
| 2225 | request.result = true; |
| 2226 | } else { |
| 2227 | request.result = false; |
| 2228 | if (ar.exception instanceof CommandException) { |
| 2229 | loge(command + ": CommandException: " + ar.exception); |
| 2230 | } else { |
| 2231 | loge(command + ": Unknown exception"); |
| 2232 | } |
| 2233 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2234 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2235 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /** |
| 2239 | * Posts the specified command to be executed on the main thread, |
| 2240 | * waits for the request to complete, and returns the result. |
| 2241 | * @see #sendRequestAsync |
| 2242 | */ |
| 2243 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2244 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2245 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | /** |
| 2249 | * Posts the specified command to be executed on the main thread, |
| 2250 | * waits for the request to complete, and returns the result. |
| 2251 | * @see #sendRequestAsync |
| 2252 | */ |
| 2253 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2254 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2255 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * Posts the specified command to be executed on the main thread, |
| 2260 | * waits for the request to complete, and returns the result. |
| 2261 | * @see #sendRequestAsync |
| 2262 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2263 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2264 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Posts the specified command to be executed on the main thread, |
| 2269 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2270 | * if not timeout or null otherwise. |
| 2271 | * @see #sendRequestAsync |
| 2272 | */ |
| 2273 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2274 | long timeoutInMs) { |
| 2275 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * Posts the specified command to be executed on the main thread, |
| 2280 | * waits for the request to complete, and returns the result. |
| 2281 | * @see #sendRequestAsync |
| 2282 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2283 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2284 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /** |
| 2288 | * Posts the specified command to be executed on the main thread, |
| 2289 | * waits for the request to complete, and returns the result. |
| 2290 | * @see #sendRequestAsync |
| 2291 | */ |
| 2292 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2293 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2294 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2298 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2299 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2300 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2301 | * @see #sendRequestAsync |
| 2302 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2303 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2304 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2305 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2306 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2307 | } |
| 2308 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2309 | MainThreadRequest request = null; |
| 2310 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2311 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2312 | } else if (phone != null) { |
| 2313 | request = new MainThreadRequest(argument, phone, workSource); |
| 2314 | } else { |
| 2315 | request = new MainThreadRequest(argument, subId, workSource); |
| 2316 | } |
| 2317 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2319 | msg.sendToTarget(); |
| 2320 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2321 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2323 | if (timeoutInMs >= 0) { |
| 2324 | // Wait for at least timeoutInMs before returning null request result |
| 2325 | long now = SystemClock.elapsedRealtime(); |
| 2326 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2327 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2328 | try { |
| 2329 | request.wait(deadline - now); |
| 2330 | } catch (InterruptedException e) { |
| 2331 | // Do nothing, go back and check if request is completed or timeout |
| 2332 | } finally { |
| 2333 | now = SystemClock.elapsedRealtime(); |
| 2334 | } |
| 2335 | } |
| 2336 | } else { |
| 2337 | // Wait for the request to complete |
| 2338 | while (request.result == null) { |
| 2339 | try { |
| 2340 | request.wait(); |
| 2341 | } catch (InterruptedException e) { |
| 2342 | // Do nothing, go back and wait until the request is complete |
| 2343 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2344 | } |
| 2345 | } |
| 2346 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2347 | if (request.result == null) { |
| 2348 | Log.wtf(LOG_TAG, |
| 2349 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | return request.result; |
| 2352 | } |
| 2353 | |
| 2354 | /** |
| 2355 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2356 | * Posts the specified command to be executed on the main thread, and |
| 2357 | * returns immediately. |
| 2358 | * @see #sendRequest |
| 2359 | */ |
| 2360 | private void sendRequestAsync(int command) { |
| 2361 | mMainThreadHandler.sendEmptyMessage(command); |
| 2362 | } |
| 2363 | |
| 2364 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2365 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2366 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2367 | */ |
| 2368 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2369 | sendRequestAsync(command, argument, null, null); |
| 2370 | } |
| 2371 | |
| 2372 | /** |
| 2373 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2374 | * @see {@link #sendRequest(int,Object)} |
| 2375 | */ |
| 2376 | private void sendRequestAsync( |
| 2377 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2378 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2379 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2380 | msg.sendToTarget(); |
| 2381 | } |
| 2382 | |
| 2383 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2384 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2385 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2386 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2387 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2388 | synchronized (PhoneInterfaceManager.class) { |
| 2389 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2390 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | } else { |
| 2392 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2393 | } |
| 2394 | return sInstance; |
| 2395 | } |
| 2396 | } |
| 2397 | |
| 2398 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2399 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2402 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2403 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2405 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2407 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2408 | mTelephonySharedPreferences = |
| 2409 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2410 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2411 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2412 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2413 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2414 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2415 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2416 | Executors.newSingleThreadExecutor(), mApp); |
| 2417 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | publish(); |
| 2419 | } |
| 2420 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2421 | private Phone getDefaultPhone() { |
| 2422 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2423 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2424 | } |
| 2425 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | private void publish() { |
| 2427 | if (DBG) log("publish: " + this); |
| 2428 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2429 | TelephonyFrameworkInitializer |
| 2430 | .getTelephonyServiceManager() |
| 2431 | .getTelephonyServiceRegisterer() |
| 2432 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2435 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2436 | if (request.phone != null) { |
| 2437 | return request.phone; |
| 2438 | } else { |
| 2439 | return getPhoneFromSubId(request.subId); |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | private Phone getPhoneFromSubId(int subId) { |
| 2444 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2445 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2446 | } |
| 2447 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2448 | @Nullable |
| 2449 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2450 | Phone phone = getPhoneFromRequest(request); |
| 2451 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2452 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2453 | } |
| 2454 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2455 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2456 | private Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2457 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2458 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2460 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2461 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2462 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2463 | } |
| 2464 | |
| 2465 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2466 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2467 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2470 | private boolean isImsAvailableOnDevice() { |
| 2471 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2472 | if (pm == null) { |
| 2473 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2474 | // so do not throw error and allow. |
| 2475 | return true; |
| 2476 | } |
| 2477 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2478 | } |
| 2479 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2481 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2484 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | if (DBG) log("dial: " + number); |
| 2486 | // No permission check needed here: This is just a wrapper around the |
| 2487 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2488 | // the UI before it does anything. |
| 2489 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | final long identity = Binder.clearCallingIdentity(); |
| 2491 | try { |
| 2492 | String url = createTelUrl(number); |
| 2493 | if (url == null) { |
| 2494 | return; |
| 2495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2497 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2498 | PhoneConstants.State state = mCM.getState(subId); |
| 2499 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2500 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2501 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2502 | mApp.startActivity(intent); |
| 2503 | } |
| 2504 | } finally { |
| 2505 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2510 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2513 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | if (DBG) log("call: " + number); |
| 2515 | |
| 2516 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2517 | // need to do a permission check since we're calling startActivity() |
| 2518 | // from the context of the phone app. |
| 2519 | enforceCallPermission(); |
| 2520 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2521 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | != AppOpsManager.MODE_ALLOWED) { |
| 2523 | return; |
| 2524 | } |
| 2525 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | final long identity = Binder.clearCallingIdentity(); |
| 2527 | try { |
| 2528 | String url = createTelUrl(number); |
| 2529 | if (url == null) { |
| 2530 | return; |
| 2531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | boolean isValid = false; |
| 2534 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2535 | if (slist != null) { |
| 2536 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2537 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2538 | isValid = true; |
| 2539 | break; |
| 2540 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2541 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2542 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2543 | if (!isValid) { |
| 2544 | return; |
| 2545 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2547 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2548 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2549 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2550 | mApp.startActivity(intent); |
| 2551 | } finally { |
| 2552 | Binder.restoreCallingIdentity(identity); |
| 2553 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2556 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2557 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2558 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2559 | } |
| 2560 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2561 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2562 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2563 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2564 | } |
| 2565 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2566 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | |
| 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2571 | Phone phone = getPhone(subId); |
| 2572 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | checkSimPin.start(); |
| 2574 | return checkSimPin.unlockSim(null, pin); |
| 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
| 2577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2580 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2581 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2585 | Phone phone = getPhone(subId); |
| 2586 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | checkSimPuk.start(); |
| 2588 | return checkSimPuk.unlockSim(puk, pin); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2595 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | * a synchronous one. |
| 2597 | */ |
| 2598 | private static class UnlockSim extends Thread { |
| 2599 | |
| 2600 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2601 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | |
| 2603 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2604 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2605 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | |
| 2607 | // For replies from SimCard interface |
| 2608 | private Handler mHandler; |
| 2609 | |
| 2610 | // For async handler to identify request type |
| 2611 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2612 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2613 | UnlockSim(int phoneId, IccCard simCard) { |
| 2614 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2615 | mSimCard = simCard; |
| 2616 | } |
| 2617 | |
| 2618 | @Override |
| 2619 | public void run() { |
| 2620 | Looper.prepare(); |
| 2621 | synchronized (UnlockSim.this) { |
| 2622 | mHandler = new Handler() { |
| 2623 | @Override |
| 2624 | public void handleMessage(Message msg) { |
| 2625 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2626 | switch (msg.what) { |
| 2627 | case SUPPLY_PIN_COMPLETE: |
| 2628 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2629 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2630 | mRetryCount = msg.arg1; |
| 2631 | if (ar.exception != null) { |
| 2632 | if (ar.exception instanceof CommandException && |
| 2633 | ((CommandException)(ar.exception)).getCommandError() |
| 2634 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2635 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2636 | } //When UiccCardApp dispose,handle message and return exception |
| 2637 | else if (ar.exception instanceof CommandException && |
| 2638 | ((CommandException) (ar.exception)).getCommandError() |
| 2639 | == CommandException.Error.ABORTED) { |
| 2640 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2641 | } else { |
| 2642 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2643 | } |
| 2644 | } else { |
| 2645 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2647 | mDone = true; |
| 2648 | UnlockSim.this.notifyAll(); |
| 2649 | } |
| 2650 | break; |
| 2651 | } |
| 2652 | } |
| 2653 | }; |
| 2654 | UnlockSim.this.notifyAll(); |
| 2655 | } |
| 2656 | Looper.loop(); |
| 2657 | } |
| 2658 | |
| 2659 | /* |
| 2660 | * Use PIN or PUK to unlock SIM card |
| 2661 | * |
| 2662 | * If PUK is null, unlock SIM card with PIN |
| 2663 | * |
| 2664 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2665 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2666 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | |
| 2668 | while (mHandler == null) { |
| 2669 | try { |
| 2670 | wait(); |
| 2671 | } catch (InterruptedException e) { |
| 2672 | Thread.currentThread().interrupt(); |
| 2673 | } |
| 2674 | } |
| 2675 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2676 | |
| 2677 | if (puk == null) { |
| 2678 | mSimCard.supplyPin(pin, callback); |
| 2679 | } else { |
| 2680 | mSimCard.supplyPuk(puk, pin, callback); |
| 2681 | } |
| 2682 | |
| 2683 | while (!mDone) { |
| 2684 | try { |
| 2685 | Log.d(LOG_TAG, "wait for done"); |
| 2686 | wait(); |
| 2687 | } catch (InterruptedException e) { |
| 2688 | // Restore the interrupted status |
| 2689 | Thread.currentThread().interrupt(); |
| 2690 | } |
| 2691 | } |
| 2692 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2693 | int[] resultArray = new int[2]; |
| 2694 | resultArray[0] = mResult; |
| 2695 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2696 | |
| 2697 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2698 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2699 | } |
| 2700 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2701 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2705 | /** |
| 2706 | * This method has been removed due to privacy and stability concerns. |
| 2707 | */ |
| 2708 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2709 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2710 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2711 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2714 | @Override |
| 2715 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2716 | mApp.getSystemService(AppOpsManager.class) |
| 2717 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2718 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2719 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2720 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2721 | // Callers targeting S have no business invoking this method. |
| 2722 | return; |
| 2723 | } |
| 2724 | |
| 2725 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2726 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2727 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2728 | .setCallingPackage(callingPackage) |
| 2729 | .setCallingFeatureId(null) |
| 2730 | .setCallingPid(Binder.getCallingPid()) |
| 2731 | .setCallingUid(Binder.getCallingUid()) |
| 2732 | .setMethod("updateServiceLocation") |
| 2733 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2734 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2735 | .build()); |
| 2736 | // Apps that lack location permission have no business calling this method; |
| 2737 | // however, because no permission was declared in the public API, denials must |
| 2738 | // all be "soft". |
| 2739 | switch (locationResult) { |
| 2740 | case DENIED_HARD: /* fall through */ |
| 2741 | case DENIED_SOFT: |
| 2742 | return; |
| 2743 | } |
| 2744 | |
| 2745 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2746 | final long identity = Binder.clearCallingIdentity(); |
| 2747 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2748 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2750 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2751 | } |
| 2752 | } finally { |
| 2753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2754 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2757 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2758 | @Override |
| 2759 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2760 | return isRadioOnWithFeature(callingPackage, null); |
| 2761 | } |
| 2762 | |
| 2763 | |
| 2764 | @Override |
| 2765 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2766 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2767 | callingFeatureId); |
| 2768 | } |
| 2769 | |
| 2770 | @Deprecated |
| 2771 | @Override |
| 2772 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2773 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2776 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2777 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2778 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2779 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2780 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2781 | return false; |
| 2782 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2783 | |
| 2784 | final long identity = Binder.clearCallingIdentity(); |
| 2785 | try { |
| 2786 | return isRadioOnForSubscriber(subId); |
| 2787 | } finally { |
| 2788 | Binder.restoreCallingIdentity(identity); |
| 2789 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2793 | final long identity = Binder.clearCallingIdentity(); |
| 2794 | try { |
| 2795 | final Phone phone = getPhone(subId); |
| 2796 | if (phone != null) { |
| 2797 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2798 | } else { |
| 2799 | return false; |
| 2800 | } |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2803 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2807 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2808 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2809 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2810 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | |
| 2813 | final long identity = Binder.clearCallingIdentity(); |
| 2814 | try { |
| 2815 | final Phone phone = getPhone(subId); |
| 2816 | if (phone != null) { |
| 2817 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2818 | } |
| 2819 | } finally { |
| 2820 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2821 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2825 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2828 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2829 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | |
| 2831 | final long identity = Binder.clearCallingIdentity(); |
| 2832 | try { |
| 2833 | final Phone phone = getPhone(subId); |
| 2834 | if (phone == null) { |
| 2835 | return false; |
| 2836 | } |
| 2837 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2838 | toggleRadioOnOffForSubscriber(subId); |
| 2839 | } |
| 2840 | return true; |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2845 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2846 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2847 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2848 | /* |
| 2849 | * If any of the Radios are available, it will need to be |
| 2850 | * shutdown. So return true if any Radio is available. |
| 2851 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| 2854 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2855 | Phone phone = PhoneFactory.getPhone(i); |
| 2856 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2857 | } |
| 2858 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2859 | return false; |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2862 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2866 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2867 | enforceModifyPermission(); |
| 2868 | |
| 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
| 2871 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2872 | logv("Shutting down Phone " + i); |
| 2873 | shutdownRadioUsingPhoneId(i); |
| 2874 | } |
| 2875 | } finally { |
| 2876 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2881 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2882 | if (phone != null && phone.isRadioAvailable()) { |
| 2883 | phone.shutdownRadio(); |
| 2884 | } |
| 2885 | } |
| 2886 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2888 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | |
| 2890 | final long identity = Binder.clearCallingIdentity(); |
| 2891 | try { |
| 2892 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2893 | if (defaultPhone != null) { |
| 2894 | defaultPhone.setRadioPower(turnOn); |
| 2895 | return true; |
| 2896 | } else { |
| 2897 | loge("There's no default phone."); |
| 2898 | return false; |
| 2899 | } |
| 2900 | } finally { |
| 2901 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2902 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2905 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | |
| 2908 | final long identity = Binder.clearCallingIdentity(); |
| 2909 | try { |
| 2910 | final Phone phone = getPhone(subId); |
| 2911 | if (phone != null) { |
| 2912 | phone.setRadioPower(turnOn); |
| 2913 | return true; |
| 2914 | } else { |
| 2915 | return false; |
| 2916 | } |
| 2917 | } finally { |
| 2918 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2919 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2920 | } |
| 2921 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2922 | /** |
| 2923 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2924 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2925 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2926 | * powering it off, and these radio off votes will be cleared. |
| 2927 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2928 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2929 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2930 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2931 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2932 | * check its vote. |
| 2933 | * |
| 2934 | * @param subId The subscription ID. |
| 2935 | * @param reason The reason for powering off radio. |
| 2936 | * @return true on success and false on failure. |
| 2937 | */ |
| 2938 | public boolean requestRadioPowerOffForReason(int subId, |
| 2939 | @TelephonyManager.RadioPowerReason int reason) { |
| 2940 | enforceModifyPermission(); |
| 2941 | |
| 2942 | final long identity = Binder.clearCallingIdentity(); |
| 2943 | try { |
| 2944 | final Phone phone = getPhone(subId); |
| 2945 | if (phone != null) { |
| 2946 | phone.setRadioPowerForReason(false, reason); |
| 2947 | return true; |
| 2948 | } else { |
| 2949 | return false; |
| 2950 | } |
| 2951 | } finally { |
| 2952 | Binder.restoreCallingIdentity(identity); |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | /** |
| 2957 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2958 | * {@link requestRadioPowerOffForReason}. |
| 2959 | * |
| 2960 | * @param subId The subscription ID. |
| 2961 | * @param reason The reason for powering off radio. |
| 2962 | * @return true on success and false on failure. |
| 2963 | */ |
| 2964 | public boolean clearRadioPowerOffForReason(int subId, |
| 2965 | @TelephonyManager.RadioPowerReason int reason) { |
| 2966 | enforceModifyPermission(); |
| 2967 | |
| 2968 | final long identity = Binder.clearCallingIdentity(); |
| 2969 | try { |
| 2970 | final Phone phone = getPhone(subId); |
| 2971 | if (phone != null) { |
| 2972 | phone.setRadioPowerForReason(true, reason); |
| 2973 | return true; |
| 2974 | } else { |
| 2975 | return false; |
| 2976 | } |
| 2977 | } finally { |
| 2978 | Binder.restoreCallingIdentity(identity); |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | /** |
| 2983 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2984 | * |
| 2985 | * @param subId The subscription ID. |
| 2986 | * @param callingPackage The package making the call. |
| 2987 | * @param callingFeatureId The feature in the package. |
| 2988 | * @return List of reasons for powering off radio. |
| 2989 | */ |
| 2990 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 2991 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 2992 | |
| 2993 | final long identity = Binder.clearCallingIdentity(); |
| 2994 | List result = new ArrayList(); |
| 2995 | try { |
| 2996 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 2997 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 2998 | return result; |
| 2999 | } |
| 3000 | |
| 3001 | final Phone phone = getPhone(subId); |
| 3002 | if (phone != null) { |
| 3003 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3004 | } |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
| 3008 | return result; |
| 3009 | } |
| 3010 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3011 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3012 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3013 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3014 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | |
| 3016 | final long identity = Binder.clearCallingIdentity(); |
| 3017 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3018 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | final Phone phone = getPhone(subId); |
| 3020 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3021 | phone.getDataSettingsManager().setDataEnabled( |
| 3022 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | return true; |
| 3024 | } else { |
| 3025 | return false; |
| 3026 | } |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3032 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3033 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3034 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3035 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3036 | |
| 3037 | final long identity = Binder.clearCallingIdentity(); |
| 3038 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3039 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3040 | final Phone phone = getPhone(subId); |
| 3041 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3042 | phone.getDataSettingsManager().setDataEnabled( |
| 3043 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | return true; |
| 3045 | } else { |
| 3046 | return false; |
| 3047 | } |
| 3048 | } finally { |
| 3049 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3053 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3054 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | final long identity = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | final Phone phone = getPhone(subId); |
| 3058 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3059 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3060 | } else { |
| 3061 | return false; |
| 3062 | } |
| 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3069 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3072 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3073 | enforceCallPermission(); |
| 3074 | |
| 3075 | final long identity = Binder.clearCallingIdentity(); |
| 3076 | try { |
| 3077 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3078 | return; |
| 3079 | } |
| 3080 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3081 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3082 | } finally { |
| 3083 | Binder.restoreCallingIdentity(identity); |
| 3084 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3085 | }; |
| 3086 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3087 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3088 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | |
| 3090 | final long identity = Binder.clearCallingIdentity(); |
| 3091 | try { |
| 3092 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3093 | return false; |
| 3094 | } |
| 3095 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 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 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3101 | /** |
| 3102 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3103 | * tag on getCallState Binder call. |
| 3104 | */ |
| 3105 | @Deprecated |
| 3106 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3107 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3108 | if (CompatChanges.isChangeEnabled( |
| 3109 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3110 | Binder.getCallingUid())) { |
| 3111 | // Do not allow this API to be called on API version 31+, it should only be |
| 3112 | // called on old apps using this Binder call directly. |
| 3113 | throw new SecurityException("This method can only be used for applications " |
| 3114 | + "targeting API version 30 or less."); |
| 3115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | final long identity = Binder.clearCallingIdentity(); |
| 3117 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3118 | Phone phone = getPhone(getDefaultSubscription()); |
| 3119 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3120 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3121 | } finally { |
| 3122 | Binder.restoreCallingIdentity(identity); |
| 3123 | } |
| 3124 | } |
| 3125 | |
| 3126 | @Override |
| 3127 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3128 | if (CompatChanges.isChangeEnabled( |
| 3129 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3130 | Binder.getCallingUid())) { |
| 3131 | // Check READ_PHONE_STATE for API version 31+ |
| 3132 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3133 | featureId, "getCallStateForSubscription")) { |
| 3134 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3135 | + "targeting API level 31+."); |
| 3136 | } |
| 3137 | } |
| 3138 | final long identity = Binder.clearCallingIdentity(); |
| 3139 | try { |
| 3140 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3141 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3142 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3148 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3149 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3150 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3151 | } |
| 3152 | |
| 3153 | @Override |
| 3154 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3155 | final long identity = Binder.clearCallingIdentity(); |
| 3156 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3157 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3159 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3160 | } else { |
| 3161 | return PhoneConstantConversions.convertDataState( |
| 3162 | PhoneConstants.DataState.DISCONNECTED); |
| 3163 | } |
| 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3166 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3169 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3170 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3171 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3175 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3176 | final long identity = Binder.clearCallingIdentity(); |
| 3177 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3178 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3179 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3180 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3181 | } else { |
| 3182 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3183 | } |
| 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3186 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3190 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3192 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3193 | |
| 3194 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3195 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3196 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3197 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3198 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3199 | .setCallingPid(Binder.getCallingPid()) |
| 3200 | .setCallingUid(Binder.getCallingUid()) |
| 3201 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3202 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3203 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3204 | .build()); |
| 3205 | switch (locationResult) { |
| 3206 | case DENIED_HARD: |
| 3207 | throw new SecurityException("Not allowed to access cell location"); |
| 3208 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3209 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3210 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3213 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | final long identity = Binder.clearCallingIdentity(); |
| 3215 | try { |
| 3216 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3217 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3218 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3219 | } finally { |
| 3220 | Binder.restoreCallingIdentity(identity); |
| 3221 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3225 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3226 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3227 | // registered cell info, so return a NULL country instead. |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3230 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3231 | // Get default phone in this case. |
| 3232 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3233 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3234 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3236 | if (phone == null) return ""; |
| 3237 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3238 | if (sst == null) return ""; |
| 3239 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3240 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3241 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3242 | } finally { |
| 3243 | Binder.restoreCallingIdentity(identity); |
| 3244 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3245 | } |
| 3246 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3247 | /** |
| 3248 | * This method was removed due to potential issues caused by performing partial |
| 3249 | * updates of service state, and lack of a credible use case. |
| 3250 | * |
| 3251 | * This has the ability to break the telephony implementation by disabling notification of |
| 3252 | * changes in device connectivity. DO NOT USE THIS! |
| 3253 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3254 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3255 | public void enableLocationUpdates() { |
| 3256 | mApp.enforceCallingOrSelfPermission( |
| 3257 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3258 | } |
| 3259 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3260 | /** |
| 3261 | * This method was removed due to potential issues caused by performing partial |
| 3262 | * updates of service state, and lack of a credible use case. |
| 3263 | * |
| 3264 | * This has the ability to break the telephony implementation by disabling notification of |
| 3265 | * changes in device connectivity. DO NOT USE THIS! |
| 3266 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3267 | @Override |
| 3268 | public void disableLocationUpdates() { |
| 3269 | mApp.enforceCallingOrSelfPermission( |
| 3270 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | @Override |
| 3274 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3275 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3276 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3277 | try { |
| 3278 | mApp.getSystemService(AppOpsManager.class) |
| 3279 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3280 | } catch (SecurityException e) { |
| 3281 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3282 | throw e; |
| 3283 | } |
| 3284 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3285 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3286 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3287 | throw new SecurityException( |
| 3288 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3289 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3290 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3291 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3292 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3293 | return null; |
| 3294 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3295 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3296 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3297 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3298 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3299 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3300 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3301 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3302 | for (CellInfo ci : info) { |
| 3303 | if (ci instanceof CellInfoGsm) { |
| 3304 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3305 | } else if (ci instanceof CellInfoWcdma) { |
| 3306 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3307 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3308 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3309 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3312 | private List<CellInfo> getCachedCellInfo() { |
| 3313 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3314 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3315 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3316 | if (info != null) cellInfos.addAll(info); |
| 3317 | } |
| 3318 | return cellInfos; |
| 3319 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3320 | |
| 3321 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3322 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3323 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3324 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3325 | |
| 3326 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3327 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3328 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3329 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3330 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3331 | .setCallingPid(Binder.getCallingPid()) |
| 3332 | .setCallingUid(Binder.getCallingUid()) |
| 3333 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3334 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3335 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3336 | .build()); |
| 3337 | switch (locationResult) { |
| 3338 | case DENIED_HARD: |
| 3339 | throw new SecurityException("Not allowed to access cell info"); |
| 3340 | case DENIED_SOFT: |
| 3341 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3342 | } |
| 3343 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3344 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3345 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3346 | return getCachedCellInfo(); |
| 3347 | } |
| 3348 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3349 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3350 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3351 | final long identity = Binder.clearCallingIdentity(); |
| 3352 | try { |
| 3353 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3354 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3355 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3356 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3357 | if (info != null) cellInfos.addAll(info); |
| 3358 | } |
| 3359 | return cellInfos; |
| 3360 | } finally { |
| 3361 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3362 | } |
| 3363 | } |
| 3364 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3365 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3366 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3367 | String callingFeatureId) { |
| 3368 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3369 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3373 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3374 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3375 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3376 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3377 | } |
| 3378 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3379 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3380 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3381 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3382 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3383 | |
| 3384 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3385 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3386 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3387 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3388 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3389 | .setCallingPid(Binder.getCallingPid()) |
| 3390 | .setCallingUid(Binder.getCallingUid()) |
| 3391 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3392 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3393 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3394 | .build()); |
| 3395 | switch (locationResult) { |
| 3396 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3397 | if (TelephonyPermissions |
| 3398 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3399 | // Safetynet logging for b/154934934 |
| 3400 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3401 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3402 | throw new SecurityException("Not allowed to access cell info"); |
| 3403 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3404 | if (TelephonyPermissions |
| 3405 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3406 | // Safetynet logging for b/154934934 |
| 3407 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3408 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3409 | try { |
| 3410 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3411 | } catch (RemoteException re) { |
| 3412 | // Drop without consequences |
| 3413 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3414 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3417 | |
| 3418 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3419 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3420 | |
| 3421 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3422 | } |
| 3423 | |
| 3424 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3425 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3426 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3427 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | |
| 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3431 | Phone phone = getPhone(subId); |
| 3432 | if (phone == null) { |
| 3433 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3434 | } else { |
| 3435 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3436 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
| 3439 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3440 | } |
| 3441 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3442 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3443 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3444 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3445 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3446 | return null; |
| 3447 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3448 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3449 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3450 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3451 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3452 | return null; |
| 3453 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3454 | |
| 3455 | final long identity = Binder.clearCallingIdentity(); |
| 3456 | try { |
| 3457 | return phone.getImei(); |
| 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
| 3460 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3464 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3465 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3466 | String tac = null; |
| 3467 | if (phone != null) { |
| 3468 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3469 | try { |
| 3470 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3471 | } catch (IndexOutOfBoundsException e) { |
| 3472 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3473 | return null; |
| 3474 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3475 | } |
| 3476 | return tac; |
| 3477 | } |
| 3478 | |
| 3479 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3480 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3481 | try { |
| 3482 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3483 | } catch (SecurityException se) { |
| 3484 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3485 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3486 | + Binder.getCallingUid()); |
| 3487 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3488 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3489 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3490 | return null; |
| 3491 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3492 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3493 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3494 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3495 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3496 | return null; |
| 3497 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | return phone.getMeid(); |
| 3502 | } finally { |
| 3503 | Binder.restoreCallingIdentity(identity); |
| 3504 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3508 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3509 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3510 | String manufacturerCode = null; |
| 3511 | if (phone != null) { |
| 3512 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3513 | try { |
| 3514 | manufacturerCode = |
| 3515 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3516 | } catch (IndexOutOfBoundsException e) { |
| 3517 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3518 | return null; |
| 3519 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3520 | } |
| 3521 | return manufacturerCode; |
| 3522 | } |
| 3523 | |
| 3524 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3525 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3526 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3527 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3528 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3529 | return null; |
| 3530 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3531 | int subId = phone.getSubId(); |
| 3532 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3533 | mApp, subId, callingPackage, callingFeatureId, |
| 3534 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3535 | return null; |
| 3536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3537 | |
| 3538 | final long identity = Binder.clearCallingIdentity(); |
| 3539 | try { |
| 3540 | return phone.getDeviceSvn(); |
| 3541 | } finally { |
| 3542 | Binder.restoreCallingIdentity(identity); |
| 3543 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3544 | } |
| 3545 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3546 | @Override |
| 3547 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3548 | final long identity = Binder.clearCallingIdentity(); |
| 3549 | try { |
| 3550 | final Phone phone = getPhone(subId); |
| 3551 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3552 | } finally { |
| 3553 | Binder.restoreCallingIdentity(identity); |
| 3554 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | @Override |
| 3558 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | final long identity = Binder.clearCallingIdentity(); |
| 3560 | try { |
| 3561 | final Phone phone = getPhone(subId); |
| 3562 | return phone == null ? null : phone.getCarrierName(); |
| 3563 | } finally { |
| 3564 | Binder.restoreCallingIdentity(identity); |
| 3565 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3566 | } |
| 3567 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3568 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3569 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3570 | final long identity = Binder.clearCallingIdentity(); |
| 3571 | try { |
| 3572 | final Phone phone = getPhone(subId); |
| 3573 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3574 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3575 | } finally { |
| 3576 | Binder.restoreCallingIdentity(identity); |
| 3577 | } |
| 3578 | } |
| 3579 | |
| 3580 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3581 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3582 | final long identity = Binder.clearCallingIdentity(); |
| 3583 | try { |
| 3584 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3585 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(identity); |
| 3588 | } |
| 3589 | } |
| 3590 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3591 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3592 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3593 | if (!isSubscriptionMccMnc) { |
| 3594 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3595 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3596 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3597 | if (phone == null) { |
| 3598 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3599 | } |
| 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3603 | } finally { |
| 3604 | Binder.restoreCallingIdentity(identity); |
| 3605 | } |
| 3606 | } |
| 3607 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3608 | // |
| 3609 | // Internal helper methods. |
| 3610 | // |
| 3611 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3612 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3613 | * Make sure the caller is the calling package itself |
| 3614 | * |
| 3615 | * @throws SecurityException if the caller is not the calling package |
| 3616 | */ |
| 3617 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3618 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3619 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3620 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3621 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3622 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3623 | } catch (PackageManager.NameNotFoundException e) { |
| 3624 | // packageUid is -1 |
| 3625 | } |
| 3626 | if (packageUid != callingUid) { |
| 3627 | throw new SecurityException(message + ": Package " + callingPackage |
| 3628 | + " does not belong to " + callingUid); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3633 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3634 | * |
| 3635 | * @throws SecurityException if the caller does not have the required permission |
| 3636 | */ |
| 3637 | private void enforceModifyPermission() { |
| 3638 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3639 | } |
| 3640 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3641 | private void enforceActiveEmergencySessionPermission() { |
| 3642 | mApp.enforceCallingOrSelfPermission( |
| 3643 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3644 | } |
| 3645 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3646 | /** |
| 3647 | * Make sure the caller has the CALL_PHONE permission. |
| 3648 | * |
| 3649 | * @throws SecurityException if the caller does not have the required permission |
| 3650 | */ |
| 3651 | private void enforceCallPermission() { |
| 3652 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3653 | } |
| 3654 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3655 | private void enforceSettingsPermission() { |
| 3656 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3659 | private void enforceRebootPermission() { |
| 3660 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3661 | } |
| 3662 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3663 | private String createTelUrl(String number) { |
| 3664 | if (TextUtils.isEmpty(number)) { |
| 3665 | return null; |
| 3666 | } |
| 3667 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3668 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3671 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3672 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3673 | } |
| 3674 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3675 | private static void logv(String msg) { |
| 3676 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3677 | } |
| 3678 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3679 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3680 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3681 | } |
| 3682 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3683 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3684 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3685 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3686 | } |
| 3687 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3688 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3689 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3690 | final long identity = Binder.clearCallingIdentity(); |
| 3691 | try { |
| 3692 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3693 | if (phone == null) { |
| 3694 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3695 | } else { |
| 3696 | return phone.getPhoneType(); |
| 3697 | } |
| 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * Returns the CDMA ERI icon index to display |
| 3705 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3706 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3707 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3708 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3709 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3712 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3713 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3714 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3716 | mApp, subId, callingPackage, callingFeatureId, |
| 3717 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3718 | return -1; |
| 3719 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3720 | |
| 3721 | final long identity = Binder.clearCallingIdentity(); |
| 3722 | try { |
| 3723 | final Phone phone = getPhone(subId); |
| 3724 | if (phone != null) { |
| 3725 | return phone.getCdmaEriIconIndex(); |
| 3726 | } else { |
| 3727 | return -1; |
| 3728 | } |
| 3729 | } finally { |
| 3730 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3731 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | /** |
| 3735 | * Returns the CDMA ERI icon mode, |
| 3736 | * 0 - ON |
| 3737 | * 1 - FLASHING |
| 3738 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3740 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3741 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3742 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3745 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3746 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3747 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3749 | mApp, subId, callingPackage, callingFeatureId, |
| 3750 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3751 | return -1; |
| 3752 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | |
| 3754 | final long identity = Binder.clearCallingIdentity(); |
| 3755 | try { |
| 3756 | final Phone phone = getPhone(subId); |
| 3757 | if (phone != null) { |
| 3758 | return phone.getCdmaEriIconMode(); |
| 3759 | } else { |
| 3760 | return -1; |
| 3761 | } |
| 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | /** |
| 3768 | * Returns the CDMA ERI text, |
| 3769 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3770 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3771 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3772 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3773 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3774 | } |
| 3775 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3776 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3777 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3778 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3779 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3780 | mApp, subId, callingPackage, callingFeatureId, |
| 3781 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3782 | return null; |
| 3783 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3784 | |
| 3785 | final long identity = Binder.clearCallingIdentity(); |
| 3786 | try { |
| 3787 | final Phone phone = getPhone(subId); |
| 3788 | if (phone != null) { |
| 3789 | return phone.getCdmaEriText(); |
| 3790 | } else { |
| 3791 | return null; |
| 3792 | } |
| 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3799 | * Returns the CDMA MDN. |
| 3800 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3801 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3802 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3803 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3804 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | |
| 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3809 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3810 | return phone.getLine1Number(); |
| 3811 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3812 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | return null; |
| 3814 | } |
| 3815 | } finally { |
| 3816 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Returns the CDMA MIN. |
| 3822 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3823 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3824 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3826 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3827 | |
| 3828 | final long identity = Binder.clearCallingIdentity(); |
| 3829 | try { |
| 3830 | final Phone phone = getPhone(subId); |
| 3831 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3832 | return phone.getCdmaMin(); |
| 3833 | } else { |
| 3834 | return null; |
| 3835 | } |
| 3836 | } finally { |
| 3837 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3838 | } |
| 3839 | } |
| 3840 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3841 | @Override |
| 3842 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3843 | INumberVerificationCallback callback, String callingPackage) { |
| 3844 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3845 | != PERMISSION_GRANTED) { |
| 3846 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3847 | } |
| 3848 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3849 | |
| 3850 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3851 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3852 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3853 | + "calling package: " + callingPackage |
| 3854 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | if (range == null) { |
| 3858 | throw new NullPointerException("Range must be non-null"); |
| 3859 | } |
| 3860 | |
| 3861 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3862 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3863 | |
| 3864 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3865 | } |
| 3866 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3867 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3868 | * Returns true if CDMA provisioning needs to run. |
| 3869 | */ |
| 3870 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | final long identity = Binder.clearCallingIdentity(); |
| 3872 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3873 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | } finally { |
| 3875 | Binder.restoreCallingIdentity(identity); |
| 3876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3880 | * Sets the voice mail number of a given subId. |
| 3881 | */ |
| 3882 | @Override |
| 3883 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3884 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3885 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3886 | |
| 3887 | final long identity = Binder.clearCallingIdentity(); |
| 3888 | try { |
| 3889 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3890 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3891 | return success; |
| 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(identity); |
| 3894 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3895 | } |
| 3896 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3897 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3898 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3899 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3900 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3901 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3902 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3903 | throw new SecurityException("caller must be system dialer"); |
| 3904 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | |
| 3906 | final long identity = Binder.clearCallingIdentity(); |
| 3907 | try { |
| 3908 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3909 | if (phoneAccountHandle == null) { |
| 3910 | return null; |
| 3911 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3912 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3915 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
| 3918 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3919 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3920 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3921 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3922 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3923 | mApp, subId, callingPackage, callingFeatureId, |
| 3924 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3925 | return null; |
| 3926 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3928 | final long identity = Binder.clearCallingIdentity(); |
| 3929 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3930 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(identity); |
| 3933 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3937 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3938 | VisualVoicemailSmsFilterSettings settings) { |
| 3939 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3940 | |
| 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
| 3943 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3944 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | } finally { |
| 3946 | Binder.restoreCallingIdentity(identity); |
| 3947 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3951 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3952 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | |
| 3954 | final long identity = Binder.clearCallingIdentity(); |
| 3955 | try { |
| 3956 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
| 3960 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3964 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3965 | String callingPackage, int subId) { |
| 3966 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | |
| 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3971 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | } finally { |
| 3973 | Binder.restoreCallingIdentity(identity); |
| 3974 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
| 3977 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3978 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3979 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3980 | |
| 3981 | final long identity = Binder.clearCallingIdentity(); |
| 3982 | try { |
| 3983 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3984 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(identity); |
| 3987 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3991 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3992 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3993 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3994 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3995 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3996 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3997 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3998 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3999 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4000 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4001 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4002 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4003 | * Sets the voice activation state of a given subId. |
| 4004 | */ |
| 4005 | @Override |
| 4006 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4008 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4009 | |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | final Phone phone = getPhone(subId); |
| 4013 | if (phone != null) { |
| 4014 | phone.setVoiceActivationState(activationState); |
| 4015 | } else { |
| 4016 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4017 | } |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4020 | } |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * Sets the data activation state of a given subId. |
| 4025 | */ |
| 4026 | @Override |
| 4027 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4029 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | |
| 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | final Phone phone = getPhone(subId); |
| 4034 | if (phone != null) { |
| 4035 | phone.setDataActivationState(activationState); |
| 4036 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4037 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4038 | } |
| 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * Returns the voice activation state of a given subId. |
| 4046 | */ |
| 4047 | @Override |
| 4048 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4051 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | if (phone != null) { |
| 4055 | return phone.getVoiceActivationState(); |
| 4056 | } else { |
| 4057 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4058 | } |
| 4059 | } finally { |
| 4060 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4061 | } |
| 4062 | } |
| 4063 | |
| 4064 | /** |
| 4065 | * Returns the data activation state of a given subId. |
| 4066 | */ |
| 4067 | @Override |
| 4068 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4069 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4070 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4071 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 | final long identity = Binder.clearCallingIdentity(); |
| 4073 | try { |
| 4074 | if (phone != null) { |
| 4075 | return phone.getDataActivationState(); |
| 4076 | } else { |
| 4077 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4078 | } |
| 4079 | } finally { |
| 4080 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4081 | } |
| 4082 | } |
| 4083 | |
| 4084 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4085 | * Returns the unread count of voicemails for a subId |
| 4086 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4087 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4088 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4089 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4091 | mApp, subId, callingPackage, callingFeatureId, |
| 4092 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4093 | return 0; |
| 4094 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4095 | final long identity = Binder.clearCallingIdentity(); |
| 4096 | try { |
| 4097 | final Phone phone = getPhone(subId); |
| 4098 | if (phone != null) { |
| 4099 | return phone.getVoiceMessageCount(); |
| 4100 | } else { |
| 4101 | return 0; |
| 4102 | } |
| 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4109 | * returns true, if the device is in a state where both voice and data |
| 4110 | * are supported simultaneously. This can change based on location or network condition. |
| 4111 | */ |
| 4112 | @Override |
| 4113 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | final Phone phone = getPhone(subId); |
| 4117 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(identity); |
| 4120 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4124 | * Send the dialer code if called from the current default dialer or the caller has |
| 4125 | * carrier privilege. |
| 4126 | * @param inputCode The dialer code to send |
| 4127 | */ |
| 4128 | @Override |
| 4129 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4130 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4131 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4132 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4133 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4134 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4135 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4136 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4137 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4138 | |
| 4139 | final long identity = Binder.clearCallingIdentity(); |
| 4140 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4141 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4142 | } finally { |
| 4143 | Binder.restoreCallingIdentity(identity); |
| 4144 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4145 | } |
| 4146 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4147 | @Override |
| 4148 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4149 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4150 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4151 | mApp, subId, "getNetworkSelectionMode"); |
| 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
| 4154 | if (!isActiveSubscription(subId)) { |
| 4155 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4156 | } |
| 4157 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4158 | } finally { |
| 4159 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4160 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4163 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4164 | public boolean isInEmergencySmsMode() { |
| 4165 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4166 | final long identity = Binder.clearCallingIdentity(); |
| 4167 | try { |
| 4168 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4169 | if (phone.isInEmergencySmsMode()) { |
| 4170 | return true; |
| 4171 | } |
| 4172 | } |
| 4173 | } finally { |
| 4174 | Binder.restoreCallingIdentity(identity); |
| 4175 | } |
| 4176 | return false; |
| 4177 | } |
| 4178 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4179 | /** |
| 4180 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4181 | * @param subId The subscription to use to check the configuration. |
| 4182 | * @param c The callback that will be used to send the result. |
| 4183 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4184 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4185 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4186 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4187 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4188 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4189 | |
| 4190 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4191 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4192 | "IMS not available on device."); |
| 4193 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | final long token = Binder.clearCallingIdentity(); |
| 4195 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4196 | int slotId = getSlotIndexOrException(subId); |
| 4197 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4198 | |
| 4199 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4200 | if (controller != null) { |
| 4201 | ImsManager imsManager = controller.getImsManager(subId); |
| 4202 | if (imsManager != null) { |
| 4203 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4204 | } else { |
| 4205 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4206 | } |
| 4207 | } else { |
| 4208 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4209 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4210 | } catch (ImsException e) { |
| 4211 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(token); |
| 4214 | } |
| 4215 | } |
| 4216 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4217 | /** |
| 4218 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4219 | * @param subId The subscription to use to check the configuration. |
| 4220 | * @param c The callback that will be used to send the result. |
| 4221 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4222 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4223 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4224 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4225 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4226 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4227 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4228 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4229 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4230 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4231 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4232 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4233 | if (controller != null) { |
| 4234 | ImsManager imsManager = controller.getImsManager(subId); |
| 4235 | if (imsManager != null) { |
| 4236 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4237 | } else { |
| 4238 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4239 | + "is inactive, ignoring unregister."); |
| 4240 | // If the ImsManager is not valid, just return, since the callback |
| 4241 | // will already have been removed internally. |
| 4242 | } |
| 4243 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(token); |
| 4246 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4247 | } |
| 4248 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4249 | /** |
| 4250 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4251 | */ |
| 4252 | @Override |
| 4253 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4254 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4255 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4256 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4257 | "IMS not available on device."); |
| 4258 | } |
| 4259 | final long token = Binder.clearCallingIdentity(); |
| 4260 | try { |
| 4261 | Phone phone = getPhone(subId); |
| 4262 | if (phone == null) { |
| 4263 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4264 | + subId + "'"); |
| 4265 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4266 | } |
| 4267 | phone.getImsRegistrationState(regState -> { |
| 4268 | try { |
| 4269 | consumer.accept((regState == null) |
| 4270 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4271 | } catch (RemoteException e) { |
| 4272 | // Ignore if the remote process is no longer available to call back. |
| 4273 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4274 | } |
| 4275 | }); |
| 4276 | } finally { |
| 4277 | Binder.restoreCallingIdentity(token); |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | /** |
| 4282 | * Get the transport type for the IMS service registration state. |
| 4283 | */ |
| 4284 | @Override |
| 4285 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4286 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4287 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4288 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4289 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4290 | "IMS not available on device."); |
| 4291 | } |
| 4292 | final long token = Binder.clearCallingIdentity(); |
| 4293 | try { |
| 4294 | Phone phone = getPhone(subId); |
| 4295 | if (phone == null) { |
| 4296 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4297 | + subId + "'"); |
| 4298 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4299 | } |
| 4300 | phone.getImsRegistrationTech(regTech -> { |
| 4301 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4302 | int regTechConverted = (regTech == null) |
| 4303 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4304 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4305 | regTechConverted); |
| 4306 | try { |
| 4307 | consumer.accept(regTechConverted); |
| 4308 | } catch (RemoteException e) { |
| 4309 | // Ignore if the remote process is no longer available to call back. |
| 4310 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4311 | } |
| 4312 | }); |
| 4313 | } finally { |
| 4314 | Binder.restoreCallingIdentity(token); |
| 4315 | } |
| 4316 | } |
| 4317 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4318 | /** |
| 4319 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4320 | * @param subId The subscription to use to check the configuration. |
| 4321 | * @param c The callback that will be used to send the result. |
| 4322 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4323 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4324 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4325 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4326 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4327 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4328 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4330 | "IMS not available on device."); |
| 4331 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4332 | final long token = Binder.clearCallingIdentity(); |
| 4333 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4334 | int slotId = getSlotIndexOrException(subId); |
| 4335 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4336 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4337 | } catch (ImsException e) { |
| 4338 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(token); |
| 4341 | } |
| 4342 | } |
| 4343 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4344 | /** |
| 4345 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4346 | * @param subId The subscription to use to check the configuration. |
| 4347 | * @param c The callback that will be used to send the result. |
| 4348 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4349 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4350 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4351 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4352 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4353 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4354 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4355 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4356 | |
| 4357 | final long token = Binder.clearCallingIdentity(); |
| 4358 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4359 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4360 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4361 | } catch (ImsException e) { |
| 4362 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4363 | + "is inactive, ignoring unregister."); |
| 4364 | // If the subscription is no longer active, just return, since the callback |
| 4365 | // will already have been removed internally. |
| 4366 | } finally { |
| 4367 | Binder.restoreCallingIdentity(token); |
| 4368 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4372 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4373 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | final long token = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4376 | int slotId = getSlotIndexOrException(subId); |
| 4377 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4378 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4379 | } catch (com.android.ims.ImsException e) { |
| 4380 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4381 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4382 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4383 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4384 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4385 | } finally { |
| 4386 | Binder.restoreCallingIdentity(token); |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4391 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4392 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4393 | final long token = Binder.clearCallingIdentity(); |
| 4394 | try { |
| 4395 | Phone phone = getPhone(subId); |
| 4396 | if (phone == null) return false; |
| 4397 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4398 | } catch (com.android.ims.ImsException e) { |
| 4399 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4400 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(token); |
| 4403 | } |
| 4404 | } |
| 4405 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4406 | /** |
| 4407 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4408 | * subscription. |
| 4409 | * @param subId The subscription to use to check the configuration. |
| 4410 | * @param callback The callback that will be used to send the result. |
| 4411 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4412 | * @param transportType The transport type of the MmTelFeature capability. |
| 4413 | */ |
| 4414 | @Override |
| 4415 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4416 | int transportType) { |
| 4417 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4418 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4419 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4420 | "IMS not available on device."); |
| 4421 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4422 | final long token = Binder.clearCallingIdentity(); |
| 4423 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4424 | int slotId = getSlotIndex(subId); |
| 4425 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4426 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4427 | + subId + "'"); |
| 4428 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4429 | } |
| 4430 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4431 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4432 | transportType, aBoolean -> { |
| 4433 | try { |
| 4434 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4435 | } catch (RemoteException e) { |
| 4436 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4437 | + "running. Ignore"); |
| 4438 | } |
| 4439 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4440 | } catch (ImsException e) { |
| 4441 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4442 | } finally { |
| 4443 | Binder.restoreCallingIdentity(token); |
| 4444 | } |
| 4445 | } |
| 4446 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4447 | /** |
| 4448 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4449 | * @param subId The subscription to use to check the configuration. |
| 4450 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4451 | @Override |
| 4452 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4453 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4454 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4455 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4456 | final long token = Binder.clearCallingIdentity(); |
| 4457 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4458 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4459 | // 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] | 4460 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4461 | } catch (ImsException e) { |
| 4462 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4463 | } finally { |
| 4464 | Binder.restoreCallingIdentity(token); |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4469 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4471 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | final long identity = Binder.clearCallingIdentity(); |
| 4473 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4474 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4475 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4476 | // 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] | 4477 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4478 | } catch (ImsException e) { |
| 4479 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
| 4482 | } |
| 4483 | } |
| 4484 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4485 | /** |
| 4486 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4487 | * @param subId The subscription to use to check the configuration. |
| 4488 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4489 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4490 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4491 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4492 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4495 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4496 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4497 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4498 | } catch (ImsException e) { |
| 4499 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | } finally { |
| 4501 | Binder.restoreCallingIdentity(identity); |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4506 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4508 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4509 | final long identity = Binder.clearCallingIdentity(); |
| 4510 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4511 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4512 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4513 | // 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] | 4514 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4515 | } catch (ImsException e) { |
| 4516 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | } finally { |
| 4518 | Binder.restoreCallingIdentity(identity); |
| 4519 | } |
| 4520 | } |
| 4521 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4522 | /** |
| 4523 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4524 | * @param subId The subscription to use to check the configuration. |
| 4525 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4526 | @Override |
| 4527 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4528 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4529 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4532 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4533 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4534 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4535 | } catch (ImsException e) { |
| 4536 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4537 | } finally { |
| 4538 | Binder.restoreCallingIdentity(identity); |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4543 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4545 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | final long identity = Binder.clearCallingIdentity(); |
| 4547 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4548 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4549 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4550 | // 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] | 4551 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4552 | } catch (ImsException e) { |
| 4553 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | } finally { |
| 4555 | Binder.restoreCallingIdentity(identity); |
| 4556 | } |
| 4557 | } |
| 4558 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4559 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4560 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4561 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4562 | * @param subId The subscription to use to check the configuration. |
| 4563 | */ |
| 4564 | @Override |
| 4565 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4566 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4567 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4568 | final long identity = Binder.clearCallingIdentity(); |
| 4569 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4570 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4571 | // 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] | 4572 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4573 | } catch (ImsException e) { |
| 4574 | throw new ServiceSpecificException(e.getCode()); |
| 4575 | } finally { |
| 4576 | Binder.restoreCallingIdentity(identity); |
| 4577 | } |
| 4578 | } |
| 4579 | |
| 4580 | /** |
| 4581 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4582 | * Requires MODIFY_PHONE_STATE permission. |
| 4583 | * @param subId The subscription to use to check the configuration. |
| 4584 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4585 | * false otherwise |
| 4586 | */ |
| 4587 | @Override |
| 4588 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4590 | "setCrossSimCallingEnabled"); |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4593 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4594 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4595 | // 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] | 4596 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4597 | } catch (ImsException e) { |
| 4598 | throw new ServiceSpecificException(e.getCode()); |
| 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4606 | * @param subId The subscription to use to check the configuration. |
| 4607 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4608 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4609 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4610 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4611 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4612 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4615 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4616 | // 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] | 4617 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4618 | } catch (ImsException e) { |
| 4619 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4626 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4627 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4628 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | final long identity = Binder.clearCallingIdentity(); |
| 4630 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4631 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4632 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4633 | // 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] | 4634 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4635 | } catch (ImsException e) { |
| 4636 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4637 | } finally { |
| 4638 | Binder.restoreCallingIdentity(identity); |
| 4639 | } |
| 4640 | } |
| 4641 | |
| 4642 | @Override |
| 4643 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4645 | "setVoWiFiNonPersistent"); |
| 4646 | final long identity = Binder.clearCallingIdentity(); |
| 4647 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4648 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4649 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4650 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4651 | } catch (ImsException e) { |
| 4652 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
| 4656 | } |
| 4657 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4658 | /** |
| 4659 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4660 | * @param subId The subscription to use to check the configuration. |
| 4661 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4662 | @Override |
| 4663 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4664 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4665 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4666 | final long identity = Binder.clearCallingIdentity(); |
| 4667 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4668 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4669 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4670 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4671 | } catch (ImsException e) { |
| 4672 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
| 4675 | } |
| 4676 | } |
| 4677 | |
| 4678 | @Override |
| 4679 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4681 | "setVoWiFiModeSetting"); |
| 4682 | final long identity = Binder.clearCallingIdentity(); |
| 4683 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4684 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4685 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4686 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4687 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4688 | } catch (ImsException e) { |
| 4689 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4690 | } finally { |
| 4691 | Binder.restoreCallingIdentity(identity); |
| 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | @Override |
| 4696 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4697 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4698 | final long identity = Binder.clearCallingIdentity(); |
| 4699 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4700 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4701 | // 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] | 4702 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4703 | } catch (ImsException e) { |
| 4704 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
| 4707 | } |
| 4708 | } |
| 4709 | |
| 4710 | @Override |
| 4711 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4713 | "setVoWiFiRoamingModeSetting"); |
| 4714 | final long identity = Binder.clearCallingIdentity(); |
| 4715 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4716 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4717 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4718 | // 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] | 4719 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4720 | } catch (ImsException e) { |
| 4721 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4722 | } finally { |
| 4723 | Binder.restoreCallingIdentity(identity); |
| 4724 | } |
| 4725 | } |
| 4726 | |
| 4727 | @Override |
| 4728 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4730 | "setRttCapabilityEnabled"); |
| 4731 | final long identity = Binder.clearCallingIdentity(); |
| 4732 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4733 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4734 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4735 | // 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] | 4736 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4737 | } catch (ImsException e) { |
| 4738 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4739 | } finally { |
| 4740 | Binder.restoreCallingIdentity(identity); |
| 4741 | } |
| 4742 | } |
| 4743 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4744 | /** |
| 4745 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4746 | * @param subId The subscription to use to check the configuration. |
| 4747 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4748 | @Override |
| 4749 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4750 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4751 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4754 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4755 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4756 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4757 | } catch (ImsException e) { |
| 4758 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(identity); |
| 4761 | } |
| 4762 | } |
| 4763 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4764 | @Override |
| 4765 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4766 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4767 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4770 | if (!isImsAvailableOnDevice()) { |
| 4771 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4772 | "IMS not available on device."); |
| 4773 | } |
| 4774 | int slotId = getSlotIndexOrException(subId); |
| 4775 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4776 | ImsManager.getInstance(mApp, slotId) |
| 4777 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4778 | } catch (ImsException e) { |
| 4779 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4780 | } finally { |
| 4781 | Binder.restoreCallingIdentity(identity); |
| 4782 | } |
| 4783 | } |
| 4784 | |
| 4785 | @Override |
| 4786 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4787 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4788 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4789 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4790 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4791 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4792 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4793 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4794 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4795 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4796 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4797 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4798 | + "is inactive, ignoring unregister."); |
| 4799 | // If the subscription is no longer active, just return, since the callback will already |
| 4800 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
| 4804 | } |
| 4805 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4806 | @Override |
| 4807 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4808 | IFeatureProvisioningCallback callback) { |
| 4809 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4810 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4811 | |
| 4812 | final long identity = Binder.clearCallingIdentity(); |
| 4813 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4814 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4815 | } |
| 4816 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4817 | try { |
| 4818 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4819 | if (controller == null) { |
| 4820 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4821 | "Device does not support IMS"); |
| 4822 | } |
| 4823 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4824 | } finally { |
| 4825 | Binder.restoreCallingIdentity(identity); |
| 4826 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | @Override |
| 4830 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4831 | IFeatureProvisioningCallback callback) { |
| 4832 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4833 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4834 | |
| 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4837 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4838 | } |
| 4839 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4840 | try { |
| 4841 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4842 | if (controller == null) { |
| 4843 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4844 | return; |
| 4845 | } |
| 4846 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4850 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4851 | |
| 4852 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4853 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4854 | message); |
| 4855 | } |
| 4856 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4857 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4858 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4859 | boolean isProvisioned) { |
| 4860 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4861 | |
| 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4864 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4865 | if (controller == null) { |
| 4866 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4867 | return; |
| 4868 | } |
| 4869 | controller.setRcsProvisioningStatusForCapability( |
| 4870 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | |
| 4877 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4878 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4879 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4880 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4881 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4882 | final long identity = Binder.clearCallingIdentity(); |
| 4883 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4884 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4885 | if (controller == null) { |
| 4886 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4887 | |
| 4888 | // device does not support IMS, this method will return true always. |
| 4889 | return true; |
| 4890 | } |
| 4891 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4892 | } finally { |
| 4893 | Binder.restoreCallingIdentity(identity); |
| 4894 | } |
| 4895 | } |
| 4896 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4897 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4898 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4899 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4900 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4901 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4902 | final long identity = Binder.clearCallingIdentity(); |
| 4903 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4904 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4905 | if (controller == null) { |
| 4906 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4907 | return; |
| 4908 | } |
| 4909 | controller.setImsProvisioningStatusForCapability( |
| 4910 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(identity); |
| 4913 | } |
| 4914 | } |
| 4915 | |
| 4916 | @Override |
| 4917 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4918 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4919 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4920 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4921 | final long identity = Binder.clearCallingIdentity(); |
| 4922 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4923 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4924 | if (controller == null) { |
| 4925 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4926 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4927 | // device does not support IMS, this method will return true always. |
| 4928 | return true; |
| 4929 | } |
| 4930 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4931 | } finally { |
| 4932 | Binder.restoreCallingIdentity(identity); |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4937 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4938 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4939 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4940 | |
| 4941 | final long identity = Binder.clearCallingIdentity(); |
| 4942 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4943 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4944 | if (controller == null) { |
| 4945 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4946 | |
| 4947 | // device does not support IMS, this method will return false |
| 4948 | return false; |
| 4949 | } |
| 4950 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4953 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4957 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4958 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4959 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4960 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4961 | final long identity = Binder.clearCallingIdentity(); |
| 4962 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4963 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4964 | if (controller == null) { |
| 4965 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4966 | |
| 4967 | // device does not support IMS, this method will return false |
| 4968 | return false; |
| 4969 | } |
| 4970 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4974 | } |
| 4975 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4976 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4977 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4978 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4979 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4980 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4981 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4982 | mApp, subId, "getImsProvisioningInt"); |
| 4983 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | try { |
| 4986 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4987 | int slotId = getSlotIndex(subId); |
| 4988 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4989 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4990 | + subId + "' for key:" + key); |
| 4991 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4992 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4993 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4994 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4995 | if (controller == null) { |
| 4996 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4997 | |
| 4998 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4999 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5000 | } |
| 5001 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5002 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5003 | return retVal; |
| 5004 | } |
| 5005 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5006 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5007 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5008 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5009 | + subId + "' for key:" + key); |
| 5010 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
| 5014 | } |
| 5015 | |
| 5016 | @Override |
| 5017 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5018 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5019 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5020 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5021 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5022 | mApp, subId, "getImsProvisioningString"); |
| 5023 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5024 | final long identity = Binder.clearCallingIdentity(); |
| 5025 | try { |
| 5026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5027 | int slotId = getSlotIndex(subId); |
| 5028 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5029 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5030 | + subId + "' for key:" + key); |
| 5031 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5032 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5033 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5034 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5035 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5036 | + subId + "' for key:" + key); |
| 5037 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5038 | } finally { |
| 5039 | Binder.restoreCallingIdentity(identity); |
| 5040 | } |
| 5041 | } |
| 5042 | |
| 5043 | @Override |
| 5044 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5045 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5046 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5047 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5049 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5050 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5051 | final long identity = Binder.clearCallingIdentity(); |
| 5052 | try { |
| 5053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5054 | int slotId = getSlotIndex(subId); |
| 5055 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5056 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5057 | + subId + "' for key:" + key); |
| 5058 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5059 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5060 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5061 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5062 | if (controller == null) { |
| 5063 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5064 | |
| 5065 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5066 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5067 | } |
| 5068 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5069 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5070 | return retVal; |
| 5071 | } |
| 5072 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5073 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5074 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5075 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5076 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5077 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5078 | } finally { |
| 5079 | Binder.restoreCallingIdentity(identity); |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | @Override |
| 5084 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5085 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5086 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5087 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5089 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
| 5092 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5093 | int slotId = getSlotIndex(subId); |
| 5094 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5095 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5096 | + subId + "' for key:" + key); |
| 5097 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5098 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5099 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5100 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5101 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5102 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5103 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5104 | } finally { |
| 5105 | Binder.restoreCallingIdentity(identity); |
| 5106 | } |
| 5107 | } |
| 5108 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5109 | /** |
| 5110 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5111 | * for the given slot ID or no ImsResolver instance has been created. |
| 5112 | * @param slotId The slot ID that the IMS service is created for. |
| 5113 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5114 | */ |
| 5115 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5116 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5117 | ImsFeature.FEATURE_MMTEL)) { |
| 5118 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5119 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5120 | } |
| 5121 | } |
| 5122 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5123 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5124 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5125 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5126 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5127 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5128 | } |
| 5129 | return slotId; |
| 5130 | } |
| 5131 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5132 | private int getSlotIndex(int subId) { |
| 5133 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5134 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5135 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5136 | } |
| 5137 | return slotId; |
| 5138 | } |
| 5139 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5140 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5141 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5142 | */ |
| 5143 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5144 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5145 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5146 | try { |
| 5147 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5148 | } catch (SecurityException se) { |
| 5149 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5150 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5151 | + Binder.getCallingUid()); |
| 5152 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5153 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5154 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5155 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5156 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5157 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5158 | mApp, subId, callingPackage, callingFeatureId, |
| 5159 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5160 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5161 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | final long identity = Binder.clearCallingIdentity(); |
| 5164 | try { |
| 5165 | final Phone phone = getPhone(subId); |
| 5166 | if (phone != null) { |
| 5167 | return phone.getServiceState().getDataNetworkType(); |
| 5168 | } else { |
| 5169 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5170 | } |
| 5171 | } finally { |
| 5172 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5173 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | /** |
| 5177 | * Returns the data network type |
| 5178 | */ |
| 5179 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5180 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5181 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5182 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | /** |
| 5186 | * Returns the data network type for a subId |
| 5187 | */ |
| 5188 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5189 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5190 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5191 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5192 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5193 | mApp, functionName)) { |
| 5194 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5195 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5196 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5197 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5198 | } |
| 5199 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5200 | final long identity = Binder.clearCallingIdentity(); |
| 5201 | try { |
| 5202 | final Phone phone = getPhone(subId); |
| 5203 | if (phone != null) { |
| 5204 | return phone.getServiceState().getDataNetworkType(); |
| 5205 | } else { |
| 5206 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5207 | } |
| 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5214 | * Returns the Voice network type for a subId |
| 5215 | */ |
| 5216 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5217 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5218 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5219 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5220 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5221 | mApp, functionName)) { |
| 5222 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5223 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5224 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5225 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5226 | } |
| 5227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | final long identity = Binder.clearCallingIdentity(); |
| 5229 | try { |
| 5230 | final Phone phone = getPhone(subId); |
| 5231 | if (phone != null) { |
| 5232 | return phone.getServiceState().getVoiceNetworkType(); |
| 5233 | } else { |
| 5234 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5235 | } |
| 5236 | } finally { |
| 5237 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | /** |
| 5242 | * @return true if a ICC card is present |
| 5243 | */ |
| 5244 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5245 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5246 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5247 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5248 | } |
| 5249 | |
| 5250 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5251 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5252 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5253 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5254 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | try { |
| 5257 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5258 | if (phone != null) { |
| 5259 | return phone.getIccCard().hasIccCard(); |
| 5260 | } else { |
| 5261 | return false; |
| 5262 | } |
| 5263 | } finally { |
| 5264 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5265 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5266 | } |
| 5267 | |
| 5268 | /** |
| 5269 | * Return if the current radio is LTE on CDMA. This |
| 5270 | * is a tri-state return value as for a period of time |
| 5271 | * the mode may be unknown. |
| 5272 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5273 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5274 | * @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] | 5275 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5276 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5277 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5278 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5279 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5280 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5283 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5284 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5285 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5286 | try { |
| 5287 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5288 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5289 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5290 | } |
| 5291 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | final long identity = Binder.clearCallingIdentity(); |
| 5293 | try { |
| 5294 | final Phone phone = getPhone(subId); |
| 5295 | if (phone == null) { |
| 5296 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5297 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5298 | return TelephonyProperties.lte_on_cdma_device() |
| 5299 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | } |
| 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5303 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5306 | /** |
| 5307 | * {@hide} |
| 5308 | * Returns Default subId, 0 in the case of single standby. |
| 5309 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5310 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5311 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5312 | } |
| 5313 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5314 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5315 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5318 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5319 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5320 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5321 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5322 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5323 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 5324 | return SubscriptionManagerService.getInstance().isActiveSubId(subId, |
| 5325 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5326 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5327 | return mSubscriptionController.isActiveSubId(subId); |
| 5328 | } |
| 5329 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5330 | /** |
| 5331 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5332 | */ |
| 5333 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | final long identity = Binder.clearCallingIdentity(); |
| 5335 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5336 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5338 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5339 | } finally { |
| 5340 | Binder.restoreCallingIdentity(identity); |
| 5341 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | /** |
| 5345 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5346 | */ |
| 5347 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5351 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
| 5355 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5356 | } |
| 5357 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5358 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5359 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5360 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5361 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5362 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5363 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5364 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5365 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5366 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5367 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5368 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5369 | } |
| 5370 | return PhoneFactory.getPhone(phoneId); |
| 5371 | } |
| 5372 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5373 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5374 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5375 | @NonNull IccLogicalChannelRequest request) { |
| 5376 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5377 | /*message=*/ "iccOpenLogicalChannel"); |
| 5378 | |
| 5379 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5380 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5381 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5382 | |
| 5383 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5384 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5385 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5386 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5387 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5388 | Phone phone; |
| 5389 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5391 | mApp, request.subId, message); |
| 5392 | phone = getPhoneFromSubId(request.subId); |
| 5393 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5394 | enforceModifyPermission(); |
| 5395 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5396 | } else { |
| 5397 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5398 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5399 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5403 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5406 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5408 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5409 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5410 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5411 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | loge("The calling package is not allowed to access ISD-R."); |
| 5413 | throw new SecurityException( |
| 5414 | "The calling package is not allowed to access ISD-R."); |
| 5415 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5416 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5417 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5418 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5419 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5420 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5421 | return response; |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5428 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5429 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5430 | /*message=*/"iccCloseLogicalChannel"); |
| 5431 | |
| 5432 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5433 | |
| 5434 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5435 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5436 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5437 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5438 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5439 | // before this feature is enabled, this API should only return false if |
| 5440 | // the operation fails instead of throwing runtime exception for |
| 5441 | // backward-compatibility. |
| 5442 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5443 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5444 | final long identity = Binder.clearCallingIdentity(); |
| 5445 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5446 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5447 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5448 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5449 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5450 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5451 | Boolean success = false; |
| 5452 | if (result instanceof RuntimeException) { |
| 5453 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5454 | if (shouldThrowExceptionOnFailure) { |
| 5455 | throw (RuntimeException) result; |
| 5456 | } else { |
| 5457 | return false; |
| 5458 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5459 | } else if (result instanceof Boolean) { |
| 5460 | success = (Boolean) result; |
| 5461 | } else { |
| 5462 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5463 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5464 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5465 | return success; |
| 5466 | } finally { |
| 5467 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5468 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5472 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5473 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5475 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5476 | if (DBG) { |
| 5477 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5478 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5479 | + p3 + " data=" + data); |
| 5480 | } |
| 5481 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5482 | command, p1, p2, p3, data); |
| 5483 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5484 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5485 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5486 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5487 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5488 | enforceModifyPermission(); |
| 5489 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5490 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5491 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5492 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5493 | } |
| 5494 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5495 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5496 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5497 | } |
| 5498 | |
| 5499 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5500 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5501 | final long identity = Binder.clearCallingIdentity(); |
| 5502 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5503 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | return ""; |
| 5505 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5506 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5508 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5509 | null /* workSource */); |
| 5510 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | // Append the returned status code to the end of the response payload. |
| 5513 | String s = Integer.toHexString( |
| 5514 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5515 | if (response.payload != null) { |
| 5516 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5517 | } |
| 5518 | return s; |
| 5519 | } finally { |
| 5520 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5521 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5522 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5523 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5524 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5525 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5526 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5528 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5530 | if (DBG) { |
| 5531 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5532 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5533 | } |
| 5534 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5535 | cla, command, p1, p2, p3, data); |
| 5536 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5537 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5538 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5539 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5540 | 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] | 5541 | enforceModifyPermission(); |
| 5542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5543 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5544 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5545 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5546 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5550 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5551 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5555 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5556 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
| 5559 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5560 | && TextUtils.equals(ISDR_AID, data)) { |
| 5561 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5562 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5563 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | if (bestComponent == null |
| 5565 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5566 | loge("The calling package is not allowed to select ISD-R."); |
| 5567 | throw new SecurityException( |
| 5568 | "The calling package is not allowed to select ISD-R."); |
| 5569 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5570 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5571 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5572 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5573 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5574 | null /* workSource */); |
| 5575 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | // Append the returned status code to the end of the response payload. |
| 5578 | String s = Integer.toHexString( |
| 5579 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5580 | if (response.payload != null) { |
| 5581 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5582 | } |
| 5583 | return s; |
| 5584 | } finally { |
| 5585 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5586 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5590 | 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] | 5591 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5592 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5593 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5594 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | final long identity = Binder.clearCallingIdentity(); |
| 5596 | try { |
| 5597 | if (DBG) { |
| 5598 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5599 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5600 | } |
| 5601 | |
| 5602 | IccIoResult response = |
| 5603 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5604 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5605 | subId); |
| 5606 | |
| 5607 | if (DBG) { |
| 5608 | log("Exchange SIM_IO [R]" + response); |
| 5609 | } |
| 5610 | |
| 5611 | byte[] result = null; |
| 5612 | int length = 2; |
| 5613 | if (response.payload != null) { |
| 5614 | length = 2 + response.payload.length; |
| 5615 | result = new byte[length]; |
| 5616 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5617 | } else { |
| 5618 | result = new byte[length]; |
| 5619 | } |
| 5620 | |
| 5621 | result[length - 1] = (byte) response.sw2; |
| 5622 | result[length - 2] = (byte) response.sw1; |
| 5623 | return result; |
| 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5626 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5627 | } |
| 5628 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5629 | /** |
| 5630 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5631 | * on a particular subscription |
| 5632 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5633 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5634 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5636 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5637 | return null; |
| 5638 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5643 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5644 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5645 | return null; |
| 5646 | } |
| 5647 | Object response = sendRequest( |
| 5648 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5649 | if (response instanceof String[]) { |
| 5650 | return (String[]) response; |
| 5651 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5652 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5654 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | } finally { |
| 5656 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5657 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5658 | } |
| 5659 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5660 | /** |
| 5661 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5662 | * subscription. |
| 5663 | * |
| 5664 | * @param subId the id of the subscription. |
| 5665 | * @param appType the uicc app type, must be USIM or SIM. |
| 5666 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5667 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5668 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5669 | * @return number of fplmns that is successfully written to the SIM. |
| 5670 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5671 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5672 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5673 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5674 | mApp, subId, "setForbiddenPlmns"); |
| 5675 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5676 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5677 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5678 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5679 | } |
| 5680 | if (fplmns == null) { |
| 5681 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5682 | } |
| 5683 | for (String fplmn : fplmns) { |
| 5684 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5685 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5686 | } |
| 5687 | } |
| 5688 | final long identity = Binder.clearCallingIdentity(); |
| 5689 | try { |
| 5690 | Object response = sendRequest( |
| 5691 | CMD_SET_FORBIDDEN_PLMNS, |
| 5692 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5693 | subId); |
| 5694 | return (int) response; |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
| 5698 | } |
| 5699 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5700 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5701 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5703 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | final long identity = Binder.clearCallingIdentity(); |
| 5706 | try { |
| 5707 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5708 | if (response.payload == null) { |
| 5709 | return ""; |
| 5710 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | // Append the returned status code to the end of the response payload. |
| 5713 | String s = Integer.toHexString( |
| 5714 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5715 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5716 | return s; |
| 5717 | } finally { |
| 5718 | Binder.restoreCallingIdentity(identity); |
| 5719 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5720 | } |
| 5721 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5722 | /** |
| 5723 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5724 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5725 | * |
| 5726 | * @param itemID the ID of the item to read |
| 5727 | * @return the NV item as a String, or null on error. |
| 5728 | */ |
| 5729 | @Override |
| 5730 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5731 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5732 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5733 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5734 | |
| 5735 | final long identity = Binder.clearCallingIdentity(); |
| 5736 | try { |
| 5737 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5738 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5740 | return value; |
| 5741 | } finally { |
| 5742 | Binder.restoreCallingIdentity(identity); |
| 5743 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /** |
| 5747 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5748 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5749 | * |
| 5750 | * @param itemID the ID of the item to read |
| 5751 | * @param itemValue the value to write, as a String |
| 5752 | * @return true on success; false on any failure |
| 5753 | */ |
| 5754 | @Override |
| 5755 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5756 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5758 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5759 | |
| 5760 | final long identity = Binder.clearCallingIdentity(); |
| 5761 | try { |
| 5762 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5763 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5764 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5766 | return success; |
| 5767 | } finally { |
| 5768 | Binder.restoreCallingIdentity(identity); |
| 5769 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | /** |
| 5773 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5774 | * Used for device configuration by some CDMA operators. |
| 5775 | * |
| 5776 | * @param preferredRoamingList byte array containing the new PRL |
| 5777 | * @return true on success; false on any failure |
| 5778 | */ |
| 5779 | @Override |
| 5780 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5782 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5783 | |
| 5784 | final long identity = Binder.clearCallingIdentity(); |
| 5785 | try { |
| 5786 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5787 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5788 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5789 | return success; |
| 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
| 5792 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5796 | * 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] | 5797 | * Used for device configuration by some CDMA operators. |
| 5798 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5799 | * @param slotIndex - device slot. |
| 5800 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5801 | * @return true on success; false on any failure |
| 5802 | */ |
| 5803 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5804 | public boolean resetModemConfig(int slotIndex) { |
| 5805 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5806 | if (phone != null) { |
| 5807 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5808 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5810 | final long identity = Binder.clearCallingIdentity(); |
| 5811 | try { |
| 5812 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5813 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5814 | return success; |
| 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
| 5817 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5819 | return false; |
| 5820 | } |
| 5821 | |
| 5822 | /** |
| 5823 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5824 | * |
| 5825 | * @param slotIndex - device slot. |
| 5826 | * |
| 5827 | * @return true on success; false on any failure |
| 5828 | */ |
| 5829 | @Override |
| 5830 | public boolean rebootModem(int slotIndex) { |
| 5831 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5832 | if (phone != null) { |
| 5833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5834 | mApp, phone.getSubId(), "rebootModem"); |
| 5835 | |
| 5836 | final long identity = Binder.clearCallingIdentity(); |
| 5837 | try { |
| 5838 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5839 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5840 | return success; |
| 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
| 5843 | } |
| 5844 | } |
| 5845 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5846 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5847 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5848 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5849 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5850 | * {@link #disableIms(int)}. |
| 5851 | * @param slotIndex device slot. |
| 5852 | */ |
| 5853 | public void resetIms(int slotIndex) { |
| 5854 | enforceModifyPermission(); |
| 5855 | |
| 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
| 5858 | if (mImsResolver == null) { |
| 5859 | // may happen if the does not support IMS. |
| 5860 | return; |
| 5861 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5862 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5863 | } finally { |
| 5864 | Binder.restoreCallingIdentity(identity); |
| 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5869 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5870 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5871 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5872 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5873 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5874 | |
| 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5878 | // may happen if the device does not support IMS. |
| 5879 | return; |
| 5880 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5881 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | } finally { |
| 5883 | Binder.restoreCallingIdentity(identity); |
| 5884 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5888 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5889 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5890 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5891 | public void disableIms(int slotId) { |
| 5892 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | |
| 5894 | final long identity = Binder.clearCallingIdentity(); |
| 5895 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5896 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5897 | // may happen if the device does not support IMS. |
| 5898 | return; |
| 5899 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5900 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | } finally { |
| 5902 | Binder.restoreCallingIdentity(identity); |
| 5903 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5907 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5908 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5909 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5910 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5911 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5912 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | |
| 5914 | final long identity = Binder.clearCallingIdentity(); |
| 5915 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5916 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5917 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5918 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5919 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5920 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5921 | } finally { |
| 5922 | Binder.restoreCallingIdentity(identity); |
| 5923 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5924 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5925 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5926 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5927 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5928 | @Override |
| 5929 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5930 | enforceModifyPermission(); |
| 5931 | |
| 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
| 5934 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5935 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5936 | } finally { |
| 5937 | Binder.restoreCallingIdentity(identity); |
| 5938 | } |
| 5939 | } |
| 5940 | |
| 5941 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5942 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5943 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5944 | */ |
| 5945 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5946 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5947 | |
| 5948 | final long identity = Binder.clearCallingIdentity(); |
| 5949 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5950 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5951 | // may happen if the device does not support IMS. |
| 5952 | return null; |
| 5953 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5954 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5958 | } |
| 5959 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5960 | /** |
| 5961 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5962 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5963 | */ |
| 5964 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5965 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5966 | |
| 5967 | final long identity = Binder.clearCallingIdentity(); |
| 5968 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5969 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5970 | // may happen if the device does not support IMS. |
| 5971 | return null; |
| 5972 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5973 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | } finally { |
| 5975 | Binder.restoreCallingIdentity(identity); |
| 5976 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5977 | } |
| 5978 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5979 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5980 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5981 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5982 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5983 | * @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] | 5984 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5985 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5986 | * @param packageName The name of the package that the current configuration will be replaced |
| 5987 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5988 | * @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] | 5989 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5990 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5991 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 5994 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5995 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5996 | final long identity = Binder.clearCallingIdentity(); |
| 5997 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5998 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5999 | // may happen if the device does not support IMS. |
| 6000 | return false; |
| 6001 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6002 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6003 | for (int featureType : featureTypes) { |
| 6004 | featureConfig.put(featureType, packageName); |
| 6005 | } |
| 6006 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6007 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | } finally { |
| 6009 | Binder.restoreCallingIdentity(identity); |
| 6010 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
| 6013 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6014 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6015 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6016 | * |
| 6017 | * This should only be used for testing. |
| 6018 | * |
| 6019 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6020 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6021 | */ |
| 6022 | @Override |
| 6023 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6024 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6025 | "clearCarrierImsServiceOverride"); |
| 6026 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6027 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6028 | |
| 6029 | final long identity = Binder.clearCallingIdentity(); |
| 6030 | try { |
| 6031 | if (mImsResolver == null) { |
| 6032 | // may happen if the device does not support IMS. |
| 6033 | return false; |
| 6034 | } |
| 6035 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
| 6038 | } |
| 6039 | } |
| 6040 | |
| 6041 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6042 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6043 | * |
| 6044 | * @param slotId The slot that the ImsService is associated with. |
| 6045 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6046 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6047 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6048 | * @return the package name of the ImsService configuration. |
| 6049 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6050 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6051 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6052 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6053 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6054 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | final long identity = Binder.clearCallingIdentity(); |
| 6057 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6058 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6059 | // may happen if the device does not support IMS. |
| 6060 | return ""; |
| 6061 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6062 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6063 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6064 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | } finally { |
| 6066 | Binder.restoreCallingIdentity(identity); |
| 6067 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6068 | } |
| 6069 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6070 | /** |
| 6071 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6072 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6073 | * @param callback A callback with an integer containing the |
| 6074 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6075 | */ |
| 6076 | @Override |
| 6077 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6078 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6079 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6080 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6081 | "IMS not available on device."); |
| 6082 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6083 | final long token = Binder.clearCallingIdentity(); |
| 6084 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6085 | int slotId = getSlotIndex(subId); |
| 6086 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6087 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6088 | + subId + "'"); |
| 6089 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6090 | } |
| 6091 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6092 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6093 | try { |
| 6094 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6095 | } catch (RemoteException e) { |
| 6096 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6097 | + "Ignore"); |
| 6098 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6099 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6100 | } catch (ImsException e) { |
| 6101 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(token); |
| 6104 | } |
| 6105 | } |
| 6106 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6107 | /** |
| 6108 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6109 | */ |
| 6110 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6111 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6112 | |
| 6113 | final long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6115 | // NOTE: Before S, this method only set the default phone. |
| 6116 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6117 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6118 | phone.setImsRegistrationState(registered); |
| 6119 | } |
| 6120 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6121 | } finally { |
| 6122 | Binder.restoreCallingIdentity(identity); |
| 6123 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
| 6126 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6127 | * Set the network selection mode to automatic. |
| 6128 | * |
| 6129 | */ |
| 6130 | @Override |
| 6131 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6133 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | |
| 6135 | final long identity = Binder.clearCallingIdentity(); |
| 6136 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6137 | if (!isActiveSubscription(subId)) { |
| 6138 | return; |
| 6139 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6141 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6142 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | } finally { |
| 6144 | Binder.restoreCallingIdentity(identity); |
| 6145 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6146 | } |
| 6147 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6148 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6149 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6150 | * |
| 6151 | * @param subId the id of the subscription. |
| 6152 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6153 | * the operator to attach to. |
| 6154 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6155 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6156 | * normal network selection next time. |
| 6157 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6158 | */ |
| 6159 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6160 | public boolean setNetworkSelectionModeManual( |
| 6161 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6163 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6164 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6165 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6166 | if (!isActiveSubscription(subId)) { |
| 6167 | return false; |
| 6168 | } |
| 6169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6170 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6171 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6173 | if (DBG) { |
| 6174 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6175 | + " operator: " + operatorInfo); |
| 6176 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
| 6180 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6181 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6182 | /** |
| 6183 | * Get the manual network selection |
| 6184 | * |
| 6185 | * @param subId the id of the subscription. |
| 6186 | * |
| 6187 | * @return the previously saved user selected PLMN |
| 6188 | */ |
| 6189 | @Override |
| 6190 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6191 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6192 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6193 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6194 | |
| 6195 | final long identity = Binder.clearCallingIdentity(); |
| 6196 | try { |
| 6197 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6198 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6199 | } |
| 6200 | |
| 6201 | final Phone phone = getPhone(subId); |
| 6202 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6203 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6204 | } |
| 6205 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6206 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6207 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
| 6210 | } |
| 6211 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6212 | |
| 6213 | /** |
| 6214 | * Scans for available networks. |
| 6215 | */ |
| 6216 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6217 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6218 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6219 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6220 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6221 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6222 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6223 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6224 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6225 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6226 | .setCallingPid(Binder.getCallingPid()) |
| 6227 | .setCallingUid(Binder.getCallingUid()) |
| 6228 | .setMethod("getCellNetworkScanResults") |
| 6229 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6230 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6231 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6232 | .build()); |
| 6233 | switch (locationResult) { |
| 6234 | case DENIED_HARD: |
| 6235 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6236 | case DENIED_SOFT: |
| 6237 | return null; |
| 6238 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6240 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | try { |
| 6242 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6243 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6244 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6245 | } finally { |
| 6246 | Binder.restoreCallingIdentity(identity); |
| 6247 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6251 | * Get the call forwarding info, given the call forwarding reason. |
| 6252 | */ |
| 6253 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6254 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6255 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6256 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6257 | long identity = Binder.clearCallingIdentity(); |
| 6258 | try { |
| 6259 | if (DBG) { |
| 6260 | log("getCallForwarding: subId " + subId |
| 6261 | + " callForwardingReason" + callForwardingReason); |
| 6262 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6263 | |
| 6264 | Phone phone = getPhone(subId); |
| 6265 | if (phone == null) { |
| 6266 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6267 | callback.onError( |
| 6268 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6269 | } catch (RemoteException e) { |
| 6270 | // ignore |
| 6271 | } |
| 6272 | return; |
| 6273 | } |
| 6274 | |
| 6275 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6276 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6277 | @Override |
| 6278 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6279 | try { |
| 6280 | callback.onCallForwardingInfoAvailable(info); |
| 6281 | } catch (RemoteException e) { |
| 6282 | // ignore |
| 6283 | } |
| 6284 | } |
| 6285 | |
| 6286 | @Override |
| 6287 | public void onError(int error) { |
| 6288 | try { |
| 6289 | callback.onError(error); |
| 6290 | } catch (RemoteException e) { |
| 6291 | // ignore |
| 6292 | } |
| 6293 | } |
| 6294 | }); |
| 6295 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6296 | } finally { |
| 6297 | Binder.restoreCallingIdentity(identity); |
| 6298 | } |
| 6299 | } |
| 6300 | |
| 6301 | /** |
| 6302 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6303 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6304 | */ |
| 6305 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6306 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6307 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6308 | enforceModifyPermission(); |
| 6309 | long identity = Binder.clearCallingIdentity(); |
| 6310 | try { |
| 6311 | if (DBG) { |
| 6312 | log("setCallForwarding: subId " + subId |
| 6313 | + " callForwardingInfo" + callForwardingInfo); |
| 6314 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6315 | |
| 6316 | Phone phone = getPhone(subId); |
| 6317 | if (phone == null) { |
| 6318 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6319 | callback.accept( |
| 6320 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6321 | } catch (RemoteException e) { |
| 6322 | // ignore |
| 6323 | } |
| 6324 | return; |
| 6325 | } |
| 6326 | |
| 6327 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6328 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6329 | |
| 6330 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6331 | } finally { |
| 6332 | Binder.restoreCallingIdentity(identity); |
| 6333 | } |
| 6334 | } |
| 6335 | |
| 6336 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6337 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6338 | */ |
| 6339 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6340 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6341 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6342 | long identity = Binder.clearCallingIdentity(); |
| 6343 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6344 | Phone phone = getPhone(subId); |
| 6345 | if (phone == null) { |
| 6346 | try { |
| 6347 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6348 | } catch (RemoteException e) { |
| 6349 | // ignore |
| 6350 | } |
| 6351 | return; |
| 6352 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6353 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6354 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6355 | boolean requireUssd = c.getBoolean( |
| 6356 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6357 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6358 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6359 | if (requireUssd) { |
| 6360 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6361 | getSubscriptionCarrierId(subId)); |
| 6362 | String newUssdCommand = ""; |
| 6363 | try { |
| 6364 | newUssdCommand = carrierXmlParser.getFeature( |
| 6365 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6366 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6367 | } catch (NullPointerException e) { |
| 6368 | loge("Failed to generate USSD number" + e); |
| 6369 | } |
| 6370 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6371 | mMainThreadHandler, callback, carrierXmlParser, |
| 6372 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6373 | final String ussdCommand = newUssdCommand; |
| 6374 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6375 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6376 | }); |
| 6377 | } else { |
| 6378 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6379 | callback::accept); |
| 6380 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6381 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6388 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6389 | */ |
| 6390 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6391 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6392 | enforceModifyPermission(); |
| 6393 | long identity = Binder.clearCallingIdentity(); |
| 6394 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6395 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6396 | |
| 6397 | Phone phone = getPhone(subId); |
| 6398 | if (phone == null) { |
| 6399 | try { |
| 6400 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6401 | } catch (RemoteException e) { |
| 6402 | // ignore |
| 6403 | } |
| 6404 | return; |
| 6405 | } |
| 6406 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6407 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6408 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6409 | boolean requireUssd = c.getBoolean( |
| 6410 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6411 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6412 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6413 | if (requireUssd) { |
| 6414 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6415 | getSubscriptionCarrierId(subId)); |
| 6416 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6417 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6418 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6419 | String newUssdCommand = ""; |
| 6420 | try { |
| 6421 | newUssdCommand = carrierXmlParser.getFeature( |
| 6422 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6423 | .makeCommand(ssAction, null); |
| 6424 | } catch (NullPointerException e) { |
| 6425 | loge("Failed to generate USSD number" + e); |
| 6426 | } |
| 6427 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6428 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6429 | final String ussdCommand = newUssdCommand; |
| 6430 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6431 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6432 | }); |
| 6433 | } else { |
| 6434 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6435 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6436 | |
| 6437 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6438 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6439 | } finally { |
| 6440 | Binder.restoreCallingIdentity(identity); |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6445 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6446 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6447 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6448 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6449 | * location related information which will be sent if the caller already possess |
| 6450 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6451 | * @param request contains the radio access networks with bands/channels to scan |
| 6452 | * @param messenger callback messenger for scan results or errors |
| 6453 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6454 | * @return the id of the requested scan which can be used to stop the scan. |
| 6455 | */ |
| 6456 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6457 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6458 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6459 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6461 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6462 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6463 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6464 | if (!renounceFineLocationAccess) { |
| 6465 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6466 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6467 | .setCallingPackage(callingPackage) |
| 6468 | .setCallingFeatureId(callingFeatureId) |
| 6469 | .setCallingPid(Binder.getCallingPid()) |
| 6470 | .setCallingUid(Binder.getCallingUid()) |
| 6471 | .setMethod("requestNetworkScan") |
| 6472 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6473 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6474 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6475 | .build()); |
| 6476 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6477 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6478 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6479 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6480 | if (e != null) { |
| 6481 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6482 | throw e; |
| 6483 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6484 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6485 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6486 | } |
| 6487 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6489 | int callingUid = Binder.getCallingUid(); |
| 6490 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6494 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6495 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6499 | } |
| 6500 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6501 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6502 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6503 | boolean hasCarrierPriv; |
| 6504 | final long identity = Binder.clearCallingIdentity(); |
| 6505 | try { |
| 6506 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6507 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6508 | } finally { |
| 6509 | Binder.restoreCallingIdentity(identity); |
| 6510 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6511 | boolean hasNetworkScanPermission = |
| 6512 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6513 | == PERMISSION_GRANTED; |
| 6514 | |
| 6515 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6516 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6517 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6521 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6522 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6523 | return new SecurityException("Specific channels must not be" |
| 6524 | + " scanned without location access."); |
| 6525 | } |
| 6526 | } |
| 6527 | } |
| 6528 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6529 | return null; |
| 6530 | } |
| 6531 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6532 | /** |
| 6533 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6534 | * |
| 6535 | * @param subId id of the subscription |
| 6536 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6537 | */ |
| 6538 | @Override |
| 6539 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6541 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6543 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6544 | final long identity = Binder.clearCallingIdentity(); |
| 6545 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6546 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | } finally { |
| 6548 | Binder.restoreCallingIdentity(identity); |
| 6549 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6553 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6554 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6555 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6556 | */ |
| 6557 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6558 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6559 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6560 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6561 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6562 | |
| 6563 | final long identity = Binder.clearCallingIdentity(); |
| 6564 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6565 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6566 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6567 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6568 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6569 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6570 | } finally { |
| 6571 | Binder.restoreCallingIdentity(identity); |
| 6572 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6573 | } |
| 6574 | |
| 6575 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6576 | * Get the allowed network types for certain reason. |
| 6577 | * |
| 6578 | * @param subId the id of the subscription. |
| 6579 | * @param reason the reason the allowed network type change is taking place |
| 6580 | * @return the allowed network types. |
| 6581 | */ |
| 6582 | @Override |
| 6583 | public long getAllowedNetworkTypesForReason(int subId, |
| 6584 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6585 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6586 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6587 | final long identity = Binder.clearCallingIdentity(); |
| 6588 | try { |
| 6589 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6590 | } finally { |
| 6591 | Binder.restoreCallingIdentity(identity); |
| 6592 | } |
| 6593 | } |
| 6594 | |
| 6595 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6596 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6597 | * @param subId subscription id of the sim card |
| 6598 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6599 | * This can be passed following states |
| 6600 | * <ol> |
| 6601 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6602 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6603 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6604 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6605 | * </ol> |
| 6606 | * @return operation result. |
| 6607 | */ |
| 6608 | @Override |
| 6609 | public int setNrDualConnectivityState(int subId, |
| 6610 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6612 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6613 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6614 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6615 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6616 | } |
| 6617 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6618 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6622 | nrDualConnectivityState, subId, |
| 6623 | workSource); |
| 6624 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6625 | return result; |
| 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | /** |
| 6632 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6633 | * @return true if dual connectivity is enabled else false |
| 6634 | */ |
| 6635 | @Override |
| 6636 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6637 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6638 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6639 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6640 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6641 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6642 | return false; |
| 6643 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6644 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6645 | final long identity = Binder.clearCallingIdentity(); |
| 6646 | try { |
| 6647 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6648 | null, subId, workSource); |
| 6649 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6650 | return isEnabled; |
| 6651 | } finally { |
| 6652 | Binder.restoreCallingIdentity(identity); |
| 6653 | } |
| 6654 | } |
| 6655 | |
| 6656 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6657 | * Set the allowed network types of the device and |
| 6658 | * provide the reason triggering the allowed network change. |
| 6659 | * |
| 6660 | * @param subId the id of the subscription. |
| 6661 | * @param reason the reason the allowed network type change is taking place |
| 6662 | * @param allowedNetworkTypes the allowed network types. |
| 6663 | * @return true on success; false on any failure. |
| 6664 | */ |
| 6665 | @Override |
| 6666 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6667 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6668 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6670 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6671 | // If the caller only has carrier privileges, then they should not be able to override |
| 6672 | // any network types which were set for security reasons. |
| 6673 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6674 | != PERMISSION_GRANTED |
| 6675 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6676 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6677 | throw new SecurityException( |
| 6678 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6679 | + " reason " |
| 6680 | + reason); |
| 6681 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6682 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6683 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6684 | return false; |
| 6685 | } |
| 6686 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6687 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6688 | return false; |
| 6689 | } |
| 6690 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6691 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6692 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6693 | |
| 6694 | |
| 6695 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6696 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6697 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6698 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6699 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6700 | final long identity = Binder.clearCallingIdentity(); |
| 6701 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6702 | Boolean success = (Boolean) sendRequest( |
| 6703 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6704 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6705 | |
| 6706 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6707 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
| 6710 | } |
| 6711 | } |
| 6712 | |
| 6713 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6714 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6715 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6716 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6717 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6718 | * @hide |
| 6719 | */ |
| 6720 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6721 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6722 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6724 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6725 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6726 | if (phone != null) { |
| 6727 | return phone.hasMatchedTetherApnSetting(); |
| 6728 | } else { |
| 6729 | return false; |
| 6730 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6733 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6734 | } |
| 6735 | |
| 6736 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6737 | * Get the user enabled state of Mobile Data. |
| 6738 | * |
| 6739 | * TODO: remove and use isUserDataEnabled. |
| 6740 | * This can't be removed now because some vendor codes |
| 6741 | * calls through ITelephony directly while they should |
| 6742 | * use TelephonyManager. |
| 6743 | * |
| 6744 | * @return true on enabled |
| 6745 | */ |
| 6746 | @Override |
| 6747 | public boolean getDataEnabled(int subId) { |
| 6748 | return isUserDataEnabled(subId); |
| 6749 | } |
| 6750 | |
| 6751 | /** |
| 6752 | * Get whether mobile data is enabled per user setting. |
| 6753 | * |
| 6754 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6755 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6756 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6757 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6758 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6759 | * |
| 6760 | * @return {@code true} if data is enabled else {@code false} |
| 6761 | */ |
| 6762 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6763 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6764 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6765 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6766 | try { |
| 6767 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6768 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6769 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6770 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6771 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6772 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6774 | mApp, subId, functionName); |
| 6775 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6776 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 | |
| 6778 | final long identity = Binder.clearCallingIdentity(); |
| 6779 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6780 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6782 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6783 | if (phone != null) { |
| 6784 | boolean retVal = phone.isUserDataEnabled(); |
| 6785 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6786 | return retVal; |
| 6787 | } else { |
| 6788 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6789 | return false; |
| 6790 | } |
| 6791 | } finally { |
| 6792 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6793 | } |
| 6794 | } |
| 6795 | |
| 6796 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6797 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6798 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6799 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6800 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6801 | * @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] | 6802 | */ |
| 6803 | @Override |
| 6804 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6805 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6806 | try { |
| 6807 | try { |
| 6808 | mApp.enforceCallingOrSelfPermission( |
| 6809 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6810 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6811 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6812 | try { |
| 6813 | mApp.enforceCallingOrSelfPermission( |
| 6814 | android.Manifest.permission.READ_PHONE_STATE, |
| 6815 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6816 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6817 | mApp.enforceCallingOrSelfPermission( |
| 6818 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6819 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6820 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6821 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6822 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6824 | |
| 6825 | final long identity = Binder.clearCallingIdentity(); |
| 6826 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6827 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6829 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6830 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6831 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6832 | return retVal; |
| 6833 | } else { |
| 6834 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6835 | return false; |
| 6836 | } |
| 6837 | } finally { |
| 6838 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6839 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6840 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6841 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6842 | /** |
| 6843 | * Check if data is enabled for a specific reason |
| 6844 | * @param subId Subscription index |
| 6845 | * @param reason the reason the data enable change is taking place |
| 6846 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6847 | */ |
| 6848 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6849 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6850 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6851 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6852 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6853 | try { |
| 6854 | mApp.enforceCallingOrSelfPermission( |
| 6855 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6856 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6857 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6858 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6859 | functionName); |
| 6860 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6861 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6862 | try { |
| 6863 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6864 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6865 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6867 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6868 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | |
| 6872 | final long identity = Binder.clearCallingIdentity(); |
| 6873 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6874 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6875 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6876 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6877 | + " reason=" + reason); |
| 6878 | } |
| 6879 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6880 | if (phone != null) { |
| 6881 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6882 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6883 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6884 | return retVal; |
| 6885 | } else { |
| 6886 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6887 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6888 | + subId + " retVal=false"); |
| 6889 | } |
| 6890 | return false; |
| 6891 | } |
| 6892 | } finally { |
| 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
| 6895 | } |
| 6896 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6897 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6898 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6899 | // No permission needed; this only lets the caller inspect their own status. |
| 6900 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6901 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6902 | |
| 6903 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6904 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6905 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6906 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6907 | } |
| 6908 | |
| 6909 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6910 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6911 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6912 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6913 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6914 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6915 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6916 | if (cpt == null) { |
| 6917 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6918 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6919 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6920 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6921 | } |
| 6922 | |
| 6923 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6924 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6925 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6926 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6927 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6928 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6929 | Phone phone = getPhone(subId); |
| 6930 | if (phone == null) { |
| 6931 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6932 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6933 | } |
| 6934 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6935 | if (cpt == null) { |
| 6936 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6937 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6938 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6939 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | @Override |
| 6943 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6944 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6945 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6946 | } |
| 6947 | |
| 6948 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6949 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6950 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6951 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6952 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6953 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6954 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6955 | if (phone == null) { |
| 6956 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6957 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6958 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6959 | if (cpt == null) { |
| 6960 | continue; |
| 6961 | } |
| 6962 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6963 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6964 | break; |
| 6965 | } |
| 6966 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6967 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6968 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6969 | |
| 6970 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6971 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6972 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6973 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6974 | if (phone == null) { |
| 6975 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6976 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6977 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6978 | if (cpt == null) { |
| 6979 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6980 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6981 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6984 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6985 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6986 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6987 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6988 | if (phone == null) { |
| 6989 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6990 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6991 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6992 | if (cpt == null) { |
| 6993 | return Collections.emptyList(); |
| 6994 | } |
| 6995 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6996 | } |
| 6997 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6998 | @Override |
| 6999 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7000 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7001 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7002 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7003 | try { |
| 7004 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7005 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7006 | } |
| 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7009 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7010 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7011 | } |
| 7012 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7013 | @Override |
| 7014 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7015 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7016 | |
| 7017 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7018 | if (phone == null) { |
| 7019 | return null; |
| 7020 | } |
| 7021 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7022 | if (cpt == null) { |
| 7023 | return null; |
| 7024 | } |
| 7025 | return cpt.getCarrierServicePackageName(); |
| 7026 | } |
| 7027 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7028 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7029 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7030 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7031 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7032 | return null; |
| 7033 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7034 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7035 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7036 | return null; |
| 7037 | } |
| 7038 | return iccId; |
| 7039 | } |
| 7040 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7041 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7042 | public void setCallComposerStatus(int subId, int status) { |
| 7043 | enforceModifyPermission(); |
| 7044 | |
| 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| 7047 | Phone phone = getPhone(subId); |
| 7048 | if (phone != null) { |
| 7049 | Phone defaultPhone = phone.getImsPhone(); |
| 7050 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7051 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7052 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7053 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7054 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7055 | } |
| 7056 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7057 | } catch (ImsException e) { |
| 7058 | throw new ServiceSpecificException(e.getCode()); |
| 7059 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
| 7062 | } |
| 7063 | |
| 7064 | @Override |
| 7065 | public int getCallComposerStatus(int subId) { |
| 7066 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7067 | |
| 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | Phone phone = getPhone(subId); |
| 7071 | if (phone != null) { |
| 7072 | Phone defaultPhone = phone.getImsPhone(); |
| 7073 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7074 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7075 | return imsPhone.getCallComposerStatus(); |
| 7076 | } |
| 7077 | } |
| 7078 | } finally { |
| 7079 | Binder.restoreCallingIdentity(identity); |
| 7080 | } |
| 7081 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7082 | } |
| 7083 | |
| 7084 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7085 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7086 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7087 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7088 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | final long identity = Binder.clearCallingIdentity(); |
| 7091 | try { |
| 7092 | final String iccId = getIccId(subId); |
| 7093 | final Phone phone = getPhone(subId); |
| 7094 | if (phone == null) { |
| 7095 | return false; |
| 7096 | } |
| 7097 | final String subscriberId = phone.getSubscriberId(); |
| 7098 | |
| 7099 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7100 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7101 | + subscriberId + " to " + number); |
| 7102 | } |
| 7103 | |
| 7104 | if (TextUtils.isEmpty(iccId)) { |
| 7105 | return false; |
| 7106 | } |
| 7107 | |
| 7108 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7109 | |
| 7110 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7111 | if (alphaTag == null) { |
| 7112 | editor.remove(alphaTagPrefKey); |
| 7113 | } else { |
| 7114 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7115 | } |
| 7116 | |
| 7117 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7118 | // track all merged IMSIs based on line number |
| 7119 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7120 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7121 | if (number == null) { |
| 7122 | editor.remove(numberPrefKey); |
| 7123 | editor.remove(subscriberPrefKey); |
| 7124 | } else { |
| 7125 | editor.putString(numberPrefKey, number); |
| 7126 | editor.putString(subscriberPrefKey, subscriberId); |
| 7127 | } |
| 7128 | |
| 7129 | editor.commit(); |
| 7130 | return true; |
| 7131 | } finally { |
| 7132 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7133 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7137 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7138 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7139 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7141 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7142 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7143 | return null; |
| 7144 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7145 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | final long identity = Binder.clearCallingIdentity(); |
| 7147 | try { |
| 7148 | String iccId = getIccId(subId); |
| 7149 | if (iccId != null) { |
| 7150 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7151 | if (DBG_MERGE) { |
| 7152 | log("getLine1NumberForDisplay returning " |
| 7153 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7154 | } |
| 7155 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7156 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7158 | return null; |
| 7159 | } finally { |
| 7160 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7161 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7162 | } |
| 7163 | |
| 7164 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7165 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7166 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7167 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7168 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7169 | return null; |
| 7170 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7172 | final long identity = Binder.clearCallingIdentity(); |
| 7173 | try { |
| 7174 | String iccId = getIccId(subId); |
| 7175 | if (iccId != null) { |
| 7176 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7177 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7178 | } |
| 7179 | return null; |
| 7180 | } finally { |
| 7181 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7182 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7183 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7184 | |
| 7185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7186 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7187 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7188 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7189 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7191 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7192 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7193 | return null; |
| 7194 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7195 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7196 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7197 | // the process, where TelephonyManager was instantiated. |
| 7198 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7201 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7202 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7203 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7204 | |
| 7205 | // Figure out what subscribers are currently active |
| 7206 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7207 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7208 | // Only consider subs which match the current subId |
| 7209 | // This logic can be simplified. See b/131189269 for progress. |
| 7210 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7211 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7212 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | |
| 7214 | // First pass, find a number override for an active subscriber |
| 7215 | String mergeNumber = null; |
| 7216 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7217 | for (String key : prefs.keySet()) { |
| 7218 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7219 | final String subscriberId = (String) prefs.get(key); |
| 7220 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7221 | final String iccId = key.substring( |
| 7222 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7223 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7224 | mergeNumber = (String) prefs.get(numberKey); |
| 7225 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7226 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | + " for active subscriber " + subscriberId); |
| 7228 | } |
| 7229 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7230 | break; |
| 7231 | } |
| 7232 | } |
| 7233 | } |
| 7234 | } |
| 7235 | |
| 7236 | // Shortcut when no active merged subscribers |
| 7237 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7238 | return null; |
| 7239 | } |
| 7240 | |
| 7241 | // Second pass, find all subscribers under that line override |
| 7242 | final ArraySet<String> result = new ArraySet<>(); |
| 7243 | for (String key : prefs.keySet()) { |
| 7244 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7245 | final String number = (String) prefs.get(key); |
| 7246 | if (mergeNumber.equals(number)) { |
| 7247 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7248 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7249 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7250 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7251 | result.add(subscriberId); |
| 7252 | } |
| 7253 | } |
| 7254 | } |
| 7255 | } |
| 7256 | |
| 7257 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7258 | Arrays.sort(resultArray); |
| 7259 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7260 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7261 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7262 | } |
| 7263 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7264 | } finally { |
| 7265 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7266 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7270 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7271 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7272 | |
| 7273 | final long identity = Binder.clearCallingIdentity(); |
| 7274 | try { |
| 7275 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7276 | TelephonyManager.class); |
| 7277 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7278 | if (subscriberId == null) { |
| 7279 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7280 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7281 | + subId); |
| 7282 | } |
| 7283 | return null; |
| 7284 | } |
| 7285 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7286 | ParcelUuid groupUuid; |
| 7287 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7288 | final SubscriptionInfo info = SubscriptionManagerService.getInstance() |
| 7289 | .getSubscriptionInfo(subId); |
| 7290 | groupUuid = info.getGroupUuid(); |
| 7291 | } else { |
| 7292 | final SubscriptionInfo info = mSubscriptionController |
| 7293 | .getSubscriptionInfo(subId); |
| 7294 | groupUuid = info.getGroupUuid(); |
| 7295 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7296 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7297 | if (groupUuid == null) { |
| 7298 | return new String[]{subscriberId}; |
| 7299 | } |
| 7300 | |
| 7301 | // Get all subscriberIds from the group. |
| 7302 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7303 | List<SubscriptionInfo> groupInfos; |
| 7304 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7305 | groupInfos = SubscriptionManagerService.getInstance() |
| 7306 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7307 | mApp.getAttributionTag()); |
| 7308 | } else { |
| 7309 | groupInfos = mSubscriptionController |
| 7310 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7311 | mApp.getAttributionTag()); |
| 7312 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7313 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7314 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7315 | if (subscriberId != null) { |
| 7316 | mergedSubscriberIds.add(subscriberId); |
| 7317 | } |
| 7318 | } |
| 7319 | |
| 7320 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7321 | } finally { |
| 7322 | Binder.restoreCallingIdentity(identity); |
| 7323 | |
| 7324 | } |
| 7325 | } |
| 7326 | |
| 7327 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7328 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7329 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7330 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 | |
| 7332 | final long identity = Binder.clearCallingIdentity(); |
| 7333 | try { |
| 7334 | final Phone phone = getPhone(subId); |
| 7335 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7336 | } finally { |
| 7337 | Binder.restoreCallingIdentity(identity); |
| 7338 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7339 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7340 | |
| 7341 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7342 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7343 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7344 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7345 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7346 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7347 | |
| 7348 | final long identity = Binder.clearCallingIdentity(); |
| 7349 | try { |
| 7350 | final Phone phone = getPhone(subId); |
| 7351 | if (phone == null) { |
| 7352 | return false; |
| 7353 | } |
| 7354 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7355 | cdmaNonRoamingList); |
| 7356 | } finally { |
| 7357 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7358 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7359 | } |
| 7360 | |
| 7361 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7362 | @Deprecated |
| 7363 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7364 | enforceModifyPermission(); |
| 7365 | |
| 7366 | int returnValue = 0; |
| 7367 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7368 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7369 | if(result.exception == null) { |
| 7370 | if (result.result != null) { |
| 7371 | byte[] responseData = (byte[])(result.result); |
| 7372 | if(responseData.length > oemResp.length) { |
| 7373 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7374 | responseData.length + "bytes. Buffer Size is " + |
| 7375 | oemResp.length + "bytes."); |
| 7376 | } |
| 7377 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7378 | returnValue = responseData.length; |
| 7379 | } |
| 7380 | } else { |
| 7381 | CommandException ex = (CommandException) result.exception; |
| 7382 | returnValue = ex.getCommandError().ordinal(); |
| 7383 | if(returnValue > 0) returnValue *= -1; |
| 7384 | } |
| 7385 | } catch (RuntimeException e) { |
| 7386 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7387 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7388 | if(returnValue > 0) returnValue *= -1; |
| 7389 | } |
| 7390 | |
| 7391 | return returnValue; |
| 7392 | } |
| 7393 | |
| 7394 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7395 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7396 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7397 | try { |
| 7398 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7399 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7400 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7401 | } catch (SecurityException e) { |
| 7402 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7403 | throw e; |
| 7404 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7405 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7406 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7407 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7408 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | final long identity = Binder.clearCallingIdentity(); |
| 7410 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7411 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7412 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7413 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7414 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7415 | } finally { |
| 7416 | Binder.restoreCallingIdentity(identity); |
| 7417 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7418 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7419 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7420 | |
| 7421 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7422 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7423 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7424 | try { |
| 7425 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7426 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7427 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7428 | } |
| 7429 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7430 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7431 | } |
| 7432 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7433 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7434 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7435 | throw new SecurityException("App must be the dialer role holder to" |
| 7436 | + " upload a call composer pic"); |
| 7437 | } |
| 7438 | |
| 7439 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7440 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7441 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7442 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7443 | boolean readUntilEnd = false; |
| 7444 | int totalBytesRead = 0; |
| 7445 | byte[] buffer = new byte[16 * 1024]; |
| 7446 | while (true) { |
| 7447 | int numRead; |
| 7448 | try { |
| 7449 | numRead = input.read(buffer); |
| 7450 | } catch (IOException e) { |
| 7451 | try { |
| 7452 | fd.checkError(); |
| 7453 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7454 | null); |
| 7455 | } catch (IOException e1) { |
| 7456 | // This means that the other side closed explicitly with an error. If this |
| 7457 | // happens, log and ignore. |
| 7458 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7459 | } |
| 7460 | break; |
| 7461 | } |
| 7462 | if (numRead == -1) { |
| 7463 | readUntilEnd = true; |
| 7464 | break; |
| 7465 | } |
| 7466 | totalBytesRead += numRead; |
| 7467 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7468 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7469 | try { |
| 7470 | input.close(); |
| 7471 | } catch (IOException e) { |
| 7472 | // ignore |
| 7473 | } |
| 7474 | break; |
| 7475 | } |
| 7476 | output.write(buffer, 0, numRead); |
| 7477 | } |
| 7478 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7479 | // close is above, where the picture size is too big. |
| 7480 | |
| 7481 | try { |
| 7482 | fd.checkError(); |
| 7483 | } catch (IOException e) { |
| 7484 | loge("Remote end for call composer closed with an error: " + e); |
| 7485 | return; |
| 7486 | } |
| 7487 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7488 | if (!readUntilEnd) { |
| 7489 | loge("Did not finish reading entire image; aborting"); |
| 7490 | return; |
| 7491 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7492 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7493 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7494 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7495 | new CallComposerPictureTransfer.Factory() {}, |
| 7496 | imageData, |
| 7497 | (result) -> { |
| 7498 | if (result.first != null) { |
| 7499 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7500 | Bundle outputResult = new Bundle(); |
| 7501 | outputResult.putParcelable( |
| 7502 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7503 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7504 | outputResult); |
| 7505 | } else { |
| 7506 | callback.send(result.second, null); |
| 7507 | } |
| 7508 | } |
| 7509 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7510 | }); |
| 7511 | } |
| 7512 | |
| 7513 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7514 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7515 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7516 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | |
| 7518 | final long identity = Binder.clearCallingIdentity(); |
| 7519 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7520 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7521 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | } finally { |
| 7523 | Binder.restoreCallingIdentity(identity); |
| 7524 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7525 | } |
| 7526 | |
| 7527 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7528 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7529 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7530 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7531 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7532 | return false; |
| 7533 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7535 | final long identity = Binder.clearCallingIdentity(); |
| 7536 | try { |
| 7537 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7538 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7539 | // In the long run, we may instead need to check if there exists a connection service |
| 7540 | // which can support video calling. |
| 7541 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7542 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7543 | return imsManager.isVtEnabledByPlatform() |
| 7544 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7545 | && imsManager.isVtEnabledByUser(); |
| 7546 | } finally { |
| 7547 | Binder.restoreCallingIdentity(identity); |
| 7548 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7549 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7550 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7551 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7552 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7553 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7555 | mApp, subId, callingPackage, callingFeatureId, |
| 7556 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | return false; |
| 7558 | } |
| 7559 | |
| 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | try { |
| 7562 | CarrierConfigManager configManager = |
| 7563 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7564 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7565 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7566 | } finally { |
| 7567 | Binder.restoreCallingIdentity(identity); |
| 7568 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7569 | } |
| 7570 | |
| 7571 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7572 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7574 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7575 | return false; |
| 7576 | } |
| 7577 | |
| 7578 | final long identity = Binder.clearCallingIdentity(); |
| 7579 | try { |
| 7580 | CarrierConfigManager configManager = |
| 7581 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7582 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7584 | } finally { |
| 7585 | Binder.restoreCallingIdentity(identity); |
| 7586 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7587 | } |
| 7588 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7589 | @Override |
| 7590 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7591 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7592 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | @Override |
| 7596 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7597 | final long identity = Binder.clearCallingIdentity(); |
| 7598 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7599 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | } finally { |
| 7601 | Binder.restoreCallingIdentity(identity); |
| 7602 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7605 | /** |
| 7606 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7607 | * support for the feature and device firmware support. |
| 7608 | * |
| 7609 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7610 | */ |
| 7611 | @Override |
| 7612 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7614 | final Phone phone = getPhone(subscriptionId); |
| 7615 | if (phone == null) { |
| 7616 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7617 | return false; |
| 7618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7619 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7620 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7622 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7623 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7624 | return isCarrierSupported && isDeviceSupported; |
| 7625 | } finally { |
| 7626 | Binder.restoreCallingIdentity(identity); |
| 7627 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7628 | } |
| 7629 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7630 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7631 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7632 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7633 | * 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] | 7634 | */ |
| 7635 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7636 | final long identity = Binder.clearCallingIdentity(); |
| 7637 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7638 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7639 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7640 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7641 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7642 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7643 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | } finally { |
| 7645 | Binder.restoreCallingIdentity(identity); |
| 7646 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7647 | } |
| 7648 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7649 | @Deprecated |
| 7650 | @Override |
| 7651 | public String getDeviceId(String callingPackage) { |
| 7652 | return getDeviceIdWithFeature(callingPackage, null); |
| 7653 | } |
| 7654 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7655 | /** |
| 7656 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7657 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7658 | * |
| 7659 | * <p>Requires Permission: |
| 7660 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7661 | */ |
| 7662 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7663 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7664 | try { |
| 7665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7666 | } catch (SecurityException se) { |
| 7667 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7668 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7669 | + Binder.getCallingUid()); |
| 7670 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7671 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7672 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7673 | return null; |
| 7674 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7675 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7676 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7677 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7678 | return null; |
| 7679 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | |
| 7681 | final long identity = Binder.clearCallingIdentity(); |
| 7682 | try { |
| 7683 | return phone.getDeviceId(); |
| 7684 | } finally { |
| 7685 | Binder.restoreCallingIdentity(identity); |
| 7686 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7687 | } |
| 7688 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7689 | /** |
| 7690 | * {@hide} |
| 7691 | * Returns the IMS Registration Status on a particular subid |
| 7692 | * |
| 7693 | * @param subId |
| 7694 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7695 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7696 | Phone phone = getPhone(subId); |
| 7697 | if (phone != null) { |
| 7698 | return phone.isImsRegistered(); |
| 7699 | } else { |
| 7700 | return false; |
| 7701 | } |
| 7702 | } |
| 7703 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7704 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7705 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7706 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7708 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7709 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7710 | } |
| 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
| 7713 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
| 7716 | } |
| 7717 | } |
| 7718 | |
| 7719 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7720 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7721 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7722 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7723 | mApp, |
| 7724 | subscriptionId, |
| 7725 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7726 | final long identity = Binder.clearCallingIdentity(); |
| 7727 | try { |
| 7728 | Phone phone = getPhone(subscriptionId); |
| 7729 | if (phone == null) { |
| 7730 | return null; |
| 7731 | } |
| 7732 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7733 | } finally { |
| 7734 | Binder.restoreCallingIdentity(identity); |
| 7735 | } |
| 7736 | } |
| 7737 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7738 | /** |
| 7739 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7740 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7741 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
| 7744 | Phone phone = getPhone(subId); |
| 7745 | if (phone != null) { |
| 7746 | return phone.isWifiCallingEnabled(); |
| 7747 | } else { |
| 7748 | return false; |
| 7749 | } |
| 7750 | } finally { |
| 7751 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7752 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7753 | } |
| 7754 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7755 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7756 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7757 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7758 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | final long identity = Binder.clearCallingIdentity(); |
| 7760 | try { |
| 7761 | Phone phone = getPhone(subId); |
| 7762 | if (phone != null) { |
| 7763 | return phone.isVideoEnabled(); |
| 7764 | } else { |
| 7765 | return false; |
| 7766 | } |
| 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | /** |
| 7773 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7774 | * defined in {@link ImsRegistrationImplBase}. |
| 7775 | */ |
| 7776 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7777 | final long identity = Binder.clearCallingIdentity(); |
| 7778 | try { |
| 7779 | Phone phone = getPhone(subId); |
| 7780 | if (phone != null) { |
| 7781 | return phone.getImsRegistrationTech(); |
| 7782 | } else { |
| 7783 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7784 | } |
| 7785 | } finally { |
| 7786 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7787 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7788 | } |
| 7789 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7790 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7791 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7792 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7793 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7794 | return; |
| 7795 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7796 | Phone defaultPhone = getDefaultPhone(); |
| 7797 | if (defaultPhone != null) { |
| 7798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7799 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7800 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7801 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7802 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7803 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7804 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7805 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7806 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7807 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7808 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7809 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7810 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7811 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7812 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7813 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7814 | // There has been issues when Sms raw table somehow stores orphan |
| 7815 | // fragments. They lead to garbled message when new fragments come |
| 7816 | // in and combined with those stale ones. In case this happens again, |
| 7817 | // user can reset all network settings which will clean up this table. |
| 7818 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7819 | // Clean up IMS settings as well here. |
| 7820 | int slotId = getSlotIndex(subId); |
| 7821 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7822 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7823 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7824 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7825 | if (defaultPhone == null) { |
| 7826 | return; |
| 7827 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7828 | // Erase modem config if erase modem on network setting is enabled. |
| 7829 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7830 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7831 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7832 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7833 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7834 | |
| 7835 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7836 | } finally { |
| 7837 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7838 | } |
| 7839 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7840 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7841 | @VisibleForTesting |
| 7842 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7843 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7844 | return; |
| 7845 | } |
| 7846 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7847 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7848 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7849 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7850 | "user=" + defaultNetworkType); |
| 7851 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7852 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7853 | defaultNetworkType, null); |
| 7854 | } |
| 7855 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7856 | private void cleanUpSmsRawTable(Context context) { |
| 7857 | ContentResolver resolver = context.getContentResolver(); |
| 7858 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7859 | resolver.delete(uri, null, null); |
| 7860 | } |
| 7861 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7862 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7863 | public String getSimLocaleForSubscriber(int subId) { |
| 7864 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7865 | final Phone phone = getPhone(subId); |
| 7866 | if (phone == null) { |
| 7867 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7868 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7869 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7872 | SubscriptionInfo info; |
| 7873 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7874 | info = SubscriptionManagerService.getInstance().getActiveSubscriptionInfo(subId, |
| 7875 | phone.getContext().getOpPackageName(), |
| 7876 | phone.getContext().getAttributionTag()); |
| 7877 | if (info == null) { |
| 7878 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7879 | return null; |
| 7880 | } |
| 7881 | } else { |
| 7882 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 7883 | phone.getContext().getOpPackageName(), |
| 7884 | phone.getContext().getAttributionTag()); |
| 7885 | if (info == null) { |
| 7886 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7887 | return null; |
| 7888 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7890 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7891 | // preferences (EF-PL and EF-LI)... |
| 7892 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7893 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7894 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7895 | if (localeFromDefaultSim != null) { |
| 7896 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7897 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7898 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7899 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7900 | } else { |
| 7901 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7902 | } |
| 7903 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7904 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7906 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7907 | // the SIM and carrier preferences does not include a country we add the country |
| 7908 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7909 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7910 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7911 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7912 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7913 | } |
| 7914 | |
| 7915 | if (DBG) log("No locale found - returning null"); |
| 7916 | return null; |
| 7917 | } finally { |
| 7918 | Binder.restoreCallingIdentity(identity); |
| 7919 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7920 | } |
| 7921 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7922 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7923 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7924 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7925 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7926 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7927 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7928 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7929 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7930 | return localeTag; |
| 7931 | } |
| 7932 | } |
| 7933 | return inputLocale.toLanguageTag(); |
| 7934 | } |
| 7935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | /** |
| 7937 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7938 | */ |
| 7939 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7940 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 7941 | return SubscriptionManagerService.getInstance().getActiveSubscriptionInfoList( |
| 7942 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 7943 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7944 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7945 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7946 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7947 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7948 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7949 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7950 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7951 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7952 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7953 | * representing the state of the modem. |
| 7954 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7955 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7956 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7957 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7958 | */ |
| 7959 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7960 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7961 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7962 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7963 | |
| 7964 | final long identity = Binder.clearCallingIdentity(); |
| 7965 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7966 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7967 | } finally { |
| 7968 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7969 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7970 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7971 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7972 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7973 | // less than total activity duration. |
| 7974 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7975 | if (info == null) { |
| 7976 | return false; |
| 7977 | } |
| 7978 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7979 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7980 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7981 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7982 | return (info.isValid() |
| 7983 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7984 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7985 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7986 | && (totalTxTimeMs <= activityDurationMs)); |
| 7987 | } |
| 7988 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7989 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7990 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7991 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7992 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7993 | |
| 7994 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7995 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7996 | } |
| 7997 | |
| 7998 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7999 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8000 | rat, |
| 8001 | freq, |
| 8002 | info.getReceiveTimeMillis(rat, freq) |
| 8003 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8004 | } |
| 8005 | |
| 8006 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8007 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8008 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8009 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8010 | |
| 8011 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8012 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8013 | } |
| 8014 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8015 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8016 | rat, |
| 8017 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8018 | } |
| 8019 | |
| 8020 | /** |
| 8021 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8022 | * @param info recent ModemActivityInfo |
| 8023 | */ |
| 8024 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8025 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8026 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8027 | boolean matched; |
| 8028 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8029 | matched = false; |
| 8030 | int rat = info.getSpecificInfoRat(i); |
| 8031 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8032 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8033 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8034 | //if it already exists |
| 8035 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8036 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8037 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8038 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8039 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8040 | updateLastModemActivityInfo(info, rat, freq); |
| 8041 | matched = true; |
| 8042 | } |
| 8043 | } else { |
| 8044 | updateLastModemActivityInfo(info, rat); |
| 8045 | matched = true; |
| 8046 | } |
| 8047 | } |
| 8048 | } |
| 8049 | |
| 8050 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8051 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8052 | new ActivityStatsTechSpecificInfo( |
| 8053 | rat, |
| 8054 | freq, |
| 8055 | info.getTransmitTimeMillis(rat, freq), |
| 8056 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8057 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8058 | } |
| 8059 | } |
| 8060 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8061 | mLastModemActivitySpecificInfo = |
| 8062 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8063 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8064 | |
| 8065 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8066 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8067 | info.getSleepTimeMillis() |
| 8068 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8069 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8070 | info.getIdleTimeMillis() |
| 8071 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8072 | |
| 8073 | mLastModemActivityInfo = |
| 8074 | new ModemActivityInfo( |
| 8075 | mLastModemActivityInfo.getTimestampMillis(), |
| 8076 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8077 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8078 | mLastModemActivitySpecificInfo); |
| 8079 | } |
| 8080 | |
| 8081 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8082 | ActivityStatsTechSpecificInfo[] info) { |
| 8083 | int infoSize = info.length; |
| 8084 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8085 | for (int i = 0; i < infoSize; i++) { |
| 8086 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8087 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8088 | info[i].getTransmitTimeMillis(), |
| 8089 | (int) info[i].getReceiveTimeMillis()); |
| 8090 | } |
| 8091 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8092 | } |
| 8093 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8094 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8095 | * Returns the service state information on specified subscription. |
| 8096 | */ |
| 8097 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8098 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8099 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8100 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8101 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8102 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8103 | return null; |
| 8104 | } |
| 8105 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8106 | boolean hasFinePermission = false; |
| 8107 | boolean hasCoarsePermission = false; |
| 8108 | if (!renounceFineLocationAccess) { |
| 8109 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8110 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8111 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8112 | .setCallingPackage(callingPackage) |
| 8113 | .setCallingFeatureId(callingFeatureId) |
| 8114 | .setCallingPid(Binder.getCallingPid()) |
| 8115 | .setCallingUid(Binder.getCallingUid()) |
| 8116 | .setMethod("getServiceStateForSubscriber") |
| 8117 | .setLogAsInfo(true) |
| 8118 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8119 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8120 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8121 | .build()); |
| 8122 | hasFinePermission = |
| 8123 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8124 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8125 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8126 | if (!renounceCoarseLocationAccess) { |
| 8127 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8128 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8129 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8130 | .setCallingPackage(callingPackage) |
| 8131 | .setCallingFeatureId(callingFeatureId) |
| 8132 | .setCallingPid(Binder.getCallingPid()) |
| 8133 | .setCallingUid(Binder.getCallingUid()) |
| 8134 | .setMethod("getServiceStateForSubscriber") |
| 8135 | .setLogAsInfo(true) |
| 8136 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8137 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8138 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8139 | .build()); |
| 8140 | hasCoarsePermission = |
| 8141 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8142 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8143 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8144 | final Phone phone = getPhone(subId); |
| 8145 | if (phone == null) { |
| 8146 | return null; |
| 8147 | } |
| 8148 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8149 | final long identity = Binder.clearCallingIdentity(); |
| 8150 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8151 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8152 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8153 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8154 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8155 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 8156 | SubscriptionInfoInternal subInfo = SubscriptionManagerService.getInstance() |
| 8157 | .getSubscriptionInfoInternal(subId); |
| 8158 | if (subInfo == null || !subInfo.isActive()) { |
| 8159 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8160 | + "subId=" + subId); |
| 8161 | return null; |
| 8162 | } |
| 8163 | } else { |
| 8164 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8165 | callingFeatureId)) { |
| 8166 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8167 | + "subId=" + subId); |
| 8168 | return null; |
| 8169 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8170 | } |
| 8171 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8172 | ServiceState ss = phone.getServiceState(); |
| 8173 | |
| 8174 | // Scrub out the location info in ServiceState depending on what level of access |
| 8175 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8176 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8177 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8178 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 | } finally { |
| 8180 | Binder.restoreCallingIdentity(identity); |
| 8181 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8182 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8183 | |
| 8184 | /** |
| 8185 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8186 | * |
| 8187 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8188 | * voicemail ringtone. |
| 8189 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8190 | * PhoneAccount. |
| 8191 | */ |
| 8192 | @Override |
| 8193 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8194 | final long identity = Binder.clearCallingIdentity(); |
| 8195 | try { |
| 8196 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8197 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8198 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8199 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8201 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
| 8204 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8208 | * Sets the per-account voicemail ringtone. |
| 8209 | * |
| 8210 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8211 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8212 | * |
| 8213 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8214 | * voicemail ringtone. |
| 8215 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8216 | * PhoneAccount. |
| 8217 | */ |
| 8218 | @Override |
| 8219 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8220 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8221 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8222 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8223 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8224 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8225 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8226 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8227 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8228 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8229 | |
| 8230 | final long identity = Binder.clearCallingIdentity(); |
| 8231 | try { |
| 8232 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8233 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8234 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8235 | } |
| 8236 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8239 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8243 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8244 | * |
| 8245 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8246 | * voicemail vibration setting. |
| 8247 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8248 | */ |
| 8249 | @Override |
| 8250 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | final long identity = Binder.clearCallingIdentity(); |
| 8252 | try { |
| 8253 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8254 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8255 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8256 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8257 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8258 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8259 | } finally { |
| 8260 | Binder.restoreCallingIdentity(identity); |
| 8261 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8262 | } |
| 8263 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8264 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8265 | * Sets the per-account voicemail vibration. |
| 8266 | * |
| 8267 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8268 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8269 | * |
| 8270 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8271 | * voicemail vibration setting. |
| 8272 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8273 | * specific PhoneAccount. |
| 8274 | */ |
| 8275 | @Override |
| 8276 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8277 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8278 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8279 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8280 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8281 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8282 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8283 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8284 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8285 | } |
| 8286 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8290 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8291 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | } |
| 8293 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8294 | } finally { |
| 8295 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8296 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8297 | } |
| 8298 | |
| 8299 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8300 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8301 | * |
| 8302 | * @throws SecurityException if the caller does not have the required permission |
| 8303 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8304 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8305 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8306 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8307 | } |
| 8308 | |
| 8309 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8310 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8311 | * permission. |
| 8312 | * |
| 8313 | * @throws SecurityException if the caller does not have the required permission |
| 8314 | */ |
| 8315 | private void enforceSendSmsPermission() { |
| 8316 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8317 | } |
| 8318 | |
| 8319 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8320 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8321 | * users permission. |
| 8322 | * |
| 8323 | * @throws SecurityException if the caller does not have the required permission |
| 8324 | */ |
| 8325 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8326 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8327 | } |
| 8328 | |
| 8329 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8330 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8331 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8332 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8333 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8334 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8335 | final long identity = Binder.clearCallingIdentity(); |
| 8336 | try { |
| 8337 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8338 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8339 | if (componentName == null) { |
| 8340 | throw new SecurityException( |
| 8341 | "Caller not current active visual voicemail package[null]"); |
| 8342 | } |
| 8343 | String vvmPackage = componentName.getPackageName(); |
| 8344 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8345 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8346 | } |
| 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8349 | } |
| 8350 | } |
| 8351 | |
| 8352 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8353 | * Return the application ID for the app type. |
| 8354 | * |
| 8355 | * @param subId the subscription ID that this request applies to. |
| 8356 | * @param appType the uicc app type. |
| 8357 | * @return Application ID for specificied app type, or null if no uicc. |
| 8358 | */ |
| 8359 | @Override |
| 8360 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8361 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8362 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8363 | |
| 8364 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8365 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8366 | if (phone == null) { |
| 8367 | return null; |
| 8368 | } |
| 8369 | String aid = null; |
| 8370 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8371 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | .getApplicationByType(appType).getAid(); |
| 8373 | } catch (Exception e) { |
| 8374 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8375 | } |
| 8376 | return aid; |
| 8377 | } finally { |
| 8378 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8379 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8380 | } |
| 8381 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8382 | /** |
| 8383 | * Return the Electronic Serial Number. |
| 8384 | * |
| 8385 | * @param subId the subscription ID that this request applies to. |
| 8386 | * @return ESN or null if error. |
| 8387 | */ |
| 8388 | @Override |
| 8389 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8390 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8391 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8392 | |
| 8393 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8394 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8395 | if (phone == null) { |
| 8396 | return null; |
| 8397 | } |
| 8398 | String esn = null; |
| 8399 | try { |
| 8400 | esn = phone.getEsn(); |
| 8401 | } catch (Exception e) { |
| 8402 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8403 | } |
| 8404 | return esn; |
| 8405 | } finally { |
| 8406 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8407 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8408 | } |
| 8409 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8410 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8411 | * Return the Preferred Roaming List Version. |
| 8412 | * |
| 8413 | * @param subId the subscription ID that this request applies to. |
| 8414 | * @return PRLVersion or null if error. |
| 8415 | */ |
| 8416 | @Override |
| 8417 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8418 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8419 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8420 | |
| 8421 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8422 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8423 | if (phone == null) { |
| 8424 | return null; |
| 8425 | } |
| 8426 | String cdmaPrlVersion = null; |
| 8427 | try { |
| 8428 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8429 | } catch (Exception e) { |
| 8430 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8431 | } |
| 8432 | return cdmaPrlVersion; |
| 8433 | } finally { |
| 8434 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8435 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8436 | } |
| 8437 | |
| 8438 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8439 | * Get snapshot of Telephony histograms |
| 8440 | * @return List of Telephony histograms |
| 8441 | * @hide |
| 8442 | */ |
| 8443 | @Override |
| 8444 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8446 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | |
| 8448 | final long identity = Binder.clearCallingIdentity(); |
| 8449 | try { |
| 8450 | return RIL.getTelephonyRILTimingHistograms(); |
| 8451 | } finally { |
| 8452 | Binder.restoreCallingIdentity(identity); |
| 8453 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8454 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8455 | |
| 8456 | /** |
| 8457 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8458 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8459 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8460 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8461 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8462 | * @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] | 8463 | */ |
| 8464 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8465 | @TelephonyManager.SetCarrierRestrictionResult |
| 8466 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8467 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8468 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8469 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8470 | if (carrierRestrictionRules == null) { |
| 8471 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8472 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8473 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8474 | final long identity = Binder.clearCallingIdentity(); |
| 8475 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8476 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8477 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
| 8480 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8481 | } |
| 8482 | |
| 8483 | /** |
| 8484 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8485 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8486 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8487 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8488 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8489 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8490 | */ |
| 8491 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8492 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8493 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8494 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8495 | |
| 8496 | final long identity = Binder.clearCallingIdentity(); |
| 8497 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8498 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8499 | if (response instanceof CarrierRestrictionRules) { |
| 8500 | return (CarrierRestrictionRules) response; |
| 8501 | } |
| 8502 | // Response is an Exception of some kind, |
| 8503 | // which is signalled to the user as a NULL retval |
| 8504 | return null; |
| 8505 | } catch (Exception e) { |
| 8506 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8507 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8508 | } finally { |
| 8509 | Binder.restoreCallingIdentity(identity); |
| 8510 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8511 | } |
| 8512 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8513 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8514 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8515 | * @param subId the subscription ID that this action applies to. |
| 8516 | * @param enabled control enable or disable radio. |
| 8517 | * {@hide} |
| 8518 | */ |
| 8519 | @Override |
| 8520 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8521 | enforceModifyPermission(); |
| 8522 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8523 | |
| 8524 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8525 | if (phone == null) { |
| 8526 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8527 | return; |
| 8528 | } |
| 8529 | try { |
| 8530 | phone.carrierActionSetRadioEnabled(enabled); |
| 8531 | } catch (Exception e) { |
| 8532 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8533 | } finally { |
| 8534 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8535 | } |
| 8536 | } |
| 8537 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8538 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8539 | * Enable or disable Voice over NR (VoNR) |
| 8540 | * @param subId the subscription ID that this action applies to. |
| 8541 | * @param enabled enable or disable VoNR. |
| 8542 | * @return operation result. |
| 8543 | */ |
| 8544 | @Override |
| 8545 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8546 | enforceModifyPermission(); |
| 8547 | final Phone phone = getPhone(subId); |
| 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | if (phone == null) { |
| 8551 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8552 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8553 | } |
| 8554 | |
| 8555 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8556 | try { |
| 8557 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8558 | workSource); |
| 8559 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8560 | |
| 8561 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8562 | if (DBG) { |
| 8563 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8564 | } |
| 8565 | SubscriptionManager.setSubscriptionProperty( |
| 8566 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8567 | (enabled ? "1" : "0")); |
| 8568 | } |
| 8569 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8570 | return result; |
| 8571 | } finally { |
| 8572 | Binder.restoreCallingIdentity(identity); |
| 8573 | } |
| 8574 | } |
| 8575 | |
| 8576 | /** |
| 8577 | * Is voice over NR enabled |
| 8578 | * @return true if VoNR is enabled else false |
| 8579 | */ |
| 8580 | @Override |
| 8581 | public boolean isVoNrEnabled(int subId) { |
| 8582 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8583 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8584 | final long identity = Binder.clearCallingIdentity(); |
| 8585 | try { |
| 8586 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8587 | null, subId, workSource); |
| 8588 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8589 | return isEnabled; |
| 8590 | } finally { |
| 8591 | Binder.restoreCallingIdentity(identity); |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8596 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8597 | * network status based on which carrier apps could apply actions accordingly, |
| 8598 | * enable/disable default url handler for example. |
| 8599 | * |
| 8600 | * @param subId the subscription ID that this action applies to. |
| 8601 | * @param report control start/stop reporting the default network status. |
| 8602 | * {@hide} |
| 8603 | */ |
| 8604 | @Override |
| 8605 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8606 | enforceModifyPermission(); |
| 8607 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8608 | |
| 8609 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8610 | if (phone == null) { |
| 8611 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8612 | return; |
| 8613 | } |
| 8614 | try { |
| 8615 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8616 | } catch (Exception e) { |
| 8617 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8618 | } finally { |
| 8619 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8620 | } |
| 8621 | } |
| 8622 | |
| 8623 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8624 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8625 | * @param subId the subscription ID that this action applies to. |
| 8626 | * {@hide} |
| 8627 | */ |
| 8628 | @Override |
| 8629 | public void carrierActionResetAll(int subId) { |
| 8630 | enforceModifyPermission(); |
| 8631 | final Phone phone = getPhone(subId); |
| 8632 | if (phone == null) { |
| 8633 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8634 | return; |
| 8635 | } |
| 8636 | try { |
| 8637 | phone.carrierActionResetAll(); |
| 8638 | } catch (Exception e) { |
| 8639 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8640 | } |
| 8641 | } |
| 8642 | |
| 8643 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8644 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8645 | * bug report is being generated. |
| 8646 | */ |
| 8647 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8648 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8649 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8650 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8651 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8652 | + Binder.getCallingPid() |
| 8653 | + ", uid=" + Binder.getCallingUid() |
| 8654 | + "without permission " |
| 8655 | + android.Manifest.permission.DUMP); |
| 8656 | return; |
| 8657 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8658 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8659 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8660 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8661 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8662 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8663 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8664 | @NonNull String[] args) { |
| 8665 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8666 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8667 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8668 | } |
| 8669 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8670 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8671 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8672 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8673 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8674 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8675 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8676 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8677 | */ |
| 8678 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8679 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8680 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8681 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8682 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8683 | try { |
| 8684 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8685 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8686 | } catch (SecurityException se) { |
| 8687 | enforceModifyPermission(); |
| 8688 | } |
| 8689 | } else { |
| 8690 | enforceModifyPermission(); |
| 8691 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8692 | |
| 8693 | final long identity = Binder.clearCallingIdentity(); |
| 8694 | try { |
| 8695 | Phone phone = getPhone(subId); |
| 8696 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8697 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8698 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8699 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8700 | phone.getDataSettingsManager().setDataEnabled( |
| 8701 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8702 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8703 | } |
| 8704 | } finally { |
| 8705 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8706 | } |
| 8707 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8708 | |
| 8709 | /** |
| 8710 | * Get Client request stats |
| 8711 | * @return List of Client Request Stats |
| 8712 | * @hide |
| 8713 | */ |
| 8714 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8715 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8716 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8718 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8719 | return null; |
| 8720 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8721 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | if (phone != null) { |
| 8726 | return phone.getClientRequestStats(); |
| 8727 | } |
| 8728 | |
| 8729 | return null; |
| 8730 | } finally { |
| 8731 | Binder.restoreCallingIdentity(identity); |
| 8732 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8733 | } |
| 8734 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8735 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8736 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8737 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8738 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8739 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8740 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8741 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8742 | // commands that plumb through the RIL as root, like so: |
| 8743 | // $ adb root |
| 8744 | // $ adb shell cmd phone ... |
| 8745 | packageName = "root"; |
| 8746 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8747 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8748 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8749 | |
| 8750 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8751 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8752 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8753 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8754 | * @param state State of SIM (power down, power up, pass through) |
| 8755 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8756 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8757 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8758 | * |
| 8759 | **/ |
| 8760 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8761 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8762 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8763 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8764 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8765 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8767 | final long identity = Binder.clearCallingIdentity(); |
| 8768 | try { |
| 8769 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8770 | phone.setSimPowerState(state, null, workSource); |
| 8771 | } |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
| 8775 | } |
| 8776 | |
| 8777 | /** |
| 8778 | * Set SIM card power state. |
| 8779 | * |
| 8780 | * @param slotIndex SIM slot id. |
| 8781 | * @param state State of SIM (power down, power up, pass through) |
| 8782 | * @param callback callback to trigger after success or failure |
| 8783 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8784 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8785 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8786 | * |
| 8787 | **/ |
| 8788 | @Override |
| 8789 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8790 | IIntegerConsumer callback) { |
| 8791 | enforceModifyPermission(); |
| 8792 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8793 | |
| 8794 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8795 | |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | if (phone != null) { |
| 8799 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8800 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8801 | } |
| 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8804 | } |
| 8805 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8806 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8807 | private boolean isUssdApiAllowed(int subId) { |
| 8808 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8809 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8810 | if (configManager == null) { |
| 8811 | return false; |
| 8812 | } |
| 8813 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8814 | if (pb == null) { |
| 8815 | return false; |
| 8816 | } |
| 8817 | return pb.getBoolean( |
| 8818 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8819 | } |
| 8820 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8821 | /** |
| 8822 | * Check if phone is in emergency callback mode |
| 8823 | * @return true if phone is in emergency callback mode |
| 8824 | * @param subId sub id |
| 8825 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8826 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8827 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8828 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8829 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8830 | |
| 8831 | final long identity = Binder.clearCallingIdentity(); |
| 8832 | try { |
| 8833 | if (phone != null) { |
| 8834 | return phone.isInEcm(); |
| 8835 | } else { |
| 8836 | return false; |
| 8837 | } |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8840 | } |
| 8841 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8842 | |
| 8843 | /** |
| 8844 | * Get the current signal strength information for the given subscription. |
| 8845 | * Because this information is not updated when the device is in a low power state |
| 8846 | * it should not be relied-upon to be current. |
| 8847 | * @param subId Subscription index |
| 8848 | * @return the most recent cached signal strength info from the modem |
| 8849 | */ |
| 8850 | @Override |
| 8851 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8852 | final long identity = Binder.clearCallingIdentity(); |
| 8853 | try { |
| 8854 | Phone p = getPhone(subId); |
| 8855 | if (p == null) { |
| 8856 | return null; |
| 8857 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8858 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8859 | return p.getSignalStrength(); |
| 8860 | } finally { |
| 8861 | Binder.restoreCallingIdentity(identity); |
| 8862 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8863 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8864 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8865 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8866 | * Get the current modem radio state for the given slot. |
| 8867 | * @param slotIndex slot index. |
| 8868 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8869 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8870 | * @return the current radio power state from the modem |
| 8871 | */ |
| 8872 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8873 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8874 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8875 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8876 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8877 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8878 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8879 | } |
| 8880 | |
| 8881 | final long identity = Binder.clearCallingIdentity(); |
| 8882 | try { |
| 8883 | return phone.getRadioPowerState(); |
| 8884 | } finally { |
| 8885 | Binder.restoreCallingIdentity(identity); |
| 8886 | } |
| 8887 | } |
| 8888 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8889 | } |
| 8890 | |
| 8891 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8892 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8893 | * |
| 8894 | * <p>Requires one of the following permissions: |
| 8895 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8896 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8897 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8898 | * privileges. |
| 8899 | * |
| 8900 | * @param subId subscription id |
| 8901 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8902 | * {@code false}. |
| 8903 | */ |
| 8904 | @Override |
| 8905 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8906 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8907 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8908 | try { |
| 8909 | mApp.enforceCallingOrSelfPermission( |
| 8910 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8911 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8912 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8913 | mApp.enforceCallingOrSelfPermission( |
| 8914 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8915 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8916 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8917 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8918 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8919 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8920 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8921 | boolean isEnabled = false; |
| 8922 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8923 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8924 | Phone phone = getPhone(subId); |
| 8925 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8926 | } finally { |
| 8927 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8928 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8929 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8930 | } |
| 8931 | |
| 8932 | |
| 8933 | /** |
| 8934 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8935 | * |
| 8936 | * <p> Requires permission: |
| 8937 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8938 | * privileges. |
| 8939 | * |
| 8940 | * @param subId subscription id |
| 8941 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8942 | */ |
| 8943 | @Override |
| 8944 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8945 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8946 | mApp, subId, "setDataRoamingEnabled"); |
| 8947 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8950 | Phone phone = getPhone(subId); |
| 8951 | if (phone != null) { |
| 8952 | phone.setDataRoamingEnabled(isEnabled); |
| 8953 | } |
| 8954 | } finally { |
| 8955 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8956 | } |
| 8957 | } |
| 8958 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8959 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8960 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8961 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8962 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8963 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8964 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8965 | boolean isAllowed = true; |
| 8966 | final long identity = Binder.clearCallingIdentity(); |
| 8967 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8968 | Phone phone = getPhone(subId); |
| 8969 | if (phone != null) { |
| 8970 | isAllowed = phone.isCspPlmnEnabled(); |
| 8971 | } |
| 8972 | } finally { |
| 8973 | Binder.restoreCallingIdentity(identity); |
| 8974 | } |
| 8975 | return isAllowed; |
| 8976 | } |
| 8977 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8978 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8979 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8980 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8981 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8982 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8983 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8984 | if (phone == null) { |
| 8985 | return false; |
| 8986 | } |
| 8987 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8988 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8989 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8990 | } |
| 8991 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8992 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8993 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8994 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8995 | mApp.getSystemService(AppOpsManager.class) |
| 8996 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8997 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8998 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8999 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9000 | try { |
| 9001 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9002 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9003 | } catch (SecurityException e) { |
| 9004 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9005 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9006 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9007 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9008 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9009 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9010 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9011 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9012 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9013 | Binder.getCallingUid())) { |
| 9014 | isIccIdAccessRestricted = true; |
| 9015 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9016 | final long identity = Binder.clearCallingIdentity(); |
| 9017 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9018 | UiccController uiccController = UiccController.getInstance(); |
| 9019 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9020 | if (hasReadPermission) { |
| 9021 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9022 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9023 | |
| 9024 | // Remove private info if the caller doesn't have access |
| 9025 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9026 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9027 | //setting the value after compatibility check |
| 9028 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9029 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9030 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9031 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9032 | if (card == null) { |
| 9033 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9034 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9035 | continue; |
| 9036 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9037 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9038 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9039 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9040 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9041 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9042 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9043 | for (UiccPortInfo portInfo : portInfos) { |
| 9044 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9045 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9046 | if (port == null) { |
| 9047 | // assume no access if port is null |
| 9048 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9049 | continue; |
| 9050 | } |
| 9051 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9052 | uiccPortInfos.add(portInfo); |
| 9053 | } else { |
| 9054 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9055 | } |
| 9056 | } |
| 9057 | filteredInfos.add(new UiccCardInfo( |
| 9058 | cardInfo.isEuicc(), |
| 9059 | cardInfo.getCardId(), |
| 9060 | null, |
| 9061 | cardInfo.getPhysicalSlotIndex(), |
| 9062 | cardInfo.isRemovable(), |
| 9063 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9064 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9065 | } |
| 9066 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9067 | } finally { |
| 9068 | Binder.restoreCallingIdentity(identity); |
| 9069 | } |
| 9070 | } |
| 9071 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9072 | /** |
| 9073 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9074 | * generally private and require carrier privileges to view. |
| 9075 | * |
| 9076 | * @hide |
| 9077 | */ |
| 9078 | @NonNull |
| 9079 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9080 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9081 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9082 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9083 | } |
| 9084 | return new UiccCardInfo( |
| 9085 | cardInfo.isEuicc(), |
| 9086 | cardInfo.getCardId(), |
| 9087 | null, |
| 9088 | cardInfo.getPhysicalSlotIndex(), |
| 9089 | cardInfo.isRemovable(), |
| 9090 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9091 | portinfo |
| 9092 | ); |
| 9093 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9094 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9095 | /** |
| 9096 | * @hide |
| 9097 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9098 | * These values are generally private and require carrier privileges to view. |
| 9099 | */ |
| 9100 | @NonNull |
| 9101 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9102 | return new UiccPortInfo( |
| 9103 | UiccPortInfo.ICCID_REDACTED, |
| 9104 | portInfo.getPortIndex(), |
| 9105 | portInfo.getLogicalSlotIndex(), |
| 9106 | portInfo.isActive() |
| 9107 | ); |
| 9108 | } |
| 9109 | @Override |
| 9110 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9111 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9112 | mApp.getSystemService(AppOpsManager.class) |
| 9113 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9114 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9115 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9116 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9117 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9118 | // we are reading iccId which is PII data. |
| 9119 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9120 | |
| 9121 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9122 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9123 | Binder.getCallingUid())) { |
| 9124 | isLogicalSlotAccessRestricted = true; |
| 9125 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9126 | final long identity = Binder.clearCallingIdentity(); |
| 9127 | try { |
| 9128 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9129 | if (slots == null || slots.length == 0) { |
| 9130 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9131 | return null; |
| 9132 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9133 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9134 | for (int i = 0; i < slots.length; i++) { |
| 9135 | UiccSlot slot = slots[i]; |
| 9136 | if (slot == null) { |
| 9137 | continue; |
| 9138 | } |
| 9139 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9140 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9141 | UiccCard card = slot.getUiccCard(); |
| 9142 | if (card != null) { |
| 9143 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9144 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9145 | cardId = slot.getEid(); |
| 9146 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9147 | // If cardId is null, use iccId of default port as cardId. |
| 9148 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9149 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9150 | } |
| 9151 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9152 | if (cardId != null) { |
| 9153 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9154 | // if cardId is an EID, it's all digits so this is fine |
| 9155 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9156 | } |
| 9157 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9158 | int cardState = 0; |
| 9159 | switch (slot.getCardState()) { |
| 9160 | case CARDSTATE_ABSENT: |
| 9161 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9162 | break; |
| 9163 | case CARDSTATE_PRESENT: |
| 9164 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9165 | break; |
| 9166 | case CARDSTATE_ERROR: |
| 9167 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9168 | break; |
| 9169 | case CARDSTATE_RESTRICTED: |
| 9170 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9171 | break; |
| 9172 | default: |
| 9173 | break; |
| 9174 | |
| 9175 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9176 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9177 | int[] portIndexes = slot.getPortList(); |
| 9178 | for (int portIdx : portIndexes) { |
| 9179 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9180 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9181 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9182 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9183 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9184 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9185 | slot.isEuicc(), |
| 9186 | cardId, |
| 9187 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9188 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9189 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9190 | //setting the value after compatibility check |
| 9191 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9192 | } |
| 9193 | return infos; |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9196 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9197 | } |
| 9198 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9199 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9200 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9201 | boolean hasReadPermission) { |
| 9202 | String iccId = slot.getIccId(portIndex); |
| 9203 | if (hasReadPermission) { // if has read permission |
| 9204 | return iccId; |
| 9205 | } else { |
| 9206 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9207 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9208 | // if no read permission, checking carrier privilege access |
| 9209 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9210 | return iccId; |
| 9211 | } |
| 9212 | } |
| 9213 | } |
| 9214 | // No read permission or carrier privilege access. |
| 9215 | return UiccPortInfo.ICCID_REDACTED; |
| 9216 | } |
| 9217 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9218 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9219 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9220 | public boolean switchSlots(int[] physicalSlots) { |
| 9221 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9222 | |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9225 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9226 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9227 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9228 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9229 | physicalSlots[i], i)); |
| 9230 | } |
| 9231 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9232 | } finally { |
| 9233 | Binder.restoreCallingIdentity(identity); |
| 9234 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9235 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9236 | |
| 9237 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9238 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9239 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9240 | enforceModifyPermission(); |
| 9241 | |
| 9242 | final long identity = Binder.clearCallingIdentity(); |
| 9243 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9244 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9245 | } finally { |
| 9246 | Binder.restoreCallingIdentity(identity); |
| 9247 | } |
| 9248 | } |
| 9249 | |
| 9250 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9251 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9252 | final long identity = Binder.clearCallingIdentity(); |
| 9253 | try { |
| 9254 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9255 | } finally { |
| 9256 | Binder.restoreCallingIdentity(identity); |
| 9257 | } |
| 9258 | } |
| 9259 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9260 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9261 | * A test API to reload the UICC profile. |
| 9262 | * |
| 9263 | * <p>Requires that the calling app has permission |
| 9264 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9265 | * @hide |
| 9266 | */ |
| 9267 | @Override |
| 9268 | public void refreshUiccProfile(int subId) { |
| 9269 | enforceModifyPermission(); |
| 9270 | |
| 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
| 9273 | Phone phone = getPhone(subId); |
| 9274 | if (phone == null) { |
| 9275 | return; |
| 9276 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9277 | UiccPort uiccPort = phone.getUiccPort(); |
| 9278 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9279 | return; |
| 9280 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9281 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9282 | if (uiccProfile == null) { |
| 9283 | return; |
| 9284 | } |
| 9285 | uiccProfile.refresh(); |
| 9286 | } finally { |
| 9287 | Binder.restoreCallingIdentity(identity); |
| 9288 | } |
| 9289 | } |
| 9290 | |
| 9291 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9292 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9293 | */ |
| 9294 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9295 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9296 | } |
| 9297 | |
| 9298 | /** |
| 9299 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9300 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9301 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9302 | */ |
| 9303 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9304 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9305 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9306 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9307 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9308 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9309 | return isDataRoamingEnabled; |
| 9310 | } |
| 9311 | |
| 9312 | /** |
| 9313 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9314 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9315 | */ |
| 9316 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9317 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9318 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9319 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9320 | return list.get(phoneId); |
| 9321 | } |
| 9322 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9323 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9324 | |
| 9325 | @Override |
| 9326 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9327 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9328 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9329 | |
| 9330 | final long identity = Binder.clearCallingIdentity(); |
| 9331 | try { |
| 9332 | final Phone phone = getPhone(subId); |
| 9333 | if (phone == null) { |
| 9334 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9335 | return; |
| 9336 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9337 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9338 | if (cpt != null) { |
| 9339 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9340 | } |
| 9341 | // 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] | 9342 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9343 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9344 | if (carrierPrivilegeRules == null) { |
| 9345 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9346 | } else { |
| 9347 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9348 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9349 | } finally { |
| 9350 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9351 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9352 | } |
| 9353 | |
| 9354 | @Override |
| 9355 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9356 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9357 | |
| 9358 | final long identity = Binder.clearCallingIdentity(); |
| 9359 | try { |
| 9360 | final Phone phone = getPhone(subId); |
| 9361 | if (phone == null) { |
| 9362 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9363 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9364 | } |
| 9365 | return phone.getCarrierIdListVersion(); |
| 9366 | } finally { |
| 9367 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9368 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9369 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9370 | |
| 9371 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9372 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9373 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9375 | mApp, subId, callingPackage, callingFeatureId, |
| 9376 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9377 | return -1; |
| 9378 | } |
| 9379 | |
| 9380 | final long identity = Binder.clearCallingIdentity(); |
| 9381 | try { |
| 9382 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9383 | } finally { |
| 9384 | Binder.restoreCallingIdentity(identity); |
| 9385 | } |
| 9386 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9387 | |
| 9388 | @Override |
| 9389 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9390 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9391 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9392 | mApp, subId, "getCdmaRoamingMode"); |
| 9393 | |
| 9394 | final long identity = Binder.clearCallingIdentity(); |
| 9395 | try { |
| 9396 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9397 | } finally { |
| 9398 | Binder.restoreCallingIdentity(identity); |
| 9399 | } |
| 9400 | } |
| 9401 | |
| 9402 | @Override |
| 9403 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9405 | mApp, subId, "setCdmaRoamingMode"); |
| 9406 | |
| 9407 | final long identity = Binder.clearCallingIdentity(); |
| 9408 | try { |
| 9409 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9410 | } finally { |
| 9411 | Binder.restoreCallingIdentity(identity); |
| 9412 | } |
| 9413 | } |
| 9414 | |
| 9415 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9416 | public int getCdmaSubscriptionMode(int subId) { |
| 9417 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9418 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9419 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9420 | |
| 9421 | final long identity = Binder.clearCallingIdentity(); |
| 9422 | try { |
| 9423 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9424 | } finally { |
| 9425 | Binder.restoreCallingIdentity(identity); |
| 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9430 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9432 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9433 | |
| 9434 | final long identity = Binder.clearCallingIdentity(); |
| 9435 | try { |
| 9436 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9437 | } finally { |
| 9438 | Binder.restoreCallingIdentity(identity); |
| 9439 | } |
| 9440 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9441 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9442 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9443 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9444 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9446 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9447 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9448 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9449 | } |
| 9450 | final long identity = Binder.clearCallingIdentity(); |
| 9451 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9452 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9453 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9454 | if (phone.getEmergencyNumberTracker() != null |
| 9455 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9456 | emergencyNumberListInternal.put( |
| 9457 | phone.getSubId(), |
| 9458 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9459 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9460 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9461 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9462 | } finally { |
| 9463 | Binder.restoreCallingIdentity(identity); |
| 9464 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9465 | } |
| 9466 | |
| 9467 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9468 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9469 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9470 | if (!exactMatch) { |
| 9471 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9472 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9473 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9474 | } |
| 9475 | final long identity = Binder.clearCallingIdentity(); |
| 9476 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9477 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9478 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9479 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9480 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9481 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9482 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9483 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9484 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9485 | } |
| 9486 | return false; |
| 9487 | } finally { |
| 9488 | Binder.restoreCallingIdentity(identity); |
| 9489 | } |
| 9490 | } |
| 9491 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9492 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9493 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9494 | */ |
| 9495 | @Override |
| 9496 | public void startEmergencyCallbackMode() { |
| 9497 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9498 | "startEmergencyCallbackMode"); |
| 9499 | enforceModifyPermission(); |
| 9500 | final long identity = Binder.clearCallingIdentity(); |
| 9501 | try { |
| 9502 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9503 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9504 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9505 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9506 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9507 | gsmCdmaPhone.obtainMessage( |
| 9508 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9509 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9510 | } |
| 9511 | } |
| 9512 | } finally { |
| 9513 | Binder.restoreCallingIdentity(identity); |
| 9514 | } |
| 9515 | } |
| 9516 | |
| 9517 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9518 | * Update emergency number list for test mode. |
| 9519 | */ |
| 9520 | @Override |
| 9521 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9522 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9523 | "updateEmergencyNumberListTestMode"); |
| 9524 | |
| 9525 | final long identity = Binder.clearCallingIdentity(); |
| 9526 | try { |
| 9527 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9528 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9529 | if (tracker != null) { |
| 9530 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9531 | } |
| 9532 | } |
| 9533 | } finally { |
| 9534 | Binder.restoreCallingIdentity(identity); |
| 9535 | } |
| 9536 | } |
| 9537 | |
| 9538 | /** |
| 9539 | * Get the full emergency number list for test mode. |
| 9540 | */ |
| 9541 | @Override |
| 9542 | public List<String> getEmergencyNumberListTestMode() { |
| 9543 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9544 | "getEmergencyNumberListTestMode"); |
| 9545 | |
| 9546 | final long identity = Binder.clearCallingIdentity(); |
| 9547 | try { |
| 9548 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9549 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9550 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9551 | if (tracker != null) { |
| 9552 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9553 | emergencyNumbers.add(num.getNumber()); |
| 9554 | } |
| 9555 | } |
| 9556 | } |
| 9557 | return new ArrayList<>(emergencyNumbers); |
| 9558 | } finally { |
| 9559 | Binder.restoreCallingIdentity(identity); |
| 9560 | } |
| 9561 | } |
| 9562 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9563 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9564 | public int getEmergencyNumberDbVersion(int subId) { |
| 9565 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9566 | |
| 9567 | final long identity = Binder.clearCallingIdentity(); |
| 9568 | try { |
| 9569 | final Phone phone = getPhone(subId); |
| 9570 | if (phone == null) { |
| 9571 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9572 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9573 | } |
| 9574 | return phone.getEmergencyNumberDbVersion(); |
| 9575 | } finally { |
| 9576 | Binder.restoreCallingIdentity(identity); |
| 9577 | } |
| 9578 | } |
| 9579 | |
| 9580 | @Override |
| 9581 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9582 | enforceModifyPermission(); |
| 9583 | |
| 9584 | final long identity = Binder.clearCallingIdentity(); |
| 9585 | try { |
| 9586 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9587 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9588 | if (tracker != null) { |
| 9589 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9590 | } |
| 9591 | } |
| 9592 | } finally { |
| 9593 | Binder.restoreCallingIdentity(identity); |
| 9594 | } |
| 9595 | } |
| 9596 | |
| 9597 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9598 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9599 | enforceActiveEmergencySessionPermission(); |
| 9600 | |
| 9601 | final long identity = Binder.clearCallingIdentity(); |
| 9602 | try { |
| 9603 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9604 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9605 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9606 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9607 | } |
| 9608 | } |
| 9609 | } finally { |
| 9610 | Binder.restoreCallingIdentity(identity); |
| 9611 | } |
| 9612 | } |
| 9613 | |
| 9614 | @Override |
| 9615 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9616 | enforceActiveEmergencySessionPermission(); |
| 9617 | |
| 9618 | final long identity = Binder.clearCallingIdentity(); |
| 9619 | try { |
| 9620 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9621 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9622 | if (tracker != null) { |
| 9623 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9624 | } |
| 9625 | } |
| 9626 | } finally { |
| 9627 | Binder.restoreCallingIdentity(identity); |
| 9628 | } |
| 9629 | } |
| 9630 | |
| 9631 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9632 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9633 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9634 | Phone phone = getPhone(subId); |
| 9635 | if (phone == null) { |
| 9636 | return null; |
| 9637 | } |
| 9638 | final long identity = Binder.clearCallingIdentity(); |
| 9639 | try { |
| 9640 | UiccProfile profile = UiccController.getInstance() |
| 9641 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9642 | if (profile != null) { |
| 9643 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9644 | } |
| 9645 | } finally { |
| 9646 | Binder.restoreCallingIdentity(identity); |
| 9647 | } |
| 9648 | return null; |
| 9649 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9650 | |
| 9651 | /** |
| 9652 | * Enable or disable a modem stack. |
| 9653 | */ |
| 9654 | @Override |
| 9655 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9656 | enforceModifyPermission(); |
| 9657 | |
| 9658 | final long identity = Binder.clearCallingIdentity(); |
| 9659 | try { |
| 9660 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9661 | if (phone == null) { |
| 9662 | return false; |
| 9663 | } else { |
| 9664 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9665 | } |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9670 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9671 | /** |
| 9672 | * Whether a modem stack is enabled or not. |
| 9673 | */ |
| 9674 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9675 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9676 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9677 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9678 | if (phone == null) return false; |
| 9679 | |
| 9680 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9681 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9682 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9683 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9684 | } |
| 9685 | |
| 9686 | final long identity = Binder.clearCallingIdentity(); |
| 9687 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9688 | try { |
| 9689 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9690 | } catch (NoSuchElementException ex) { |
| 9691 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9692 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9693 | } finally { |
| 9694 | Binder.restoreCallingIdentity(identity); |
| 9695 | } |
| 9696 | } |
| 9697 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9698 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9699 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9700 | enforceModifyPermission(); |
| 9701 | |
| 9702 | final long identity = Binder.clearCallingIdentity(); |
| 9703 | try { |
| 9704 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9705 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9706 | .commit(); |
| 9707 | } finally { |
| 9708 | Binder.restoreCallingIdentity(identity); |
| 9709 | } |
| 9710 | } |
| 9711 | |
| 9712 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9713 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9714 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9716 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9717 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9718 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9719 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9720 | |
| 9721 | final long identity = Binder.clearCallingIdentity(); |
| 9722 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9723 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9724 | } finally { |
| 9725 | Binder.restoreCallingIdentity(identity); |
| 9726 | } |
| 9727 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9728 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9729 | @TelephonyManager.IsMultiSimSupportedResult |
| 9730 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9731 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9732 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9733 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9734 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9735 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9736 | } |
| 9737 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9738 | // supported by the modem, indicate that it is restricted. |
| 9739 | PhoneCapability staticCapability = |
| 9740 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9741 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9742 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9743 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9744 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9745 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9746 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9747 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9748 | } |
| 9749 | // Check if support of multiple SIMs is restricted by carrier |
| 9750 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9751 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9752 | } |
| 9753 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9754 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9755 | } |
| 9756 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9757 | /** |
| 9758 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9759 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9760 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9761 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9762 | * @param numOfSims number of active sims we want to switch to |
| 9763 | */ |
| 9764 | @Override |
| 9765 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9766 | if (numOfSims == 1) { |
| 9767 | enforceModifyPermission(); |
| 9768 | } else { |
| 9769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9770 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9771 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9772 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9773 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9774 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9775 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9776 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9777 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9778 | return; |
| 9779 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9780 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9781 | } finally { |
| 9782 | Binder.restoreCallingIdentity(identity); |
| 9783 | } |
| 9784 | } |
| 9785 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9786 | @Override |
| 9787 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9788 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9789 | Phone phone = getPhone(subId); |
| 9790 | if (phone == null) { |
| 9791 | return false; |
| 9792 | } |
| 9793 | final long identity = Binder.clearCallingIdentity(); |
| 9794 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9795 | UiccPort uiccPort = phone.getUiccPort(); |
| 9796 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9797 | return false; |
| 9798 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9799 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9800 | if (uiccProfile == null) { |
| 9801 | return false; |
| 9802 | } |
| 9803 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9804 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9805 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9806 | } |
| 9807 | return false; |
| 9808 | } finally { |
| 9809 | Binder.restoreCallingIdentity(identity); |
| 9810 | } |
| 9811 | } |
| 9812 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9813 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9814 | * Get whether making changes to modem configurations will trigger reboot. |
| 9815 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9816 | */ |
| 9817 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9818 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9819 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9820 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9821 | mApp, subId, callingPackage, callingFeatureId, |
| 9822 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9823 | return false; |
| 9824 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9825 | final long identity = Binder.clearCallingIdentity(); |
| 9826 | try { |
| 9827 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9833 | private void updateModemStateMetrics() { |
| 9834 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9835 | // TODO: check the state for each modem if the api is ready. |
| 9836 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9837 | } |
| 9838 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9839 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9840 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9841 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9842 | // Verify that the callingPackage belongs to the calling UID |
| 9843 | mApp.getSystemService(AppOpsManager.class) |
| 9844 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9845 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9846 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9847 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9848 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9849 | if (slotInfos != null) { |
| 9850 | for (int i = 0; i < slotInfos.length; i++) { |
| 9851 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9852 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9853 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9854 | portInfo.getLogicalSlotIndex())); |
| 9855 | } |
| 9856 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9857 | } |
| 9858 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9859 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9860 | } finally { |
| 9861 | Binder.restoreCallingIdentity(identity); |
| 9862 | } |
| 9863 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9864 | |
| 9865 | /** |
| 9866 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9867 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9868 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9869 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9870 | @Override |
| 9871 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9872 | return getHalVersion(HAL_SERVICE_RADIO); |
| 9873 | } |
| 9874 | |
| 9875 | /** |
| 9876 | * Get the HAL Version of a specific service |
| 9877 | */ |
| 9878 | @Override |
| 9879 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9880 | Phone phone = getDefaultPhone(); |
| 9881 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 9882 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9883 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9884 | return hv.major * 100 + hv.minor; |
| 9885 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9886 | |
| 9887 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9888 | * Get the current calling package name. |
| 9889 | * @return the current calling package name |
| 9890 | */ |
| 9891 | @Override |
| 9892 | public String getCurrentPackageName() { |
| 9893 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9894 | } |
| 9895 | |
| 9896 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9897 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9898 | * corresponding network requests on a subId. |
| 9899 | * |
| 9900 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9901 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9902 | * 2) APN is un-metered for this subscription, or |
| 9903 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9904 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9905 | * |
| 9906 | * @return whether data is allowed for a apn type. |
| 9907 | * |
| 9908 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9909 | */ |
| 9910 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9911 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9912 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9913 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9914 | |
| 9915 | // Now that all security checks passes, perform the operation as ourselves. |
| 9916 | final long identity = Binder.clearCallingIdentity(); |
| 9917 | try { |
| 9918 | Phone phone = getPhone(subId); |
| 9919 | if (phone == null) return false; |
| 9920 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9921 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9922 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9923 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9924 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9925 | phone.getServiceState().getDataRoaming()); |
| 9926 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9927 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9928 | } finally { |
| 9929 | Binder.restoreCallingIdentity(identity); |
| 9930 | } |
| 9931 | } |
| 9932 | |
| 9933 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9934 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9935 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9936 | |
| 9937 | // Now that all security checks passes, perform the operation as ourselves. |
| 9938 | final long identity = Binder.clearCallingIdentity(); |
| 9939 | try { |
| 9940 | Phone phone = getPhone(subId); |
| 9941 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9942 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9943 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9944 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9945 | } finally { |
| 9946 | Binder.restoreCallingIdentity(identity); |
| 9947 | } |
| 9948 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9949 | |
| 9950 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9951 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9952 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9953 | enforceModifyPermission(); |
| 9954 | long token = Binder.clearCallingIdentity(); |
| 9955 | try { |
| 9956 | Phone phone = getPhone(subscriptionId); |
| 9957 | if (phone == null) { |
| 9958 | try { |
| 9959 | if (resultCallback != null) { |
| 9960 | resultCallback.accept(false); |
| 9961 | } |
| 9962 | } catch (RemoteException e) { |
| 9963 | // ignore |
| 9964 | } |
| 9965 | return; |
| 9966 | } |
| 9967 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9968 | Pair.create(specifiers, (x) -> { |
| 9969 | try { |
| 9970 | if (resultCallback != null) { |
| 9971 | resultCallback.accept(x); |
| 9972 | } |
| 9973 | } catch (RemoteException e) { |
| 9974 | // ignore |
| 9975 | } |
| 9976 | }); |
| 9977 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(token); |
| 9980 | } |
| 9981 | } |
| 9982 | |
| 9983 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9984 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9985 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9986 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9987 | mApp, subId, "getSystemSelectionChannels"); |
| 9988 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9989 | final long identity = Binder.clearCallingIdentity(); |
| 9990 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9991 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9992 | if (result instanceof IllegalStateException) { |
| 9993 | throw (IllegalStateException) result; |
| 9994 | } |
| 9995 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9996 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9997 | return specifiers; |
| 9998 | } finally { |
| 9999 | Binder.restoreCallingIdentity(identity); |
| 10000 | } |
| 10001 | } |
| 10002 | |
| 10003 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10004 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10005 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10006 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10007 | } |
| 10008 | |
| 10009 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10010 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10011 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10012 | if (callingPackage == null) { |
| 10013 | callingPackage = getCurrentPackageName(); |
| 10014 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10015 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10016 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10017 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10018 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10019 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10020 | } |
| 10021 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10022 | Intent intent = new Intent(); |
| 10023 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10024 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10025 | // Bring up choose default SMS subscription dialog right now |
| 10026 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10027 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10028 | mApp.startActivity(intent); |
| 10029 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10030 | |
| 10031 | @Override |
| 10032 | public String getMmsUAProfUrl(int subId) { |
| 10033 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10034 | final long identity = Binder.clearCallingIdentity(); |
| 10035 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10036 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10037 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10038 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10039 | return carrierUAProfUrl; |
| 10040 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10041 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10042 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10043 | } finally { |
| 10044 | Binder.restoreCallingIdentity(identity); |
| 10045 | } |
| 10046 | } |
| 10047 | |
| 10048 | @Override |
| 10049 | public String getMmsUserAgent(int subId) { |
| 10050 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10051 | final long identity = Binder.clearCallingIdentity(); |
| 10052 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10053 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10054 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10055 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10056 | return carrierUserAgent; |
| 10057 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10058 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10059 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10060 | } finally { |
| 10061 | Binder.restoreCallingIdentity(identity); |
| 10062 | } |
| 10063 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10064 | |
| 10065 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10066 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10067 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10068 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10069 | final long identity = Binder.clearCallingIdentity(); |
| 10070 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10071 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10072 | if (phone == null) return false; |
| 10073 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10074 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10075 | } finally { |
| 10076 | Binder.restoreCallingIdentity(identity); |
| 10077 | } |
| 10078 | } |
| 10079 | |
| 10080 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10081 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10082 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10083 | enforceModifyPermission(); |
| 10084 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10085 | final long identity = Binder.clearCallingIdentity(); |
| 10086 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10087 | Phone phone = getPhone(subscriptionId); |
| 10088 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10089 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10090 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10091 | } finally { |
| 10092 | Binder.restoreCallingIdentity(identity); |
| 10093 | } |
| 10094 | } |
| 10095 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10096 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10097 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10098 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10099 | * otherwise. |
| 10100 | */ |
| 10101 | @Override |
| 10102 | public void setCepEnabled(boolean isCepEnabled) { |
| 10103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10104 | |
| 10105 | final long identity = Binder.clearCallingIdentity(); |
| 10106 | try { |
| 10107 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10108 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10109 | Phone defaultPhone = phone.getImsPhone(); |
| 10110 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10111 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10112 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10113 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10114 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10115 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10116 | + imsPhone.getMsisdn()); |
| 10117 | } |
| 10118 | } |
| 10119 | } finally { |
| 10120 | Binder.restoreCallingIdentity(identity); |
| 10121 | } |
| 10122 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10123 | |
| 10124 | /** |
| 10125 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10126 | * |
| 10127 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10128 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10129 | * before being read. |
| 10130 | */ |
| 10131 | @Override |
| 10132 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10133 | isCompressed) { |
| 10134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10135 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10136 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10137 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10138 | } |
| 10139 | if (!isImsAvailableOnDevice()) { |
| 10140 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10141 | "IMS not available on device."); |
| 10142 | } |
| 10143 | |
| 10144 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10145 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10146 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10147 | } finally { |
| 10148 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10149 | } |
| 10150 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10151 | |
| 10152 | @Override |
| 10153 | public boolean isIccLockEnabled(int subId) { |
| 10154 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10155 | |
| 10156 | // Now that all security checks passes, perform the operation as ourselves. |
| 10157 | final long identity = Binder.clearCallingIdentity(); |
| 10158 | try { |
| 10159 | Phone phone = getPhone(subId); |
| 10160 | if (phone != null && phone.getIccCard() != null) { |
| 10161 | return phone.getIccCard().getIccLockEnabled(); |
| 10162 | } else { |
| 10163 | return false; |
| 10164 | } |
| 10165 | } finally { |
| 10166 | Binder.restoreCallingIdentity(identity); |
| 10167 | } |
| 10168 | } |
| 10169 | |
| 10170 | /** |
| 10171 | * Set the ICC pin lock enabled or disabled. |
| 10172 | * |
| 10173 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10174 | * three cases: |
| 10175 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10176 | * successfully. |
| 10177 | * - Positive number and zero for remaining password attempts. |
| 10178 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10179 | * |
| 10180 | */ |
| 10181 | @Override |
| 10182 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10183 | enforceModifyPermission(); |
| 10184 | |
| 10185 | Phone phone = getPhone(subId); |
| 10186 | if (phone == null) { |
| 10187 | return 0; |
| 10188 | } |
| 10189 | // Now that all security checks passes, perform the operation as ourselves. |
| 10190 | final long identity = Binder.clearCallingIdentity(); |
| 10191 | try { |
| 10192 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10193 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10194 | return attemptsRemaining; |
| 10195 | |
| 10196 | } catch (Exception e) { |
| 10197 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10198 | } finally { |
| 10199 | Binder.restoreCallingIdentity(identity); |
| 10200 | } |
| 10201 | return 0; |
| 10202 | } |
| 10203 | |
| 10204 | /** |
| 10205 | * Change the ICC password used in ICC pin lock. |
| 10206 | * |
| 10207 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10208 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10209 | * - Positive number and zero for remaining password attempts. |
| 10210 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10211 | * |
| 10212 | */ |
| 10213 | @Override |
| 10214 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10215 | enforceModifyPermission(); |
| 10216 | |
| 10217 | Phone phone = getPhone(subId); |
| 10218 | if (phone == null) { |
| 10219 | return 0; |
| 10220 | } |
| 10221 | // Now that all security checks passes, perform the operation as ourselves. |
| 10222 | final long identity = Binder.clearCallingIdentity(); |
| 10223 | try { |
| 10224 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10225 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10226 | return attemptsRemaining; |
| 10227 | |
| 10228 | } catch (Exception e) { |
| 10229 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10230 | } finally { |
| 10231 | Binder.restoreCallingIdentity(identity); |
| 10232 | } |
| 10233 | return 0; |
| 10234 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10235 | |
| 10236 | /** |
| 10237 | * Request for receiving user activity notification |
| 10238 | */ |
| 10239 | @Override |
| 10240 | public void requestUserActivityNotification() { |
| 10241 | if (!mNotifyUserActivity.get() |
| 10242 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10243 | mNotifyUserActivity.set(true); |
| 10244 | } |
| 10245 | } |
| 10246 | |
| 10247 | /** |
| 10248 | * Called when userActivity is signalled in the power manager. |
| 10249 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10250 | */ |
| 10251 | @Override |
| 10252 | public void userActivity() { |
| 10253 | // *************************************** |
| 10254 | // * Inherited from PhoneWindowManager * |
| 10255 | // *************************************** |
| 10256 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10257 | // WITH ITS LOCKS HELD. |
| 10258 | // |
| 10259 | // This code must be VERY careful about the locks |
| 10260 | // it acquires. |
| 10261 | // In fact, the current code acquires way too many, |
| 10262 | // and probably has lurking deadlocks. |
| 10263 | |
| 10264 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10265 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10266 | } |
| 10267 | |
| 10268 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10269 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10270 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10271 | } |
| 10272 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10273 | |
| 10274 | @Override |
| 10275 | public boolean canConnectTo5GInDsdsMode() { |
| 10276 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10277 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10278 | |
| 10279 | @Override |
| 10280 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10281 | String callingFeatureId) { |
| 10282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10283 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10284 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10285 | } |
| 10286 | |
| 10287 | Phone phone = getPhone(subId); |
| 10288 | if (phone == null) { |
| 10289 | throw new RuntimeException("phone is not available"); |
| 10290 | } |
| 10291 | // Now that all security checks passes, perform the operation as ourselves. |
| 10292 | final long identity = Binder.clearCallingIdentity(); |
| 10293 | try { |
| 10294 | return phone.getEquivalentHomePlmns(); |
| 10295 | } finally { |
| 10296 | Binder.restoreCallingIdentity(identity); |
| 10297 | } |
| 10298 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10299 | |
| 10300 | @Override |
| 10301 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10302 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10303 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10304 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10305 | if (radioInterfaceCapabilities == null) { |
| 10306 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10307 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10308 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10309 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10310 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10311 | @Override |
| 10312 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10313 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10314 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10315 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10316 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10317 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10318 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10319 | if (DBG) { |
| 10320 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10321 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10322 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10323 | } |
| 10324 | |
| 10325 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10326 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10327 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10328 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10329 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10330 | if (callback != null) { |
| 10331 | try { |
| 10332 | callback.onAuthenticationFailure( |
| 10333 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10334 | } catch (RemoteException exception) { |
| 10335 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10336 | } |
| 10337 | return; |
| 10338 | } |
| 10339 | } |
| 10340 | |
| 10341 | final long token = Binder.clearCallingIdentity(); |
| 10342 | try { |
| 10343 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10344 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10345 | forceBootStrapping, callback)); |
| 10346 | } finally { |
| 10347 | Binder.restoreCallingIdentity(token); |
| 10348 | } |
| 10349 | } |
| 10350 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10351 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10352 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10353 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10354 | * requested radio power state will actually be set. See {@link |
| 10355 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10356 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10357 | * @param enable {@code true} if trying to turn radio on. |
| 10358 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10359 | * false}. |
| 10360 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10361 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10362 | boolean isPhoneAvailable = false; |
| 10363 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10364 | Phone phone = PhoneFactory.getPhone(i); |
| 10365 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10366 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10367 | isPhoneAvailable = true; |
| 10368 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10369 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10370 | |
| 10371 | // return true if successfully informed the phone object about the thermal radio power |
| 10372 | // request. |
| 10373 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10374 | } |
| 10375 | |
| 10376 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10377 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10378 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10379 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10380 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10381 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10382 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10383 | } |
| 10384 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10385 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10386 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10387 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10388 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10389 | } |
| 10390 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10391 | setDataEnabledForReason( |
| 10392 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10393 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10394 | if (isDataThrottlingSupported) { |
| 10395 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10396 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10397 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10398 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10399 | } else if (thermalMitigationResult |
| 10400 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10401 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10402 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10403 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10404 | } |
| 10405 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10406 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10407 | |
| 10408 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10409 | } |
| 10410 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10411 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10412 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10413 | for (String pckg : context.getResources() |
| 10414 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10415 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10416 | } |
| 10417 | } |
| 10418 | |
| 10419 | return sThermalMitigationAllowlistedPackages; |
| 10420 | } |
| 10421 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10422 | private boolean isAnyPhoneInEmergencyState() { |
| 10423 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10424 | if (tm.isInEmergencyCall()) { |
| 10425 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10426 | return true; |
| 10427 | } |
| 10428 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10429 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10430 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10431 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10432 | + phone.isInEcm()); |
| 10433 | return true; |
| 10434 | } |
| 10435 | } |
| 10436 | |
| 10437 | return false; |
| 10438 | } |
| 10439 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10440 | /** |
| 10441 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10442 | * @param packageName name of package to be allowlisted |
| 10443 | * @param context |
| 10444 | */ |
| 10445 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10446 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10447 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10448 | } |
| 10449 | |
| 10450 | /** |
| 10451 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10452 | * @param packageName name of package to remove from allowlist |
| 10453 | * @param context |
| 10454 | */ |
| 10455 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10456 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10457 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10458 | } |
| 10459 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10460 | /** |
| 10461 | * Thermal mitigation request to control functionalities at modem. |
| 10462 | * |
| 10463 | * @param subId the id of the subscription. |
| 10464 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10465 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10466 | * |
| 10467 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10468 | */ |
| 10469 | @Override |
| 10470 | @ThermalMitigationResult |
| 10471 | public int sendThermalMitigationRequest( |
| 10472 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10473 | ThermalMitigationRequest thermalMitigationRequest, |
| 10474 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10475 | enforceModifyPermission(); |
| 10476 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10477 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10478 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10479 | .contains(callingPackage)) { |
| 10480 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10481 | + "calling package: " + callingPackage); |
| 10482 | } |
| 10483 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10484 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10485 | final long identity = Binder.clearCallingIdentity(); |
| 10486 | |
| 10487 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10488 | try { |
| 10489 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10490 | switch (thermalMitigationAction) { |
| 10491 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10492 | thermalMitigationResult = |
| 10493 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10494 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10495 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10496 | break; |
| 10497 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10498 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10499 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10500 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10501 | } |
| 10502 | |
| 10503 | // Ensure that radio is on. If not able to power on due to phone being |
| 10504 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10505 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10506 | thermalMitigationResult = |
| 10507 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10508 | break; |
| 10509 | } |
| 10510 | |
| 10511 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10512 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10513 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10514 | break; |
| 10515 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10516 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10517 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10518 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10519 | } |
| 10520 | |
| 10521 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10522 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10523 | Phone phone = getPhone(subId); |
| 10524 | if (phone == null) { |
| 10525 | thermalMitigationResult = |
| 10526 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10527 | break; |
| 10528 | } |
| 10529 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10530 | TelephonyConnectionService service = |
| 10531 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10532 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10533 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10534 | thermalMitigationResult = |
| 10535 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10536 | break; |
| 10537 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10538 | thermalMitigationResult = |
| 10539 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10540 | break; |
| 10541 | } |
| 10542 | } else { |
| 10543 | thermalMitigationResult = |
| 10544 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10545 | break; |
| 10546 | } |
| 10547 | |
| 10548 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10549 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10550 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10551 | thermalMitigationResult = |
| 10552 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10553 | break; |
| 10554 | } |
| 10555 | thermalMitigationResult = |
| 10556 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10557 | break; |
| 10558 | default: |
| 10559 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10560 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10561 | } |
| 10562 | } catch (IllegalArgumentException e) { |
| 10563 | throw e; |
| 10564 | } catch (Exception e) { |
| 10565 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10566 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10567 | } finally { |
| 10568 | Binder.restoreCallingIdentity(identity); |
| 10569 | } |
| 10570 | |
| 10571 | if (DBG) { |
| 10572 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10573 | + thermalMitigationResult); |
| 10574 | } |
| 10575 | |
| 10576 | return thermalMitigationResult; |
| 10577 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10578 | |
| 10579 | /** |
| 10580 | * Set the GbaService Package Name that Telephony will bind to. |
| 10581 | * |
| 10582 | * @param subId The sim that the GbaService is associated with. |
| 10583 | * @param packageName The name of the package to be replaced with. |
| 10584 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10585 | */ |
| 10586 | @Override |
| 10587 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10588 | enforceModifyPermission(); |
| 10589 | |
| 10590 | final long identity = Binder.clearCallingIdentity(); |
| 10591 | try { |
| 10592 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10593 | } finally { |
| 10594 | Binder.restoreCallingIdentity(identity); |
| 10595 | } |
| 10596 | } |
| 10597 | |
| 10598 | /** |
| 10599 | * Return the package name of the currently bound GbaService. |
| 10600 | * |
| 10601 | * @param subId The sim that the GbaService is associated with. |
| 10602 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10603 | */ |
| 10604 | @Override |
| 10605 | public String getBoundGbaService(int subId) { |
| 10606 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10607 | |
| 10608 | final long identity = Binder.clearCallingIdentity(); |
| 10609 | try { |
| 10610 | return getGbaManager(subId).getServicePackage(); |
| 10611 | } finally { |
| 10612 | Binder.restoreCallingIdentity(identity); |
| 10613 | } |
| 10614 | } |
| 10615 | |
| 10616 | /** |
| 10617 | * Set the release time for telephony to unbind GbaService. |
| 10618 | * |
| 10619 | * @param subId The sim that the GbaService is associated with. |
| 10620 | * @param interval The release time to unbind GbaService by millisecond. |
| 10621 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10622 | */ |
| 10623 | @Override |
| 10624 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10625 | enforceModifyPermission(); |
| 10626 | |
| 10627 | final long identity = Binder.clearCallingIdentity(); |
| 10628 | try { |
| 10629 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10630 | } finally { |
| 10631 | Binder.restoreCallingIdentity(identity); |
| 10632 | } |
| 10633 | } |
| 10634 | |
| 10635 | /** |
| 10636 | * Return the release time for telephony to unbind GbaService. |
| 10637 | * |
| 10638 | * @param subId The sim that the GbaService is associated with. |
| 10639 | * @return The release time to unbind GbaService by millisecond. |
| 10640 | */ |
| 10641 | @Override |
| 10642 | public int getGbaReleaseTime(int subId) { |
| 10643 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10644 | |
| 10645 | final long identity = Binder.clearCallingIdentity(); |
| 10646 | try { |
| 10647 | return getGbaManager(subId).getReleaseTime(); |
| 10648 | } finally { |
| 10649 | Binder.restoreCallingIdentity(identity); |
| 10650 | } |
| 10651 | } |
| 10652 | |
| 10653 | private GbaManager getGbaManager(int subId) { |
| 10654 | GbaManager instance = GbaManager.getInstance(subId); |
| 10655 | if (instance == null) { |
| 10656 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10657 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10658 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10659 | } |
| 10660 | return instance; |
| 10661 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10662 | |
| 10663 | /** |
| 10664 | * indicate whether the device and the carrier can support |
| 10665 | * RCS VoLTE single registration. |
| 10666 | */ |
| 10667 | @Override |
| 10668 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10669 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10670 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10671 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10672 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10673 | |
| 10674 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10675 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10676 | } |
| 10677 | |
| 10678 | final long identity = Binder.clearCallingIdentity(); |
| 10679 | try { |
| 10680 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10681 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10682 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10683 | if (isCapable != null) { |
| 10684 | return isCapable; |
| 10685 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10686 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10687 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10688 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10689 | } finally { |
| 10690 | Binder.restoreCallingIdentity(identity); |
| 10691 | } |
| 10692 | } |
| 10693 | |
| 10694 | /** |
| 10695 | * Register RCS provisioning callback. |
| 10696 | */ |
| 10697 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10698 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10699 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10700 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10701 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10702 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10703 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10704 | |
| 10705 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10706 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10707 | } |
| 10708 | if (!isImsAvailableOnDevice()) { |
| 10709 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10710 | "IMS not available on device."); |
| 10711 | } |
| 10712 | |
| 10713 | final long identity = Binder.clearCallingIdentity(); |
| 10714 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10715 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10716 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10717 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10718 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10719 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10720 | } finally { |
| 10721 | Binder.restoreCallingIdentity(identity); |
| 10722 | } |
| 10723 | } |
| 10724 | |
| 10725 | /** |
| 10726 | * Unregister RCS provisioning callback. |
| 10727 | */ |
| 10728 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10729 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10730 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10731 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10732 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10733 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10734 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10735 | |
| 10736 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10737 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10738 | } |
| 10739 | if (!isImsAvailableOnDevice()) { |
| 10740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10741 | "IMS not available on device."); |
| 10742 | } |
| 10743 | |
| 10744 | final long identity = Binder.clearCallingIdentity(); |
| 10745 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10746 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10747 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10748 | } finally { |
| 10749 | Binder.restoreCallingIdentity(identity); |
| 10750 | } |
| 10751 | } |
| 10752 | |
| 10753 | /** |
| 10754 | * trigger RCS reconfiguration. |
| 10755 | */ |
| 10756 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10757 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10758 | "triggerRcsReconfiguration", |
| 10759 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10760 | |
| 10761 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10762 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10763 | } |
| 10764 | if (!isImsAvailableOnDevice()) { |
| 10765 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10766 | "IMS not available on device."); |
| 10767 | } |
| 10768 | |
| 10769 | final long identity = Binder.clearCallingIdentity(); |
| 10770 | try { |
| 10771 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10772 | } finally { |
| 10773 | Binder.restoreCallingIdentity(identity); |
| 10774 | } |
| 10775 | } |
| 10776 | |
| 10777 | /** |
| 10778 | * Provide the client configuration parameters of the RCS application. |
| 10779 | */ |
| 10780 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10781 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10782 | "setRcsClientConfiguration", |
| 10783 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10784 | |
| 10785 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10786 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10787 | } |
| 10788 | if (!isImsAvailableOnDevice()) { |
| 10789 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10790 | "IMS not available on device."); |
| 10791 | } |
| 10792 | |
| 10793 | final long identity = Binder.clearCallingIdentity(); |
| 10794 | |
| 10795 | try { |
| 10796 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10797 | if (configBinder == null) { |
| 10798 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10799 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10800 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10801 | } else { |
| 10802 | configBinder.setRcsClientConfiguration(rcc); |
| 10803 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10804 | |
| 10805 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10806 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10807 | } catch (RemoteException e) { |
| 10808 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10809 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10810 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10811 | } finally { |
| 10812 | Binder.restoreCallingIdentity(identity); |
| 10813 | } |
| 10814 | } |
| 10815 | |
| 10816 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10817 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10818 | */ |
| 10819 | @Override |
| 10820 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10821 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10822 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10823 | |
| 10824 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10825 | } |
| 10826 | |
| 10827 | /** |
| 10828 | * Gets the test mode for RCS VoLTE single registration. |
| 10829 | */ |
| 10830 | @Override |
| 10831 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10832 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10833 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10834 | |
| 10835 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10836 | } |
| 10837 | |
| 10838 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10839 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10840 | */ |
| 10841 | @Override |
| 10842 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10843 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10844 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10845 | enforceModifyPermission(); |
| 10846 | |
| 10847 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10848 | : Boolean.parseBoolean(enabledStr); |
| 10849 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10850 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10851 | } |
| 10852 | |
| 10853 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10854 | * Sends a device to device communication message. Only usable via shell. |
| 10855 | * @param message message to send. |
| 10856 | * @param value message value. |
| 10857 | */ |
| 10858 | @Override |
| 10859 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10860 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10861 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10862 | enforceModifyPermission(); |
| 10863 | |
| 10864 | final long identity = Binder.clearCallingIdentity(); |
| 10865 | try { |
| 10866 | TelephonyConnectionService service = |
| 10867 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10868 | if (service == null) { |
| 10869 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10870 | return; |
| 10871 | } |
| 10872 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10873 | } finally { |
| 10874 | Binder.restoreCallingIdentity(identity); |
| 10875 | } |
| 10876 | } |
| 10877 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10878 | /** |
| 10879 | * Sets the specified device to device transport active. |
| 10880 | * @param transport The transport to set active. |
| 10881 | */ |
| 10882 | @Override |
| 10883 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10884 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10885 | "setActiveDeviceToDeviceTransport"); |
| 10886 | enforceModifyPermission(); |
| 10887 | |
| 10888 | final long identity = Binder.clearCallingIdentity(); |
| 10889 | try { |
| 10890 | TelephonyConnectionService service = |
| 10891 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10892 | if (service == null) { |
| 10893 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10894 | return; |
| 10895 | } |
| 10896 | service.setActiveDeviceToDeviceTransport(transport); |
| 10897 | } finally { |
| 10898 | Binder.restoreCallingIdentity(identity); |
| 10899 | } |
| 10900 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10901 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10902 | @Override |
| 10903 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10904 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10905 | "setDeviceToDeviceForceEnabled"); |
| 10906 | |
| 10907 | final long identity = Binder.clearCallingIdentity(); |
| 10908 | try { |
| 10909 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10910 | p -> { |
| 10911 | Phone thePhone = p.getImsPhone(); |
| 10912 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10913 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10914 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10915 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10916 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10917 | (ImsPhoneCallTracker) tracker; |
| 10918 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10919 | } |
| 10920 | } |
| 10921 | } |
| 10922 | ); |
| 10923 | } finally { |
| 10924 | Binder.restoreCallingIdentity(identity); |
| 10925 | } |
| 10926 | } |
| 10927 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10928 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10929 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10930 | */ |
| 10931 | @Override |
| 10932 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10933 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10934 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10935 | } |
| 10936 | |
| 10937 | /** |
| 10938 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10939 | */ |
| 10940 | @Override |
| 10941 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10942 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10943 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10944 | enforceModifyPermission(); |
| 10945 | |
| 10946 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10947 | : Boolean.parseBoolean(enabledStr); |
| 10948 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10949 | subId, enabled); |
| 10950 | } |
| 10951 | |
| 10952 | /** |
| 10953 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10954 | */ |
| 10955 | @Override |
| 10956 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10957 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10958 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10959 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10960 | |
| 10961 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10962 | * Overrides the ims feature validation result |
| 10963 | */ |
| 10964 | @Override |
| 10965 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10966 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10967 | "setImsFeatureValidationOverride"); |
| 10968 | |
| 10969 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10970 | : Boolean.parseBoolean(enabledStr); |
| 10971 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10972 | subId, enabled); |
| 10973 | } |
| 10974 | |
| 10975 | /** |
| 10976 | * Gets the ims feature validation override value |
| 10977 | */ |
| 10978 | @Override |
| 10979 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10980 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10981 | "getImsFeatureValidationOverride"); |
| 10982 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10983 | } |
| 10984 | |
| 10985 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10986 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10987 | * their mobile plan. |
| 10988 | */ |
| 10989 | @Override |
| 10990 | public String getMobileProvisioningUrl() { |
| 10991 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10992 | final long identity = Binder.clearCallingIdentity(); |
| 10993 | try { |
| 10994 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10995 | } finally { |
| 10996 | Binder.restoreCallingIdentity(identity); |
| 10997 | } |
| 10998 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10999 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11000 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11001 | * Get the EAB contact from the EAB database. |
| 11002 | */ |
| 11003 | @Override |
| 11004 | public String getContactFromEab(String contact) { |
| 11005 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11006 | enforceModifyPermission(); |
| 11007 | final long identity = Binder.clearCallingIdentity(); |
| 11008 | try { |
| 11009 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11010 | } finally { |
| 11011 | Binder.restoreCallingIdentity(identity); |
| 11012 | } |
| 11013 | } |
| 11014 | |
| 11015 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11016 | * Get the EAB capability from the EAB database. |
| 11017 | */ |
| 11018 | @Override |
| 11019 | public String getCapabilityFromEab(String contact) { |
| 11020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11021 | enforceModifyPermission(); |
| 11022 | final long identity = Binder.clearCallingIdentity(); |
| 11023 | try { |
| 11024 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11025 | } finally { |
| 11026 | Binder.restoreCallingIdentity(identity); |
| 11027 | } |
| 11028 | } |
| 11029 | |
| 11030 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11031 | * Remove the EAB contacts from the EAB database. |
| 11032 | */ |
| 11033 | @Override |
| 11034 | public int removeContactFromEab(int subId, String contacts) { |
| 11035 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11036 | enforceModifyPermission(); |
| 11037 | final long identity = Binder.clearCallingIdentity(); |
| 11038 | try { |
| 11039 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(identity); |
| 11042 | } |
| 11043 | } |
| 11044 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11045 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11046 | public boolean getDeviceUceEnabled() { |
| 11047 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11048 | final long identity = Binder.clearCallingIdentity(); |
| 11049 | try { |
| 11050 | return mApp.getDeviceUceEnabled(); |
| 11051 | } finally { |
| 11052 | Binder.restoreCallingIdentity(identity); |
| 11053 | } |
| 11054 | } |
| 11055 | |
| 11056 | @Override |
| 11057 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11058 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11059 | final long identity = Binder.clearCallingIdentity(); |
| 11060 | try { |
| 11061 | mApp.setDeviceUceEnabled(isEnabled); |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
| 11066 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11067 | /** |
| 11068 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11069 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11070 | */ |
| 11071 | // Used for SHELL command only right now. |
| 11072 | @Override |
| 11073 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11074 | List<String> featureTags) { |
| 11075 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11076 | "addUceRegistrationOverrideShell"); |
| 11077 | final long identity = Binder.clearCallingIdentity(); |
| 11078 | try { |
| 11079 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11080 | new ArraySet<>(featureTags)); |
| 11081 | } catch (ImsException e) { |
| 11082 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11083 | } finally { |
| 11084 | Binder.restoreCallingIdentity(identity); |
| 11085 | } |
| 11086 | } |
| 11087 | |
| 11088 | /** |
| 11089 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11090 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11091 | */ |
| 11092 | // Used for SHELL command only right now. |
| 11093 | @Override |
| 11094 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11095 | List<String> featureTags) { |
| 11096 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11097 | "removeUceRegistrationOverrideShell"); |
| 11098 | final long identity = Binder.clearCallingIdentity(); |
| 11099 | try { |
| 11100 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11101 | new ArraySet<>(featureTags)); |
| 11102 | } catch (ImsException e) { |
| 11103 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
| 11106 | } |
| 11107 | } |
| 11108 | |
| 11109 | /** |
| 11110 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11111 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11112 | */ |
| 11113 | // Used for SHELL command only right now. |
| 11114 | @Override |
| 11115 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11116 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11117 | "clearUceRegistrationOverrideShell"); |
| 11118 | final long identity = Binder.clearCallingIdentity(); |
| 11119 | try { |
| 11120 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11121 | } catch (ImsException e) { |
| 11122 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11123 | } finally { |
| 11124 | Binder.restoreCallingIdentity(identity); |
| 11125 | } |
| 11126 | } |
| 11127 | |
| 11128 | /** |
| 11129 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11130 | */ |
| 11131 | // Used for SHELL command only right now. |
| 11132 | @Override |
| 11133 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11134 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11135 | "getLatestRcsContactUceCapabilityShell"); |
| 11136 | final long identity = Binder.clearCallingIdentity(); |
| 11137 | try { |
| 11138 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11139 | } catch (ImsException e) { |
| 11140 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11141 | } finally { |
| 11142 | Binder.restoreCallingIdentity(identity); |
| 11143 | } |
| 11144 | } |
| 11145 | |
| 11146 | /** |
| 11147 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11148 | * device does not have an active PUBLISH. |
| 11149 | */ |
| 11150 | // Used for SHELL command only right now. |
| 11151 | @Override |
| 11152 | public String getLastUcePidfXmlShell(int subId) { |
| 11153 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11154 | final long identity = Binder.clearCallingIdentity(); |
| 11155 | try { |
| 11156 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11157 | } catch (ImsException e) { |
| 11158 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11159 | } finally { |
| 11160 | Binder.restoreCallingIdentity(identity); |
| 11161 | } |
| 11162 | } |
| 11163 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11164 | /** |
| 11165 | * Remove UCE requests cannot be sent to the network status. |
| 11166 | */ |
| 11167 | // Used for SHELL command only right now. |
| 11168 | @Override |
| 11169 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11170 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11171 | final long identity = Binder.clearCallingIdentity(); |
| 11172 | try { |
| 11173 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11174 | } catch (ImsException e) { |
| 11175 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11176 | } finally { |
| 11177 | Binder.restoreCallingIdentity(identity); |
| 11178 | } |
| 11179 | } |
| 11180 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11181 | /** |
| 11182 | * Remove UCE requests cannot be sent to the network status. |
| 11183 | */ |
| 11184 | // Used for SHELL command only. |
| 11185 | @Override |
| 11186 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11187 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11188 | final long identity = Binder.clearCallingIdentity(); |
| 11189 | try { |
| 11190 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11191 | } catch (ImsException e) { |
| 11192 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11193 | } finally { |
| 11194 | Binder.restoreCallingIdentity(identity); |
| 11195 | } |
| 11196 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11197 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11198 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11199 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11200 | String callingPackage) { |
| 11201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11202 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11203 | |
| 11204 | final int callingUid = Binder.getCallingUid(); |
| 11205 | // Verify that tha callingPackage belongs to the calling UID |
| 11206 | mApp.getSystemService(AppOpsManager.class) |
| 11207 | .checkPackage(callingUid, callingPackage); |
| 11208 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11209 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11210 | |
| 11211 | final long identity = Binder.clearCallingIdentity(); |
| 11212 | try { |
| 11213 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11214 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11215 | |
| 11216 | if (result instanceof IllegalStateException) { |
| 11217 | throw (IllegalStateException) result; |
| 11218 | } |
| 11219 | } finally { |
| 11220 | Binder.restoreCallingIdentity(identity); |
| 11221 | } |
| 11222 | } |
| 11223 | |
| 11224 | @Override |
| 11225 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11226 | String callingPackage) { |
| 11227 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11228 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11229 | |
| 11230 | final int callingUid = Binder.getCallingUid(); |
| 11231 | // Verify that tha callingPackage belongs to the calling UID |
| 11232 | mApp.getSystemService(AppOpsManager.class) |
| 11233 | .checkPackage(callingUid, callingPackage); |
| 11234 | |
| 11235 | final long identity = Binder.clearCallingIdentity(); |
| 11236 | try { |
| 11237 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11238 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11239 | |
| 11240 | if (result instanceof IllegalStateException) { |
| 11241 | throw (IllegalStateException) result; |
| 11242 | } |
| 11243 | } finally { |
| 11244 | Binder.restoreCallingIdentity(identity); |
| 11245 | } |
| 11246 | } |
| 11247 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11248 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11249 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11250 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11251 | // phone/system process do not have further restriction on request |
| 11252 | return; |
| 11253 | } |
| 11254 | |
| 11255 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11256 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11257 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11258 | context.enforceCallingOrSelfPermission( |
| 11259 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11260 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11261 | } |
| 11262 | |
| 11263 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11264 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11265 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11266 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11267 | || info.isEnabled()) { |
| 11268 | throw new IllegalArgumentException( |
| 11269 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11270 | } |
| 11271 | |
| 11272 | // Thresholds length for each RAN need in range. This has been validated in |
| 11273 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11274 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11275 | final int[] thresholds = info.getThresholds(); |
| 11276 | Objects.requireNonNull(thresholds); |
| 11277 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11278 | || thresholds.length |
| 11279 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11280 | throw new IllegalArgumentException( |
| 11281 | "thresholds length is out of range: " + thresholds.length); |
| 11282 | } |
| 11283 | } |
| 11284 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11285 | |
| 11286 | /** |
| 11287 | * Gets the current phone capability. |
| 11288 | * |
| 11289 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11290 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11291 | * It's used to evaluate possible phone config change, for example from single |
| 11292 | * SIM device to multi-SIM device. |
| 11293 | */ |
| 11294 | @Override |
| 11295 | public PhoneCapability getPhoneCapability() { |
| 11296 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11297 | final long identity = Binder.clearCallingIdentity(); |
| 11298 | try { |
| 11299 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11300 | } finally { |
| 11301 | Binder.restoreCallingIdentity(identity); |
| 11302 | } |
| 11303 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11304 | |
| 11305 | /** |
| 11306 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11307 | * required to be done shortly after the API is invoked. |
| 11308 | */ |
| 11309 | @Override |
| 11310 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11311 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11312 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11313 | enforceRebootPermission(); |
| 11314 | |
| 11315 | final long identity = Binder.clearCallingIdentity(); |
| 11316 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11317 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11318 | } finally { |
| 11319 | Binder.restoreCallingIdentity(identity); |
| 11320 | } |
| 11321 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11322 | |
| 11323 | /** |
| 11324 | * Request to get the current slicing configuration including URSP rules and |
| 11325 | * NSSAIs (configured, allowed and rejected). |
| 11326 | * |
| 11327 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11328 | */ |
| 11329 | @Override |
| 11330 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11331 | TelephonyPermissions |
| 11332 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11333 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11334 | |
| 11335 | final long identity = Binder.clearCallingIdentity(); |
| 11336 | try { |
| 11337 | Phone phone = getDefaultPhone(); |
| 11338 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11339 | } finally { |
| 11340 | Binder.restoreCallingIdentity(identity); |
| 11341 | } |
| 11342 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11343 | |
| 11344 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11345 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11346 | * |
| 11347 | * @param capability The premium capability to check. |
| 11348 | * @param subId The subId to check the premium capability for. |
| 11349 | * |
| 11350 | * @return Whether the given premium capability is available to purchase. |
| 11351 | */ |
| 11352 | @Override |
| 11353 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11354 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11355 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11356 | log("Premium capability " |
| 11357 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11358 | + " is not available for purchase due to missing permissions."); |
| 11359 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11360 | + "permission READ_BASIC_PHONE_STATE."); |
| 11361 | } |
| 11362 | |
| 11363 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11364 | if (phone == null) { |
| 11365 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11366 | return false; |
| 11367 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11368 | final long identity = Binder.clearCallingIdentity(); |
| 11369 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11370 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11371 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11372 | } finally { |
| 11373 | Binder.restoreCallingIdentity(identity); |
| 11374 | } |
| 11375 | } |
| 11376 | |
| 11377 | /** |
| 11378 | * Purchase the given premium capability from the carrier. |
| 11379 | * |
| 11380 | * @param capability The premium capability to purchase. |
| 11381 | * @param callback The result of the purchase request. |
| 11382 | * @param subId The subId to purchase the premium capability for. |
| 11383 | */ |
| 11384 | @Override |
| 11385 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11386 | log("purchasePremiumCapability: capability=" |
| 11387 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11388 | + getCurrentPackageName()); |
| 11389 | |
| 11390 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11391 | mApp, "purchasePremiumCapability")) { |
| 11392 | log("purchasePremiumCapability " |
| 11393 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11394 | + " failed due to missing permissions."); |
| 11395 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11396 | + "READ_BASIC_PHONE_STATE."); |
| 11397 | } |
| 11398 | |
| 11399 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11400 | if (phone == null) { |
| 11401 | try { |
| 11402 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11403 | callback.accept(result); |
| 11404 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11405 | } catch (RemoteException e) { |
| 11406 | String logStr = "Purchase premium capability " |
| 11407 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11408 | + " failed due to RemoteException handling null phone: " + e; |
| 11409 | if (DBG) log(logStr); |
| 11410 | AnomalyReporter.reportAnomaly( |
| 11411 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11412 | } |
| 11413 | return; |
| 11414 | } |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11415 | String appName; |
| 11416 | try { |
| 11417 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11418 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11419 | } catch (PackageManager.NameNotFoundException e) { |
| 11420 | appName = "An application"; |
| 11421 | } |
| 11422 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11423 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11424 | } |
| 11425 | |
| 11426 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11427 | * Register an IMS connection state callback |
| 11428 | */ |
| 11429 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11430 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11431 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11432 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11433 | // ImsMmTelManager |
| 11434 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11435 | TelephonyPermissions |
| 11436 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11437 | mApp, subId, "registerImsStateCallback"); |
| 11438 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11439 | // ImsRcsManager or SipDelegateManager |
| 11440 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11441 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11442 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11443 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11444 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11445 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11446 | } |
| 11447 | |
| 11448 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11449 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11450 | "IMS not available on device."); |
| 11451 | } |
| 11452 | |
| 11453 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11454 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11455 | } |
| 11456 | |
| 11457 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11458 | if (controller == null) { |
| 11459 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11460 | "IMS not available on device."); |
| 11461 | } |
| 11462 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11463 | if (callingPackage == null) { |
| 11464 | callingPackage = getCurrentPackageName(); |
| 11465 | } |
| 11466 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11467 | final long token = Binder.clearCallingIdentity(); |
| 11468 | try { |
| 11469 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11470 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11471 | } catch (ImsException e) { |
| 11472 | throw new ServiceSpecificException(e.getCode()); |
| 11473 | } finally { |
| 11474 | Binder.restoreCallingIdentity(token); |
| 11475 | } |
| 11476 | } |
| 11477 | |
| 11478 | /** |
| 11479 | * Unregister an IMS connection state callback |
| 11480 | */ |
| 11481 | @Override |
| 11482 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11483 | final long token = Binder.clearCallingIdentity(); |
| 11484 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11485 | if (controller == null) { |
| 11486 | return; |
| 11487 | } |
| 11488 | try { |
| 11489 | controller.unregisterImsStateCallback(cb); |
| 11490 | } finally { |
| 11491 | Binder.restoreCallingIdentity(token); |
| 11492 | } |
| 11493 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11494 | |
| 11495 | /** |
| 11496 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11497 | * |
| 11498 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11499 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11500 | * SecurityException. |
| 11501 | * If there is current registered network this value will be same as the registered cell |
| 11502 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11503 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11504 | * it will be cleared and null will be returned. |
| 11505 | * |
| 11506 | */ |
| 11507 | @Override |
| 11508 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11509 | String callingFeatureId) { |
| 11510 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11511 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11512 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11513 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11514 | .setCallingPackage(callingPackage) |
| 11515 | .setCallingFeatureId(callingFeatureId) |
| 11516 | .setCallingPid(Binder.getCallingPid()) |
| 11517 | .setCallingUid(Binder.getCallingUid()) |
| 11518 | .setMethod("getLastKnownCellIdentity") |
| 11519 | .setLogAsInfo(true) |
| 11520 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11521 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11522 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11523 | .build()); |
| 11524 | |
| 11525 | boolean hasFinePermission = |
| 11526 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11527 | if (!hasFinePermission |
| 11528 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11529 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11530 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11531 | } |
| 11532 | |
| 11533 | final long identity = Binder.clearCallingIdentity(); |
| 11534 | try { |
| 11535 | Phone phone = getPhone(subId); |
| 11536 | if (phone == null) return null; |
| 11537 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11538 | if (sst == null) return null; |
| 11539 | return sst.getLastKnownCellIdentity(); |
| 11540 | } finally { |
| 11541 | Binder.restoreCallingIdentity(identity); |
| 11542 | } |
| 11543 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11544 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11545 | /** |
| 11546 | * Sets the modem service class Name that Telephony will bind to. |
| 11547 | * |
| 11548 | * @param serviceName The class name of the modem service. |
| 11549 | * @return true if the operation is succeed, otherwise false. |
| 11550 | */ |
| 11551 | public boolean setModemService(String serviceName) { |
| 11552 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11553 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11554 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11555 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11556 | "setModemService"); |
| 11557 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11558 | } |
| 11559 | |
| 11560 | /** |
| 11561 | * Return the class name of the currently bounded modem service. |
| 11562 | * |
| 11563 | * @return the class name of the modem service. |
| 11564 | */ |
| 11565 | public String getModemService() { |
| 11566 | String result; |
| 11567 | Log.d(LOG_TAG, "getModemService"); |
| 11568 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11569 | TelephonyPermissions |
| 11570 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11571 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11572 | "getModemService"); |
| 11573 | result = mPhoneConfigurationManager.getModemService(); |
| 11574 | Log.d(LOG_TAG, "result = " + result); |
| 11575 | return result; |
| 11576 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11577 | |
| 11578 | @Override |
| 11579 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11580 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11581 | mApp.enforceCallingOrSelfPermission( |
| 11582 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11583 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11584 | |
| 11585 | final long identity = Binder.clearCallingIdentity(); |
| 11586 | try { |
| 11587 | Phone phone = getPhone(subId); |
| 11588 | if (phone == null) return; |
| 11589 | phone.setVoiceServiceStateOverride(hasService); |
| 11590 | } finally { |
| 11591 | Binder.restoreCallingIdentity(identity); |
| 11592 | } |
| 11593 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11594 | |
| 11595 | /** |
| 11596 | * set removable eSIM as default eUICC. |
| 11597 | * |
| 11598 | * @hide |
| 11599 | */ |
| 11600 | @Override |
| 11601 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11602 | enforceModifyPermission(); |
| 11603 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11604 | |
| 11605 | final long identity = Binder.clearCallingIdentity(); |
| 11606 | try { |
| 11607 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11608 | } finally { |
| 11609 | Binder.restoreCallingIdentity(identity); |
| 11610 | } |
| 11611 | } |
| 11612 | |
| 11613 | /** |
| 11614 | * Returns whether the removable eSIM is default eUICC or not. |
| 11615 | * |
| 11616 | * @hide |
| 11617 | */ |
| 11618 | @Override |
| 11619 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11620 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11621 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11622 | |
| 11623 | final long identity = Binder.clearCallingIdentity(); |
| 11624 | try { |
| 11625 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11626 | } finally { |
| 11627 | Binder.restoreCallingIdentity(identity); |
| 11628 | } |
| 11629 | } |
| 11630 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11631 | /** |
| 11632 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11633 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11634 | * application currently configured for this user. |
| 11635 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11636 | * {@code null} if the functionality is not supported. |
| 11637 | * @hide |
| 11638 | */ |
| 11639 | @Override |
| 11640 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11641 | boolean updateIfNeeded) { |
| 11642 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11643 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11644 | Context context = getPhone(subId).getContext(); |
| 11645 | UserHandle userHandle = null; |
| 11646 | final long identity = Binder.clearCallingIdentity(); |
| 11647 | try { |
| 11648 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11649 | } finally { |
| 11650 | Binder.restoreCallingIdentity(identity); |
| 11651 | } |
| 11652 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11653 | updateIfNeeded, userHandle); |
| 11654 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11655 | |
| 11656 | /** |
| 11657 | * Get the SIM state for the slot index. |
| 11658 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 11659 | * |
| 11660 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 11661 | */ |
| 11662 | @Override |
| 11663 | @SimState |
| 11664 | public int getSimStateForSlotIndex(int slotIndex) { |
| 11665 | IccCardConstants.State simState; |
| 11666 | if (slotIndex < 0) { |
| 11667 | simState = IccCardConstants.State.UNKNOWN; |
| 11668 | } else { |
| 11669 | Phone phone = null; |
| 11670 | try { |
| 11671 | phone = PhoneFactory.getPhone(slotIndex); |
| 11672 | } catch (IllegalStateException e) { |
| 11673 | // ignore |
| 11674 | } |
| 11675 | if (phone == null) { |
| 11676 | simState = IccCardConstants.State.UNKNOWN; |
| 11677 | } else { |
| 11678 | IccCard icc = phone.getIccCard(); |
| 11679 | if (icc == null) { |
| 11680 | simState = IccCardConstants.State.UNKNOWN; |
| 11681 | } else { |
| 11682 | simState = icc.getState(); |
| 11683 | } |
| 11684 | } |
| 11685 | } |
| 11686 | return simState.ordinal(); |
| 11687 | } |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11688 | } |