Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 28 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; |
| 41 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; |
| 45 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; |
| 50 | import android.os.AsyncResult; |
| 51 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 54 | import android.os.DropBoxManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.IBinder; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 57 | import android.os.ICancellationSignal; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 58 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 59 | import android.os.Looper; |
| 60 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 61 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 62 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 63 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 64 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 65 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 66 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 67 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 68 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 69 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 70 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 71 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 72 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 73 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 74 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 75 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 76 | import android.provider.Telephony; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 77 | import android.service.carrier.CarrierIdentifier; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 78 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 80 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 81 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 82 | import android.telephony.AccessNetworkConstants; |
| 83 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 85 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 86 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 87 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 88 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 89 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 90 | import android.telephony.CarrierRestrictionRules; |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 91 | import android.telephony.CellBroadcastIdRange; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 92 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 93 | import android.telephony.CellIdentityCdma; |
| 94 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 96 | import android.telephony.CellInfoGsm; |
| 97 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 98 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 100 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 101 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 102 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 103 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 104 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 105 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 106 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 108 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 109 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 110 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 111 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 113 | import android.telephony.SignalStrengthUpdateRequest; |
| 114 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 117 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 119 | import android.telephony.TelephonyManager; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyManager.SimState; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 121 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 122 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 123 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 124 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 126 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 127 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 128 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 129 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 130 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 131 | import android.telephony.gba.GbaAuthRequest; |
| 132 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 133 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 136 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 137 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 144 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 145 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 147 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteDatagramCallback; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 149 | import android.telephony.satellite.ISatelliteProvisionStateCallback; |
| 150 | import android.telephony.satellite.ISatelliteStateCallback; |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 151 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 152 | import android.telephony.satellite.SatelliteCapabilities; |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 153 | import android.telephony.satellite.SatelliteDatagram; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteDatagramCallback; |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteManager; |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 156 | import android.telephony.satellite.SatelliteProvisionStateCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 158 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 159 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 160 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 161 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 162 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 163 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 164 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 165 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 166 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 181 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.IIntegerConsumer; |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.ILongConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.IccCard; |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.IccCardConstants; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 199 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.ServiceStateTracker; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 206 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 207 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.data.DataUtils; |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 209 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 210 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 211 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 212 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 213 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 214 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 215 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 216 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 217 | import com.android.internal.telephony.satellite.SatelliteController; |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 218 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; |
| 219 | import com.android.internal.telephony.subscription.SubscriptionManagerService; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 221 | import com.android.internal.telephony.uicc.IccIoResult; |
| 222 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 229 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 230 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 231 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 232 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 233 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 234 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 235 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 236 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 237 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 238 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 239 | import com.android.phone.slice.SlicePurchaseController; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 240 | import com.android.phone.utils.CarrierAllowListInfo; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 241 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 242 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 243 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 244 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 245 | import com.android.services.telephony.TelecomAccountRegistry; |
| 246 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 247 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 248 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 249 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 250 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 251 | import java.io.IOException; |
| 252 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 253 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 254 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 255 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 256 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 257 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 258 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 259 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 260 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 261 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 262 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 263 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 264 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 265 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 266 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 267 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 268 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 269 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | |
| 271 | /** |
| 272 | * Implementation of the ITelephony interface. |
| 273 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 274 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 275 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 276 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 277 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 278 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | |
| 280 | // Message codes used with mMainThreadHandler |
| 281 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 282 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 283 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 284 | private static final int CMD_OPEN_CHANNEL = 9; |
| 285 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 286 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 287 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 288 | private static final int CMD_NV_READ_ITEM = 13; |
| 289 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 290 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 291 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 292 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 293 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 294 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 295 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 296 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 297 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 298 | private static final int CMD_SEND_ENVELOPE = 25; |
| 299 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 300 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 301 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 302 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 303 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 304 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 305 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 306 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 307 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 308 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 309 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 310 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 311 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 312 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 313 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 314 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 315 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 316 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 317 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 318 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 319 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 320 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 321 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 322 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 323 | private static final int CMD_SWITCH_SLOTS = 50; |
| 324 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 325 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 326 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 327 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 328 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 329 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 330 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 331 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 332 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 333 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 334 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 335 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 336 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 337 | private static final int CMD_MODEM_REBOOT = 64; |
| 338 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 339 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 340 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 341 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 342 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 343 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 344 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 345 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 346 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 347 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 348 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 349 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 350 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 351 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 352 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 353 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 354 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 355 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 356 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 357 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 358 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 359 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 360 | private static final int CMD_GET_CALL_WAITING = 87; |
| 361 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 362 | private static final int CMD_SET_CALL_WAITING = 89; |
| 363 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 364 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 365 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 366 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 367 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 368 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 369 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 370 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 371 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 372 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 373 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 374 | private static final int CMD_SET_SIM_POWER = 101; |
| 375 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 376 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 377 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 378 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 379 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 380 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 381 | 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] | 382 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 383 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 384 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 385 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 386 | private static final int CMD_ENABLE_VONR = 113; |
| 387 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 388 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 389 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 390 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 391 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 392 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 393 | // Parameters of select command. |
| 394 | private static final int SELECT_COMMAND = 0xA4; |
| 395 | private static final int SELECT_P1 = 0x04; |
| 396 | private static final int SELECT_P2 = 0; |
| 397 | private static final int SELECT_P3 = 0x10; |
| 398 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 399 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 |
| 400 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; |
| 401 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | /** The singleton instance. */ |
| 403 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 404 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 406 | private final PhoneGlobals mApp; |
| 407 | private final CallManager mCM; |
| 408 | private final ImsResolver mImsResolver; |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 409 | |
| 410 | private final SatelliteController mSatelliteController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 411 | private final UserManager mUserManager; |
| 412 | private final AppOpsManager mAppOps; |
| 413 | private final MainThreadHandler mMainThreadHandler; |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 414 | private final SubscriptionController mSubscriptionController; |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 415 | private final SharedPreferences mTelephonySharedPreferences; |
| 416 | private final PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 417 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 419 | /** User Activity */ |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 420 | private final AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 421 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 422 | |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 423 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 424 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 425 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 426 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 427 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 428 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 429 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 430 | // String to store multi SIM allowed |
| 431 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 432 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 433 | // The AID of ISD-R. |
| 434 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 435 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 436 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 437 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 438 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 439 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 440 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 441 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 442 | 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] | 443 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 444 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 445 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 446 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 447 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 448 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 449 | */ |
| 450 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 451 | "reset_network_erase_modem_config_enabled"; |
| 452 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 453 | 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] | 454 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 455 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; |
| 456 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 457 | /** |
| 458 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 459 | * one ICCID active at the same time. |
| 460 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 461 | * |
| 462 | * @hide |
| 463 | */ |
| 464 | @ChangeId |
| 465 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 466 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 467 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 468 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 469 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 470 | * operation fails. |
| 471 | */ |
| 472 | @ChangeId |
| 473 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 474 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 475 | |
| 476 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | * A request object to use for transmitting data to an ICC. |
| 478 | */ |
| 479 | private static final class IccAPDUArgument { |
| 480 | public int channel, cla, command, p1, p2, p3; |
| 481 | public String data; |
| 482 | |
| 483 | public IccAPDUArgument(int channel, int cla, int command, |
| 484 | int p1, int p2, int p3, String data) { |
| 485 | this.channel = channel; |
| 486 | this.cla = cla; |
| 487 | this.command = command; |
| 488 | this.p1 = p1; |
| 489 | this.p2 = p2; |
| 490 | this.p3 = p3; |
| 491 | this.data = data; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 496 | * A request object to use for transmitting data to an ICC. |
| 497 | */ |
| 498 | private static final class ManualNetworkSelectionArgument { |
| 499 | public OperatorInfo operatorInfo; |
| 500 | public boolean persistSelection; |
| 501 | |
| 502 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 503 | this.operatorInfo = operatorInfo; |
| 504 | this.persistSelection = persistSelection; |
| 505 | } |
| 506 | } |
| 507 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 508 | private static final class PurchasePremiumCapabilityArgument { |
| 509 | public @TelephonyManager.PremiumCapability int capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 510 | public @NonNull IIntegerConsumer callback; |
| 511 | |
| 512 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 513 | @NonNull IIntegerConsumer callback) { |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 514 | this.capability = capability; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 515 | this.callback = callback; |
| 516 | } |
| 517 | } |
| 518 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 519 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 521 | * request after sending. The main thread will notify the request when it is complete. |
| 522 | */ |
| 523 | private static final class MainThreadRequest { |
| 524 | /** The argument to use for the request */ |
| 525 | public Object argument; |
| 526 | /** The result of the request that is run on the main thread */ |
| 527 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 528 | // The subscriber id that this request applies to. Defaults to |
| 529 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 530 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 532 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 533 | public Phone phone; |
| 534 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 535 | public WorkSource workSource; |
| 536 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 537 | public MainThreadRequest(Object argument) { |
| 538 | this.argument = argument; |
| 539 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 540 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 541 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 542 | this.argument = argument; |
| 543 | if (phone != null) { |
| 544 | this.phone = phone; |
| 545 | } |
| 546 | this.workSource = workSource; |
| 547 | } |
| 548 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 549 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 550 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 551 | if (subId != null) { |
| 552 | this.subId = subId; |
| 553 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 554 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 555 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 558 | private static final class IncomingThirdPartyCallArgs { |
| 559 | public final ComponentName component; |
| 560 | public final String callId; |
| 561 | public final String callerDisplayName; |
| 562 | |
| 563 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 564 | String callerDisplayName) { |
| 565 | this.component = component; |
| 566 | this.callId = callId; |
| 567 | this.callerDisplayName = callerDisplayName; |
| 568 | } |
| 569 | } |
| 570 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 571 | /** |
| 572 | * A handler that processes messages on the main thread in the phone process. Since many |
| 573 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 574 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 575 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 576 | * on, which will be notified when the operation completes and will contain the result of the |
| 577 | * request. |
| 578 | * |
| 579 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 580 | * note that request.result must be set to something non-null for the calling thread to |
| 581 | * unblock. |
| 582 | */ |
| 583 | private final class MainThreadHandler extends Handler { |
| 584 | @Override |
| 585 | public void handleMessage(Message msg) { |
| 586 | MainThreadRequest request; |
| 587 | Message onCompleted; |
| 588 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 589 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 591 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 592 | |
| 593 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | case CMD_HANDLE_USSD_REQUEST: { |
| 595 | request = (MainThreadRequest) msg.obj; |
| 596 | final Phone phone = getPhoneFromRequest(request); |
| 597 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 598 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 600 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 601 | if (!isUssdApiAllowed(request.subId)) { |
| 602 | // Carrier does not support use of this API, return failure. |
| 603 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 604 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 605 | Bundle returnData = new Bundle(); |
| 606 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 607 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 608 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 609 | request.result = true; |
| 610 | notifyRequester(request); |
| 611 | return; |
| 612 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 613 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | try { |
| 615 | request.result = phone != null |
| 616 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 617 | } catch (CallStateException cse) { |
| 618 | request.result = false; |
| 619 | } |
| 620 | // Wake up the requesting thread |
| 621 | notifyRequester(request); |
| 622 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 625 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 626 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 627 | final Phone phone = getPhoneFromRequest(request); |
| 628 | request.result = phone != null ? |
| 629 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 630 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 631 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 633 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 635 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 639 | uiccPort = getUiccPortFromRequest(request); |
| 640 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 641 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 642 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 645 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 646 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 647 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 648 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 649 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 650 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 651 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | break; |
| 653 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | ar = (AsyncResult) msg.obj; |
| 656 | request = (MainThreadRequest) ar.userObj; |
| 657 | if (ar.exception == null && ar.result != null) { |
| 658 | request.result = ar.result; |
| 659 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 660 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 661 | if (ar.result == null) { |
| 662 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 663 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | } else { |
| 667 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 668 | } |
| 669 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 670 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | break; |
| 672 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 674 | request = (MainThreadRequest) msg.obj; |
| 675 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 676 | uiccPort = getUiccPortFromRequest(request); |
| 677 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 679 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 680 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | } else { |
| 682 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 683 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 684 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 685 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 686 | iccArgument.p2, |
| 687 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | } |
| 689 | break; |
| 690 | |
| 691 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 692 | ar = (AsyncResult) msg.obj; |
| 693 | request = (MainThreadRequest) ar.userObj; |
| 694 | if (ar.exception == null && ar.result != null) { |
| 695 | request.result = ar.result; |
| 696 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 697 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 698 | if (ar.result == null) { |
| 699 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 700 | } else if (ar.exception instanceof CommandException) { |
| 701 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 702 | ar.exception); |
| 703 | } else { |
| 704 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 705 | } |
| 706 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 707 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case CMD_EXCHANGE_SIM_IO: |
| 711 | request = (MainThreadRequest) msg.obj; |
| 712 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 713 | uiccPort = getUiccPortFromRequest(request); |
| 714 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 715 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 718 | } else { |
| 719 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 720 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 721 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 722 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 723 | iccArgument.data, onCompleted); |
| 724 | } |
| 725 | break; |
| 726 | |
| 727 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 728 | ar = (AsyncResult) msg.obj; |
| 729 | request = (MainThreadRequest) ar.userObj; |
| 730 | if (ar.exception == null && ar.result != null) { |
| 731 | request.result = ar.result; |
| 732 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 733 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 734 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 736 | break; |
| 737 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 738 | case CMD_SEND_ENVELOPE: |
| 739 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 740 | uiccPort = getUiccPortFromRequest(request); |
| 741 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 742 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 743 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 744 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 745 | } else { |
| 746 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 747 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 748 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_SEND_ENVELOPE_DONE: |
| 752 | ar = (AsyncResult) msg.obj; |
| 753 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 754 | if (ar.exception == null && ar.result != null) { |
| 755 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 756 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 757 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 758 | if (ar.result == null) { |
| 759 | loge("sendEnvelopeWithStatus: Empty response"); |
| 760 | } else if (ar.exception instanceof CommandException) { |
| 761 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 762 | ar.exception); |
| 763 | } else { |
| 764 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 765 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 766 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 767 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 770 | case CMD_OPEN_CHANNEL: |
| 771 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 772 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 773 | IccLogicalChannelRequest openChannelRequest = |
| 774 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 775 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 776 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 777 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 778 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 779 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 780 | } else { |
| 781 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 782 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 783 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 784 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_OPEN_CHANNEL_DONE: |
| 788 | ar = (AsyncResult) msg.obj; |
| 789 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 790 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 791 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 792 | int[] result = (int[]) ar.result; |
| 793 | int channelId = result[0]; |
| 794 | byte[] selectResponse = null; |
| 795 | if (result.length > 1) { |
| 796 | selectResponse = new byte[result.length - 1]; |
| 797 | for (int i = 1; i < result.length; ++i) { |
| 798 | selectResponse[i - 1] = (byte) result[i]; |
| 799 | } |
| 800 | } |
| 801 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 802 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 803 | |
| 804 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 805 | if (uiccPort == null) { |
| 806 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 807 | } else { |
| 808 | IccLogicalChannelRequest channelRequest = |
| 809 | (IccLogicalChannelRequest) request.argument; |
| 810 | channelRequest.channel = channelId; |
| 811 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 812 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 814 | if (ar.result == null) { |
| 815 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 816 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 817 | if (ar.exception != null) { |
| 818 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 819 | } |
| 820 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 821 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 822 | if (ar.exception instanceof CommandException) { |
| 823 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 824 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 825 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 826 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 827 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 828 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 832 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 833 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 834 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 835 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 836 | break; |
| 837 | |
| 838 | case CMD_CLOSE_CHANNEL: |
| 839 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 840 | uiccPort = getUiccPortFromRequest(request); |
| 841 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 842 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 843 | request.result = new IllegalArgumentException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 844 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 845 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 846 | } else { |
| 847 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 848 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 849 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 853 | ar = (AsyncResult) msg.obj; |
| 854 | request = (MainThreadRequest) ar.userObj; |
| 855 | if (ar.exception == null) { |
| 856 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 857 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 858 | if (uiccPort == null) { |
| 859 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 860 | } else { |
| 861 | final int channelId = (Integer) request.argument; |
| 862 | uiccPort.onLogicalChannelClosed(channelId); |
| 863 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 864 | } else { |
| 865 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 866 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 867 | if (ar.exception instanceof CommandException) { |
| 868 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 869 | CommandException.Error error = |
| 870 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 871 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 872 | // should only throw exceptions from the binder threads. |
| 873 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 874 | "iccCloseLogicalChannel: invalid argument "); |
| 875 | } |
| 876 | } else { |
| 877 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 878 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 879 | request.result = (exception != null) ? exception : |
| 880 | new IllegalStateException( |
| 881 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 882 | } |
| 883 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case CMD_NV_READ_ITEM: |
| 887 | request = (MainThreadRequest) msg.obj; |
| 888 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 889 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 890 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 894 | ar = (AsyncResult) msg.obj; |
| 895 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 896 | if (ar.exception == null && ar.result != null) { |
| 897 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 898 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 899 | request.result = ""; |
| 900 | if (ar.result == null) { |
| 901 | loge("nvReadItem: Empty response"); |
| 902 | } else if (ar.exception instanceof CommandException) { |
| 903 | loge("nvReadItem: CommandException: " + |
| 904 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 905 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 906 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 907 | } |
| 908 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 909 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 910 | break; |
| 911 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 912 | case CMD_NV_WRITE_ITEM: |
| 913 | request = (MainThreadRequest) msg.obj; |
| 914 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 915 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 916 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 917 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 918 | break; |
| 919 | |
| 920 | case EVENT_NV_WRITE_ITEM_DONE: |
| 921 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 922 | break; |
| 923 | |
| 924 | case CMD_NV_WRITE_CDMA_PRL: |
| 925 | request = (MainThreadRequest) msg.obj; |
| 926 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 927 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 931 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 932 | break; |
| 933 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 934 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 935 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 936 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 937 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 938 | break; |
| 939 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 940 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 941 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 944 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 945 | request = (MainThreadRequest) msg.obj; |
| 946 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 947 | request); |
| 948 | Phone phone = getPhoneFromRequest(request); |
| 949 | if (phone != null) { |
| 950 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 951 | } else { |
| 952 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 953 | request.result = false; |
| 954 | notifyRequester(request); |
| 955 | } |
| 956 | break; |
| 957 | } |
| 958 | |
| 959 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 960 | ar = (AsyncResult) msg.obj; |
| 961 | request = (MainThreadRequest) ar.userObj; |
| 962 | if (ar.exception == null && ar.result != null) { |
| 963 | request.result = ar.result; |
| 964 | } else { |
| 965 | // request.result must be set to something non-null |
| 966 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 967 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 968 | request.result = ar.result; |
| 969 | } else { |
| 970 | request.result = false; |
| 971 | } |
| 972 | if (ar.result == null) { |
| 973 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 974 | } else if (ar.exception instanceof CommandException) { |
| 975 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 976 | + ar.exception); |
| 977 | } else { |
| 978 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 979 | } |
| 980 | } |
| 981 | notifyRequester(request); |
| 982 | break; |
| 983 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 984 | case CMD_IS_VONR_ENABLED: { |
| 985 | request = (MainThreadRequest) msg.obj; |
| 986 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 987 | request); |
| 988 | Phone phone = getPhoneFromRequest(request); |
| 989 | if (phone != null) { |
| 990 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 991 | } else { |
| 992 | loge("isVoNrEnabled: No phone object"); |
| 993 | request.result = false; |
| 994 | notifyRequester(request); |
| 995 | } |
| 996 | break; |
| 997 | } |
| 998 | |
| 999 | case EVENT_IS_VONR_ENABLED_DONE: |
| 1000 | ar = (AsyncResult) msg.obj; |
| 1001 | request = (MainThreadRequest) ar.userObj; |
| 1002 | if (ar.exception == null && ar.result != null) { |
| 1003 | request.result = ar.result; |
| 1004 | } else { |
| 1005 | // request.result must be set to something non-null |
| 1006 | // for the calling thread to unblock |
| 1007 | if (ar.result != null) { |
| 1008 | request.result = ar.result; |
| 1009 | } else { |
| 1010 | request.result = false; |
| 1011 | } |
| 1012 | if (ar.result == null) { |
| 1013 | loge("isVoNrEnabled: Empty response"); |
| 1014 | } else if (ar.exception instanceof CommandException) { |
| 1015 | loge("isVoNrEnabled: CommandException: " |
| 1016 | + ar.exception); |
| 1017 | } else { |
| 1018 | loge("isVoNrEnabled: Unknown exception"); |
| 1019 | } |
| 1020 | } |
| 1021 | notifyRequester(request); |
| 1022 | break; |
| 1023 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1024 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 1025 | request = (MainThreadRequest) msg.obj; |
| 1026 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1027 | Phone phone = getPhoneFromRequest(request); |
| 1028 | if (phone != null) { |
| 1029 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1030 | request.workSource); |
| 1031 | } else { |
| 1032 | loge("enableNrDualConnectivity: No phone object"); |
| 1033 | request.result = |
| 1034 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1035 | notifyRequester(request); |
| 1036 | } |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
| 1043 | if (ar.exception == null) { |
| 1044 | request.result = |
| 1045 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1046 | } else { |
| 1047 | request.result = |
| 1048 | TelephonyManager |
| 1049 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1050 | if (ar.exception instanceof CommandException) { |
| 1051 | CommandException.Error error = |
| 1052 | ((CommandException) (ar.exception)).getCommandError(); |
| 1053 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1054 | request.result = |
| 1055 | TelephonyManager |
| 1056 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1057 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1058 | request.result = |
| 1059 | TelephonyManager |
| 1060 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1061 | } |
| 1062 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1063 | + ar.exception); |
| 1064 | } else { |
| 1065 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1066 | } |
| 1067 | } |
| 1068 | notifyRequester(request); |
| 1069 | break; |
| 1070 | } |
| 1071 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1072 | case CMD_ENABLE_VONR: { |
| 1073 | request = (MainThreadRequest) msg.obj; |
| 1074 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1075 | Phone phone = getPhoneFromRequest(request); |
| 1076 | if (phone != null) { |
| 1077 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1078 | request.workSource); |
| 1079 | } else { |
| 1080 | loge("setVoNrEnabled: No phone object"); |
| 1081 | request.result = |
| 1082 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1083 | notifyRequester(request); |
| 1084 | } |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | case EVENT_ENABLE_VONR_DONE: { |
| 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
| 1091 | if (ar.exception == null) { |
| 1092 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1093 | } else { |
| 1094 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1095 | if (ar.exception instanceof CommandException) { |
| 1096 | CommandException.Error error = |
| 1097 | ((CommandException) (ar.exception)).getCommandError(); |
| 1098 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1099 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1100 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1101 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1102 | } else { |
| 1103 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1104 | } |
| 1105 | loge("setVoNrEnabled" + ": CommandException: " |
| 1106 | + ar.exception); |
| 1107 | } else { |
| 1108 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1109 | } |
| 1110 | } |
| 1111 | notifyRequester(request); |
| 1112 | break; |
| 1113 | } |
| 1114 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1115 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1116 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1117 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1118 | request); |
| 1119 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1120 | break; |
| 1121 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1122 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1123 | ar = (AsyncResult) msg.obj; |
| 1124 | request = (MainThreadRequest) ar.userObj; |
| 1125 | if (ar.exception == null && ar.result != null) { |
| 1126 | request.result = ar.result; // Integer |
| 1127 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1128 | // request.result must be set to something non-null |
| 1129 | // for the calling thread to unblock |
| 1130 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1131 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1132 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1133 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1134 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1135 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1136 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1137 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1138 | } |
| 1139 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1140 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1141 | break; |
| 1142 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1143 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1144 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1145 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1146 | request); |
| 1147 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1148 | (Pair<Integer, Long>) request.argument; |
| 1149 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1150 | reasonWithNetworkTypes.first, |
| 1151 | reasonWithNetworkTypes.second, |
| 1152 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1153 | break; |
| 1154 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1155 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1156 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1157 | break; |
| 1158 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1159 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1160 | request = (MainThreadRequest)msg.obj; |
| 1161 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1162 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | |
| 1165 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1166 | ar = (AsyncResult)msg.obj; |
| 1167 | request = (MainThreadRequest)ar.userObj; |
| 1168 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1169 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1170 | break; |
| 1171 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1172 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1173 | request = (MainThreadRequest) msg.obj; |
| 1174 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1175 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1176 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1177 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1178 | break; |
| 1179 | |
| 1180 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1181 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1182 | break; |
| 1183 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1184 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1185 | request = (MainThreadRequest) msg.obj; |
| 1186 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1187 | request); |
| 1188 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1189 | break; |
| 1190 | |
| 1191 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1192 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1193 | break; |
| 1194 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1195 | case CMD_PERFORM_NETWORK_SCAN: |
| 1196 | request = (MainThreadRequest) msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1198 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1199 | break; |
| 1200 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1205 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1206 | request.argument; |
| 1207 | int callForwardingReason = args.first; |
| 1208 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1210 | } |
| 1211 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | ar = (AsyncResult) msg.obj; |
| 1213 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1215 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1216 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1220 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1221 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1222 | // any service for voice call. |
| 1223 | if ((callForwardInfo.serviceClass |
| 1224 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1225 | callForwardingInfo = new CallForwardingInfo( |
| 1226 | callForwardInfo.status |
| 1227 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | callForwardInfo.reason, |
| 1229 | callForwardInfo.number, |
| 1230 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | break; |
| 1232 | } |
| 1233 | } |
| 1234 | // Didn't find a call forward info for voice call. |
| 1235 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1237 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1239 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1240 | } else { |
| 1241 | if (ar.result == null) { |
| 1242 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1243 | } |
| 1244 | if (ar.exception != null) { |
| 1245 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1246 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1247 | int errorCode = TelephonyManager |
| 1248 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | if (ar.exception instanceof CommandException) { |
| 1250 | CommandException.Error error = |
| 1251 | ((CommandException) (ar.exception)).getCommandError(); |
| 1252 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1253 | errorCode = TelephonyManager |
| 1254 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1256 | errorCode = TelephonyManager |
| 1257 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | } |
| 1259 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | request = (MainThreadRequest) msg.obj; |
| 1267 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1269 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1271 | request.argument).first; |
| 1272 | request.phone.setCallForwardingOption( |
| 1273 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1274 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1275 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | callForwardingInfoToSet.getReason(), |
| 1277 | callForwardingInfoToSet.getNumber(), |
| 1278 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1279 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1282 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | ar = (AsyncResult) msg.obj; |
| 1284 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | Consumer<Integer> callback = |
| 1286 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1287 | request.argument).second; |
| 1288 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1290 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1291 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1292 | if (ar.exception instanceof CommandException) { |
| 1293 | CommandException.Error error = |
| 1294 | ((CommandException) (ar.exception)).getCommandError(); |
| 1295 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1296 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1297 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1299 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1300 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | callback.accept(errorCode); |
| 1304 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1305 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1308 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1309 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | request = (MainThreadRequest) msg.obj; |
| 1312 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1313 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1314 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1318 | ar = (AsyncResult) msg.obj; |
| 1319 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1321 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1323 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | // Service Class is a bit mask per 3gpp 27.007. |
| 1325 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1326 | if (callForwardResults.length > 1 |
| 1327 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1329 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1331 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1332 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1333 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | } |
| 1335 | } else { |
| 1336 | if (ar.result == null) { |
| 1337 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1338 | } |
| 1339 | if (ar.exception != null) { |
| 1340 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1341 | } |
| 1342 | if (ar.exception instanceof CommandException) { |
| 1343 | CommandException.Error error = |
| 1344 | ((CommandException) (ar.exception)).getCommandError(); |
| 1345 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1346 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1348 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1349 | callWaitingStatus = |
| 1350 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1351 | } |
| 1352 | } |
| 1353 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1354 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1355 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1356 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1357 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1358 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1359 | request = (MainThreadRequest) msg.obj; |
| 1360 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1361 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1362 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1363 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1364 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1367 | ar = (AsyncResult) msg.obj; |
| 1368 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1369 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1370 | Consumer<Integer> callback = |
| 1371 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1372 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1373 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1374 | if (ar.exception instanceof CommandException) { |
| 1375 | CommandException.Error error = |
| 1376 | ((CommandException) (ar.exception)).getCommandError(); |
| 1377 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1378 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1379 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1380 | callback.accept( |
| 1381 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1382 | } else { |
| 1383 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1384 | } |
| 1385 | } else { |
| 1386 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1387 | } |
| 1388 | } else { |
| 1389 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1390 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1392 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1393 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1394 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1395 | ar = (AsyncResult) msg.obj; |
| 1396 | request = (MainThreadRequest) ar.userObj; |
| 1397 | CellNetworkScanResult cellScanResult; |
| 1398 | if (ar.exception == null && ar.result != null) { |
| 1399 | cellScanResult = new CellNetworkScanResult( |
| 1400 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1401 | (List<OperatorInfo>) ar.result); |
| 1402 | } else { |
| 1403 | if (ar.result == null) { |
| 1404 | loge("getCellNetworkScanResults: Empty response"); |
| 1405 | } |
| 1406 | if (ar.exception != null) { |
| 1407 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1408 | } |
| 1409 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1410 | if (ar.exception instanceof CommandException) { |
| 1411 | CommandException.Error error = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1412 | ((CommandException) (ar.exception)).getCommandError(); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1413 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1414 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1415 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1416 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1417 | } |
| 1418 | } |
| 1419 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1420 | } |
| 1421 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1422 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | |
| 1425 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1426 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1427 | ManualNetworkSelectionArgument selArg = |
| 1428 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1429 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1430 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1431 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1432 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1433 | break; |
| 1434 | |
| 1435 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1436 | ar = (AsyncResult) msg.obj; |
| 1437 | request = (MainThreadRequest) ar.userObj; |
| 1438 | if (ar.exception == null) { |
| 1439 | request.result = true; |
| 1440 | } else { |
| 1441 | request.result = false; |
| 1442 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1443 | } |
| 1444 | notifyRequester(request); |
| 1445 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1446 | break; |
| 1447 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1448 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1449 | request = (MainThreadRequest) msg.obj; |
| 1450 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1451 | if (defaultPhone != null) { |
| 1452 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1453 | } else { |
| 1454 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1455 | Bundle bundle = new Bundle(); |
| 1456 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1457 | new ModemActivityInfo(0, 0, 0, |
| 1458 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1459 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1460 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1461 | break; |
| 1462 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1463 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1466 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1467 | int error = 0; |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1468 | ModemActivityInfo ret = null; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1469 | if (mLastModemActivityInfo == null) { |
| 1470 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1471 | mLastModemActivitySpecificInfo[0] = |
| 1472 | new ActivityStatsTechSpecificInfo( |
| 1473 | 0, |
| 1474 | 0, |
| 1475 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1476 | 0); |
| 1477 | mLastModemActivityInfo = |
| 1478 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1479 | } |
| 1480 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1481 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1482 | // Update the last modem activity info and the result of the request. |
| 1483 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1484 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1485 | mergeModemActivityInfo(info); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1486 | } else { |
| 1487 | loge("queryModemActivityInfo: invalid response"); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1488 | } |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1489 | // This is needed to decouple ret from mLastModemActivityInfo |
| 1490 | // We don't want to return mLastModemActivityInfo which is updated |
| 1491 | // inside mergeModemActivityInfo() |
| 1492 | ret = new ModemActivityInfo( |
| 1493 | mLastModemActivityInfo.getTimestampMillis(), |
| 1494 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1495 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1496 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1497 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1498 | } else { |
| 1499 | if (ar.result == null) { |
| 1500 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1501 | error = TelephonyManager.ModemActivityInfoException |
| 1502 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1503 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1504 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1505 | error = TelephonyManager.ModemActivityInfoException |
| 1506 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1507 | } else { |
| 1508 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1509 | error = TelephonyManager.ModemActivityInfoException |
| 1510 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1511 | } |
| 1512 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1513 | Bundle bundle = new Bundle(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1514 | if (ret != null) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1515 | bundle.putParcelable( |
| 1516 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1517 | ret); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1518 | } else { |
| 1519 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1520 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1521 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1522 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1523 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1524 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1525 | |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1526 | case CMD_SET_ALLOWED_CARRIERS: { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1527 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1528 | CarrierRestrictionRules argument = |
| 1529 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1530 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1531 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1532 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1533 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1534 | |
| 1535 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1536 | ar = (AsyncResult) msg.obj; |
| 1537 | request = (MainThreadRequest) ar.userObj; |
| 1538 | if (ar.exception == null && ar.result != null) { |
| 1539 | request.result = ar.result; |
| 1540 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1541 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1542 | if (ar.exception instanceof CommandException) { |
| 1543 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1544 | CommandException.Error error = |
| 1545 | ((CommandException) (ar.exception)).getCommandError(); |
| 1546 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1547 | request.result = |
| 1548 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1549 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1550 | } else { |
| 1551 | loge("setAllowedCarriers: Unknown exception"); |
| 1552 | } |
| 1553 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1554 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1555 | break; |
| 1556 | |
| 1557 | case CMD_GET_ALLOWED_CARRIERS: |
| 1558 | request = (MainThreadRequest) msg.obj; |
| 1559 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1560 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | |
| 1563 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1564 | ar = (AsyncResult) msg.obj; |
| 1565 | request = (MainThreadRequest) ar.userObj; |
| 1566 | if (ar.exception == null && ar.result != null) { |
| 1567 | request.result = ar.result; |
| 1568 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1569 | request.result = new IllegalStateException( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1570 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1571 | if (ar.result == null) { |
| 1572 | loge("getAllowedCarriers: Empty response"); |
| 1573 | } else if (ar.exception instanceof CommandException) { |
| 1574 | loge("getAllowedCarriers: CommandException: " + |
| 1575 | ar.exception); |
| 1576 | } else { |
| 1577 | loge("getAllowedCarriers: Unknown exception"); |
| 1578 | } |
| 1579 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1580 | if (request.argument != null) { |
| 1581 | // This is for the implementation of carrierRestrictionStatus. |
| 1582 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; |
| 1583 | Consumer<Integer> callback = callbackInfo.getConsumer(); |
| 1584 | int callerCarrierId = callbackInfo.getCarrierId(); |
| 1585 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; |
| 1586 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { |
| 1587 | CarrierRestrictionRules carrierRestrictionRules = |
| 1588 | (CarrierRestrictionRules) ar.result; |
| 1589 | int carrierId = -1; |
| 1590 | try { |
| 1591 | CarrierIdentifier carrierIdentifier = |
| 1592 | carrierRestrictionRules.getAllowedCarriers().get(0); |
| 1593 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, |
| 1594 | carrierIdentifier); |
| 1595 | } catch (NullPointerException | IndexOutOfBoundsException ex) { |
| 1596 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); |
| 1597 | } |
| 1598 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); |
| 1599 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus |
| 1600 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1601 | lockStatus = TelephonyManager |
| 1602 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1603 | } |
| 1604 | } else { |
| 1605 | Rlog.e(LOG_TAG, |
| 1606 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); |
| 1607 | } |
| 1608 | callback.accept(lockStatus); |
| 1609 | } else { |
| 1610 | // This is for the implementation of getAllowedCarriers. |
| 1611 | notifyRequester(request); |
| 1612 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1613 | break; |
| 1614 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1615 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1616 | ar = (AsyncResult) msg.obj; |
| 1617 | request = (MainThreadRequest) ar.userObj; |
| 1618 | if (ar.exception == null && ar.result != null) { |
| 1619 | request.result = ar.result; |
| 1620 | } else { |
| 1621 | request.result = new IllegalArgumentException( |
| 1622 | "Failed to retrieve Forbidden Plmns"); |
| 1623 | if (ar.result == null) { |
| 1624 | loge("getForbiddenPlmns: Empty response"); |
| 1625 | } else { |
| 1626 | loge("getForbiddenPlmns: Unknown exception"); |
| 1627 | } |
| 1628 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1629 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1630 | break; |
| 1631 | |
| 1632 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1633 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1634 | uiccPort = getUiccPortFromRequest(request); |
| 1635 | if (uiccPort == null) { |
| 1636 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1637 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1638 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1639 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1640 | break; |
| 1641 | } |
| 1642 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1643 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1644 | if (uiccApp == null) { |
| 1645 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1646 | + appType); |
| 1647 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1648 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | } else { |
| 1651 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1652 | + " specified type -- " + appType); |
| 1653 | } |
| 1654 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1655 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1656 | onCompleted); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1657 | break; |
| 1658 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1659 | case CMD_SWITCH_SLOTS: |
| 1660 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1661 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1662 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1663 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1664 | break; |
| 1665 | |
| 1666 | case EVENT_SWITCH_SLOTS_DONE: |
| 1667 | ar = (AsyncResult) msg.obj; |
| 1668 | request = (MainThreadRequest) ar.userObj; |
| 1669 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1670 | notifyRequester(request); |
| 1671 | break; |
| 1672 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1673 | request = (MainThreadRequest) msg.obj; |
| 1674 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1675 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1676 | break; |
| 1677 | |
| 1678 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1679 | ar = (AsyncResult) msg.obj; |
| 1680 | request = (MainThreadRequest) ar.userObj; |
| 1681 | if (ar.exception != null) { |
| 1682 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1683 | } else { |
| 1684 | int mode = ((int[]) ar.result)[0]; |
| 1685 | if (mode == 0) { |
| 1686 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1687 | } else { |
| 1688 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1689 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1691 | notifyRequester(request); |
| 1692 | break; |
| 1693 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1694 | request = (MainThreadRequest) msg.obj; |
| 1695 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1696 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1697 | break; |
| 1698 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1699 | ar = (AsyncResult) msg.obj; |
| 1700 | request = (MainThreadRequest) ar.userObj; |
| 1701 | if (ar.exception != null) { |
| 1702 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1703 | } else { |
| 1704 | request.result = ((int[]) ar.result)[0]; |
| 1705 | } |
| 1706 | notifyRequester(request); |
| 1707 | break; |
| 1708 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1711 | int mode = (int) request.argument; |
| 1712 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1713 | break; |
| 1714 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1715 | ar = (AsyncResult) msg.obj; |
| 1716 | request = (MainThreadRequest) ar.userObj; |
| 1717 | request.result = ar.exception == null; |
| 1718 | notifyRequester(request); |
| 1719 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1720 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1721 | request = (MainThreadRequest) msg.obj; |
| 1722 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1723 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1724 | break; |
| 1725 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1726 | ar = (AsyncResult) msg.obj; |
| 1727 | request = (MainThreadRequest) ar.userObj; |
| 1728 | if (ar.exception != null) { |
| 1729 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1730 | } else { |
| 1731 | request.result = ((int[]) ar.result)[0]; |
| 1732 | } |
| 1733 | notifyRequester(request); |
| 1734 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1735 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1736 | request = (MainThreadRequest) msg.obj; |
| 1737 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1738 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1739 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1740 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1741 | break; |
| 1742 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1743 | ar = (AsyncResult) msg.obj; |
| 1744 | request = (MainThreadRequest) ar.userObj; |
| 1745 | request.result = ar.exception == null; |
| 1746 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1747 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1748 | case CMD_GET_ALL_CELL_INFO: |
| 1749 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1750 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1751 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1752 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1753 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1754 | ar = (AsyncResult) msg.obj; |
| 1755 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1756 | // If a timeout occurs, the response will be null |
| 1757 | request.result = (ar.exception == null && ar.result != null) |
| 1758 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1759 | synchronized (request) { |
| 1760 | request.notifyAll(); |
| 1761 | } |
| 1762 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1763 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1764 | request = (MainThreadRequest) msg.obj; |
| 1765 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1766 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1767 | break; |
| 1768 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1769 | ar = (AsyncResult) msg.obj; |
| 1770 | request = (MainThreadRequest) ar.userObj; |
| 1771 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1772 | try { |
| 1773 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1774 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1775 | cb.onError( |
| 1776 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1777 | ar.exception.getClass().getName(), |
| 1778 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1780 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1781 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1782 | } else { |
| 1783 | // use the result as returned |
| 1784 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1785 | } |
| 1786 | } catch (RemoteException re) { |
| 1787 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1788 | } |
| 1789 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1790 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1791 | request = (MainThreadRequest) msg.obj; |
| 1792 | WorkSource ws = (WorkSource) request.argument; |
| 1793 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1794 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1795 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1796 | } |
| 1797 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1798 | ar = (AsyncResult) msg.obj; |
| 1799 | request = (MainThreadRequest) ar.userObj; |
| 1800 | if (ar.exception == null) { |
| 1801 | request.result = ar.result; |
| 1802 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1803 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1804 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1805 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | synchronized (request) { |
| 1809 | request.notifyAll(); |
| 1810 | } |
| 1811 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1812 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1813 | case CMD_MODEM_REBOOT: |
| 1814 | request = (MainThreadRequest) msg.obj; |
| 1815 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1816 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1817 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1818 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1819 | handleNullReturnEvent(msg, "rebootModem"); |
| 1820 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1821 | case CMD_REQUEST_ENABLE_MODEM: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1822 | request = (MainThreadRequest) msg.obj; |
| 1823 | boolean enable = (boolean) request.argument; |
| 1824 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1825 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1826 | PhoneConfigurationManager.getInstance() |
| 1827 | .enablePhone(request.phone, enable, onCompleted); |
| 1828 | break; |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1829 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1830 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1831 | ar = (AsyncResult) msg.obj; |
| 1832 | request = (MainThreadRequest) ar.userObj; |
| 1833 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1834 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1835 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1836 | if ((boolean) request.result) { |
| 1837 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1838 | updateModemStateMetrics(); |
| 1839 | } else { |
| 1840 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1841 | + ar.exception); |
| 1842 | } |
| 1843 | notifyRequester(request); |
| 1844 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1845 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1846 | case CMD_GET_MODEM_STATUS: |
| 1847 | request = (MainThreadRequest) msg.obj; |
| 1848 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1849 | PhoneConfigurationManager.getInstance() |
| 1850 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1851 | break; |
| 1852 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1853 | ar = (AsyncResult) msg.obj; |
| 1854 | request = (MainThreadRequest) ar.userObj; |
| 1855 | int id = request.phone.getPhoneId(); |
| 1856 | if (ar.exception == null && ar.result != null) { |
| 1857 | request.result = ar.result; |
| 1858 | //update the cache as modem status has changed |
| 1859 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1860 | (boolean) request.result); |
| 1861 | } else { |
| 1862 | // Return true if modem status cannot be retrieved. For most cases, |
| 1863 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1864 | // and disable modem are not supported. Modem is always on. |
| 1865 | // TODO: this should be fixed in R to support a third |
| 1866 | // status UNKNOWN b/131631629 |
| 1867 | request.result = true; |
| 1868 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1869 | + ar.exception); |
| 1870 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1871 | notifyRequester(request); |
| 1872 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1873 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1874 | request = (MainThreadRequest) msg.obj; |
| 1875 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1876 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1877 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1878 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1879 | break; |
| 1880 | } |
| 1881 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1882 | ar = (AsyncResult) msg.obj; |
| 1883 | request = (MainThreadRequest) ar.userObj; |
| 1884 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1885 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1886 | args.second.accept(ar.exception == null); |
| 1887 | notifyRequester(request); |
| 1888 | break; |
| 1889 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1890 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1891 | request = (MainThreadRequest) msg.obj; |
| 1892 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1893 | Phone phone = getPhoneFromRequest(request); |
| 1894 | if (phone != null) { |
| 1895 | phone.getSystemSelectionChannels(onCompleted); |
| 1896 | } else { |
| 1897 | loge("getSystemSelectionChannels: No phone object"); |
| 1898 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1899 | notifyRequester(request); |
| 1900 | } |
| 1901 | break; |
| 1902 | } |
| 1903 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1904 | ar = (AsyncResult) msg.obj; |
| 1905 | request = (MainThreadRequest) ar.userObj; |
| 1906 | if (ar.exception == null && ar.result != null) { |
| 1907 | request.result = ar.result; |
| 1908 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1909 | request.result = new IllegalStateException( |
| 1910 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1911 | if (ar.result == null) { |
| 1912 | loge("getSystemSelectionChannels: Empty response"); |
| 1913 | } else { |
| 1914 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1915 | } |
| 1916 | } |
| 1917 | notifyRequester(request); |
| 1918 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1919 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1920 | ar = (AsyncResult) msg.obj; |
| 1921 | request = (MainThreadRequest) ar.userObj; |
| 1922 | if (ar.exception == null && ar.result != null) { |
| 1923 | request.result = ar.result; |
| 1924 | } else { |
| 1925 | request.result = -1; |
| 1926 | loge("Failed to set Forbidden Plmns"); |
| 1927 | if (ar.result == null) { |
| 1928 | loge("setForbidenPlmns: Empty response"); |
| 1929 | } else if (ar.exception != null) { |
| 1930 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1931 | request.result = -1; |
| 1932 | } else { |
| 1933 | loge("setForbiddenPlmns: Unknown exception"); |
| 1934 | } |
| 1935 | } |
| 1936 | notifyRequester(request); |
| 1937 | break; |
| 1938 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1939 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1940 | uiccPort = getUiccPortFromRequest(request); |
| 1941 | if (uiccPort == null) { |
| 1942 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1943 | request.result = -1; |
| 1944 | notifyRequester(request); |
| 1945 | break; |
| 1946 | } |
| 1947 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1948 | (Pair<Integer, List<String>>) request.argument; |
| 1949 | appType = setFplmnsArgs.first; |
| 1950 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1951 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1952 | if (uiccApp == null) { |
| 1953 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1954 | request.result = -1; |
| 1955 | loge("Failed to get UICC App"); |
| 1956 | notifyRequester(request); |
| 1957 | } else { |
| 1958 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1959 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1960 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1961 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1962 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1963 | case CMD_ERASE_MODEM_CONFIG: |
| 1964 | request = (MainThreadRequest) msg.obj; |
| 1965 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1966 | defaultPhone.eraseModemConfig(onCompleted); |
| 1967 | break; |
| 1968 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1969 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1970 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1971 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1972 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1973 | request = (MainThreadRequest) msg.obj; |
| 1974 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1975 | notifyRequester(request); |
| 1976 | break; |
| 1977 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1978 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1979 | request = (MainThreadRequest) msg.obj; |
| 1980 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1981 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1982 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1983 | changed.first, changed.second, onCompleted); |
| 1984 | break; |
| 1985 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1986 | ar = (AsyncResult) msg.obj; |
| 1987 | request = (MainThreadRequest) ar.userObj; |
| 1988 | if (ar.exception == null) { |
| 1989 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1990 | // If the operation is successful, update the PIN storage |
| 1991 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1992 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1993 | UiccController.getInstance().getPinStorage() |
| 1994 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1995 | } else { |
| 1996 | request.result = msg.arg1; |
| 1997 | } |
| 1998 | notifyRequester(request); |
| 1999 | break; |
| 2000 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2001 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2002 | request = (MainThreadRequest) msg.obj; |
| 2003 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 2004 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2005 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 2006 | enabled.first, enabled.second, onCompleted); |
| 2007 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2008 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2009 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 2010 | ar = (AsyncResult) msg.obj; |
| 2011 | request = (MainThreadRequest) ar.userObj; |
| 2012 | if (ar.exception == null) { |
| 2013 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2014 | // If the operation is successful, update the PIN storage |
| 2015 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 2016 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 2017 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2018 | UiccController.getInstance().getPinStorage() |
| 2019 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2020 | } else { |
| 2021 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 2022 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2023 | } else { |
| 2024 | request.result = msg.arg1; |
| 2025 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2026 | |
| 2027 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2028 | notifyRequester(request); |
| 2029 | break; |
| 2030 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2031 | case MSG_NOTIFY_USER_ACTIVITY: |
| 2032 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2033 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2034 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 2035 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 2036 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 2037 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2038 | |
| 2039 | case CMD_SET_DATA_THROTTLING: { |
| 2040 | request = (MainThreadRequest) msg.obj; |
| 2041 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 2042 | DataThrottlingRequest dataThrottlingRequest = |
| 2043 | (DataThrottlingRequest) request.argument; |
| 2044 | Phone phone = getPhoneFromRequest(request); |
| 2045 | if (phone != null) { |
| 2046 | phone.setDataThrottling(onCompleted, |
| 2047 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 2048 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 2049 | } else { |
| 2050 | loge("setDataThrottling: No phone object"); |
| 2051 | request.result = |
| 2052 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2053 | notifyRequester(request); |
| 2054 | } |
| 2055 | |
| 2056 | break; |
| 2057 | } |
| 2058 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 2059 | ar = (AsyncResult) msg.obj; |
| 2060 | request = (MainThreadRequest) ar.userObj; |
| 2061 | |
| 2062 | if (ar.exception == null) { |
| 2063 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 2064 | } else if (ar.exception instanceof CommandException) { |
| 2065 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2066 | CommandException.Error error = |
| 2067 | ((CommandException) (ar.exception)).getCommandError(); |
| 2068 | |
| 2069 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2070 | request.result = TelephonyManager |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2071 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2072 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2073 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2074 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2075 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2076 | } else { |
| 2077 | request.result = |
| 2078 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2079 | } |
| 2080 | } else { |
| 2081 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2082 | } |
| 2083 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2084 | notifyRequester(request); |
| 2085 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2086 | |
| 2087 | case CMD_SET_SIM_POWER: { |
| 2088 | request = (MainThreadRequest) msg.obj; |
| 2089 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2090 | request = (MainThreadRequest) msg.obj; |
| 2091 | int stateToSet = |
| 2092 | ((Pair<Integer, IIntegerConsumer>) |
| 2093 | request.argument).first; |
| 2094 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2095 | break; |
| 2096 | } |
| 2097 | case EVENT_SET_SIM_POWER_DONE: { |
| 2098 | ar = (AsyncResult) msg.obj; |
| 2099 | request = (MainThreadRequest) ar.userObj; |
| 2100 | IIntegerConsumer callback = |
| 2101 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2102 | if (ar.exception != null) { |
| 2103 | loge("setSimPower exception: " + ar.exception); |
| 2104 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2105 | .RESULT_ERROR_UNKNOWN; |
| 2106 | if (ar.exception instanceof CommandException) { |
| 2107 | CommandException.Error error = |
| 2108 | ((CommandException) (ar.exception)).getCommandError(); |
| 2109 | if (error == CommandException.Error.SIM_ERR) { |
| 2110 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2111 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2112 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2113 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2114 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2115 | } else { |
| 2116 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2117 | } |
| 2118 | } |
| 2119 | try { |
| 2120 | callback.accept(errorCode); |
| 2121 | } catch (RemoteException e) { |
| 2122 | // Ignore if the remote process is no longer available to call back. |
| 2123 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2124 | } |
| 2125 | } else { |
| 2126 | try { |
| 2127 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2128 | } catch (RemoteException e) { |
| 2129 | // Ignore if the remote process is no longer available to call back. |
| 2130 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2131 | } |
| 2132 | } |
| 2133 | break; |
| 2134 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2135 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2136 | request = (MainThreadRequest) msg.obj; |
| 2137 | |
| 2138 | final Phone phone = getPhoneFromRequest(request); |
| 2139 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2140 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2141 | notifyRequester(request); |
| 2142 | break; |
| 2143 | } |
| 2144 | |
| 2145 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2146 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2147 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2148 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2149 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2150 | request.subId, pair.first /*callingUid*/, |
| 2151 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2152 | break; |
| 2153 | } |
| 2154 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2155 | ar = (AsyncResult) msg.obj; |
| 2156 | request = (MainThreadRequest) ar.userObj; |
| 2157 | // request.result will be the exception of ar if present, true otherwise. |
| 2158 | // Be cautious not to leave result null which will wait() forever |
| 2159 | request.result = ar.exception != null ? ar.exception : true; |
| 2160 | notifyRequester(request); |
| 2161 | break; |
| 2162 | } |
| 2163 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2164 | request = (MainThreadRequest) msg.obj; |
| 2165 | |
| 2166 | Phone phone = getPhoneFromRequest(request); |
| 2167 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2168 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2169 | notifyRequester(request); |
| 2170 | break; |
| 2171 | } |
| 2172 | |
| 2173 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2174 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2175 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2176 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2177 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2178 | request.subId, pair.first /*callingUid*/, |
| 2179 | pair.second /*request*/, onCompleted); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2180 | break; |
| 2181 | } |
| 2182 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2183 | ar = (AsyncResult) msg.obj; |
| 2184 | request = (MainThreadRequest) ar.userObj; |
| 2185 | request.result = ar.exception != null ? ar.exception : true; |
| 2186 | notifyRequester(request); |
| 2187 | break; |
| 2188 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2189 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2190 | case CMD_GET_SLICING_CONFIG: { |
| 2191 | request = (MainThreadRequest) msg.obj; |
| 2192 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2193 | request.phone.getSlicingConfig(onCompleted); |
| 2194 | break; |
| 2195 | } |
| 2196 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2197 | ar = (AsyncResult) msg.obj; |
| 2198 | request = (MainThreadRequest) ar.userObj; |
| 2199 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2200 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2201 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2202 | Bundle bundle = new Bundle(); |
| 2203 | int resultCode = 0; |
| 2204 | if (ar.exception != null) { |
| 2205 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2206 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2207 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2208 | } else if (ar.result == null) { |
| 2209 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2210 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2211 | } else { |
| 2212 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2213 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2214 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2218 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2219 | } |
| 2220 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2221 | result.send(resultCode, bundle); |
| 2222 | notifyRequester(request); |
| 2223 | break; |
| 2224 | } |
| 2225 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2226 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2227 | request = (MainThreadRequest) msg.obj; |
| 2228 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2229 | PurchasePremiumCapabilityArgument arg = |
| 2230 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2231 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2232 | arg.capability, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2233 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2234 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2235 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2236 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2237 | ar = (AsyncResult) msg.obj; |
| 2238 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2239 | PurchasePremiumCapabilityArgument arg = |
| 2240 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2241 | try { |
| 2242 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2243 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2244 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2245 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2246 | + ", result= " |
| 2247 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2248 | } catch (RemoteException e) { |
| 2249 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2250 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2251 | + " failed: " + e; |
| 2252 | if (DBG) log(logStr); |
| 2253 | AnomalyReporter.reportAnomaly( |
| 2254 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2255 | } |
| 2256 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2257 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2258 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2259 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2260 | request = (MainThreadRequest) msg.obj; |
| 2261 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2262 | UiccController.getInstance().getPinStorage() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2263 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2264 | notifyRequester(request); |
| 2265 | break; |
| 2266 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2267 | default: |
| 2268 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2269 | break; |
| 2270 | } |
| 2271 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2272 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2273 | private void notifyRequester(MainThreadRequest request) { |
| 2274 | synchronized (request) { |
| 2275 | request.notifyAll(); |
| 2276 | } |
| 2277 | } |
| 2278 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2279 | private void handleNullReturnEvent(Message msg, String command) { |
| 2280 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2281 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2282 | if (ar.exception == null) { |
| 2283 | request.result = true; |
| 2284 | } else { |
| 2285 | request.result = false; |
| 2286 | if (ar.exception instanceof CommandException) { |
| 2287 | loge(command + ": CommandException: " + ar.exception); |
| 2288 | } else { |
| 2289 | loge(command + ": Unknown exception"); |
| 2290 | } |
| 2291 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2292 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Posts the specified command to be executed on the main thread, |
| 2298 | * waits for the request to complete, and returns the result. |
| 2299 | * @see #sendRequestAsync |
| 2300 | */ |
| 2301 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2302 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2303 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * Posts the specified command to be executed on the main thread, |
| 2308 | * waits for the request to complete, and returns the result. |
| 2309 | * @see #sendRequestAsync |
| 2310 | */ |
| 2311 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2312 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2313 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * Posts the specified command to be executed on the main thread, |
| 2318 | * waits for the request to complete, and returns the result. |
| 2319 | * @see #sendRequestAsync |
| 2320 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2321 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2322 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * Posts the specified command to be executed on the main thread, |
| 2327 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2328 | * if not timeout or null otherwise. |
| 2329 | * @see #sendRequestAsync |
| 2330 | */ |
| 2331 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2332 | long timeoutInMs) { |
| 2333 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | /** |
| 2337 | * Posts the specified command to be executed on the main thread, |
| 2338 | * waits for the request to complete, and returns the result. |
| 2339 | * @see #sendRequestAsync |
| 2340 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2341 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2342 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | /** |
| 2346 | * Posts the specified command to be executed on the main thread, |
| 2347 | * waits for the request to complete, and returns the result. |
| 2348 | * @see #sendRequestAsync |
| 2349 | */ |
| 2350 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2351 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2352 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2356 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2357 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2358 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2359 | * @see #sendRequestAsync |
| 2360 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2361 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2362 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2364 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2365 | } |
| 2366 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2367 | MainThreadRequest request = null; |
| 2368 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2369 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2370 | } else if (phone != null) { |
| 2371 | request = new MainThreadRequest(argument, phone, workSource); |
| 2372 | } else { |
| 2373 | request = new MainThreadRequest(argument, subId, workSource); |
| 2374 | } |
| 2375 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2377 | msg.sendToTarget(); |
| 2378 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2379 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2381 | if (timeoutInMs >= 0) { |
| 2382 | // Wait for at least timeoutInMs before returning null request result |
| 2383 | long now = SystemClock.elapsedRealtime(); |
| 2384 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2385 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2386 | try { |
| 2387 | request.wait(deadline - now); |
| 2388 | } catch (InterruptedException e) { |
| 2389 | // Do nothing, go back and check if request is completed or timeout |
| 2390 | } finally { |
| 2391 | now = SystemClock.elapsedRealtime(); |
| 2392 | } |
| 2393 | } |
| 2394 | } else { |
| 2395 | // Wait for the request to complete |
| 2396 | while (request.result == null) { |
| 2397 | try { |
| 2398 | request.wait(); |
| 2399 | } catch (InterruptedException e) { |
| 2400 | // Do nothing, go back and wait until the request is complete |
| 2401 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | } |
| 2403 | } |
| 2404 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2405 | if (request.result == null) { |
| 2406 | Log.wtf(LOG_TAG, |
| 2407 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2409 | return request.result; |
| 2410 | } |
| 2411 | |
| 2412 | /** |
| 2413 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2414 | * Posts the specified command to be executed on the main thread, and |
| 2415 | * returns immediately. |
| 2416 | * @see #sendRequest |
| 2417 | */ |
| 2418 | private void sendRequestAsync(int command) { |
| 2419 | mMainThreadHandler.sendEmptyMessage(command); |
| 2420 | } |
| 2421 | |
| 2422 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2423 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2424 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2425 | */ |
| 2426 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2427 | sendRequestAsync(command, argument, null, null); |
| 2428 | } |
| 2429 | |
| 2430 | /** |
| 2431 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2432 | * @see {@link #sendRequest(int,Object)} |
| 2433 | */ |
| 2434 | private void sendRequestAsync( |
| 2435 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2436 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2437 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2438 | msg.sendToTarget(); |
| 2439 | } |
| 2440 | |
| 2441 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2443 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2444 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2445 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | synchronized (PhoneInterfaceManager.class) { |
| 2447 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2448 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | } else { |
| 2450 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2451 | } |
| 2452 | return sInstance; |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2457 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2459 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2460 | mImsResolver = ImsResolver.getInstance(); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2461 | mSatelliteController = SatelliteController.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2462 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2464 | mMainThreadHandler = new MainThreadHandler(); |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2465 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
| 2466 | mSubscriptionController = SubscriptionController.getInstance(); |
| 2467 | } else { |
| 2468 | mSubscriptionController = null; |
| 2469 | } |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2470 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2471 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2472 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2473 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2474 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2475 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | publish(); |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2477 | CarrierAllowListInfo.loadInstance(mApp); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2480 | @VisibleForTesting |
| 2481 | public SharedPreferences getSharedPreferences() { |
| 2482 | return mTelephonySharedPreferences; |
| 2483 | } |
| 2484 | |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2485 | /** |
| 2486 | * Get the default phone for this device. |
| 2487 | */ |
| 2488 | @VisibleForTesting |
| 2489 | public Phone getDefaultPhone() { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2490 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2491 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2492 | } |
| 2493 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2494 | private void publish() { |
| 2495 | if (DBG) log("publish: " + this); |
| 2496 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2497 | TelephonyFrameworkInitializer |
| 2498 | .getTelephonyServiceManager() |
| 2499 | .getTelephonyServiceRegisterer() |
| 2500 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2503 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2504 | if (request.phone != null) { |
| 2505 | return request.phone; |
| 2506 | } else { |
| 2507 | return getPhoneFromSubId(request.subId); |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | private Phone getPhoneFromSubId(int subId) { |
| 2512 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2513 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2514 | } |
| 2515 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2516 | /** |
| 2517 | * Get phone object associated with a subscription. |
| 2518 | * Return default phone if phone object associated with subscription is null |
| 2519 | * @param subId - subscriptionId |
| 2520 | * @return phone object associated with a subscription or default phone if null. |
| 2521 | */ |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2522 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2523 | Phone phone = getPhoneFromSubId(subId); |
| 2524 | if (phone == null) { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2525 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2526 | phone = getDefaultPhone(); |
| 2527 | } |
| 2528 | return phone; |
| 2529 | } |
| 2530 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2531 | @Nullable |
| 2532 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2533 | Phone phone = getPhoneFromRequest(request); |
| 2534 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2535 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2536 | } |
| 2537 | |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2538 | /** |
| 2539 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing |
| 2540 | * in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= |
| 2541 | * {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. |
| 2542 | * @return The Phone associated the sub Id |
| 2543 | */ |
| 2544 | private @Nullable Phone getPhone(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2545 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2548 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2549 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2550 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2551 | } |
| 2552 | |
| 2553 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2554 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2555 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2558 | private boolean isImsAvailableOnDevice() { |
| 2559 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2560 | if (pm == null) { |
| 2561 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2562 | // so do not throw error and allow. |
| 2563 | return true; |
| 2564 | } |
| 2565 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2566 | } |
| 2567 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2569 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2572 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | if (DBG) log("dial: " + number); |
| 2574 | // No permission check needed here: This is just a wrapper around the |
| 2575 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2576 | // the UI before it does anything. |
| 2577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2578 | final long identity = Binder.clearCallingIdentity(); |
| 2579 | try { |
| 2580 | String url = createTelUrl(number); |
| 2581 | if (url == null) { |
| 2582 | return; |
| 2583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2585 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2586 | PhoneConstants.State state = mCM.getState(subId); |
| 2587 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2588 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2589 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2590 | mApp.startActivity(intent); |
| 2591 | } |
| 2592 | } finally { |
| 2593 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2598 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2601 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | if (DBG) log("call: " + number); |
| 2603 | |
| 2604 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2605 | // need to do a permission check since we're calling startActivity() |
| 2606 | // from the context of the phone app. |
| 2607 | enforceCallPermission(); |
| 2608 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2609 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | != AppOpsManager.MODE_ALLOWED) { |
| 2611 | return; |
| 2612 | } |
| 2613 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | final long identity = Binder.clearCallingIdentity(); |
| 2615 | try { |
| 2616 | String url = createTelUrl(number); |
| 2617 | if (url == null) { |
| 2618 | return; |
| 2619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | boolean isValid = false; |
| 2622 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2623 | if (slist != null) { |
| 2624 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2625 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2626 | isValid = true; |
| 2627 | break; |
| 2628 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2629 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2630 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2631 | if (!isValid) { |
| 2632 | return; |
| 2633 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2634 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2636 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2637 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2638 | mApp.startActivity(intent); |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
| 2641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2644 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2645 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2646 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2647 | } |
| 2648 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2649 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2650 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2651 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2652 | } |
| 2653 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2654 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2656 | |
| 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2659 | Phone phone = getPhone(subId); |
| 2660 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | checkSimPin.start(); |
| 2662 | return checkSimPin.unlockSim(null, pin); |
| 2663 | } finally { |
| 2664 | Binder.restoreCallingIdentity(identity); |
| 2665 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 | } |
| 2667 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2668 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2669 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2670 | |
| 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2673 | Phone phone = getPhone(subId); |
| 2674 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | checkSimPuk.start(); |
| 2676 | return checkSimPuk.unlockSim(puk, pin); |
| 2677 | } finally { |
| 2678 | Binder.restoreCallingIdentity(identity); |
| 2679 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2683 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | * a synchronous one. |
| 2685 | */ |
| 2686 | private static class UnlockSim extends Thread { |
| 2687 | |
| 2688 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2689 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2690 | |
| 2691 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2692 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2693 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | |
| 2695 | // For replies from SimCard interface |
| 2696 | private Handler mHandler; |
| 2697 | |
| 2698 | // For async handler to identify request type |
| 2699 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2700 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2701 | UnlockSim(int phoneId, IccCard simCard) { |
| 2702 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | mSimCard = simCard; |
| 2704 | } |
| 2705 | |
| 2706 | @Override |
| 2707 | public void run() { |
| 2708 | Looper.prepare(); |
| 2709 | synchronized (UnlockSim.this) { |
| 2710 | mHandler = new Handler() { |
| 2711 | @Override |
| 2712 | public void handleMessage(Message msg) { |
| 2713 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2714 | switch (msg.what) { |
| 2715 | case SUPPLY_PIN_COMPLETE: |
| 2716 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2717 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2718 | mRetryCount = msg.arg1; |
| 2719 | if (ar.exception != null) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2720 | CommandException.Error error = null; |
| 2721 | if (ar.exception instanceof CommandException) { |
| 2722 | error = ((CommandException) (ar.exception)) |
| 2723 | .getCommandError(); |
| 2724 | } |
| 2725 | if (error == CommandException.Error.PASSWORD_INCORRECT) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2726 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2727 | } else if (error == CommandException.Error.ABORTED) { |
| 2728 | /* When UiccCardApp dispose, handle message and return |
| 2729 | exception */ |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2730 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2731 | } else { |
| 2732 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2733 | } |
| 2734 | } else { |
| 2735 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2736 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | mDone = true; |
| 2738 | UnlockSim.this.notifyAll(); |
| 2739 | } |
| 2740 | break; |
| 2741 | } |
| 2742 | } |
| 2743 | }; |
| 2744 | UnlockSim.this.notifyAll(); |
| 2745 | } |
| 2746 | Looper.loop(); |
| 2747 | } |
| 2748 | |
| 2749 | /* |
| 2750 | * Use PIN or PUK to unlock SIM card |
| 2751 | * |
| 2752 | * If PUK is null, unlock SIM card with PIN |
| 2753 | * |
| 2754 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2755 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2756 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2757 | |
| 2758 | while (mHandler == null) { |
| 2759 | try { |
| 2760 | wait(); |
| 2761 | } catch (InterruptedException e) { |
| 2762 | Thread.currentThread().interrupt(); |
| 2763 | } |
| 2764 | } |
| 2765 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2766 | |
| 2767 | if (puk == null) { |
| 2768 | mSimCard.supplyPin(pin, callback); |
| 2769 | } else { |
| 2770 | mSimCard.supplyPuk(puk, pin, callback); |
| 2771 | } |
| 2772 | |
| 2773 | while (!mDone) { |
| 2774 | try { |
| 2775 | Log.d(LOG_TAG, "wait for done"); |
| 2776 | wait(); |
| 2777 | } catch (InterruptedException e) { |
| 2778 | // Restore the interrupted status |
| 2779 | Thread.currentThread().interrupt(); |
| 2780 | } |
| 2781 | } |
| 2782 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2783 | int[] resultArray = new int[2]; |
| 2784 | resultArray[0] = mResult; |
| 2785 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2786 | |
| 2787 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2788 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2789 | } |
| 2790 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2791 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } |
| 2794 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2795 | /** |
| 2796 | * This method has been removed due to privacy and stability concerns. |
| 2797 | */ |
| 2798 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2799 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2800 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2801 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2804 | @Override |
| 2805 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2806 | mApp.getSystemService(AppOpsManager.class) |
| 2807 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2808 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2809 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2810 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2811 | // Callers targeting S have no business invoking this method. |
| 2812 | return; |
| 2813 | } |
| 2814 | |
| 2815 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2816 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2817 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2818 | .setCallingPackage(callingPackage) |
| 2819 | .setCallingFeatureId(null) |
| 2820 | .setCallingPid(Binder.getCallingPid()) |
| 2821 | .setCallingUid(Binder.getCallingUid()) |
| 2822 | .setMethod("updateServiceLocation") |
| 2823 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2824 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2825 | .build()); |
| 2826 | // Apps that lack location permission have no business calling this method; |
| 2827 | // however, because no permission was declared in the public API, denials must |
| 2828 | // all be "soft". |
| 2829 | switch (locationResult) { |
| 2830 | case DENIED_HARD: /* fall through */ |
| 2831 | case DENIED_SOFT: |
| 2832 | return; |
| 2833 | } |
| 2834 | |
| 2835 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | final long identity = Binder.clearCallingIdentity(); |
| 2837 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2838 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2839 | } finally { |
| 2840 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2841 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2844 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2845 | @Override |
| 2846 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2847 | return isRadioOnWithFeature(callingPackage, null); |
| 2848 | } |
| 2849 | |
| 2850 | |
| 2851 | @Override |
| 2852 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2853 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2854 | callingFeatureId); |
| 2855 | } |
| 2856 | |
| 2857 | @Deprecated |
| 2858 | @Override |
| 2859 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2860 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2863 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2864 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2865 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2866 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2867 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2868 | return false; |
| 2869 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2870 | |
| 2871 | final long identity = Binder.clearCallingIdentity(); |
| 2872 | try { |
| 2873 | return isRadioOnForSubscriber(subId); |
| 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(identity); |
| 2876 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2880 | final long identity = Binder.clearCallingIdentity(); |
| 2881 | try { |
| 2882 | final Phone phone = getPhone(subId); |
| 2883 | if (phone != null) { |
| 2884 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2885 | } else { |
| 2886 | return false; |
| 2887 | } |
| 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2890 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2894 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2896 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2897 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | final Phone phone = getPhone(subId); |
| 2903 | if (phone != null) { |
| 2904 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2905 | } |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2908 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2912 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2915 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2916 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | |
| 2918 | final long identity = Binder.clearCallingIdentity(); |
| 2919 | try { |
| 2920 | final Phone phone = getPhone(subId); |
| 2921 | if (phone == null) { |
| 2922 | return false; |
| 2923 | } |
| 2924 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2925 | toggleRadioOnOffForSubscriber(subId); |
| 2926 | } |
| 2927 | return true; |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2930 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2931 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2932 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2933 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2934 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2935 | /* |
| 2936 | * If any of the Radios are available, it will need to be |
| 2937 | * shutdown. So return true if any Radio is available. |
| 2938 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
| 2941 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2942 | Phone phone = PhoneFactory.getPhone(i); |
| 2943 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2944 | } |
| 2945 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2946 | return false; |
| 2947 | } finally { |
| 2948 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2949 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2952 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2953 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | enforceModifyPermission(); |
| 2955 | |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2959 | logv("Shutting down Phone " + i); |
| 2960 | shutdownRadioUsingPhoneId(i); |
| 2961 | } |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2968 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2969 | if (phone != null && phone.isRadioAvailable()) { |
| 2970 | phone.shutdownRadio(); |
| 2971 | } |
| 2972 | } |
| 2973 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2974 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2975 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2976 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2977 | if (!turnOn) { |
| 2978 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); |
| 2979 | } |
| 2980 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | final long identity = Binder.clearCallingIdentity(); |
| 2982 | try { |
| 2983 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2984 | if (defaultPhone != null) { |
| 2985 | defaultPhone.setRadioPower(turnOn); |
| 2986 | return true; |
| 2987 | } else { |
| 2988 | loge("There's no default phone."); |
| 2989 | return false; |
| 2990 | } |
| 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2993 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2996 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2999 | if (!turnOn) { |
| 3000 | log("setRadioPowerForSubscriber off: subId=" + subId |
| 3001 | + ",callingPackage=" + getCurrentPackageName()); |
| 3002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | final long identity = Binder.clearCallingIdentity(); |
| 3004 | try { |
| 3005 | final Phone phone = getPhone(subId); |
| 3006 | if (phone != null) { |
| 3007 | phone.setRadioPower(turnOn); |
| 3008 | return true; |
| 3009 | } else { |
| 3010 | return false; |
| 3011 | } |
| 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3017 | /** |
| 3018 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 3019 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 3020 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 3021 | * powering it off, and these radio off votes will be cleared. |
| 3022 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 3023 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 3024 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 3025 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 3026 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 3027 | * check its vote. |
| 3028 | * |
| 3029 | * @param subId The subscription ID. |
| 3030 | * @param reason The reason for powering off radio. |
| 3031 | * @return true on success and false on failure. |
| 3032 | */ |
| 3033 | public boolean requestRadioPowerOffForReason(int subId, |
| 3034 | @TelephonyManager.RadioPowerReason int reason) { |
| 3035 | enforceModifyPermission(); |
| 3036 | |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3037 | log("requestRadioPowerOffForReason: subId=" + subId |
| 3038 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3039 | final long identity = Binder.clearCallingIdentity(); |
| 3040 | try { |
| 3041 | final Phone phone = getPhone(subId); |
| 3042 | if (phone != null) { |
| 3043 | phone.setRadioPowerForReason(false, reason); |
| 3044 | return true; |
| 3045 | } else { |
| 3046 | return false; |
| 3047 | } |
| 3048 | } finally { |
| 3049 | Binder.restoreCallingIdentity(identity); |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | /** |
| 3054 | * Remove the vote on powering off the radio for a reason, as requested by |
| 3055 | * {@link requestRadioPowerOffForReason}. |
| 3056 | * |
| 3057 | * @param subId The subscription ID. |
| 3058 | * @param reason The reason for powering off radio. |
| 3059 | * @return true on success and false on failure. |
| 3060 | */ |
| 3061 | public boolean clearRadioPowerOffForReason(int subId, |
| 3062 | @TelephonyManager.RadioPowerReason int reason) { |
| 3063 | enforceModifyPermission(); |
| 3064 | |
| 3065 | final long identity = Binder.clearCallingIdentity(); |
| 3066 | try { |
| 3067 | final Phone phone = getPhone(subId); |
| 3068 | if (phone != null) { |
| 3069 | phone.setRadioPowerForReason(true, reason); |
| 3070 | return true; |
| 3071 | } else { |
| 3072 | return false; |
| 3073 | } |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | /** |
| 3080 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 3081 | * |
| 3082 | * @param subId The subscription ID. |
| 3083 | * @param callingPackage The package making the call. |
| 3084 | * @param callingFeatureId The feature in the package. |
| 3085 | * @return List of reasons for powering off radio. |
| 3086 | */ |
| 3087 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 3088 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 3089 | |
| 3090 | final long identity = Binder.clearCallingIdentity(); |
| 3091 | List result = new ArrayList(); |
| 3092 | try { |
| 3093 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 3094 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 3095 | return result; |
| 3096 | } |
| 3097 | |
| 3098 | final Phone phone = getPhone(subId); |
| 3099 | if (phone != null) { |
| 3100 | result.addAll(phone.getRadioPowerOffReasons()); |
| 3101 | } |
| 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
| 3105 | return result; |
| 3106 | } |
| 3107 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3108 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3109 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3110 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | |
| 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3115 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | final Phone phone = getPhone(subId); |
| 3117 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3118 | phone.getDataSettingsManager().setDataEnabled( |
| 3119 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3120 | return true; |
| 3121 | } else { |
| 3122 | return false; |
| 3123 | } |
| 3124 | } finally { |
| 3125 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3129 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3130 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3131 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | |
| 3134 | final long identity = Binder.clearCallingIdentity(); |
| 3135 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3136 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | final Phone phone = getPhone(subId); |
| 3138 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3139 | phone.getDataSettingsManager().setDataEnabled( |
| 3140 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3141 | return true; |
| 3142 | } else { |
| 3143 | return false; |
| 3144 | } |
| 3145 | } finally { |
| 3146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3150 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3151 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | final long identity = Binder.clearCallingIdentity(); |
| 3153 | try { |
| 3154 | final Phone phone = getPhone(subId); |
| 3155 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3156 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3157 | } else { |
| 3158 | return false; |
| 3159 | } |
| 3160 | } finally { |
| 3161 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3166 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3169 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3170 | enforceCallPermission(); |
| 3171 | |
| 3172 | final long identity = Binder.clearCallingIdentity(); |
| 3173 | try { |
| 3174 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3175 | return; |
| 3176 | } |
| 3177 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3178 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3179 | } finally { |
| 3180 | Binder.restoreCallingIdentity(identity); |
| 3181 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3182 | }; |
| 3183 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3184 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3185 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3186 | |
| 3187 | final long identity = Binder.clearCallingIdentity(); |
| 3188 | try { |
| 3189 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3190 | return false; |
| 3191 | } |
| 3192 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3195 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3198 | /** |
| 3199 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3200 | * tag on getCallState Binder call. |
| 3201 | */ |
| 3202 | @Deprecated |
| 3203 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3204 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3205 | if (CompatChanges.isChangeEnabled( |
| 3206 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3207 | Binder.getCallingUid())) { |
| 3208 | // Do not allow this API to be called on API version 31+, it should only be |
| 3209 | // called on old apps using this Binder call directly. |
| 3210 | throw new SecurityException("This method can only be used for applications " |
| 3211 | + "targeting API version 30 or less."); |
| 3212 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | final long identity = Binder.clearCallingIdentity(); |
| 3214 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3215 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); |
| 3216 | return PhoneConstantConversions.convertCallState(phone.getState()); |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3217 | } finally { |
| 3218 | Binder.restoreCallingIdentity(identity); |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | @Override |
| 3223 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3224 | if (CompatChanges.isChangeEnabled( |
| 3225 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3226 | Binder.getCallingUid())) { |
| 3227 | // Check READ_PHONE_STATE for API version 31+ |
| 3228 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3229 | featureId, "getCallStateForSubscription")) { |
| 3230 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3231 | + "targeting API level 31+."); |
| 3232 | } |
| 3233 | } |
| 3234 | final long identity = Binder.clearCallingIdentity(); |
| 3235 | try { |
| 3236 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3238 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3239 | } finally { |
| 3240 | Binder.restoreCallingIdentity(identity); |
| 3241 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3242 | } |
| 3243 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3244 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3245 | public int getDataState() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3246 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | @Override |
| 3250 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | final long identity = Binder.clearCallingIdentity(); |
| 3252 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3253 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3254 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3255 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3256 | } else { |
| 3257 | return PhoneConstantConversions.convertDataState( |
| 3258 | PhoneConstants.DataState.DISCONNECTED); |
| 3259 | } |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3265 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3266 | public @DataActivityType int getDataActivity() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3267 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3271 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3274 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3275 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3276 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | } else { |
| 3278 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3279 | } |
| 3280 | } finally { |
| 3281 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3282 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3283 | } |
| 3284 | |
| 3285 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3286 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3287 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3288 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3289 | |
| 3290 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3291 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3292 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3293 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3294 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3295 | .setCallingPid(Binder.getCallingPid()) |
| 3296 | .setCallingUid(Binder.getCallingUid()) |
| 3297 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3298 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3299 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3300 | .build()); |
| 3301 | switch (locationResult) { |
| 3302 | case DENIED_HARD: |
| 3303 | throw new SecurityException("Not allowed to access cell location"); |
| 3304 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3305 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3306 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3309 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | if (DBG_LOC) log("getCellLocation: is active user"); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3313 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3314 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(identity); |
| 3317 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3320 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3321 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3322 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3323 | // registered cell info, so return a NULL country instead. |
| 3324 | final long identity = Binder.clearCallingIdentity(); |
| 3325 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3326 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3327 | // Get default phone in this case. |
| 3328 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3329 | } |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3330 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3331 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3332 | if (phone == null) return ""; |
| 3333 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3334 | if (sst == null) return ""; |
| 3335 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3336 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3337 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3338 | } finally { |
| 3339 | Binder.restoreCallingIdentity(identity); |
| 3340 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3341 | } |
| 3342 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3343 | /** |
| 3344 | * This method was removed due to potential issues caused by performing partial |
| 3345 | * updates of service state, and lack of a credible use case. |
| 3346 | * |
| 3347 | * This has the ability to break the telephony implementation by disabling notification of |
| 3348 | * changes in device connectivity. DO NOT USE THIS! |
| 3349 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3350 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3351 | public void enableLocationUpdates() { |
| 3352 | mApp.enforceCallingOrSelfPermission( |
| 3353 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3356 | /** |
| 3357 | * This method was removed due to potential issues caused by performing partial |
| 3358 | * updates of service state, and lack of a credible use case. |
| 3359 | * |
| 3360 | * This has the ability to break the telephony implementation by disabling notification of |
| 3361 | * changes in device connectivity. DO NOT USE THIS! |
| 3362 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3363 | @Override |
| 3364 | public void disableLocationUpdates() { |
| 3365 | mApp.enforceCallingOrSelfPermission( |
| 3366 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | @Override |
| 3370 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3371 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3372 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3373 | try { |
| 3374 | mApp.getSystemService(AppOpsManager.class) |
| 3375 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3376 | } catch (SecurityException e) { |
| 3377 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3378 | throw e; |
| 3379 | } |
| 3380 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3381 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3382 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3383 | throw new SecurityException( |
| 3384 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3385 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3386 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3387 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3388 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3389 | return null; |
| 3390 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3391 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3392 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3393 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3394 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3395 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3396 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3397 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3398 | for (CellInfo ci : info) { |
| 3399 | if (ci instanceof CellInfoGsm) { |
| 3400 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3401 | } else if (ci instanceof CellInfoWcdma) { |
| 3402 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3403 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3404 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3405 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3408 | private List<CellInfo> getCachedCellInfo() { |
| 3409 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3410 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3411 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3412 | if (info != null) cellInfos.addAll(info); |
| 3413 | } |
| 3414 | return cellInfos; |
| 3415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3416 | |
| 3417 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3418 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3419 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3420 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3421 | |
| 3422 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3423 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3424 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3425 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3426 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3427 | .setCallingPid(Binder.getCallingPid()) |
| 3428 | .setCallingUid(Binder.getCallingUid()) |
| 3429 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3430 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3431 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3432 | .build()); |
| 3433 | switch (locationResult) { |
| 3434 | case DENIED_HARD: |
| 3435 | throw new SecurityException("Not allowed to access cell info"); |
| 3436 | case DENIED_SOFT: |
| 3437 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3438 | } |
| 3439 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3440 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3441 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3442 | return getCachedCellInfo(); |
| 3443 | } |
| 3444 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3445 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3446 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | final long identity = Binder.clearCallingIdentity(); |
| 3448 | try { |
| 3449 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3450 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3451 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3452 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3453 | if (info != null) cellInfos.addAll(info); |
| 3454 | } |
| 3455 | return cellInfos; |
| 3456 | } finally { |
| 3457 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3461 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3462 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3463 | String callingFeatureId) { |
| 3464 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3465 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3469 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3470 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3471 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3472 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3473 | } |
| 3474 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3475 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3476 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3477 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3478 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3479 | |
| 3480 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3481 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3482 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3483 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3484 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3485 | .setCallingPid(Binder.getCallingPid()) |
| 3486 | .setCallingUid(Binder.getCallingUid()) |
| 3487 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3488 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3489 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3490 | .build()); |
| 3491 | switch (locationResult) { |
| 3492 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3493 | if (TelephonyPermissions |
| 3494 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3495 | // Safetynet logging for b/154934934 |
| 3496 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3497 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3498 | throw new SecurityException("Not allowed to access cell info"); |
| 3499 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3500 | if (TelephonyPermissions |
| 3501 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3502 | // Safetynet logging for b/154934934 |
| 3503 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3504 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3505 | try { |
| 3506 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3507 | } catch (RemoteException re) { |
| 3508 | // Drop without consequences |
| 3509 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3510 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3513 | |
| 3514 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3515 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3516 | |
| 3517 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3518 | } |
| 3519 | |
| 3520 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3521 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3522 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3523 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3524 | |
| 3525 | final long identity = Binder.clearCallingIdentity(); |
| 3526 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3527 | Phone phone = getPhone(subId); |
| 3528 | if (phone == null) { |
| 3529 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3530 | } else { |
| 3531 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
| 3535 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3539 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3540 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3541 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3542 | return null; |
| 3543 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3544 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3545 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3546 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3547 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3548 | return null; |
| 3549 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3550 | |
| 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | return phone.getImei(); |
| 3554 | } finally { |
| 3555 | Binder.restoreCallingIdentity(identity); |
| 3556 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3557 | } |
| 3558 | |
| 3559 | @Override |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3560 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { |
| 3561 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); |
| 3562 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, |
| 3563 | callingFeatureId, "getPrimaryImei")) { |
| 3564 | throw new SecurityException("Caller does not have permission"); |
| 3565 | } |
| 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3569 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { |
| 3570 | return phone.getImei(); |
| 3571 | } |
| 3572 | } |
| 3573 | throw new UnsupportedOperationException("Operation not supported"); |
| 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3580 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3581 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3582 | String tac = null; |
| 3583 | if (phone != null) { |
| 3584 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3585 | try { |
| 3586 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3587 | } catch (IndexOutOfBoundsException e) { |
| 3588 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3589 | return null; |
| 3590 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3591 | } |
| 3592 | return tac; |
| 3593 | } |
| 3594 | |
| 3595 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3596 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3597 | try { |
| 3598 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3599 | } catch (SecurityException se) { |
| 3600 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3601 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3602 | + Binder.getCallingUid()); |
| 3603 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3604 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3605 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3606 | return null; |
| 3607 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3608 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3609 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3610 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3611 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3612 | return null; |
| 3613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3614 | |
| 3615 | final long identity = Binder.clearCallingIdentity(); |
| 3616 | try { |
| 3617 | return phone.getMeid(); |
| 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
| 3620 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3624 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3625 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3626 | String manufacturerCode = null; |
| 3627 | if (phone != null) { |
| 3628 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3629 | try { |
| 3630 | manufacturerCode = |
| 3631 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3632 | } catch (IndexOutOfBoundsException e) { |
| 3633 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3634 | return null; |
| 3635 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3636 | } |
| 3637 | return manufacturerCode; |
| 3638 | } |
| 3639 | |
| 3640 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3641 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3642 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3643 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3644 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3645 | return null; |
| 3646 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3647 | int subId = phone.getSubId(); |
| 3648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3649 | mApp, subId, callingPackage, callingFeatureId, |
| 3650 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3651 | return null; |
| 3652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3653 | |
| 3654 | final long identity = Binder.clearCallingIdentity(); |
| 3655 | try { |
| 3656 | return phone.getDeviceSvn(); |
| 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3660 | } |
| 3661 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3662 | @Override |
| 3663 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | final long identity = Binder.clearCallingIdentity(); |
| 3665 | try { |
| 3666 | final Phone phone = getPhone(subId); |
| 3667 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3671 | } |
| 3672 | |
| 3673 | @Override |
| 3674 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3675 | final long identity = Binder.clearCallingIdentity(); |
| 3676 | try { |
| 3677 | final Phone phone = getPhone(subId); |
| 3678 | return phone == null ? null : phone.getCarrierName(); |
| 3679 | } finally { |
| 3680 | Binder.restoreCallingIdentity(identity); |
| 3681 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3682 | } |
| 3683 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3684 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3685 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3686 | final long identity = Binder.clearCallingIdentity(); |
| 3687 | try { |
| 3688 | final Phone phone = getPhone(subId); |
| 3689 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3690 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
| 3693 | } |
| 3694 | } |
| 3695 | |
| 3696 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3697 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3698 | final long identity = Binder.clearCallingIdentity(); |
| 3699 | try { |
| 3700 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3701 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3702 | } finally { |
| 3703 | Binder.restoreCallingIdentity(identity); |
| 3704 | } |
| 3705 | } |
| 3706 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3707 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3708 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3709 | if (!isSubscriptionMccMnc) { |
| 3710 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3711 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3712 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3713 | if (phone == null) { |
| 3714 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3715 | } |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
| 3721 | } |
| 3722 | } |
| 3723 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3724 | // |
| 3725 | // Internal helper methods. |
| 3726 | // |
| 3727 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3728 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3729 | * Make sure the caller is the calling package itself |
| 3730 | * |
| 3731 | * @throws SecurityException if the caller is not the calling package |
| 3732 | */ |
| 3733 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3734 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3735 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3736 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3737 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3738 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3739 | } catch (PackageManager.NameNotFoundException e) { |
| 3740 | // packageUid is -1 |
| 3741 | } |
| 3742 | if (packageUid != callingUid) { |
| 3743 | throw new SecurityException(message + ": Package " + callingPackage |
| 3744 | + " does not belong to " + callingUid); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3749 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3750 | * |
| 3751 | * @throws SecurityException if the caller does not have the required permission |
| 3752 | */ |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3753 | @VisibleForTesting |
| 3754 | public void enforceModifyPermission() { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3755 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3756 | } |
| 3757 | |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3758 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3759 | * Make sure the caller has the READ_PHONE_STATE permission. |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3760 | * |
| 3761 | * @throws SecurityException if the caller does not have the required permission |
| 3762 | */ |
| 3763 | @VisibleForTesting |
| 3764 | public void enforceReadPermission() { |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3765 | enforceReadPermission(null); |
| 3766 | } |
| 3767 | |
| 3768 | /** |
| 3769 | * Make sure the caller has the READ_PHONE_STATE permissions. |
| 3770 | * |
| 3771 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. |
| 3772 | */ |
| 3773 | @VisibleForTesting |
| 3774 | public void enforceReadPermission(String msg) { |
| 3775 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3776 | } |
| 3777 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3778 | private void enforceActiveEmergencySessionPermission() { |
| 3779 | mApp.enforceCallingOrSelfPermission( |
| 3780 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3781 | } |
| 3782 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3783 | /** |
| 3784 | * Make sure the caller has the CALL_PHONE permission. |
| 3785 | * |
| 3786 | * @throws SecurityException if the caller does not have the required permission |
| 3787 | */ |
| 3788 | private void enforceCallPermission() { |
| 3789 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3790 | } |
| 3791 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3792 | private void enforceSettingsPermission() { |
| 3793 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3796 | private void enforceRebootPermission() { |
| 3797 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3798 | } |
| 3799 | |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3800 | /** |
| 3801 | * Make sure the caller has SATELLITE_COMMUNICATION permission. |
| 3802 | * @param message - log message to print. |
| 3803 | * @throws SecurityException if the caller does not have the required permission |
| 3804 | */ |
| 3805 | private void enforceSatelliteCommunicationPermission(String message) { |
| 3806 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); |
| 3807 | } |
| 3808 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3809 | private String createTelUrl(String number) { |
| 3810 | if (TextUtils.isEmpty(number)) { |
| 3811 | return null; |
| 3812 | } |
| 3813 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3814 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3815 | } |
| 3816 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3817 | private static void log(String msg) { |
Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3818 | Log.d(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3821 | private static void logv(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3822 | Log.v(LOG_TAG, msg); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3825 | private static void loge(String msg) { |
Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3826 | Log.e(LOG_TAG, msg); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3827 | } |
| 3828 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3829 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3830 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3831 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3832 | } |
| 3833 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3834 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3835 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | final long identity = Binder.clearCallingIdentity(); |
| 3837 | try { |
| 3838 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3839 | if (phone == null) { |
| 3840 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3841 | } else { |
| 3842 | return phone.getPhoneType(); |
| 3843 | } |
| 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3846 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | /** |
| 3850 | * Returns the CDMA ERI icon index to display |
| 3851 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3852 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3853 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3854 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3855 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3856 | } |
| 3857 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3858 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3859 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3860 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3861 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3862 | mApp, subId, callingPackage, callingFeatureId, |
| 3863 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3864 | return -1; |
| 3865 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | |
| 3867 | final long identity = Binder.clearCallingIdentity(); |
| 3868 | try { |
| 3869 | final Phone phone = getPhone(subId); |
| 3870 | if (phone != null) { |
| 3871 | return phone.getCdmaEriIconIndex(); |
| 3872 | } else { |
| 3873 | return -1; |
| 3874 | } |
| 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3877 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | /** |
| 3881 | * Returns the CDMA ERI icon mode, |
| 3882 | * 0 - ON |
| 3883 | * 1 - FLASHING |
| 3884 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3885 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3886 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3887 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3888 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3889 | } |
| 3890 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3891 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3892 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3893 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3894 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3895 | mApp, subId, callingPackage, callingFeatureId, |
| 3896 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3897 | return -1; |
| 3898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3899 | |
| 3900 | final long identity = Binder.clearCallingIdentity(); |
| 3901 | try { |
| 3902 | final Phone phone = getPhone(subId); |
| 3903 | if (phone != null) { |
| 3904 | return phone.getCdmaEriIconMode(); |
| 3905 | } else { |
| 3906 | return -1; |
| 3907 | } |
| 3908 | } finally { |
| 3909 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3910 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3911 | } |
| 3912 | |
| 3913 | /** |
| 3914 | * Returns the CDMA ERI text, |
| 3915 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3916 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3917 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3918 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3919 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3920 | } |
| 3921 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3922 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3923 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3924 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3926 | mApp, subId, callingPackage, callingFeatureId, |
| 3927 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3928 | return null; |
| 3929 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3930 | |
| 3931 | final long identity = Binder.clearCallingIdentity(); |
| 3932 | try { |
| 3933 | final Phone phone = getPhone(subId); |
| 3934 | if (phone != null) { |
| 3935 | return phone.getCdmaEriText(); |
| 3936 | } else { |
| 3937 | return null; |
| 3938 | } |
| 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3945 | * Returns the CDMA MDN. |
| 3946 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3947 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3948 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3950 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3951 | |
| 3952 | final long identity = Binder.clearCallingIdentity(); |
| 3953 | try { |
| 3954 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3955 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3956 | return phone.getLine1Number(); |
| 3957 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3958 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | return null; |
| 3960 | } |
| 3961 | } finally { |
| 3962 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | /** |
| 3967 | * Returns the CDMA MIN. |
| 3968 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3969 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3970 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3971 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3972 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3973 | |
| 3974 | final long identity = Binder.clearCallingIdentity(); |
| 3975 | try { |
| 3976 | final Phone phone = getPhone(subId); |
| 3977 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3978 | return phone.getCdmaMin(); |
| 3979 | } else { |
| 3980 | return null; |
| 3981 | } |
| 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3984 | } |
| 3985 | } |
| 3986 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3987 | @Override |
| 3988 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3989 | INumberVerificationCallback callback, String callingPackage) { |
| 3990 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3991 | != PERMISSION_GRANTED) { |
| 3992 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3993 | } |
| 3994 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3995 | |
| 3996 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3997 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3998 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3999 | + "calling package: " + callingPackage |
| 4000 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | if (range == null) { |
| 4004 | throw new NullPointerException("Range must be non-null"); |
| 4005 | } |
| 4006 | |
| 4007 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4008 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4009 | |
| 4010 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 4011 | } |
| 4012 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4013 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4014 | * Returns true if CDMA provisioning needs to run. |
| 4015 | */ |
| 4016 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4019 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4020 | } finally { |
| 4021 | Binder.restoreCallingIdentity(identity); |
| 4022 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4026 | * Sets the voice mail number of a given subId. |
| 4027 | */ |
| 4028 | @Override |
| 4029 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4030 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 4031 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4032 | |
| 4033 | final long identity = Binder.clearCallingIdentity(); |
| 4034 | try { |
| 4035 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 4036 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 4037 | return success; |
| 4038 | } finally { |
| 4039 | Binder.restoreCallingIdentity(identity); |
| 4040 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4043 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4044 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 4045 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4046 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 4047 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4048 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 4049 | throw new SecurityException("caller must be system dialer"); |
| 4050 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4051 | |
| 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 4055 | if (phoneAccountHandle == null) { |
| 4056 | return null; |
| 4057 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4058 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4059 | } finally { |
| 4060 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4061 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4065 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 4066 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4067 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4069 | mApp, subId, callingPackage, callingFeatureId, |
| 4070 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4071 | return null; |
| 4072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4076 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4077 | } finally { |
| 4078 | Binder.restoreCallingIdentity(identity); |
| 4079 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4083 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 4084 | VisualVoicemailSmsFilterSettings settings) { |
| 4085 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | |
| 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4090 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4097 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 4098 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4099 | |
| 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4103 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4110 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 4111 | String callingPackage, int subId) { |
| 4112 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4113 | |
| 4114 | final long identity = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4117 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4118 | } finally { |
| 4119 | Binder.restoreCallingIdentity(identity); |
| 4120 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4124 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4126 | |
| 4127 | final long identity = Binder.clearCallingIdentity(); |
| 4128 | try { |
| 4129 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4130 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4131 | } finally { |
| 4132 | Binder.restoreCallingIdentity(identity); |
| 4133 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4137 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 4138 | String callingAttributionTag, int subId, String number, int port, String text, |
| 4139 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4140 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4141 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4142 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4143 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4144 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 4145 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4146 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4147 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4148 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4149 | * Sets the voice activation state of a given subId. |
| 4150 | */ |
| 4151 | @Override |
| 4152 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4153 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4154 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4155 | |
| 4156 | final long identity = Binder.clearCallingIdentity(); |
| 4157 | try { |
| 4158 | final Phone phone = getPhone(subId); |
| 4159 | if (phone != null) { |
| 4160 | phone.setVoiceActivationState(activationState); |
| 4161 | } else { |
| 4162 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4163 | } |
| 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | /** |
| 4170 | * Sets the data activation state of a given subId. |
| 4171 | */ |
| 4172 | @Override |
| 4173 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4174 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4175 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4176 | |
| 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
| 4179 | final Phone phone = getPhone(subId); |
| 4180 | if (phone != null) { |
| 4181 | phone.setDataActivationState(activationState); |
| 4182 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4183 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4184 | } |
| 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * Returns the voice activation state of a given subId. |
| 4192 | */ |
| 4193 | @Override |
| 4194 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4196 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4197 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4198 | final long identity = Binder.clearCallingIdentity(); |
| 4199 | try { |
| 4200 | if (phone != null) { |
| 4201 | return phone.getVoiceActivationState(); |
| 4202 | } else { |
| 4203 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4204 | } |
| 4205 | } finally { |
| 4206 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | /** |
| 4211 | * Returns the data activation state of a given subId. |
| 4212 | */ |
| 4213 | @Override |
| 4214 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4216 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4217 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
| 4220 | if (phone != null) { |
| 4221 | return phone.getDataActivationState(); |
| 4222 | } else { |
| 4223 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4224 | } |
| 4225 | } finally { |
| 4226 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4231 | * Returns the unread count of voicemails for a subId |
| 4232 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4233 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4234 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4235 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4236 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4237 | mApp, subId, callingPackage, callingFeatureId, |
| 4238 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4239 | return 0; |
| 4240 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4241 | final long identity = Binder.clearCallingIdentity(); |
| 4242 | try { |
| 4243 | final Phone phone = getPhone(subId); |
| 4244 | if (phone != null) { |
| 4245 | return phone.getVoiceMessageCount(); |
| 4246 | } else { |
| 4247 | return 0; |
| 4248 | } |
| 4249 | } finally { |
| 4250 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4251 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4255 | * returns true, if the device is in a state where both voice and data |
| 4256 | * are supported simultaneously. This can change based on location or network condition. |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4257 | */ |
| 4258 | @Override |
| 4259 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | final long identity = Binder.clearCallingIdentity(); |
| 4261 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4262 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | } finally { |
| 4264 | Binder.restoreCallingIdentity(identity); |
| 4265 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4269 | * Send the dialer code if called from the current default dialer or the caller has |
| 4270 | * carrier privilege. |
| 4271 | * @param inputCode The dialer code to send |
| 4272 | */ |
| 4273 | @Override |
| 4274 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4275 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4277 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4278 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4279 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4280 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4281 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4283 | |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4286 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(identity); |
| 4289 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4290 | } |
| 4291 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4292 | @Override |
| 4293 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4294 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4295 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4296 | mApp, subId, "getNetworkSelectionMode"); |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4297 | final long identity = Binder.clearCallingIdentity(); |
| 4298 | try { |
| 4299 | if (!isActiveSubscription(subId)) { |
| 4300 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4301 | } |
| 4302 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4303 | } finally { |
| 4304 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4305 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4306 | } |
| 4307 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4308 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4309 | public boolean isInEmergencySmsMode() { |
| 4310 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4311 | final long identity = Binder.clearCallingIdentity(); |
| 4312 | try { |
| 4313 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4314 | if (phone.isInEmergencySmsMode()) { |
| 4315 | return true; |
| 4316 | } |
| 4317 | } |
| 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
| 4321 | return false; |
| 4322 | } |
| 4323 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4324 | /** |
| 4325 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4326 | * @param subId The subscription to use to check the configuration. |
| 4327 | * @param c The callback that will be used to send the result. |
| 4328 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4329 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4330 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4331 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4332 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4333 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4334 | |
| 4335 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4336 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4337 | "IMS not available on device."); |
| 4338 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4339 | final long token = Binder.clearCallingIdentity(); |
| 4340 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4341 | int slotId = getSlotIndexOrException(subId); |
| 4342 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4343 | |
| 4344 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4345 | if (controller != null) { |
| 4346 | ImsManager imsManager = controller.getImsManager(subId); |
| 4347 | if (imsManager != null) { |
| 4348 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4349 | } else { |
| 4350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4351 | } |
| 4352 | } else { |
| 4353 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4354 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4355 | } catch (ImsException e) { |
| 4356 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4357 | } finally { |
| 4358 | Binder.restoreCallingIdentity(token); |
| 4359 | } |
| 4360 | } |
| 4361 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4362 | /** |
| 4363 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4364 | * @param subId The subscription to use to check the configuration. |
| 4365 | * @param c The callback that will be used to send the result. |
| 4366 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4367 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4368 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4369 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4370 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4371 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4372 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4373 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4374 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4375 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4376 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4377 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4378 | if (controller != null) { |
| 4379 | ImsManager imsManager = controller.getImsManager(subId); |
| 4380 | if (imsManager != null) { |
| 4381 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4382 | } else { |
| 4383 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4384 | + "is inactive, ignoring unregister."); |
| 4385 | // If the ImsManager is not valid, just return, since the callback |
| 4386 | // will already have been removed internally. |
| 4387 | } |
| 4388 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4389 | } finally { |
| 4390 | Binder.restoreCallingIdentity(token); |
| 4391 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4392 | } |
| 4393 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4394 | /** |
| 4395 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4396 | */ |
| 4397 | @Override |
| 4398 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4399 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4400 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4401 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4402 | "IMS not available on device."); |
| 4403 | } |
| 4404 | final long token = Binder.clearCallingIdentity(); |
| 4405 | try { |
| 4406 | Phone phone = getPhone(subId); |
| 4407 | if (phone == null) { |
| 4408 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4409 | + subId + "'"); |
| 4410 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4411 | } |
| 4412 | phone.getImsRegistrationState(regState -> { |
| 4413 | try { |
| 4414 | consumer.accept((regState == null) |
| 4415 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4416 | } catch (RemoteException e) { |
| 4417 | // Ignore if the remote process is no longer available to call back. |
| 4418 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4419 | } |
| 4420 | }); |
| 4421 | } finally { |
| 4422 | Binder.restoreCallingIdentity(token); |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | /** |
| 4427 | * Get the transport type for the IMS service registration state. |
| 4428 | */ |
| 4429 | @Override |
| 4430 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4431 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4432 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4433 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4434 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4435 | "IMS not available on device."); |
| 4436 | } |
| 4437 | final long token = Binder.clearCallingIdentity(); |
| 4438 | try { |
| 4439 | Phone phone = getPhone(subId); |
| 4440 | if (phone == null) { |
| 4441 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4442 | + subId + "'"); |
| 4443 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4444 | } |
| 4445 | phone.getImsRegistrationTech(regTech -> { |
| 4446 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4447 | int regTechConverted = (regTech == null) |
| 4448 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4449 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4450 | regTechConverted); |
| 4451 | try { |
| 4452 | consumer.accept(regTechConverted); |
| 4453 | } catch (RemoteException e) { |
| 4454 | // Ignore if the remote process is no longer available to call back. |
| 4455 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4456 | } |
| 4457 | }); |
| 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(token); |
| 4460 | } |
| 4461 | } |
| 4462 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4463 | /** |
| 4464 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4465 | * @param subId The subscription to use to check the configuration. |
| 4466 | * @param c The callback that will be used to send the result. |
| 4467 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4468 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4469 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4470 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4471 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4472 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4473 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4474 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4475 | "IMS not available on device."); |
| 4476 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4477 | final long token = Binder.clearCallingIdentity(); |
| 4478 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4479 | int slotId = getSlotIndexOrException(subId); |
| 4480 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4481 | |
| 4482 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4483 | if (controller != null) { |
| 4484 | ImsManager imsManager = controller.getImsManager(subId); |
| 4485 | if (imsManager != null) { |
| 4486 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); |
| 4487 | } else { |
| 4488 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4489 | } |
| 4490 | } else { |
| 4491 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4492 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4493 | } catch (ImsException e) { |
| 4494 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(token); |
| 4497 | } |
| 4498 | } |
| 4499 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4500 | /** |
| 4501 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4502 | * @param subId The subscription to use to check the configuration. |
| 4503 | * @param c The callback that will be used to send the result. |
| 4504 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4505 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4506 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4507 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4508 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4509 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4510 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4511 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4512 | |
| 4513 | final long token = Binder.clearCallingIdentity(); |
| 4514 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4515 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4516 | if (controller != null) { |
| 4517 | ImsManager imsManager = controller.getImsManager(subId); |
| 4518 | if (imsManager != null) { |
| 4519 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); |
| 4520 | } else { |
| 4521 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4522 | + " is inactive, ignoring unregister."); |
| 4523 | // If the ImsManager is not valid, just return, since the callback |
| 4524 | // will already have been removed internally. |
| 4525 | } |
| 4526 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(token); |
| 4529 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4533 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4534 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4535 | final long token = Binder.clearCallingIdentity(); |
| 4536 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4537 | int slotId = getSlotIndexOrException(subId); |
| 4538 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4539 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4540 | } catch (com.android.ims.ImsException e) { |
| 4541 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4542 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4543 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4544 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4545 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(token); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4552 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4553 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | final long token = Binder.clearCallingIdentity(); |
| 4555 | try { |
| 4556 | Phone phone = getPhone(subId); |
| 4557 | if (phone == null) return false; |
| 4558 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4559 | } catch (com.android.ims.ImsException e) { |
| 4560 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4561 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(token); |
| 4564 | } |
| 4565 | } |
| 4566 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4567 | /** |
| 4568 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4569 | * subscription. |
| 4570 | * @param subId The subscription to use to check the configuration. |
| 4571 | * @param callback The callback that will be used to send the result. |
| 4572 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4573 | * @param transportType The transport type of the MmTelFeature capability. |
| 4574 | */ |
| 4575 | @Override |
| 4576 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4577 | int transportType) { |
| 4578 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4579 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4580 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4581 | "IMS not available on device."); |
| 4582 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4583 | final long token = Binder.clearCallingIdentity(); |
| 4584 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4585 | int slotId = getSlotIndex(subId); |
| 4586 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4587 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4588 | + subId + "'"); |
| 4589 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4590 | } |
| 4591 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4592 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4593 | transportType, aBoolean -> { |
| 4594 | try { |
| 4595 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4596 | } catch (RemoteException e) { |
| 4597 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4598 | + "running. Ignore"); |
| 4599 | } |
| 4600 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4601 | } catch (ImsException e) { |
| 4602 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4603 | } finally { |
| 4604 | Binder.restoreCallingIdentity(token); |
| 4605 | } |
| 4606 | } |
| 4607 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4608 | /** |
| 4609 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4610 | * @param subId The subscription to use to check the configuration. |
| 4611 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4612 | @Override |
| 4613 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4614 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4615 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4616 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4617 | final long token = Binder.clearCallingIdentity(); |
| 4618 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4619 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4620 | // 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] | 4621 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4622 | } catch (ImsException e) { |
| 4623 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4624 | } finally { |
| 4625 | Binder.restoreCallingIdentity(token); |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4630 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4632 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4633 | final long identity = Binder.clearCallingIdentity(); |
| 4634 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4635 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4636 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4637 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4638 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4639 | } catch (ImsException e) { |
| 4640 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
| 4644 | } |
| 4645 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4646 | /** |
| 4647 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4648 | * @param subId The subscription to use to check the configuration. |
| 4649 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4650 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4651 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4652 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4653 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4654 | final long identity = Binder.clearCallingIdentity(); |
| 4655 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4656 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4657 | // 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] | 4658 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4659 | } catch (ImsException e) { |
| 4660 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4661 | } finally { |
| 4662 | Binder.restoreCallingIdentity(identity); |
| 4663 | } |
| 4664 | } |
| 4665 | |
| 4666 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4667 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4669 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4670 | final long identity = Binder.clearCallingIdentity(); |
| 4671 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4672 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4673 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4674 | // 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] | 4675 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4676 | } catch (ImsException e) { |
| 4677 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4678 | } finally { |
| 4679 | Binder.restoreCallingIdentity(identity); |
| 4680 | } |
| 4681 | } |
| 4682 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4683 | /** |
| 4684 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4685 | * @param subId The subscription to use to check the configuration. |
| 4686 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4687 | @Override |
| 4688 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4689 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4690 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4693 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4694 | // 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] | 4695 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4696 | } catch (ImsException e) { |
| 4697 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4698 | } finally { |
| 4699 | Binder.restoreCallingIdentity(identity); |
| 4700 | } |
| 4701 | } |
| 4702 | |
| 4703 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4704 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4705 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4706 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4707 | final long identity = Binder.clearCallingIdentity(); |
| 4708 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4709 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4710 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4711 | // 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] | 4712 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4713 | } catch (ImsException e) { |
| 4714 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4715 | } finally { |
| 4716 | Binder.restoreCallingIdentity(identity); |
| 4717 | } |
| 4718 | } |
| 4719 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4720 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4721 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4722 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4723 | * @param subId The subscription to use to check the configuration. |
| 4724 | */ |
| 4725 | @Override |
| 4726 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4727 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4728 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4731 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4732 | // 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] | 4733 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4734 | } catch (ImsException e) { |
| 4735 | throw new ServiceSpecificException(e.getCode()); |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
| 4739 | } |
| 4740 | |
| 4741 | /** |
| 4742 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4743 | * Requires MODIFY_PHONE_STATE permission. |
| 4744 | * @param subId The subscription to use to check the configuration. |
| 4745 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4746 | * false otherwise |
| 4747 | */ |
| 4748 | @Override |
| 4749 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4751 | "setCrossSimCallingEnabled"); |
| 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4754 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4755 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4756 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4757 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4758 | } catch (ImsException e) { |
| 4759 | throw new ServiceSpecificException(e.getCode()); |
| 4760 | } finally { |
| 4761 | Binder.restoreCallingIdentity(identity); |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4766 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4767 | * @param subId The subscription to use to check the configuration. |
| 4768 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4769 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4770 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4771 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4772 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4773 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4774 | final long identity = Binder.clearCallingIdentity(); |
| 4775 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4776 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4777 | // 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] | 4778 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4779 | } catch (ImsException e) { |
| 4780 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4781 | } finally { |
| 4782 | Binder.restoreCallingIdentity(identity); |
| 4783 | } |
| 4784 | } |
| 4785 | |
| 4786 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4787 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4789 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4790 | final long identity = Binder.clearCallingIdentity(); |
| 4791 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4792 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4793 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4794 | // 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] | 4795 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4796 | } catch (ImsException e) { |
| 4797 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4798 | } finally { |
| 4799 | Binder.restoreCallingIdentity(identity); |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | @Override |
| 4804 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4805 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4806 | "setVoWiFiNonPersistent"); |
| 4807 | final long identity = Binder.clearCallingIdentity(); |
| 4808 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4809 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4810 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4811 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4812 | } catch (ImsException e) { |
| 4813 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4814 | } finally { |
| 4815 | Binder.restoreCallingIdentity(identity); |
| 4816 | } |
| 4817 | } |
| 4818 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4819 | /** |
| 4820 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4821 | * @param subId The subscription to use to check the configuration. |
| 4822 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4823 | @Override |
| 4824 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4825 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4826 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4829 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4830 | // 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] | 4831 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4832 | } catch (ImsException e) { |
| 4833 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4834 | } finally { |
| 4835 | Binder.restoreCallingIdentity(identity); |
| 4836 | } |
| 4837 | } |
| 4838 | |
| 4839 | @Override |
| 4840 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4841 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4842 | "setVoWiFiModeSetting"); |
| 4843 | final long identity = Binder.clearCallingIdentity(); |
| 4844 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4845 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4846 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4847 | // 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] | 4848 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4849 | } catch (ImsException e) { |
| 4850 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4851 | } finally { |
| 4852 | Binder.restoreCallingIdentity(identity); |
| 4853 | } |
| 4854 | } |
| 4855 | |
| 4856 | @Override |
| 4857 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4858 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4859 | final long identity = Binder.clearCallingIdentity(); |
| 4860 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4861 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4862 | // 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] | 4863 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4864 | } catch (ImsException e) { |
| 4865 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | @Override |
| 4872 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4874 | "setVoWiFiRoamingModeSetting"); |
| 4875 | final long identity = Binder.clearCallingIdentity(); |
| 4876 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4877 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4878 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4879 | // 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] | 4880 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4881 | } catch (ImsException e) { |
| 4882 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4883 | } finally { |
| 4884 | Binder.restoreCallingIdentity(identity); |
| 4885 | } |
| 4886 | } |
| 4887 | |
| 4888 | @Override |
| 4889 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4891 | "setRttCapabilityEnabled"); |
| 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4894 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4895 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4896 | // 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] | 4897 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4898 | } catch (ImsException e) { |
| 4899 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
| 4902 | } |
| 4903 | } |
| 4904 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4905 | /** |
| 4906 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4907 | * @param subId The subscription to use to check the configuration. |
| 4908 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4909 | @Override |
| 4910 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4911 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4912 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4913 | final long identity = Binder.clearCallingIdentity(); |
| 4914 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4915 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4916 | // 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] | 4917 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4918 | } catch (ImsException e) { |
| 4919 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
| 4923 | } |
| 4924 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4925 | @Override |
| 4926 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4927 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4928 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4929 | final long identity = Binder.clearCallingIdentity(); |
| 4930 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4931 | if (!isImsAvailableOnDevice()) { |
| 4932 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4933 | "IMS not available on device."); |
| 4934 | } |
| 4935 | int slotId = getSlotIndexOrException(subId); |
| 4936 | verifyImsMmTelConfiguredOrThrow(slotId); |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4937 | |
| 4938 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4939 | if (controller != null) { |
| 4940 | ImsManager imsManager = controller.getImsManager(subId); |
| 4941 | if (imsManager != null) { |
| 4942 | imsManager.addProvisioningCallbackForSubscription(callback, subId); |
| 4943 | } else { |
| 4944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4945 | } |
| 4946 | } else { |
| 4947 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4948 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4949 | } catch (ImsException e) { |
| 4950 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
| 4954 | } |
| 4955 | |
| 4956 | @Override |
| 4957 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4958 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4959 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4960 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4961 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4962 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4963 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4964 | try { |
Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4965 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4966 | if (controller != null) { |
| 4967 | ImsManager imsManager = controller.getImsManager(subId); |
| 4968 | if (imsManager != null) { |
| 4969 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); |
| 4970 | } else { |
| 4971 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4972 | + " is inactive, ignoring unregister."); |
| 4973 | // If the ImsManager is not valid, just return, since the callback will already |
| 4974 | // have been removed internally. |
| 4975 | } |
| 4976 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
| 4979 | } |
| 4980 | } |
| 4981 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4982 | @Override |
| 4983 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4984 | IFeatureProvisioningCallback callback) { |
| 4985 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4986 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4987 | |
| 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4990 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4991 | } |
| 4992 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4993 | try { |
| 4994 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4995 | if (controller == null) { |
| 4996 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4997 | "Device does not support IMS"); |
| 4998 | } |
| 4999 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 5000 | } finally { |
| 5001 | Binder.restoreCallingIdentity(identity); |
| 5002 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | @Override |
| 5006 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 5007 | IFeatureProvisioningCallback callback) { |
| 5008 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5009 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 5010 | |
| 5011 | final long identity = Binder.clearCallingIdentity(); |
| 5012 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5013 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 5014 | } |
| 5015 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5016 | try { |
| 5017 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5018 | if (controller == null) { |
| 5019 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 5020 | return; |
| 5021 | } |
| 5022 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 5023 | } finally { |
| 5024 | Binder.restoreCallingIdentity(identity); |
| 5025 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5026 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5027 | |
| 5028 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 5029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5030 | message); |
| 5031 | } |
| 5032 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5033 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5034 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5035 | boolean isProvisioned) { |
| 5036 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 5037 | |
| 5038 | final long identity = Binder.clearCallingIdentity(); |
| 5039 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5040 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5041 | if (controller == null) { |
| 5042 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5043 | return; |
| 5044 | } |
| 5045 | controller.setRcsProvisioningStatusForCapability( |
| 5046 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | |
| 5053 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5054 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 5055 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5056 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 5057 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5060 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5061 | if (controller == null) { |
| 5062 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 5063 | |
| 5064 | // device does not support IMS, this method will return true always. |
| 5065 | return true; |
| 5066 | } |
| 5067 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5068 | } finally { |
| 5069 | Binder.restoreCallingIdentity(identity); |
| 5070 | } |
| 5071 | } |
| 5072 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5073 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5074 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 5075 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5076 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5077 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5078 | final long identity = Binder.clearCallingIdentity(); |
| 5079 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5080 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5081 | if (controller == null) { |
| 5082 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 5083 | return; |
| 5084 | } |
| 5085 | controller.setImsProvisioningStatusForCapability( |
| 5086 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | @Override |
| 5093 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5094 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5095 | mApp, subId, "getProvisioningStatusForCapability"); |
| 5096 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5099 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5100 | if (controller == null) { |
| 5101 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5102 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5103 | // device does not support IMS, this method will return true always. |
| 5104 | return true; |
| 5105 | } |
| 5106 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5107 | } finally { |
| 5108 | Binder.restoreCallingIdentity(identity); |
| 5109 | } |
| 5110 | } |
| 5111 | |
| 5112 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5113 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5114 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5115 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 5116 | |
| 5117 | final long identity = Binder.clearCallingIdentity(); |
| 5118 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5119 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5120 | if (controller == null) { |
| 5121 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 5122 | |
| 5123 | // device does not support IMS, this method will return false |
| 5124 | return false; |
| 5125 | } |
| 5126 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5127 | } finally { |
| 5128 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5129 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5133 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 5134 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5135 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5136 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5139 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5140 | if (controller == null) { |
| 5141 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 5142 | |
| 5143 | // device does not support IMS, this method will return false |
| 5144 | return false; |
| 5145 | } |
| 5146 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5147 | } finally { |
| 5148 | Binder.restoreCallingIdentity(identity); |
| 5149 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5150 | } |
| 5151 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5152 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5153 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5154 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5155 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5156 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5157 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5158 | mApp, subId, "getImsProvisioningInt"); |
| 5159 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5160 | final long identity = Binder.clearCallingIdentity(); |
| 5161 | try { |
| 5162 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5163 | int slotId = getSlotIndex(subId); |
| 5164 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5165 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 5166 | + subId + "' for key:" + key); |
| 5167 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5168 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5169 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5170 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5171 | if (controller == null) { |
| 5172 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 5173 | |
| 5174 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 5175 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 5176 | } |
| 5177 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5178 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5179 | return retVal; |
| 5180 | } |
| 5181 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5182 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5183 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5184 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5185 | + subId + "' for key:" + key); |
| 5186 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5187 | } finally { |
| 5188 | Binder.restoreCallingIdentity(identity); |
| 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | @Override |
| 5193 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5194 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5195 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5196 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5197 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5198 | mApp, subId, "getImsProvisioningString"); |
| 5199 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5200 | final long identity = Binder.clearCallingIdentity(); |
| 5201 | try { |
| 5202 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5203 | int slotId = getSlotIndex(subId); |
| 5204 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5205 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5206 | + subId + "' for key:" + key); |
| 5207 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5208 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5209 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5210 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5211 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5212 | + subId + "' for key:" + key); |
| 5213 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5214 | } finally { |
| 5215 | Binder.restoreCallingIdentity(identity); |
| 5216 | } |
| 5217 | } |
| 5218 | |
| 5219 | @Override |
| 5220 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5221 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5222 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5223 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5224 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5225 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5226 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5227 | final long identity = Binder.clearCallingIdentity(); |
| 5228 | try { |
| 5229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5230 | int slotId = getSlotIndex(subId); |
| 5231 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5232 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5233 | + subId + "' for key:" + key); |
| 5234 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5235 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5236 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5237 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5238 | if (controller == null) { |
| 5239 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5240 | |
| 5241 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5242 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5243 | } |
| 5244 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5245 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5246 | return retVal; |
| 5247 | } |
| 5248 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5249 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5250 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5251 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5252 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5253 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
| 5257 | } |
| 5258 | |
| 5259 | @Override |
| 5260 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5261 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5262 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5263 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5265 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5266 | final long identity = Binder.clearCallingIdentity(); |
| 5267 | try { |
| 5268 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5269 | int slotId = getSlotIndex(subId); |
| 5270 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5271 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5272 | + subId + "' for key:" + key); |
| 5273 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5274 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5275 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5276 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5277 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5278 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5279 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
| 5282 | } |
| 5283 | } |
| 5284 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5285 | /** |
| 5286 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5287 | * for the given slot ID or no ImsResolver instance has been created. |
| 5288 | * @param slotId The slot ID that the IMS service is created for. |
| 5289 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5290 | */ |
| 5291 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5292 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5293 | ImsFeature.FEATURE_MMTEL)) { |
| 5294 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5295 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5296 | } |
| 5297 | } |
| 5298 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5299 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5300 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5301 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5302 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5303 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5304 | } |
| 5305 | return slotId; |
| 5306 | } |
| 5307 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5308 | private int getSlotIndex(int subId) { |
| 5309 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5310 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5311 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5312 | } |
| 5313 | return slotId; |
| 5314 | } |
| 5315 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5316 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5317 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5318 | */ |
| 5319 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5320 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5321 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5322 | try { |
| 5323 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5324 | } catch (SecurityException se) { |
| 5325 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5326 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5327 | + Binder.getCallingUid()); |
| 5328 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5329 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5330 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5331 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5332 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5333 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5334 | mApp, subId, callingPackage, callingFeatureId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5335 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5336 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5337 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | final Phone phone = getPhone(subId); |
| 5342 | if (phone != null) { |
| 5343 | return phone.getServiceState().getDataNetworkType(); |
| 5344 | } else { |
| 5345 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5346 | } |
| 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | /** |
| 5353 | * Returns the data network type |
| 5354 | */ |
| 5355 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5356 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5357 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5358 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | /** |
| 5362 | * Returns the data network type for a subId |
| 5363 | */ |
| 5364 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5365 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5366 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5367 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5368 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5369 | mApp, functionName)) { |
| 5370 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5371 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5372 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5373 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | try { |
| 5378 | final Phone phone = getPhone(subId); |
| 5379 | if (phone != null) { |
| 5380 | return phone.getServiceState().getDataNetworkType(); |
| 5381 | } else { |
| 5382 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5383 | } |
| 5384 | } finally { |
| 5385 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5386 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5387 | } |
| 5388 | |
| 5389 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5390 | * Returns the Voice network type for a subId |
| 5391 | */ |
| 5392 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5393 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5394 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5395 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5396 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5397 | mApp, functionName)) { |
| 5398 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5399 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5400 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5401 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
| 5406 | final Phone phone = getPhone(subId); |
| 5407 | if (phone != null) { |
| 5408 | return phone.getServiceState().getVoiceNetworkType(); |
| 5409 | } else { |
| 5410 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5411 | } |
| 5412 | } finally { |
| 5413 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5414 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | /** |
| 5418 | * @return true if a ICC card is present |
| 5419 | */ |
| 5420 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5421 | // FIXME Make changes to pass defaultSimId of type int |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5422 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5423 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5427 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5428 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5429 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5430 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | final long identity = Binder.clearCallingIdentity(); |
| 5432 | try { |
| 5433 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5434 | if (phone != null) { |
| 5435 | return phone.getIccCard().hasIccCard(); |
| 5436 | } else { |
| 5437 | return false; |
| 5438 | } |
| 5439 | } finally { |
| 5440 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5441 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | /** |
| 5445 | * Return if the current radio is LTE on CDMA. This |
| 5446 | * is a tri-state return value as for a period of time |
| 5447 | * the mode may be unknown. |
| 5448 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5449 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5450 | * @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] | 5451 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5452 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5453 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5454 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5455 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5456 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5459 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5460 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5461 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5462 | try { |
| 5463 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5464 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5465 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5466 | } |
| 5467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5468 | final long identity = Binder.clearCallingIdentity(); |
| 5469 | try { |
| 5470 | final Phone phone = getPhone(subId); |
| 5471 | if (phone == null) { |
| 5472 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5473 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5474 | return TelephonyProperties.lte_on_cdma_device() |
| 5475 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | } |
| 5477 | } finally { |
| 5478 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5479 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5480 | } |
| 5481 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5482 | /** |
| 5483 | * {@hide} |
| 5484 | * Returns Default subId, 0 in the case of single standby. |
| 5485 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5486 | private int getDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5487 | return SubscriptionManager.getDefaultSubscriptionId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5488 | } |
| 5489 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5490 | private int getSlotForDefaultSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5491 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5494 | private int getPreferredVoiceSubscription() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5495 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5496 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5497 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5498 | private boolean isActiveSubscription(int subId) { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5499 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 5500 | return getSubscriptionManagerService().isActiveSubId(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5501 | mApp.getOpPackageName(), mApp.getFeatureId()); |
| 5502 | } |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5503 | return mSubscriptionController.isActiveSubId(subId); |
| 5504 | } |
| 5505 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5506 | /** |
| 5507 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5508 | */ |
| 5509 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5510 | final long identity = Binder.clearCallingIdentity(); |
| 5511 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5512 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5513 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5514 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5515 | } finally { |
| 5516 | Binder.restoreCallingIdentity(identity); |
| 5517 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5518 | } |
| 5519 | |
| 5520 | /** |
| 5521 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5522 | */ |
| 5523 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | final long identity = Binder.clearCallingIdentity(); |
| 5525 | try { |
| 5526 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5527 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
| 5531 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5532 | } |
| 5533 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5534 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5535 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5536 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5537 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5538 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5539 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5540 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5541 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5542 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5543 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5544 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5545 | } |
| 5546 | return PhoneFactory.getPhone(phoneId); |
| 5547 | } |
| 5548 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5549 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5550 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5551 | @NonNull IccLogicalChannelRequest request) { |
| 5552 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5553 | /*message=*/ "iccOpenLogicalChannel"); |
| 5554 | |
| 5555 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5556 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5557 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5558 | |
| 5559 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5560 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5561 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5562 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5563 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5564 | Phone phone; |
| 5565 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5567 | mApp, request.subId, message); |
| 5568 | phone = getPhoneFromSubId(request.subId); |
| 5569 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5570 | enforceModifyPermission(); |
| 5571 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5572 | } else { |
| 5573 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5574 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5575 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5579 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 | final long identity = Binder.clearCallingIdentity(); |
| 5581 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5582 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5584 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5585 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5586 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5587 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | loge("The calling package is not allowed to access ISD-R."); |
| 5589 | throw new SecurityException( |
| 5590 | "The calling package is not allowed to access ISD-R."); |
| 5591 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5592 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5593 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5594 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5595 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5596 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | return response; |
| 5598 | } finally { |
| 5599 | Binder.restoreCallingIdentity(identity); |
| 5600 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
| 5603 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5604 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5605 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5606 | /*message=*/"iccCloseLogicalChannel"); |
| 5607 | |
| 5608 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5609 | |
| 5610 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5611 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5612 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5613 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5614 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5615 | // before this feature is enabled, this API should only return false if |
| 5616 | // the operation fails instead of throwing runtime exception for |
| 5617 | // backward-compatibility. |
| 5618 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5619 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | final long identity = Binder.clearCallingIdentity(); |
| 5621 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5622 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5623 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5624 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5625 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5626 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5627 | Boolean success = false; |
| 5628 | if (result instanceof RuntimeException) { |
| 5629 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5630 | if (shouldThrowExceptionOnFailure) { |
| 5631 | throw (RuntimeException) result; |
| 5632 | } else { |
| 5633 | return false; |
| 5634 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5635 | } else if (result instanceof Boolean) { |
| 5636 | success = (Boolean) result; |
| 5637 | } else { |
| 5638 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5639 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5640 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | return success; |
| 5642 | } finally { |
| 5643 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5644 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5645 | } |
| 5646 | |
| 5647 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5648 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5649 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5650 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5651 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5652 | if (DBG) { |
| 5653 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5654 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5655 | + p3 + " data=" + data); |
| 5656 | } |
| 5657 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5658 | command, p1, p2, p3, data); |
| 5659 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5660 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5661 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5662 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5663 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5664 | enforceModifyPermission(); |
| 5665 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5666 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5667 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5668 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5669 | } |
| 5670 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5671 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5672 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5673 | } |
| 5674 | |
| 5675 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5676 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5679 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5680 | return ""; |
| 5681 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5684 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5685 | null /* workSource */); |
| 5686 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5687 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | // Append the returned status code to the end of the response payload. |
| 5689 | String s = Integer.toHexString( |
| 5690 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5691 | if (response.payload != null) { |
| 5692 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5693 | } |
| 5694 | return s; |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5697 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5698 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5699 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5700 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5701 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5702 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5704 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5706 | if (DBG) { |
| 5707 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5708 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5709 | } |
| 5710 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5711 | cla, command, p1, p2, p3, data); |
| 5712 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5713 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5714 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5715 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5716 | 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] | 5717 | enforceModifyPermission(); |
| 5718 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5719 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5720 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5721 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5722 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5723 | } |
| 5724 | |
| 5725 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5726 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5727 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5731 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5732 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | final long identity = Binder.clearCallingIdentity(); |
| 5734 | try { |
| 5735 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5736 | && TextUtils.equals(ISDR_AID, data)) { |
| 5737 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5738 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5739 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5740 | if (bestComponent == null |
| 5741 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5742 | loge("The calling package is not allowed to select ISD-R."); |
| 5743 | throw new SecurityException( |
| 5744 | "The calling package is not allowed to select ISD-R."); |
| 5745 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5746 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5747 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5749 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5750 | null /* workSource */); |
| 5751 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5753 | // Append the returned status code to the end of the response payload. |
| 5754 | String s = Integer.toHexString( |
| 5755 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5756 | if (response.payload != null) { |
| 5757 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5758 | } |
| 5759 | return s; |
| 5760 | } finally { |
| 5761 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5762 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5763 | } |
| 5764 | |
| 5765 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5766 | 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] | 5767 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5769 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5770 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | final long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
| 5773 | if (DBG) { |
| 5774 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5775 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5776 | } |
| 5777 | |
| 5778 | IccIoResult response = |
| 5779 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5780 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5781 | subId); |
| 5782 | |
| 5783 | if (DBG) { |
| 5784 | log("Exchange SIM_IO [R]" + response); |
| 5785 | } |
| 5786 | |
| 5787 | byte[] result = null; |
| 5788 | int length = 2; |
| 5789 | if (response.payload != null) { |
| 5790 | length = 2 + response.payload.length; |
| 5791 | result = new byte[length]; |
| 5792 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5793 | } else { |
| 5794 | result = new byte[length]; |
| 5795 | } |
| 5796 | |
| 5797 | result[length - 1] = (byte) response.sw2; |
| 5798 | result[length - 2] = (byte) response.sw1; |
| 5799 | return result; |
| 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5802 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5803 | } |
| 5804 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5805 | /** |
| 5806 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5807 | * on a particular subscription |
| 5808 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5809 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5810 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5811 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5812 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5813 | return null; |
| 5814 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | |
| 5816 | final long identity = Binder.clearCallingIdentity(); |
| 5817 | try { |
| 5818 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5819 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5820 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5821 | return null; |
| 5822 | } |
| 5823 | Object response = sendRequest( |
| 5824 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5825 | if (response instanceof String[]) { |
| 5826 | return (String[]) response; |
| 5827 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5828 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5830 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | } finally { |
| 5832 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5833 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5834 | } |
| 5835 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5836 | /** |
| 5837 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5838 | * subscription. |
| 5839 | * |
| 5840 | * @param subId the id of the subscription. |
| 5841 | * @param appType the uicc app type, must be USIM or SIM. |
| 5842 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5843 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5844 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5845 | * @return number of fplmns that is successfully written to the SIM. |
| 5846 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5847 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5848 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5850 | mApp, subId, "setForbiddenPlmns"); |
| 5851 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5852 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5853 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5854 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5855 | } |
| 5856 | if (fplmns == null) { |
| 5857 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5858 | } |
| 5859 | for (String fplmn : fplmns) { |
| 5860 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5861 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5862 | } |
| 5863 | } |
| 5864 | final long identity = Binder.clearCallingIdentity(); |
| 5865 | try { |
| 5866 | Object response = sendRequest( |
| 5867 | CMD_SET_FORBIDDEN_PLMNS, |
| 5868 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5869 | subId); |
| 5870 | return (int) response; |
| 5871 | } finally { |
| 5872 | Binder.restoreCallingIdentity(identity); |
| 5873 | } |
| 5874 | } |
| 5875 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5876 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5877 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5879 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5880 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
| 5883 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5884 | if (response.payload == null) { |
| 5885 | return ""; |
| 5886 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5887 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | // Append the returned status code to the end of the response payload. |
| 5889 | String s = Integer.toHexString( |
| 5890 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5891 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5892 | return s; |
| 5893 | } finally { |
| 5894 | Binder.restoreCallingIdentity(identity); |
| 5895 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5898 | /** |
| 5899 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5900 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5901 | * |
| 5902 | * @param itemID the ID of the item to read |
| 5903 | * @return the NV item as a String, or null on error. |
| 5904 | */ |
| 5905 | @Override |
| 5906 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5907 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5909 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5910 | |
| 5911 | final long identity = Binder.clearCallingIdentity(); |
| 5912 | try { |
| 5913 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5914 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5915 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5916 | return value; |
| 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
| 5919 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | /** |
| 5923 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5924 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5925 | * |
| 5926 | * @param itemID the ID of the item to read |
| 5927 | * @param itemValue the value to write, as a String |
| 5928 | * @return true on success; false on any failure |
| 5929 | */ |
| 5930 | @Override |
| 5931 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5932 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5934 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | |
| 5936 | final long identity = Binder.clearCallingIdentity(); |
| 5937 | try { |
| 5938 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5939 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5940 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5941 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5942 | return success; |
| 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
| 5945 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5946 | } |
| 5947 | |
| 5948 | /** |
| 5949 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5950 | * Used for device configuration by some CDMA operators. |
| 5951 | * |
| 5952 | * @param preferredRoamingList byte array containing the new PRL |
| 5953 | * @return true on success; false on any failure |
| 5954 | */ |
| 5955 | @Override |
| 5956 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5958 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
| 5961 | try { |
| 5962 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5963 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5964 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5965 | return success; |
| 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
| 5968 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5969 | } |
| 5970 | |
| 5971 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5972 | * 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] | 5973 | * Used for device configuration by some CDMA operators. |
| 5974 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5975 | * @param slotIndex - device slot. |
| 5976 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5977 | * @return true on success; false on any failure |
| 5978 | */ |
| 5979 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5980 | public boolean resetModemConfig(int slotIndex) { |
| 5981 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5982 | if (phone != null) { |
| 5983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5984 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5985 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5986 | final long identity = Binder.clearCallingIdentity(); |
| 5987 | try { |
| 5988 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5989 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5990 | return success; |
| 5991 | } finally { |
| 5992 | Binder.restoreCallingIdentity(identity); |
| 5993 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5994 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5995 | return false; |
| 5996 | } |
| 5997 | |
| 5998 | /** |
| 5999 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 6000 | * |
| 6001 | * @param slotIndex - device slot. |
| 6002 | * |
| 6003 | * @return true on success; false on any failure |
| 6004 | */ |
| 6005 | @Override |
| 6006 | public boolean rebootModem(int slotIndex) { |
| 6007 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6008 | if (phone != null) { |
| 6009 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6010 | mApp, phone.getSubId(), "rebootModem"); |
| 6011 | |
| 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
| 6014 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 6015 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 6016 | return success; |
| 6017 | } finally { |
| 6018 | Binder.restoreCallingIdentity(identity); |
| 6019 | } |
| 6020 | } |
| 6021 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6022 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6023 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6024 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6025 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 6026 | * {@link #disableIms(int)}. |
| 6027 | * @param slotIndex device slot. |
| 6028 | */ |
| 6029 | public void resetIms(int slotIndex) { |
| 6030 | enforceModifyPermission(); |
| 6031 | |
| 6032 | final long identity = Binder.clearCallingIdentity(); |
| 6033 | try { |
| 6034 | if (mImsResolver == null) { |
| 6035 | // may happen if the does not support IMS. |
| 6036 | return; |
| 6037 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6038 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6039 | } finally { |
| 6040 | Binder.restoreCallingIdentity(identity); |
| 6041 | } |
| 6042 | } |
| 6043 | |
| 6044 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6045 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 6046 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6047 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6048 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6049 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | |
| 6051 | final long identity = Binder.clearCallingIdentity(); |
| 6052 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6053 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6054 | // may happen if the device does not support IMS. |
| 6055 | return; |
| 6056 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6057 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6058 | } finally { |
| 6059 | Binder.restoreCallingIdentity(identity); |
| 6060 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6064 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 6065 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6066 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6067 | public void disableIms(int slotId) { |
| 6068 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | |
| 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6072 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6073 | // may happen if the device does not support IMS. |
| 6074 | return; |
| 6075 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6076 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6077 | } finally { |
| 6078 | Binder.restoreCallingIdentity(identity); |
| 6079 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6083 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 6084 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6085 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6086 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6087 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6088 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | |
| 6090 | final long identity = Binder.clearCallingIdentity(); |
| 6091 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6092 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6094 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6095 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6096 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6097 | } finally { |
| 6098 | Binder.restoreCallingIdentity(identity); |
| 6099 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6100 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6101 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6102 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 6103 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6104 | @Override |
| 6105 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6106 | enforceModifyPermission(); |
| 6107 | |
| 6108 | final long identity = Binder.clearCallingIdentity(); |
| 6109 | try { |
| 6110 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6111 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6112 | } finally { |
| 6113 | Binder.restoreCallingIdentity(identity); |
| 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6118 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6119 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6120 | */ |
| 6121 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 6122 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6123 | |
| 6124 | final long identity = Binder.clearCallingIdentity(); |
| 6125 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6126 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6127 | // may happen if the device does not support IMS. |
| 6128 | return null; |
| 6129 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6130 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | } finally { |
| 6132 | Binder.restoreCallingIdentity(identity); |
| 6133 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6134 | } |
| 6135 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6136 | /** |
| 6137 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6138 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6139 | */ |
| 6140 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 6141 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | |
| 6143 | final long identity = Binder.clearCallingIdentity(); |
| 6144 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6145 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6146 | // may happen if the device does not support IMS. |
| 6147 | return null; |
| 6148 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6149 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
| 6152 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6153 | } |
| 6154 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6155 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6156 | * Sets the ImsService Package Name that Telephony will bind to. |
| 6157 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6158 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6159 | * @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] | 6160 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6161 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 6162 | * @param packageName The name of the package that the current configuration will be replaced |
| 6163 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6164 | * @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] | 6165 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6166 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 6167 | int[] featureTypes, String packageName) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6168 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6169 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6170 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | final long identity = Binder.clearCallingIdentity(); |
| 6173 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6174 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6175 | // may happen if the device does not support IMS. |
| 6176 | return false; |
| 6177 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6178 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 6179 | for (int featureType : featureTypes) { |
| 6180 | featureConfig.put(featureType, packageName); |
| 6181 | } |
| 6182 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 6183 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6184 | } finally { |
| 6185 | Binder.restoreCallingIdentity(identity); |
| 6186 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6190 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6191 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6192 | * |
| 6193 | * This should only be used for testing. |
| 6194 | * |
| 6195 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6196 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6197 | */ |
| 6198 | @Override |
| 6199 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6200 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6201 | "clearCarrierImsServiceOverride"); |
| 6202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6203 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6204 | |
| 6205 | final long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
| 6207 | if (mImsResolver == null) { |
| 6208 | // may happen if the device does not support IMS. |
| 6209 | return false; |
| 6210 | } |
| 6211 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6212 | } finally { |
| 6213 | Binder.restoreCallingIdentity(identity); |
| 6214 | } |
| 6215 | } |
| 6216 | |
| 6217 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6218 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6219 | * |
| 6220 | * @param slotId The slot that the ImsService is associated with. |
| 6221 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6222 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6223 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6224 | * @return the package name of the ImsService configuration. |
| 6225 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6226 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6227 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6228 | TelephonyPermissions |
Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6229 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, |
| 6230 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6231 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6232 | final long identity = Binder.clearCallingIdentity(); |
| 6233 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6234 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6235 | // may happen if the device does not support IMS. |
| 6236 | return ""; |
| 6237 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6238 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6239 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6240 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | } finally { |
| 6242 | Binder.restoreCallingIdentity(identity); |
| 6243 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6246 | /** |
| 6247 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6248 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6249 | * @param callback A callback with an integer containing the |
| 6250 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6251 | */ |
| 6252 | @Override |
| 6253 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6254 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6255 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6256 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6257 | "IMS not available on device."); |
| 6258 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6259 | final long token = Binder.clearCallingIdentity(); |
| 6260 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6261 | int slotId = getSlotIndex(subId); |
| 6262 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6263 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6264 | + subId + "'"); |
| 6265 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6266 | } |
| 6267 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6268 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6269 | try { |
| 6270 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6271 | } catch (RemoteException e) { |
| 6272 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6273 | + "Ignore"); |
| 6274 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6275 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6276 | } catch (ImsException e) { |
| 6277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6278 | } finally { |
| 6279 | Binder.restoreCallingIdentity(token); |
| 6280 | } |
| 6281 | } |
| 6282 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6283 | /** |
| 6284 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6285 | */ |
| 6286 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6287 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6288 | |
| 6289 | final long identity = Binder.clearCallingIdentity(); |
| 6290 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6291 | // NOTE: Before S, this method only set the default phone. |
| 6292 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6293 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6294 | phone.setImsRegistrationState(registered); |
| 6295 | } |
| 6296 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 | } finally { |
| 6298 | Binder.restoreCallingIdentity(identity); |
| 6299 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6303 | * Set the network selection mode to automatic. |
| 6304 | * |
| 6305 | */ |
| 6306 | @Override |
| 6307 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6309 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6310 | |
| 6311 | final long identity = Binder.clearCallingIdentity(); |
| 6312 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6313 | if (!isActiveSubscription(subId)) { |
| 6314 | return; |
| 6315 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6316 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6317 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6318 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
| 6321 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6322 | } |
| 6323 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6324 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6325 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6326 | * |
| 6327 | * @param subId the id of the subscription. |
| 6328 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6329 | * the operator to attach to. |
| 6330 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6331 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6332 | * normal network selection next time. |
| 6333 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6334 | */ |
| 6335 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6336 | public boolean setNetworkSelectionModeManual( |
| 6337 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6338 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6339 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6340 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6341 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6342 | if (!isActiveSubscription(subId)) { |
| 6343 | return false; |
| 6344 | } |
| 6345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6346 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6347 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6349 | if (DBG) { |
| 6350 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6351 | + " operator: " + operatorInfo); |
| 6352 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6354 | } finally { |
| 6355 | Binder.restoreCallingIdentity(identity); |
| 6356 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6357 | } |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6358 | /** |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6359 | * Get the manual network selection |
| 6360 | * |
| 6361 | * @param subId the id of the subscription. |
| 6362 | * |
| 6363 | * @return the previously saved user selected PLMN |
| 6364 | */ |
| 6365 | @Override |
| 6366 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6367 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6368 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 6369 | mApp, subId, "getManualNetworkSelectionPlmn"); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6370 | |
| 6371 | final long identity = Binder.clearCallingIdentity(); |
| 6372 | try { |
| 6373 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6374 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | final Phone phone = getPhone(subId); |
| 6378 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6379 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6380 | } |
| 6381 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6382 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6383 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6384 | } finally { |
| 6385 | Binder.restoreCallingIdentity(identity); |
| 6386 | } |
| 6387 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6388 | |
| 6389 | /** |
| 6390 | * Scans for available networks. |
| 6391 | */ |
| 6392 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6393 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6394 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6395 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6396 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6397 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6398 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6399 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6400 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6401 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6402 | .setCallingPid(Binder.getCallingPid()) |
| 6403 | .setCallingUid(Binder.getCallingUid()) |
| 6404 | .setMethod("getCellNetworkScanResults") |
| 6405 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6406 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6407 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6408 | .build()); |
| 6409 | switch (locationResult) { |
| 6410 | case DENIED_HARD: |
| 6411 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6412 | case DENIED_SOFT: |
| 6413 | return null; |
| 6414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6416 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | try { |
| 6418 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6419 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | } finally { |
| 6422 | Binder.restoreCallingIdentity(identity); |
| 6423 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6427 | * Get the call forwarding info, given the call forwarding reason. |
| 6428 | */ |
| 6429 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6430 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6431 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6432 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6433 | long identity = Binder.clearCallingIdentity(); |
| 6434 | try { |
| 6435 | if (DBG) { |
| 6436 | log("getCallForwarding: subId " + subId |
| 6437 | + " callForwardingReason" + callForwardingReason); |
| 6438 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6439 | |
| 6440 | Phone phone = getPhone(subId); |
| 6441 | if (phone == null) { |
| 6442 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6443 | callback.onError( |
| 6444 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6445 | } catch (RemoteException e) { |
| 6446 | // ignore |
| 6447 | } |
| 6448 | return; |
| 6449 | } |
| 6450 | |
| 6451 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6452 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6453 | @Override |
| 6454 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6455 | try { |
| 6456 | callback.onCallForwardingInfoAvailable(info); |
| 6457 | } catch (RemoteException e) { |
| 6458 | // ignore |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | @Override |
| 6463 | public void onError(int error) { |
| 6464 | try { |
| 6465 | callback.onError(error); |
| 6466 | } catch (RemoteException e) { |
| 6467 | // ignore |
| 6468 | } |
| 6469 | } |
| 6470 | }); |
| 6471 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
| 6474 | } |
| 6475 | } |
| 6476 | |
| 6477 | /** |
| 6478 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6479 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6480 | */ |
| 6481 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6482 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6483 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6484 | enforceModifyPermission(); |
| 6485 | long identity = Binder.clearCallingIdentity(); |
| 6486 | try { |
| 6487 | if (DBG) { |
| 6488 | log("setCallForwarding: subId " + subId |
| 6489 | + " callForwardingInfo" + callForwardingInfo); |
| 6490 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6491 | |
| 6492 | Phone phone = getPhone(subId); |
| 6493 | if (phone == null) { |
| 6494 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6495 | callback.accept( |
| 6496 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6497 | } catch (RemoteException e) { |
| 6498 | // ignore |
| 6499 | } |
| 6500 | return; |
| 6501 | } |
| 6502 | |
| 6503 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6504 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6505 | |
| 6506 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6513 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6514 | */ |
| 6515 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6516 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6517 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6518 | long identity = Binder.clearCallingIdentity(); |
| 6519 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6520 | Phone phone = getPhone(subId); |
| 6521 | if (phone == null) { |
| 6522 | try { |
| 6523 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6524 | } catch (RemoteException e) { |
| 6525 | // ignore |
| 6526 | } |
| 6527 | return; |
| 6528 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6529 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6530 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6531 | boolean requireUssd = c.getBoolean( |
| 6532 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6533 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6534 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6535 | if (requireUssd) { |
| 6536 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6537 | getSubscriptionCarrierId(subId)); |
| 6538 | String newUssdCommand = ""; |
| 6539 | try { |
| 6540 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6541 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6542 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6543 | } catch (NullPointerException e) { |
| 6544 | loge("Failed to generate USSD number" + e); |
| 6545 | } |
| 6546 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6547 | mMainThreadHandler, callback, carrierXmlParser, |
| 6548 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6549 | final String ussdCommand = newUssdCommand; |
| 6550 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6551 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6552 | }); |
| 6553 | } else { |
| 6554 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6555 | callback::accept); |
| 6556 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6557 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6558 | } finally { |
| 6559 | Binder.restoreCallingIdentity(identity); |
| 6560 | } |
| 6561 | } |
| 6562 | |
| 6563 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6564 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6565 | */ |
| 6566 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6567 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6568 | enforceModifyPermission(); |
| 6569 | long identity = Binder.clearCallingIdentity(); |
| 6570 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6571 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6572 | |
| 6573 | Phone phone = getPhone(subId); |
| 6574 | if (phone == null) { |
| 6575 | try { |
| 6576 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6577 | } catch (RemoteException e) { |
| 6578 | // ignore |
| 6579 | } |
| 6580 | return; |
| 6581 | } |
| 6582 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6583 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6584 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6585 | boolean requireUssd = c.getBoolean( |
| 6586 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6587 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6588 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6589 | if (requireUssd) { |
| 6590 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6591 | getSubscriptionCarrierId(subId)); |
| 6592 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6593 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6594 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6595 | String newUssdCommand = ""; |
| 6596 | try { |
| 6597 | newUssdCommand = carrierXmlParser.getFeature( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6598 | CarrierXmlParser.FEATURE_CALL_WAITING) |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6599 | .makeCommand(ssAction, null); |
| 6600 | } catch (NullPointerException e) { |
| 6601 | loge("Failed to generate USSD number" + e); |
| 6602 | } |
| 6603 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6604 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6605 | final String ussdCommand = newUssdCommand; |
| 6606 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6607 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6608 | }); |
| 6609 | } else { |
| 6610 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6611 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6612 | |
| 6613 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6614 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6615 | } finally { |
| 6616 | Binder.restoreCallingIdentity(identity); |
| 6617 | } |
| 6618 | } |
| 6619 | |
| 6620 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6621 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6622 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6623 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6624 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6625 | * location related information which will be sent if the caller already possess |
| 6626 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6627 | * @param request contains the radio access networks with bands/channels to scan |
| 6628 | * @param messenger callback messenger for scan results or errors |
| 6629 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6630 | * @return the id of the requested scan which can be used to stop the scan. |
| 6631 | */ |
| 6632 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6633 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6634 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6635 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6637 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6638 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6639 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6640 | if (!renounceFineLocationAccess) { |
| 6641 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6642 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6643 | .setCallingPackage(callingPackage) |
| 6644 | .setCallingFeatureId(callingFeatureId) |
| 6645 | .setCallingPid(Binder.getCallingPid()) |
| 6646 | .setCallingUid(Binder.getCallingUid()) |
| 6647 | .setMethod("requestNetworkScan") |
| 6648 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6649 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6650 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6651 | .build()); |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6652 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6653 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6654 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6655 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6656 | if (e != null) { |
| 6657 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6658 | throw e; |
| 6659 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6660 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6661 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6662 | } |
| 6663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6664 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6665 | int callingUid = Binder.getCallingUid(); |
| 6666 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6667 | final long identity = Binder.clearCallingIdentity(); |
| 6668 | try { |
| 6669 | return mNetworkScanRequestTracker.startNetworkScan( |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6670 | renounceFineLocationAccess, request, messenger, binder, |
| 6671 | getPhoneFromSubIdOrDefault(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6672 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6673 | } finally { |
| 6674 | Binder.restoreCallingIdentity(identity); |
| 6675 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6678 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6679 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6680 | boolean hasCarrierPriv; |
| 6681 | final long identity = Binder.clearCallingIdentity(); |
| 6682 | try { |
| 6683 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6684 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(identity); |
| 6687 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6688 | boolean hasNetworkScanPermission = |
| 6689 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6690 | == PERMISSION_GRANTED; |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6691 | |
| 6692 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6693 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6694 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6695 | } |
| 6696 | |
| 6697 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6698 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6699 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6700 | return new SecurityException("Specific channels must not be" |
| 6701 | + " scanned without location access."); |
| 6702 | } |
| 6703 | } |
| 6704 | } |
| 6705 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6706 | return null; |
| 6707 | } |
| 6708 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6709 | /** |
| 6710 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6711 | * |
| 6712 | * @param subId id of the subscription |
| 6713 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6714 | */ |
| 6715 | @Override |
| 6716 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6718 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6719 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6720 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6721 | final long identity = Binder.clearCallingIdentity(); |
| 6722 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6723 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | } finally { |
| 6725 | Binder.restoreCallingIdentity(identity); |
| 6726 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6727 | } |
| 6728 | |
| 6729 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6730 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6731 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6732 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6733 | */ |
| 6734 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6735 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6736 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6737 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6738 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6739 | |
| 6740 | final long identity = Binder.clearCallingIdentity(); |
| 6741 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6742 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6743 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6744 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6745 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6746 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6747 | } finally { |
| 6748 | Binder.restoreCallingIdentity(identity); |
| 6749 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6750 | } |
| 6751 | |
| 6752 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6753 | * Get the allowed network types for certain reason. |
| 6754 | * |
| 6755 | * @param subId the id of the subscription. |
| 6756 | * @param reason the reason the allowed network type change is taking place |
| 6757 | * @return the allowed network types. |
| 6758 | */ |
| 6759 | @Override |
| 6760 | public long getAllowedNetworkTypesForReason(int subId, |
| 6761 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6762 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6763 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6764 | final long identity = Binder.clearCallingIdentity(); |
| 6765 | try { |
Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6766 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6767 | } finally { |
| 6768 | Binder.restoreCallingIdentity(identity); |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6773 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6774 | * @param subId subscription id of the sim card |
| 6775 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6776 | * This can be passed following states |
| 6777 | * <ol> |
| 6778 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6779 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6780 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6781 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6782 | * </ol> |
| 6783 | * @return operation result. |
| 6784 | */ |
| 6785 | @Override |
| 6786 | public int setNrDualConnectivityState(int subId, |
| 6787 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6788 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6789 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6790 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6791 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6792 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6793 | } |
| 6794 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6796 | final long identity = Binder.clearCallingIdentity(); |
| 6797 | try { |
| 6798 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6799 | nrDualConnectivityState, subId, |
| 6800 | workSource); |
| 6801 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6802 | return result; |
| 6803 | } finally { |
| 6804 | Binder.restoreCallingIdentity(identity); |
| 6805 | } |
| 6806 | } |
| 6807 | |
| 6808 | /** |
| 6809 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6810 | * @return true if dual connectivity is enabled else false |
| 6811 | */ |
| 6812 | @Override |
| 6813 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6814 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6815 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6816 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6817 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6818 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6819 | return false; |
| 6820 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6821 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6822 | final long identity = Binder.clearCallingIdentity(); |
| 6823 | try { |
| 6824 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6825 | null, subId, workSource); |
| 6826 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6827 | return isEnabled; |
| 6828 | } finally { |
| 6829 | Binder.restoreCallingIdentity(identity); |
| 6830 | } |
| 6831 | } |
| 6832 | |
| 6833 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6834 | * Set the allowed network types of the device and |
| 6835 | * provide the reason triggering the allowed network change. |
| 6836 | * |
| 6837 | * @param subId the id of the subscription. |
| 6838 | * @param reason the reason the allowed network type change is taking place |
| 6839 | * @param allowedNetworkTypes the allowed network types. |
| 6840 | * @return true on success; false on any failure. |
| 6841 | */ |
| 6842 | @Override |
| 6843 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6844 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6845 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6847 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6848 | // If the caller only has carrier privileges, then they should not be able to override |
| 6849 | // any network types which were set for security reasons. |
| 6850 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6851 | != PERMISSION_GRANTED |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6852 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6853 | throw new SecurityException( |
| 6854 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6855 | + " reason " + reason); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6856 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6857 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6858 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6859 | return false; |
| 6860 | } |
| 6861 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6862 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6863 | return false; |
| 6864 | } |
| 6865 | |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6866 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " |
| 6867 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6868 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6869 | Phone phone = getPhone(subId); |
| 6870 | if (phone == null) { |
| 6871 | return false; |
| 6872 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6873 | |
Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6874 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { |
Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6875 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6876 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6877 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6878 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6879 | final long identity = Binder.clearCallingIdentity(); |
| 6880 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6881 | Boolean success = (Boolean) sendRequest( |
| 6882 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6883 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6884 | |
| 6885 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6886 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6887 | } finally { |
| 6888 | Binder.restoreCallingIdentity(identity); |
| 6889 | } |
| 6890 | } |
| 6891 | |
| 6892 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6893 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6894 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6895 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6896 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6897 | * @hide |
| 6898 | */ |
| 6899 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6900 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6901 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6902 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6903 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6905 | if (phone != null) { |
| 6906 | return phone.hasMatchedTetherApnSetting(); |
| 6907 | } else { |
| 6908 | return false; |
| 6909 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6910 | } finally { |
| 6911 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6912 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6913 | } |
| 6914 | |
| 6915 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6916 | * Get the user enabled state of Mobile Data. |
| 6917 | * |
| 6918 | * TODO: remove and use isUserDataEnabled. |
| 6919 | * This can't be removed now because some vendor codes |
| 6920 | * calls through ITelephony directly while they should |
| 6921 | * use TelephonyManager. |
| 6922 | * |
| 6923 | * @return true on enabled |
| 6924 | */ |
| 6925 | @Override |
| 6926 | public boolean getDataEnabled(int subId) { |
| 6927 | return isUserDataEnabled(subId); |
| 6928 | } |
| 6929 | |
| 6930 | /** |
| 6931 | * Get whether mobile data is enabled per user setting. |
| 6932 | * |
| 6933 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6934 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6935 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6936 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6937 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6938 | * |
| 6939 | * @return {@code true} if data is enabled else {@code false} |
| 6940 | */ |
| 6941 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6942 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6943 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6944 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6945 | try { |
| 6946 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6947 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6948 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6949 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6950 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6951 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6953 | mApp, subId, functionName); |
| 6954 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6955 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6956 | |
| 6957 | final long identity = Binder.clearCallingIdentity(); |
| 6958 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6959 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6960 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6961 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6962 | if (phone != null) { |
| 6963 | boolean retVal = phone.isUserDataEnabled(); |
| 6964 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6965 | return retVal; |
| 6966 | } else { |
| 6967 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6968 | return false; |
| 6969 | } |
| 6970 | } finally { |
| 6971 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6972 | } |
| 6973 | } |
| 6974 | |
| 6975 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6976 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6977 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6978 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6979 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6980 | * @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] | 6981 | */ |
| 6982 | @Override |
| 6983 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6984 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6985 | try { |
| 6986 | try { |
| 6987 | mApp.enforceCallingOrSelfPermission( |
| 6988 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6989 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6990 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6991 | try { |
| 6992 | mApp.enforceCallingOrSelfPermission( |
| 6993 | android.Manifest.permission.READ_PHONE_STATE, |
| 6994 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6995 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6996 | mApp.enforceCallingOrSelfPermission( |
| 6997 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6998 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6999 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7000 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7001 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | |
| 7004 | final long identity = Binder.clearCallingIdentity(); |
| 7005 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7006 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7007 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7008 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7009 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7010 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7011 | return retVal; |
| 7012 | } else { |
| 7013 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 7014 | return false; |
| 7015 | } |
| 7016 | } finally { |
| 7017 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7018 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7019 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7020 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7021 | /** |
| 7022 | * Check if data is enabled for a specific reason |
| 7023 | * @param subId Subscription index |
| 7024 | * @param reason the reason the data enable change is taking place |
| 7025 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 7026 | */ |
| 7027 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7028 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7029 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7030 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7031 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7032 | try { |
| 7033 | mApp.enforceCallingOrSelfPermission( |
| 7034 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7035 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7036 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7037 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 7038 | functionName); |
| 7039 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7040 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7041 | try { |
| 7042 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7043 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7044 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7045 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7046 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7047 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7048 | } |
| 7049 | |
| 7050 | |
| 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7053 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7054 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7055 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7056 | + " reason=" + reason); |
| 7057 | } |
| 7058 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7059 | if (phone != null) { |
| 7060 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7061 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7062 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7063 | return retVal; |
| 7064 | } else { |
| 7065 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7066 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7067 | + subId + " retVal=false"); |
| 7068 | } |
| 7069 | return false; |
| 7070 | } |
| 7071 | } finally { |
| 7072 | Binder.restoreCallingIdentity(identity); |
| 7073 | } |
| 7074 | } |
| 7075 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7076 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7077 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7078 | // No permission needed; this only lets the caller inspect their own status. |
| 7079 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7080 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7081 | |
| 7082 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7083 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7084 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7085 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 7086 | } |
| 7087 | |
| 7088 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 7089 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7090 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7091 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7092 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7093 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7094 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7095 | if (cpt == null) { |
| 7096 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7097 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7098 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7099 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7103 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7104 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7105 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7106 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7107 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7108 | Phone phone = getPhone(subId); |
| 7109 | if (phone == null) { |
| 7110 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 7111 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 7112 | } |
| 7113 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7114 | if (cpt == null) { |
| 7115 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7116 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 7117 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7118 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7119 | } |
| 7120 | |
| 7121 | @Override |
| 7122 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7123 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7124 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 7125 | } |
| 7126 | |
| 7127 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7128 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7129 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7130 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7131 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7132 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 7133 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7134 | if (phone == null) { |
| 7135 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7136 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7137 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7138 | if (cpt == null) { |
| 7139 | continue; |
| 7140 | } |
| 7141 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7142 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7143 | break; |
| 7144 | } |
| 7145 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7146 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7147 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7148 | |
| 7149 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7150 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7151 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7152 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7153 | if (phone == null) { |
| 7154 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7155 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7156 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7157 | if (cpt == null) { |
| 7158 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7159 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7160 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7161 | } |
| 7162 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7163 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7164 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7165 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7166 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 7167 | if (phone == null) { |
| 7168 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7169 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7170 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7171 | if (cpt == null) { |
| 7172 | return Collections.emptyList(); |
| 7173 | } |
| 7174 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7175 | } |
| 7176 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7177 | @Override |
| 7178 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7179 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7180 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7181 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7182 | try { |
| 7183 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 7184 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 7185 | } |
| 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7188 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7189 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7190 | } |
| 7191 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7192 | @Override |
| 7193 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 7194 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 7195 | |
| 7196 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7197 | if (phone == null) { |
| 7198 | return null; |
| 7199 | } |
| 7200 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7201 | if (cpt == null) { |
| 7202 | return null; |
| 7203 | } |
| 7204 | return cpt.getCarrierServicePackageName(); |
| 7205 | } |
| 7206 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7207 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7208 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7209 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7210 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7211 | return null; |
| 7212 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7213 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7214 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7215 | return null; |
| 7216 | } |
| 7217 | return iccId; |
| 7218 | } |
| 7219 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7220 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7221 | public void setCallComposerStatus(int subId, int status) { |
| 7222 | enforceModifyPermission(); |
| 7223 | |
| 7224 | final long identity = Binder.clearCallingIdentity(); |
| 7225 | try { |
| 7226 | Phone phone = getPhone(subId); |
| 7227 | if (phone != null) { |
| 7228 | Phone defaultPhone = phone.getImsPhone(); |
| 7229 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7230 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7231 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7232 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7233 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7234 | } |
| 7235 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7236 | } catch (ImsException e) { |
| 7237 | throw new ServiceSpecificException(e.getCode()); |
| 7238 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7239 | Binder.restoreCallingIdentity(identity); |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | @Override |
| 7244 | public int getCallComposerStatus(int subId) { |
| 7245 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7246 | |
| 7247 | final long identity = Binder.clearCallingIdentity(); |
| 7248 | try { |
| 7249 | Phone phone = getPhone(subId); |
| 7250 | if (phone != null) { |
| 7251 | Phone defaultPhone = phone.getImsPhone(); |
| 7252 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7253 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7254 | return imsPhone.getCallComposerStatus(); |
| 7255 | } |
| 7256 | } |
| 7257 | } finally { |
| 7258 | Binder.restoreCallingIdentity(identity); |
| 7259 | } |
| 7260 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7261 | } |
| 7262 | |
| 7263 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7264 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7265 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7266 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7267 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | final String iccId = getIccId(subId); |
| 7272 | final Phone phone = getPhone(subId); |
| 7273 | if (phone == null) { |
| 7274 | return false; |
| 7275 | } |
| 7276 | final String subscriberId = phone.getSubscriberId(); |
| 7277 | |
| 7278 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7279 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7280 | + subscriberId + " to " + number); |
| 7281 | } |
| 7282 | |
| 7283 | if (TextUtils.isEmpty(iccId)) { |
| 7284 | return false; |
| 7285 | } |
| 7286 | |
| 7287 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7288 | |
| 7289 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7290 | if (alphaTag == null) { |
| 7291 | editor.remove(alphaTagPrefKey); |
| 7292 | } else { |
| 7293 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7294 | } |
| 7295 | |
| 7296 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7297 | // track all merged IMSIs based on line number |
| 7298 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7299 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7300 | if (number == null) { |
| 7301 | editor.remove(numberPrefKey); |
| 7302 | editor.remove(subscriberPrefKey); |
| 7303 | } else { |
| 7304 | editor.putString(numberPrefKey, number); |
| 7305 | editor.putString(subscriberPrefKey, subscriberId); |
| 7306 | } |
| 7307 | |
| 7308 | editor.commit(); |
| 7309 | return true; |
| 7310 | } finally { |
| 7311 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7312 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7313 | } |
| 7314 | |
| 7315 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7316 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7317 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7318 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7319 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7320 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7321 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7322 | return null; |
| 7323 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7324 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7325 | final long identity = Binder.clearCallingIdentity(); |
| 7326 | try { |
| 7327 | String iccId = getIccId(subId); |
| 7328 | if (iccId != null) { |
| 7329 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7330 | if (DBG_MERGE) { |
| 7331 | log("getLine1NumberForDisplay returning " |
| 7332 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7333 | } |
| 7334 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7335 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7336 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7337 | return null; |
| 7338 | } finally { |
| 7339 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7340 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7341 | } |
| 7342 | |
| 7343 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7344 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7345 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7346 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7347 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7348 | return null; |
| 7349 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7351 | final long identity = Binder.clearCallingIdentity(); |
| 7352 | try { |
| 7353 | String iccId = getIccId(subId); |
| 7354 | if (iccId != null) { |
| 7355 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7356 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7357 | } |
| 7358 | return null; |
| 7359 | } finally { |
| 7360 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7361 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7362 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7363 | |
| 7364 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7365 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7366 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7367 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7368 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7369 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7370 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7371 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7372 | return null; |
| 7373 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7374 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7375 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7376 | // the process, where TelephonyManager was instantiated. |
| 7377 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7378 | final long identity = Binder.clearCallingIdentity(); |
| 7379 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7380 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7381 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7382 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7383 | |
| 7384 | // Figure out what subscribers are currently active |
| 7385 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7386 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7387 | // Only consider subs which match the current subId |
| 7388 | // This logic can be simplified. See b/131189269 for progress. |
| 7389 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7390 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7391 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | |
| 7393 | // First pass, find a number override for an active subscriber |
| 7394 | String mergeNumber = null; |
| 7395 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7396 | for (String key : prefs.keySet()) { |
| 7397 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7398 | final String subscriberId = (String) prefs.get(key); |
| 7399 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7400 | final String iccId = key.substring( |
| 7401 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7402 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7403 | mergeNumber = (String) prefs.get(numberKey); |
| 7404 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7405 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | + " for active subscriber " + subscriberId); |
| 7407 | } |
| 7408 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7409 | break; |
| 7410 | } |
| 7411 | } |
| 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | // Shortcut when no active merged subscribers |
| 7416 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7417 | return null; |
| 7418 | } |
| 7419 | |
| 7420 | // Second pass, find all subscribers under that line override |
| 7421 | final ArraySet<String> result = new ArraySet<>(); |
| 7422 | for (String key : prefs.keySet()) { |
| 7423 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7424 | final String number = (String) prefs.get(key); |
| 7425 | if (mergeNumber.equals(number)) { |
| 7426 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7427 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7428 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7429 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7430 | result.add(subscriberId); |
| 7431 | } |
| 7432 | } |
| 7433 | } |
| 7434 | } |
| 7435 | |
| 7436 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7437 | Arrays.sort(resultArray); |
| 7438 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7439 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7441 | } |
| 7442 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7445 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7446 | } |
| 7447 | |
| 7448 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7449 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7450 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7451 | |
| 7452 | final long identity = Binder.clearCallingIdentity(); |
| 7453 | try { |
| 7454 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7455 | TelephonyManager.class); |
| 7456 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7457 | if (subscriberId == null) { |
| 7458 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7459 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7460 | + subId); |
| 7461 | } |
| 7462 | return null; |
| 7463 | } |
| 7464 | |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7465 | ParcelUuid groupUuid; |
| 7466 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7467 | final SubscriptionInfo info = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7468 | .getSubscriptionInfo(subId); |
| 7469 | groupUuid = info.getGroupUuid(); |
| 7470 | } else { |
| 7471 | final SubscriptionInfo info = mSubscriptionController |
| 7472 | .getSubscriptionInfo(subId); |
| 7473 | groupUuid = info.getGroupUuid(); |
| 7474 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7475 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7476 | if (groupUuid == null) { |
| 7477 | return new String[]{subscriberId}; |
| 7478 | } |
| 7479 | |
| 7480 | // Get all subscriberIds from the group. |
| 7481 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7482 | List<SubscriptionInfo> groupInfos; |
| 7483 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7484 | groupInfos = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7485 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7486 | mApp.getAttributionTag()); |
| 7487 | } else { |
| 7488 | groupInfos = mSubscriptionController |
| 7489 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 7490 | mApp.getAttributionTag()); |
| 7491 | } |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7492 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7493 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7494 | if (subscriberId != null) { |
| 7495 | mergedSubscriberIds.add(subscriberId); |
| 7496 | } |
| 7497 | } |
| 7498 | |
| 7499 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7500 | } finally { |
| 7501 | Binder.restoreCallingIdentity(identity); |
| 7502 | |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7507 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7508 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7509 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7510 | |
| 7511 | final long identity = Binder.clearCallingIdentity(); |
| 7512 | try { |
| 7513 | final Phone phone = getPhone(subId); |
| 7514 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7515 | } finally { |
| 7516 | Binder.restoreCallingIdentity(identity); |
| 7517 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7518 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7519 | |
| 7520 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7521 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7522 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7523 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7524 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7525 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | |
| 7527 | final long identity = Binder.clearCallingIdentity(); |
| 7528 | try { |
| 7529 | final Phone phone = getPhone(subId); |
| 7530 | if (phone == null) { |
| 7531 | return false; |
| 7532 | } |
| 7533 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7534 | cdmaNonRoamingList); |
| 7535 | } finally { |
| 7536 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7537 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7541 | @Deprecated |
| 7542 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7543 | enforceModifyPermission(); |
| 7544 | |
| 7545 | int returnValue = 0; |
| 7546 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7547 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7548 | if(result.exception == null) { |
| 7549 | if (result.result != null) { |
| 7550 | byte[] responseData = (byte[])(result.result); |
| 7551 | if(responseData.length > oemResp.length) { |
| 7552 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7553 | responseData.length + "bytes. Buffer Size is " + |
| 7554 | oemResp.length + "bytes."); |
| 7555 | } |
| 7556 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7557 | returnValue = responseData.length; |
| 7558 | } |
| 7559 | } else { |
| 7560 | CommandException ex = (CommandException) result.exception; |
| 7561 | returnValue = ex.getCommandError().ordinal(); |
| 7562 | if(returnValue > 0) returnValue *= -1; |
| 7563 | } |
| 7564 | } catch (RuntimeException e) { |
| 7565 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7566 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7567 | if(returnValue > 0) returnValue *= -1; |
| 7568 | } |
| 7569 | |
| 7570 | return returnValue; |
| 7571 | } |
| 7572 | |
| 7573 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7574 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7575 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7576 | Phone phone = PhoneFactory.getPhone(phoneId); |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7577 | if (phone == null) { |
| 7578 | return raf; |
| 7579 | } |
| 7580 | |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7581 | try { |
| 7582 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7583 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7584 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7585 | } catch (SecurityException e) { |
| 7586 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7587 | throw e; |
| 7588 | } |
Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7589 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | final long identity = Binder.clearCallingIdentity(); |
| 7591 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7592 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | } finally { |
| 7594 | Binder.restoreCallingIdentity(identity); |
| 7595 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7596 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7597 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7598 | |
| 7599 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7600 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7601 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7602 | try { |
| 7603 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7604 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7605 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7606 | } |
| 7607 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7608 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7609 | } |
| 7610 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7611 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7612 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7613 | throw new SecurityException("App must be the dialer role holder to" |
| 7614 | + " upload a call composer pic"); |
| 7615 | } |
| 7616 | |
| 7617 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7618 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7619 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7620 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7621 | boolean readUntilEnd = false; |
| 7622 | int totalBytesRead = 0; |
| 7623 | byte[] buffer = new byte[16 * 1024]; |
| 7624 | while (true) { |
| 7625 | int numRead; |
| 7626 | try { |
| 7627 | numRead = input.read(buffer); |
| 7628 | } catch (IOException e) { |
| 7629 | try { |
| 7630 | fd.checkError(); |
| 7631 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7632 | null); |
| 7633 | } catch (IOException e1) { |
| 7634 | // This means that the other side closed explicitly with an error. If this |
| 7635 | // happens, log and ignore. |
| 7636 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7637 | } |
| 7638 | break; |
| 7639 | } |
| 7640 | if (numRead == -1) { |
| 7641 | readUntilEnd = true; |
| 7642 | break; |
| 7643 | } |
| 7644 | totalBytesRead += numRead; |
| 7645 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7646 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7647 | try { |
| 7648 | input.close(); |
| 7649 | } catch (IOException e) { |
| 7650 | // ignore |
| 7651 | } |
| 7652 | break; |
| 7653 | } |
| 7654 | output.write(buffer, 0, numRead); |
| 7655 | } |
| 7656 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7657 | // close is above, where the picture size is too big. |
| 7658 | |
| 7659 | try { |
| 7660 | fd.checkError(); |
| 7661 | } catch (IOException e) { |
| 7662 | loge("Remote end for call composer closed with an error: " + e); |
| 7663 | return; |
| 7664 | } |
| 7665 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7666 | if (!readUntilEnd) { |
| 7667 | loge("Did not finish reading entire image; aborting"); |
| 7668 | return; |
| 7669 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7670 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7671 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7672 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7673 | new CallComposerPictureTransfer.Factory() {}, |
| 7674 | imageData, |
| 7675 | (result) -> { |
| 7676 | if (result.first != null) { |
| 7677 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7678 | Bundle outputResult = new Bundle(); |
| 7679 | outputResult.putParcelable( |
| 7680 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7681 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7682 | outputResult); |
| 7683 | } else { |
| 7684 | callback.send(result.second, null); |
| 7685 | } |
| 7686 | } |
| 7687 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7688 | }); |
| 7689 | } |
| 7690 | |
| 7691 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7692 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7693 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7694 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7695 | |
| 7696 | final long identity = Binder.clearCallingIdentity(); |
| 7697 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7698 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7699 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | } finally { |
| 7701 | Binder.restoreCallingIdentity(identity); |
| 7702 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7703 | } |
| 7704 | |
| 7705 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7706 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7707 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7708 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7709 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7710 | return false; |
| 7711 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7713 | final long identity = Binder.clearCallingIdentity(); |
| 7714 | try { |
| 7715 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7716 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7717 | // In the long run, we may instead need to check if there exists a connection service |
| 7718 | // which can support video calling. |
| 7719 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7720 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7721 | return imsManager.isVtEnabledByPlatform() |
| 7722 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7723 | && imsManager.isVtEnabledByUser(); |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
| 7726 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7727 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7728 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7729 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7730 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7731 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7733 | mApp, subId, callingPackage, callingFeatureId, |
| 7734 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | return false; |
| 7736 | } |
| 7737 | |
| 7738 | final long identity = Binder.clearCallingIdentity(); |
| 7739 | try { |
| 7740 | CarrierConfigManager configManager = |
| 7741 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7742 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7743 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7744 | } finally { |
| 7745 | Binder.restoreCallingIdentity(identity); |
| 7746 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7750 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7752 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7753 | return false; |
| 7754 | } |
| 7755 | |
| 7756 | final long identity = Binder.clearCallingIdentity(); |
| 7757 | try { |
| 7758 | CarrierConfigManager configManager = |
| 7759 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7760 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7761 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7762 | } finally { |
| 7763 | Binder.restoreCallingIdentity(identity); |
| 7764 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7765 | } |
| 7766 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7767 | @Override |
| 7768 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7769 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7770 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7771 | } |
| 7772 | |
| 7773 | @Override |
| 7774 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7775 | final long identity = Binder.clearCallingIdentity(); |
| 7776 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7777 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7778 | } finally { |
| 7779 | Binder.restoreCallingIdentity(identity); |
| 7780 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7781 | } |
| 7782 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7783 | /** |
| 7784 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7785 | * support for the feature and device firmware support. |
| 7786 | * |
| 7787 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7788 | */ |
| 7789 | @Override |
| 7790 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7791 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7792 | final Phone phone = getPhone(subscriptionId); |
| 7793 | if (phone == null) { |
| 7794 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7795 | return false; |
| 7796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7798 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7800 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7801 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | return isCarrierSupported && isDeviceSupported; |
| 7803 | } finally { |
| 7804 | Binder.restoreCallingIdentity(identity); |
| 7805 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7806 | } |
| 7807 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7808 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7809 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7810 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7811 | * 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] | 7812 | */ |
| 7813 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7816 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7817 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7818 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7819 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7820 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7821 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
| 7824 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7825 | } |
| 7826 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7827 | @Deprecated |
| 7828 | @Override |
| 7829 | public String getDeviceId(String callingPackage) { |
| 7830 | return getDeviceIdWithFeature(callingPackage, null); |
| 7831 | } |
| 7832 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7833 | /** |
| 7834 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7835 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7836 | * |
| 7837 | * <p>Requires Permission: |
| 7838 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7839 | */ |
| 7840 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7841 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7842 | try { |
| 7843 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7844 | } catch (SecurityException se) { |
| 7845 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7846 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7847 | + Binder.getCallingUid()); |
| 7848 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7849 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7850 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7851 | return null; |
| 7852 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7853 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7854 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7855 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7856 | return null; |
| 7857 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7858 | |
| 7859 | final long identity = Binder.clearCallingIdentity(); |
| 7860 | try { |
| 7861 | return phone.getDeviceId(); |
| 7862 | } finally { |
| 7863 | Binder.restoreCallingIdentity(identity); |
| 7864 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7865 | } |
| 7866 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7867 | /** |
| 7868 | * {@hide} |
| 7869 | * Returns the IMS Registration Status on a particular subid |
| 7870 | * |
| 7871 | * @param subId |
| 7872 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7873 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7874 | Phone phone = getPhone(subId); |
| 7875 | if (phone != null) { |
| 7876 | return phone.isImsRegistered(); |
| 7877 | } else { |
| 7878 | return false; |
| 7879 | } |
| 7880 | } |
| 7881 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7882 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7883 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7884 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7885 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7886 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7887 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7888 | } |
| 7889 | final long identity = Binder.clearCallingIdentity(); |
| 7890 | try { |
| 7891 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7892 | } finally { |
| 7893 | Binder.restoreCallingIdentity(identity); |
| 7894 | } |
| 7895 | } |
| 7896 | |
| 7897 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7898 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7899 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7900 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7901 | mApp, |
| 7902 | subscriptionId, |
| 7903 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " |
| 7904 | + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
| 7907 | Phone phone = getPhone(subscriptionId); |
| 7908 | if (phone == null) { |
| 7909 | return null; |
| 7910 | } |
| 7911 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7912 | } finally { |
| 7913 | Binder.restoreCallingIdentity(identity); |
| 7914 | } |
| 7915 | } |
| 7916 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7917 | /** |
| 7918 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7919 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7920 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7921 | final long identity = Binder.clearCallingIdentity(); |
| 7922 | try { |
| 7923 | Phone phone = getPhone(subId); |
| 7924 | if (phone != null) { |
| 7925 | return phone.isWifiCallingEnabled(); |
| 7926 | } else { |
| 7927 | return false; |
| 7928 | } |
| 7929 | } finally { |
| 7930 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7931 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7932 | } |
| 7933 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7934 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7935 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7936 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7937 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | try { |
| 7940 | Phone phone = getPhone(subId); |
| 7941 | if (phone != null) { |
| 7942 | return phone.isVideoEnabled(); |
| 7943 | } else { |
| 7944 | return false; |
| 7945 | } |
| 7946 | } finally { |
| 7947 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7948 | } |
| 7949 | } |
| 7950 | |
| 7951 | /** |
| 7952 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7953 | * defined in {@link ImsRegistrationImplBase}. |
| 7954 | */ |
| 7955 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7956 | final long identity = Binder.clearCallingIdentity(); |
| 7957 | try { |
| 7958 | Phone phone = getPhone(subId); |
| 7959 | if (phone != null) { |
| 7960 | return phone.getImsRegistrationTech(); |
| 7961 | } else { |
| 7962 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7963 | } |
| 7964 | } finally { |
| 7965 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7966 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7967 | } |
| 7968 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7969 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7970 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7971 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7972 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7973 | return; |
| 7974 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7975 | Phone defaultPhone = getDefaultPhone(); |
| 7976 | if (defaultPhone != null) { |
| 7977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7978 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7979 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7980 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7981 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7982 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7983 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7984 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7985 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7986 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7987 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7988 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7989 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7990 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7991 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7992 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7993 | // There has been issues when Sms raw table somehow stores orphan |
| 7994 | // fragments. They lead to garbled message when new fragments come |
| 7995 | // in and combined with those stale ones. In case this happens again, |
| 7996 | // user can reset all network settings which will clean up this table. |
| 7997 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7998 | // Clean up IMS settings as well here. |
| 7999 | int slotId = getSlotIndex(subId); |
| 8000 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 8001 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 8002 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8003 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8004 | if (defaultPhone == null) { |
| 8005 | return; |
| 8006 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8007 | // Erase modem config if erase modem on network setting is enabled. |
| 8008 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 8009 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 8010 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8011 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8012 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8013 | |
| 8014 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8015 | } finally { |
| 8016 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8017 | } |
| 8018 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8019 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8020 | @VisibleForTesting |
| 8021 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 8022 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 8023 | return; |
| 8024 | } |
| 8025 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 8026 | RILConstants.PREFERRED_NETWORK_MODE); |
| 8027 | SubscriptionManager.setSubscriptionProperty(subId, |
| 8028 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 8029 | "user=" + defaultNetworkType); |
| 8030 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 8031 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 8032 | defaultNetworkType, null); |
| 8033 | } |
| 8034 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8035 | private void cleanUpSmsRawTable(Context context) { |
| 8036 | ContentResolver resolver = context.getContentResolver(); |
| 8037 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 8038 | resolver.delete(uri, null, null); |
| 8039 | } |
| 8040 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8041 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8042 | public String getSimLocaleForSubscriber(int subId) { |
| 8043 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 8044 | final Phone phone = getPhone(subId); |
| 8045 | if (phone == null) { |
| 8046 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8047 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | final long identity = Binder.clearCallingIdentity(); |
| 8050 | try { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8051 | SubscriptionInfo info; |
| 8052 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8053 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8054 | phone.getContext().getOpPackageName(), |
| 8055 | phone.getContext().getAttributionTag()); |
| 8056 | if (info == null) { |
| 8057 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8058 | return null; |
| 8059 | } |
| 8060 | } else { |
| 8061 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
| 8062 | phone.getContext().getOpPackageName(), |
| 8063 | phone.getContext().getAttributionTag()); |
| 8064 | if (info == null) { |
| 8065 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 8066 | return null; |
| 8067 | } |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8069 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 8070 | // preferences (EF-PL and EF-LI)... |
| 8071 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8072 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8073 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 8074 | if (localeFromDefaultSim != null) { |
| 8075 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 8076 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 8077 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8078 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8079 | } else { |
| 8080 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8081 | } |
| 8082 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8083 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 8085 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 8086 | // the SIM and carrier preferences does not include a country we add the country |
| 8087 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8088 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8089 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8090 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8091 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8092 | } |
| 8093 | |
| 8094 | if (DBG) log("No locale found - returning null"); |
| 8095 | return null; |
| 8096 | } finally { |
| 8097 | Binder.restoreCallingIdentity(identity); |
| 8098 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8099 | } |
| 8100 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8101 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8102 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8103 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8104 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8105 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8106 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 8107 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8108 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 8109 | return localeTag; |
| 8110 | } |
| 8111 | } |
| 8112 | return inputLocale.toLanguageTag(); |
| 8113 | } |
| 8114 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8115 | /** |
| 8116 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 8117 | */ |
| 8118 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8119 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8120 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8121 | mApp.getOpPackageName(), mApp.getAttributionTag()); |
| 8122 | } |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8123 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8124 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8125 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8126 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8127 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 8128 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8129 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8130 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8131 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 8132 | * representing the state of the modem. |
| 8133 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8134 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 8135 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8136 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8137 | */ |
| 8138 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8139 | public void requestModemActivityInfo(ResultReceiver result) { |
| 8140 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8141 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8142 | |
| 8143 | final long identity = Binder.clearCallingIdentity(); |
| 8144 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8145 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8146 | } finally { |
| 8147 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8148 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8149 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8150 | |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8151 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8152 | // less than total activity duration. |
| 8153 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 8154 | if (info == null) { |
| 8155 | return false; |
| 8156 | } |
| 8157 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8158 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8159 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; |
| 8160 | |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8161 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 8162 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8163 | return (info.isValid() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8164 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 8165 | && (info.getIdleTimeMillis() <= activityDurationMs)); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8166 | } |
| 8167 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8168 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 8169 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8170 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 8171 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 8172 | |
| 8173 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8174 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8175 | } |
| 8176 | |
| 8177 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 8178 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8179 | rat, |
| 8180 | freq, |
| 8181 | info.getReceiveTimeMillis(rat, freq) |
| 8182 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 8183 | } |
| 8184 | |
| 8185 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 8186 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 8187 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 8188 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 8189 | |
| 8190 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 8191 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 8192 | } |
| 8193 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 8194 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 8195 | rat, |
| 8196 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 8197 | } |
| 8198 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8199 | /** |
| 8200 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 8201 | * @param info recent ModemActivityInfo |
| 8202 | */ |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8203 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 8204 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8205 | ActivityStatsTechSpecificInfo deltaSpecificInfo; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8206 | boolean matched; |
| 8207 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 8208 | matched = false; |
| 8209 | int rat = info.getSpecificInfoRat(i); |
| 8210 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 8211 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 8212 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 8213 | //if it already exists |
| 8214 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 8215 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 8216 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 8217 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 8218 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 8219 | updateLastModemActivityInfo(info, rat, freq); |
| 8220 | matched = true; |
| 8221 | } |
| 8222 | } else { |
| 8223 | updateLastModemActivityInfo(info, rat); |
| 8224 | matched = true; |
| 8225 | } |
| 8226 | } |
| 8227 | } |
| 8228 | |
| 8229 | if (!matched) { |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8230 | deltaSpecificInfo = |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8231 | new ActivityStatsTechSpecificInfo( |
| 8232 | rat, |
| 8233 | freq, |
| 8234 | info.getTransmitTimeMillis(rat, freq), |
| 8235 | (int) info.getReceiveTimeMillis(rat, freq)); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8236 | merged.addAll(Arrays.asList(deltaSpecificInfo)); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8237 | } |
| 8238 | } |
| 8239 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8240 | mLastModemActivitySpecificInfo = |
| 8241 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8242 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8243 | |
| 8244 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8245 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8246 | info.getSleepTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8247 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8248 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8249 | info.getIdleTimeMillis() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8250 | + mLastModemActivityInfo.getIdleTimeMillis()); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8251 | |
| 8252 | mLastModemActivityInfo = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8253 | new ModemActivityInfo( |
| 8254 | mLastModemActivityInfo.getTimestampMillis(), |
| 8255 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 8256 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 8257 | mLastModemActivitySpecificInfo); |
Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8258 | } |
| 8259 | |
| 8260 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( |
| 8261 | ActivityStatsTechSpecificInfo[] info) { |
| 8262 | int infoSize = info.length; |
| 8263 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; |
| 8264 | for (int i = 0; i < infoSize; i++) { |
| 8265 | ret[i] = new ActivityStatsTechSpecificInfo( |
| 8266 | info[i].getRat(), info[i].getFrequencyRange(), |
| 8267 | info[i].getTransmitTimeMillis(), |
| 8268 | (int) info[i].getReceiveTimeMillis()); |
| 8269 | } |
| 8270 | return ret; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8271 | } |
| 8272 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8273 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8274 | * Returns the service state information on specified subscription. |
| 8275 | */ |
| 8276 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8277 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8278 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8279 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8280 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8281 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8282 | return null; |
| 8283 | } |
| 8284 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8285 | boolean hasFinePermission = false; |
| 8286 | boolean hasCoarsePermission = false; |
| 8287 | if (!renounceFineLocationAccess) { |
| 8288 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8289 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8290 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8291 | .setCallingPackage(callingPackage) |
| 8292 | .setCallingFeatureId(callingFeatureId) |
| 8293 | .setCallingPid(Binder.getCallingPid()) |
| 8294 | .setCallingUid(Binder.getCallingUid()) |
| 8295 | .setMethod("getServiceStateForSubscriber") |
| 8296 | .setLogAsInfo(true) |
| 8297 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8298 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8299 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8300 | .build()); |
| 8301 | hasFinePermission = |
| 8302 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8303 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8304 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8305 | if (!renounceCoarseLocationAccess) { |
| 8306 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8307 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8308 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8309 | .setCallingPackage(callingPackage) |
| 8310 | .setCallingFeatureId(callingFeatureId) |
| 8311 | .setCallingPid(Binder.getCallingPid()) |
| 8312 | .setCallingUid(Binder.getCallingUid()) |
| 8313 | .setMethod("getServiceStateForSubscriber") |
| 8314 | .setLogAsInfo(true) |
| 8315 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8316 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8317 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8318 | .build()); |
| 8319 | hasCoarsePermission = |
| 8320 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8321 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8322 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8323 | final Phone phone = getPhone(subId); |
| 8324 | if (phone == null) { |
| 8325 | return null; |
| 8326 | } |
| 8327 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8328 | final long identity = Binder.clearCallingIdentity(); |
| 8329 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8330 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8331 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8333 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8334 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8335 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8336 | .getSubscriptionInfoInternal(subId); |
| 8337 | if (subInfo == null || !subInfo.isActive()) { |
| 8338 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8339 | + "subId=" + subId); |
| 8340 | return null; |
| 8341 | } |
| 8342 | } else { |
| 8343 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, |
| 8344 | callingFeatureId)) { |
| 8345 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " |
| 8346 | + "subId=" + subId); |
| 8347 | return null; |
| 8348 | } |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8349 | } |
| 8350 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8351 | ServiceState ss = phone.getServiceState(); |
| 8352 | |
| 8353 | // Scrub out the location info in ServiceState depending on what level of access |
| 8354 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8355 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8356 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8357 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8358 | } finally { |
| 8359 | Binder.restoreCallingIdentity(identity); |
| 8360 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8361 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8362 | |
| 8363 | /** |
| 8364 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8365 | * |
| 8366 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8367 | * voicemail ringtone. |
| 8368 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8369 | * PhoneAccount. |
| 8370 | */ |
| 8371 | @Override |
| 8372 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8373 | final long identity = Binder.clearCallingIdentity(); |
| 8374 | try { |
| 8375 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8376 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8377 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8378 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8380 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8381 | } finally { |
| 8382 | Binder.restoreCallingIdentity(identity); |
| 8383 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8384 | } |
| 8385 | |
| 8386 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8387 | * Sets the per-account voicemail ringtone. |
| 8388 | * |
| 8389 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8390 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8391 | * |
| 8392 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8393 | * voicemail ringtone. |
| 8394 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8395 | * PhoneAccount. |
| 8396 | */ |
| 8397 | @Override |
| 8398 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8399 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8400 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8401 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8402 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8403 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8404 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8405 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8406 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8407 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
| 8411 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8412 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8413 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8414 | } |
| 8415 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8416 | } finally { |
| 8417 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8418 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8419 | } |
| 8420 | |
| 8421 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8422 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8423 | * |
| 8424 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8425 | * voicemail vibration setting. |
| 8426 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8427 | */ |
| 8428 | @Override |
| 8429 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | final long identity = Binder.clearCallingIdentity(); |
| 8431 | try { |
| 8432 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8433 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8434 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8437 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
| 8440 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8441 | } |
| 8442 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8443 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8444 | * Sets the per-account voicemail vibration. |
| 8445 | * |
| 8446 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8447 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8448 | * |
| 8449 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8450 | * voicemail vibration setting. |
| 8451 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8452 | * specific PhoneAccount. |
| 8453 | */ |
| 8454 | @Override |
| 8455 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8456 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8457 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8459 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8460 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8462 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8463 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8464 | } |
| 8465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8466 | final long identity = Binder.clearCallingIdentity(); |
| 8467 | try { |
| 8468 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8469 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8470 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8471 | } |
| 8472 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8473 | } finally { |
| 8474 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8475 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8476 | } |
| 8477 | |
| 8478 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8479 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8480 | * |
| 8481 | * @throws SecurityException if the caller does not have the required permission |
| 8482 | */ |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8483 | @VisibleForTesting |
| 8484 | public void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8485 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8486 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8487 | } |
| 8488 | |
| 8489 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8490 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8491 | * permission. |
| 8492 | * |
| 8493 | * @throws SecurityException if the caller does not have the required permission |
| 8494 | */ |
| 8495 | private void enforceSendSmsPermission() { |
| 8496 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8497 | } |
| 8498 | |
| 8499 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8500 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8501 | * users permission. |
| 8502 | * |
| 8503 | * @throws SecurityException if the caller does not have the required permission |
| 8504 | */ |
| 8505 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8506 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8507 | } |
| 8508 | |
| 8509 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8510 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8511 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8512 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8513 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8514 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8515 | final long identity = Binder.clearCallingIdentity(); |
| 8516 | try { |
| 8517 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8518 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8519 | if (componentName == null) { |
| 8520 | throw new SecurityException( |
| 8521 | "Caller not current active visual voicemail package[null]"); |
| 8522 | } |
| 8523 | String vvmPackage = componentName.getPackageName(); |
| 8524 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8525 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8526 | } |
| 8527 | } finally { |
| 8528 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8529 | } |
| 8530 | } |
| 8531 | |
| 8532 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8533 | * Return the application ID for the app type. |
| 8534 | * |
| 8535 | * @param subId the subscription ID that this request applies to. |
| 8536 | * @param appType the uicc app type. |
| 8537 | * @return Application ID for specificied app type, or null if no uicc. |
| 8538 | */ |
| 8539 | @Override |
| 8540 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8541 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8542 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8543 | |
| 8544 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8545 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8546 | if (phone == null) { |
| 8547 | return null; |
| 8548 | } |
| 8549 | String aid = null; |
| 8550 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8551 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8552 | .getApplicationByType(appType).getAid(); |
| 8553 | } catch (Exception e) { |
| 8554 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8555 | } |
| 8556 | return aid; |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8559 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8560 | } |
| 8561 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8562 | /** |
| 8563 | * Return the Electronic Serial Number. |
| 8564 | * |
| 8565 | * @param subId the subscription ID that this request applies to. |
| 8566 | * @return ESN or null if error. |
| 8567 | */ |
| 8568 | @Override |
| 8569 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8570 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8571 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8572 | |
| 8573 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8574 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8575 | if (phone == null) { |
| 8576 | return null; |
| 8577 | } |
| 8578 | String esn = null; |
| 8579 | try { |
| 8580 | esn = phone.getEsn(); |
| 8581 | } catch (Exception e) { |
| 8582 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8583 | } |
| 8584 | return esn; |
| 8585 | } finally { |
| 8586 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8587 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8588 | } |
| 8589 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8590 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8591 | * Return the Preferred Roaming List Version. |
| 8592 | * |
| 8593 | * @param subId the subscription ID that this request applies to. |
| 8594 | * @return PRLVersion or null if error. |
| 8595 | */ |
| 8596 | @Override |
| 8597 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8598 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8599 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8600 | |
| 8601 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8602 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8603 | if (phone == null) { |
| 8604 | return null; |
| 8605 | } |
| 8606 | String cdmaPrlVersion = null; |
| 8607 | try { |
| 8608 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8609 | } catch (Exception e) { |
| 8610 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8611 | } |
| 8612 | return cdmaPrlVersion; |
| 8613 | } finally { |
| 8614 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8615 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8616 | } |
| 8617 | |
| 8618 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8619 | * Get snapshot of Telephony histograms |
| 8620 | * @return List of Telephony histograms |
| 8621 | * @hide |
| 8622 | */ |
| 8623 | @Override |
| 8624 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8626 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8627 | |
| 8628 | final long identity = Binder.clearCallingIdentity(); |
| 8629 | try { |
| 8630 | return RIL.getTelephonyRILTimingHistograms(); |
| 8631 | } finally { |
| 8632 | Binder.restoreCallingIdentity(identity); |
| 8633 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8634 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8635 | |
| 8636 | /** |
| 8637 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8638 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8639 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8640 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8641 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8642 | * @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] | 8643 | */ |
| 8644 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8645 | @TelephonyManager.SetCarrierRestrictionResult |
| 8646 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8647 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8648 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8649 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8650 | if (carrierRestrictionRules == null) { |
| 8651 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8652 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8653 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8654 | final long identity = Binder.clearCallingIdentity(); |
| 8655 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8656 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8657 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8658 | } finally { |
| 8659 | Binder.restoreCallingIdentity(identity); |
| 8660 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8661 | } |
| 8662 | |
| 8663 | /** |
| 8664 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8665 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8666 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8667 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8668 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8669 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8670 | */ |
| 8671 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8672 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8673 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8674 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8675 | |
| 8676 | final long identity = Binder.clearCallingIdentity(); |
| 8677 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8678 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8679 | if (response instanceof CarrierRestrictionRules) { |
| 8680 | return (CarrierRestrictionRules) response; |
| 8681 | } |
| 8682 | // Response is an Exception of some kind, |
| 8683 | // which is signalled to the user as a NULL retval |
| 8684 | return null; |
| 8685 | } catch (Exception e) { |
| 8686 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8687 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8688 | } finally { |
| 8689 | Binder.restoreCallingIdentity(identity); |
| 8690 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8691 | } |
| 8692 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8693 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8694 | * Fetches the carrier restriction status of the device and sends the status to the caller |
| 8695 | * through the callback. |
| 8696 | * |
| 8697 | * @param callback The callback that will be used to send the result. |
| 8698 | * @throws SecurityException if the caller does not have the required permission/privileges or |
| 8699 | * the caller is not allowlisted. |
| 8700 | */ |
| 8701 | @Override |
| 8702 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { |
| 8703 | enforceReadPermission("getCarrierRestrictionStatus"); |
| 8704 | int carrierId = validateCallerAndGetCarrierId(packageName); |
| 8705 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { |
| 8706 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); |
| 8707 | throw new SecurityException("Not an authorized caller"); |
| 8708 | } |
| 8709 | final long identity = Binder.clearCallingIdentity(); |
| 8710 | try { |
| 8711 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 8712 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); |
| 8713 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); |
| 8714 | } finally { |
| 8715 | Binder.restoreCallingIdentity(identity); |
| 8716 | } |
| 8717 | } |
| 8718 | |
| 8719 | @VisibleForTesting |
| 8720 | public int validateCallerAndGetCarrierId(String packageName) { |
| 8721 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); |
| 8722 | return allowListInfo.validateCallerAndGetCarrierId(packageName); |
| 8723 | } |
| 8724 | |
| 8725 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8726 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8727 | * @param subId the subscription ID that this action applies to. |
| 8728 | * @param enabled control enable or disable radio. |
| 8729 | * {@hide} |
| 8730 | */ |
| 8731 | @Override |
| 8732 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8733 | enforceModifyPermission(); |
| 8734 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8735 | |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8737 | if (phone == null) { |
| 8738 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8739 | return; |
| 8740 | } |
| 8741 | try { |
| 8742 | phone.carrierActionSetRadioEnabled(enabled); |
| 8743 | } catch (Exception e) { |
| 8744 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8745 | } finally { |
| 8746 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8747 | } |
| 8748 | } |
| 8749 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8750 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8751 | * Enable or disable Voice over NR (VoNR) |
| 8752 | * @param subId the subscription ID that this action applies to. |
| 8753 | * @param enabled enable or disable VoNR. |
| 8754 | * @return operation result. |
| 8755 | */ |
| 8756 | @Override |
| 8757 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8758 | enforceModifyPermission(); |
| 8759 | final Phone phone = getPhone(subId); |
| 8760 | |
| 8761 | final long identity = Binder.clearCallingIdentity(); |
| 8762 | if (phone == null) { |
| 8763 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8764 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8765 | } |
| 8766 | |
| 8767 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8768 | try { |
| 8769 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8770 | workSource); |
| 8771 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8772 | |
| 8773 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8774 | if (DBG) { |
| 8775 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8776 | } |
| 8777 | SubscriptionManager.setSubscriptionProperty( |
| 8778 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8779 | (enabled ? "1" : "0")); |
| 8780 | } |
| 8781 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8782 | return result; |
| 8783 | } finally { |
| 8784 | Binder.restoreCallingIdentity(identity); |
| 8785 | } |
| 8786 | } |
| 8787 | |
| 8788 | /** |
| 8789 | * Is voice over NR enabled |
| 8790 | * @return true if VoNR is enabled else false |
| 8791 | */ |
| 8792 | @Override |
| 8793 | public boolean isVoNrEnabled(int subId) { |
| 8794 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8799 | null, subId, workSource); |
| 8800 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8801 | return isEnabled; |
| 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(identity); |
| 8804 | } |
| 8805 | } |
| 8806 | |
| 8807 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8808 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8809 | * network status based on which carrier apps could apply actions accordingly, |
| 8810 | * enable/disable default url handler for example. |
| 8811 | * |
| 8812 | * @param subId the subscription ID that this action applies to. |
| 8813 | * @param report control start/stop reporting the default network status. |
| 8814 | * {@hide} |
| 8815 | */ |
| 8816 | @Override |
| 8817 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8818 | enforceModifyPermission(); |
| 8819 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8820 | |
| 8821 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8822 | if (phone == null) { |
| 8823 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8824 | return; |
| 8825 | } |
| 8826 | try { |
| 8827 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8828 | } catch (Exception e) { |
| 8829 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8830 | } finally { |
| 8831 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8832 | } |
| 8833 | } |
| 8834 | |
| 8835 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8836 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8837 | * @param subId the subscription ID that this action applies to. |
| 8838 | * {@hide} |
| 8839 | */ |
| 8840 | @Override |
| 8841 | public void carrierActionResetAll(int subId) { |
| 8842 | enforceModifyPermission(); |
| 8843 | final Phone phone = getPhone(subId); |
| 8844 | if (phone == null) { |
| 8845 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8846 | return; |
| 8847 | } |
| 8848 | try { |
| 8849 | phone.carrierActionResetAll(); |
| 8850 | } catch (Exception e) { |
| 8851 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8852 | } |
| 8853 | } |
| 8854 | |
| 8855 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8856 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8857 | * bug report is being generated. |
| 8858 | */ |
| 8859 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8860 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8861 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8862 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8863 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8864 | + Binder.getCallingPid() |
| 8865 | + ", uid=" + Binder.getCallingUid() |
| 8866 | + "without permission " |
| 8867 | + android.Manifest.permission.DUMP); |
| 8868 | return; |
| 8869 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8870 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8871 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8872 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8873 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8874 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8875 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8876 | @NonNull String[] args) { |
| 8877 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8878 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8879 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8880 | } |
| 8881 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8882 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8883 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8884 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8885 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8886 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8887 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8888 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8889 | */ |
| 8890 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8891 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8892 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8893 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8894 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8895 | try { |
| 8896 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8897 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8898 | } catch (SecurityException se) { |
| 8899 | enforceModifyPermission(); |
| 8900 | } |
| 8901 | } else { |
| 8902 | enforceModifyPermission(); |
| 8903 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8904 | |
| 8905 | final long identity = Binder.clearCallingIdentity(); |
| 8906 | try { |
| 8907 | Phone phone = getPhone(subId); |
| 8908 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8909 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8910 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8911 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8912 | phone.getDataSettingsManager().setDataEnabled( |
| 8913 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8915 | } |
| 8916 | } finally { |
| 8917 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8918 | } |
| 8919 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8920 | |
| 8921 | /** |
| 8922 | * Get Client request stats |
| 8923 | * @return List of Client Request Stats |
| 8924 | * @hide |
| 8925 | */ |
| 8926 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8927 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8928 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8930 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8931 | return null; |
| 8932 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8933 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8935 | final long identity = Binder.clearCallingIdentity(); |
| 8936 | try { |
| 8937 | if (phone != null) { |
| 8938 | return phone.getClientRequestStats(); |
| 8939 | } |
| 8940 | |
| 8941 | return null; |
| 8942 | } finally { |
| 8943 | Binder.restoreCallingIdentity(identity); |
| 8944 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8945 | } |
| 8946 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8947 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8948 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8949 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8950 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8951 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8952 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8953 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8954 | // commands that plumb through the RIL as root, like so: |
| 8955 | // $ adb root |
| 8956 | // $ adb shell cmd phone ... |
| 8957 | packageName = "root"; |
| 8958 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8959 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8960 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8961 | |
| 8962 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8963 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8964 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8965 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8966 | * @param state State of SIM (power down, power up, pass through) |
| 8967 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8968 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8969 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8970 | * |
| 8971 | **/ |
| 8972 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8973 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8974 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8975 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8976 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8977 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | final long identity = Binder.clearCallingIdentity(); |
| 8980 | try { |
| 8981 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8982 | phone.setSimPowerState(state, null, workSource); |
| 8983 | } |
| 8984 | } finally { |
| 8985 | Binder.restoreCallingIdentity(identity); |
| 8986 | } |
| 8987 | } |
| 8988 | |
| 8989 | /** |
| 8990 | * Set SIM card power state. |
| 8991 | * |
| 8992 | * @param slotIndex SIM slot id. |
| 8993 | * @param state State of SIM (power down, power up, pass through) |
| 8994 | * @param callback callback to trigger after success or failure |
| 8995 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8996 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8997 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8998 | * |
| 8999 | **/ |
| 9000 | @Override |
| 9001 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 9002 | IIntegerConsumer callback) { |
| 9003 | enforceModifyPermission(); |
| 9004 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9005 | |
| 9006 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9007 | |
| 9008 | final long identity = Binder.clearCallingIdentity(); |
| 9009 | try { |
| 9010 | if (phone != null) { |
| 9011 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 9012 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9013 | } |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9016 | } |
| 9017 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9018 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9019 | private boolean isUssdApiAllowed(int subId) { |
| 9020 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9021 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9022 | if (configManager == null) { |
| 9023 | return false; |
| 9024 | } |
| 9025 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 9026 | if (pb == null) { |
| 9027 | return false; |
| 9028 | } |
| 9029 | return pb.getBoolean( |
| 9030 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 9031 | } |
| 9032 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9033 | /** |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9034 | * Check if phone is in emergency callback mode. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9035 | * @return true if phone is in emergency callback mode |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9036 | * @param subId sub Id, but the check is in fact irrlevant to sub Id. |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9037 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9038 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9039 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9040 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9041 | final long identity = Binder.clearCallingIdentity(); |
| 9042 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9043 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9044 | } finally { |
| 9045 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9046 | } |
| 9047 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9048 | |
| 9049 | /** |
| 9050 | * Get the current signal strength information for the given subscription. |
| 9051 | * Because this information is not updated when the device is in a low power state |
| 9052 | * it should not be relied-upon to be current. |
| 9053 | * @param subId Subscription index |
| 9054 | * @return the most recent cached signal strength info from the modem |
| 9055 | */ |
| 9056 | @Override |
| 9057 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9058 | final long identity = Binder.clearCallingIdentity(); |
| 9059 | try { |
| 9060 | Phone p = getPhone(subId); |
| 9061 | if (p == null) { |
| 9062 | return null; |
| 9063 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | return p.getSignalStrength(); |
| 9066 | } finally { |
| 9067 | Binder.restoreCallingIdentity(identity); |
| 9068 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9069 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9070 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9071 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9072 | * Get the current modem radio state for the given slot. |
| 9073 | * @param slotIndex slot index. |
| 9074 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9075 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9076 | * @return the current radio power state from the modem |
| 9077 | */ |
| 9078 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9079 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9080 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9081 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9082 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 9083 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9084 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9085 | } |
| 9086 | |
| 9087 | final long identity = Binder.clearCallingIdentity(); |
| 9088 | try { |
| 9089 | return phone.getRadioPowerState(); |
| 9090 | } finally { |
| 9091 | Binder.restoreCallingIdentity(identity); |
| 9092 | } |
| 9093 | } |
| 9094 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 9095 | } |
| 9096 | |
| 9097 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9098 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 9099 | * |
| 9100 | * <p>Requires one of the following permissions: |
| 9101 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9102 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9103 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 9104 | * privileges. |
| 9105 | * |
| 9106 | * @param subId subscription id |
| 9107 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 9108 | * {@code false}. |
| 9109 | */ |
| 9110 | @Override |
| 9111 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9112 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9113 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9114 | try { |
| 9115 | mApp.enforceCallingOrSelfPermission( |
| 9116 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 9117 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9118 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9119 | mApp.enforceCallingOrSelfPermission( |
| 9120 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 9121 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9122 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9123 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9124 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9125 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9126 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9127 | boolean isEnabled = false; |
| 9128 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9129 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9130 | Phone phone = getPhone(subId); |
| 9131 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9134 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9135 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9136 | } |
| 9137 | |
| 9138 | |
| 9139 | /** |
| 9140 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 9141 | * |
| 9142 | * <p> Requires permission: |
| 9143 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 9144 | * privileges. |
| 9145 | * |
| 9146 | * @param subId subscription id |
| 9147 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 9148 | */ |
| 9149 | @Override |
| 9150 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9152 | mApp, subId, "setDataRoamingEnabled"); |
| 9153 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9154 | final long identity = Binder.clearCallingIdentity(); |
| 9155 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9156 | Phone phone = getPhone(subId); |
| 9157 | if (phone != null) { |
| 9158 | phone.setDataRoamingEnabled(isEnabled); |
| 9159 | } |
| 9160 | } finally { |
| 9161 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9162 | } |
| 9163 | } |
| 9164 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9165 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9166 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9167 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9168 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9169 | mApp, subId, "isManualNetworkSelectionAllowed"); |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9170 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9171 | boolean isAllowed = true; |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9174 | Phone phone = getPhone(subId); |
| 9175 | if (phone != null) { |
| 9176 | isAllowed = phone.isCspPlmnEnabled(); |
| 9177 | } |
| 9178 | } finally { |
| 9179 | Binder.restoreCallingIdentity(identity); |
| 9180 | } |
| 9181 | return isAllowed; |
| 9182 | } |
| 9183 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9184 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 9185 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9186 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9187 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9188 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9189 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 9190 | if (phone == null) { |
| 9191 | return false; |
| 9192 | } |
| 9193 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9194 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 9195 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9196 | } |
| 9197 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9198 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9199 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9200 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9201 | mApp.getSystemService(AppOpsManager.class) |
| 9202 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9203 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9204 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9205 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9206 | try { |
| 9207 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9208 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9209 | } catch (SecurityException e) { |
| 9210 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 9211 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9212 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9213 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9214 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9215 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9216 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9217 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9218 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9219 | Binder.getCallingUid())) { |
| 9220 | isIccIdAccessRestricted = true; |
| 9221 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9222 | final long identity = Binder.clearCallingIdentity(); |
| 9223 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9224 | UiccController uiccController = UiccController.getInstance(); |
| 9225 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9226 | if (hasReadPermission) { |
| 9227 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9228 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9229 | |
| 9230 | // Remove private info if the caller doesn't have access |
| 9231 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 9232 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9233 | //setting the value after compatibility check |
| 9234 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9235 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 9236 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9237 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9238 | if (card == null) { |
| 9239 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9240 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9241 | continue; |
| 9242 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9243 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 9244 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9245 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9246 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9247 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9248 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 9249 | for (UiccPortInfo portInfo : portInfos) { |
| 9250 | UiccPort port = uiccController.getUiccPortForSlot( |
| 9251 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 9252 | if (port == null) { |
| 9253 | // assume no access if port is null |
| 9254 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9255 | continue; |
| 9256 | } |
| 9257 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9258 | uiccPortInfos.add(portInfo); |
| 9259 | } else { |
| 9260 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 9261 | } |
| 9262 | } |
| 9263 | filteredInfos.add(new UiccCardInfo( |
| 9264 | cardInfo.isEuicc(), |
| 9265 | cardInfo.getCardId(), |
| 9266 | null, |
| 9267 | cardInfo.getPhysicalSlotIndex(), |
| 9268 | cardInfo.isRemovable(), |
| 9269 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9270 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9271 | } |
| 9272 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9273 | } finally { |
| 9274 | Binder.restoreCallingIdentity(identity); |
| 9275 | } |
| 9276 | } |
| 9277 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9278 | /** |
| 9279 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9280 | * generally private and require carrier privileges to view. |
| 9281 | * |
| 9282 | * @hide |
| 9283 | */ |
| 9284 | @NonNull |
| 9285 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9286 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9287 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9288 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9289 | } |
| 9290 | return new UiccCardInfo( |
| 9291 | cardInfo.isEuicc(), |
| 9292 | cardInfo.getCardId(), |
| 9293 | null, |
| 9294 | cardInfo.getPhysicalSlotIndex(), |
| 9295 | cardInfo.isRemovable(), |
| 9296 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9297 | portinfo |
| 9298 | ); |
| 9299 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9300 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9301 | /** |
| 9302 | * @hide |
| 9303 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9304 | * These values are generally private and require carrier privileges to view. |
| 9305 | */ |
| 9306 | @NonNull |
| 9307 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9308 | return new UiccPortInfo( |
| 9309 | UiccPortInfo.ICCID_REDACTED, |
| 9310 | portInfo.getPortIndex(), |
| 9311 | portInfo.getLogicalSlotIndex(), |
| 9312 | portInfo.isActive() |
| 9313 | ); |
| 9314 | } |
| 9315 | @Override |
| 9316 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9317 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9318 | mApp.getSystemService(AppOpsManager.class) |
| 9319 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9320 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9321 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9322 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9323 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9324 | // we are reading iccId which is PII data. |
| 9325 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9326 | |
| 9327 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9328 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9329 | Binder.getCallingUid())) { |
| 9330 | isLogicalSlotAccessRestricted = true; |
| 9331 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9332 | final long identity = Binder.clearCallingIdentity(); |
| 9333 | try { |
| 9334 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9335 | if (slots == null || slots.length == 0) { |
| 9336 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9337 | return null; |
| 9338 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9339 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9340 | for (int i = 0; i < slots.length; i++) { |
| 9341 | UiccSlot slot = slots[i]; |
| 9342 | if (slot == null) { |
| 9343 | continue; |
| 9344 | } |
| 9345 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9346 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9347 | UiccCard card = slot.getUiccCard(); |
| 9348 | if (card != null) { |
| 9349 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9350 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9351 | cardId = slot.getEid(); |
| 9352 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9353 | // If cardId is null, use iccId of default port as cardId. |
| 9354 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9355 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9356 | } |
| 9357 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9358 | if (cardId != null) { |
| 9359 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9360 | // if cardId is an EID, it's all digits so this is fine |
| 9361 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9362 | } |
| 9363 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9364 | int cardState = 0; |
| 9365 | switch (slot.getCardState()) { |
| 9366 | case CARDSTATE_ABSENT: |
| 9367 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9368 | break; |
| 9369 | case CARDSTATE_PRESENT: |
| 9370 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9371 | break; |
| 9372 | case CARDSTATE_ERROR: |
| 9373 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9374 | break; |
| 9375 | case CARDSTATE_RESTRICTED: |
| 9376 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9377 | break; |
| 9378 | default: |
| 9379 | break; |
| 9380 | |
| 9381 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9382 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9383 | int[] portIndexes = slot.getPortList(); |
| 9384 | for (int portIdx : portIndexes) { |
| 9385 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9386 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9387 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9388 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9391 | slot.isEuicc(), |
| 9392 | cardId, |
| 9393 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9394 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9395 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9396 | //setting the value after compatibility check |
| 9397 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9398 | } |
| 9399 | return infos; |
| 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9402 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9403 | } |
| 9404 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9405 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9406 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9407 | boolean hasReadPermission) { |
| 9408 | String iccId = slot.getIccId(portIndex); |
| 9409 | if (hasReadPermission) { // if has read permission |
| 9410 | return iccId; |
| 9411 | } else { |
| 9412 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9413 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9414 | // if no read permission, checking carrier privilege access |
| 9415 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9416 | return iccId; |
| 9417 | } |
| 9418 | } |
| 9419 | } |
| 9420 | // No read permission or carrier privilege access. |
| 9421 | return UiccPortInfo.ICCID_REDACTED; |
| 9422 | } |
| 9423 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9424 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9425 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9426 | public boolean switchSlots(int[] physicalSlots) { |
| 9427 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9428 | |
| 9429 | final long identity = Binder.clearCallingIdentity(); |
| 9430 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9431 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9432 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9433 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9434 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9435 | physicalSlots[i], i)); |
| 9436 | } |
| 9437 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9438 | } finally { |
| 9439 | Binder.restoreCallingIdentity(identity); |
| 9440 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9441 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9442 | |
| 9443 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9444 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9445 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9446 | enforceModifyPermission(); |
| 9447 | |
| 9448 | final long identity = Binder.clearCallingIdentity(); |
| 9449 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9450 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9451 | } finally { |
| 9452 | Binder.restoreCallingIdentity(identity); |
| 9453 | } |
| 9454 | } |
| 9455 | |
| 9456 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9457 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9458 | final long identity = Binder.clearCallingIdentity(); |
| 9459 | try { |
| 9460 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9461 | } finally { |
| 9462 | Binder.restoreCallingIdentity(identity); |
| 9463 | } |
| 9464 | } |
| 9465 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9466 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9467 | * A test API to reload the UICC profile. |
| 9468 | * |
| 9469 | * <p>Requires that the calling app has permission |
| 9470 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9471 | * @hide |
| 9472 | */ |
| 9473 | @Override |
| 9474 | public void refreshUiccProfile(int subId) { |
| 9475 | enforceModifyPermission(); |
| 9476 | |
| 9477 | final long identity = Binder.clearCallingIdentity(); |
| 9478 | try { |
| 9479 | Phone phone = getPhone(subId); |
| 9480 | if (phone == null) { |
| 9481 | return; |
| 9482 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9483 | UiccPort uiccPort = phone.getUiccPort(); |
| 9484 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9485 | return; |
| 9486 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9487 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9488 | if (uiccProfile == null) { |
| 9489 | return; |
| 9490 | } |
| 9491 | uiccProfile.refresh(); |
| 9492 | } finally { |
| 9493 | Binder.restoreCallingIdentity(identity); |
| 9494 | } |
| 9495 | } |
| 9496 | |
| 9497 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9498 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9499 | */ |
| 9500 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9501 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9502 | } |
| 9503 | |
| 9504 | /** |
| 9505 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9506 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9507 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9508 | */ |
| 9509 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9510 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9511 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9512 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9513 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9514 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9515 | return isDataRoamingEnabled; |
| 9516 | } |
| 9517 | |
| 9518 | /** |
| 9519 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9520 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9521 | */ |
| 9522 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9523 | List<Integer> list = TelephonyProperties.default_network(); |
Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9524 | int phoneId = SubscriptionManager.getPhoneId(subId); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9525 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9526 | return list.get(phoneId); |
| 9527 | } |
| 9528 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9529 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9530 | |
| 9531 | @Override |
| 9532 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9533 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9534 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9535 | |
| 9536 | final long identity = Binder.clearCallingIdentity(); |
| 9537 | try { |
| 9538 | final Phone phone = getPhone(subId); |
| 9539 | if (phone == null) { |
| 9540 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9541 | return; |
| 9542 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9543 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9544 | if (cpt != null) { |
| 9545 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9546 | } |
| 9547 | // 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] | 9548 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9549 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9550 | if (carrierPrivilegeRules == null) { |
| 9551 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9552 | } else { |
| 9553 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9554 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9555 | } finally { |
| 9556 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9557 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9558 | } |
| 9559 | |
| 9560 | @Override |
Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9561 | public void setCarrierServicePackageOverride( |
| 9562 | int subId, String carrierServicePackage, String callingPackage) { |
| 9563 | TelephonyPermissions.enforceShellOnly( |
| 9564 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); |
| 9565 | |
| 9566 | // Verify that the callingPackage belongs to the calling UID |
| 9567 | mApp.getSystemService(AppOpsManager.class) |
| 9568 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9569 | |
| 9570 | final long identity = Binder.clearCallingIdentity(); |
| 9571 | try { |
| 9572 | final Phone phone = getPhone(subId); |
| 9573 | if (phone == null || phone.getSubId() != subId) { |
| 9574 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); |
| 9575 | throw new IllegalArgumentException("No phone for subid"); |
| 9576 | } |
| 9577 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9578 | if (cpt == null) { |
| 9579 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); |
| 9580 | throw new IllegalStateException("No CPT for phone"); |
| 9581 | } |
| 9582 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); |
| 9583 | } finally { |
| 9584 | Binder.restoreCallingIdentity(identity); |
| 9585 | } |
| 9586 | } |
| 9587 | |
| 9588 | @Override |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9589 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9590 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9591 | |
| 9592 | final long identity = Binder.clearCallingIdentity(); |
| 9593 | try { |
| 9594 | final Phone phone = getPhone(subId); |
| 9595 | if (phone == null) { |
| 9596 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9597 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9598 | } |
| 9599 | return phone.getCarrierIdListVersion(); |
| 9600 | } finally { |
| 9601 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9602 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9603 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9604 | |
| 9605 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9606 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9607 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9608 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9609 | mApp, subId, callingPackage, callingFeatureId, |
| 9610 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9611 | return -1; |
| 9612 | } |
| 9613 | |
| 9614 | final long identity = Binder.clearCallingIdentity(); |
| 9615 | try { |
| 9616 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9617 | } finally { |
| 9618 | Binder.restoreCallingIdentity(identity); |
| 9619 | } |
| 9620 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9621 | |
| 9622 | @Override |
| 9623 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9624 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9625 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9626 | mApp, subId, "getCdmaRoamingMode"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9627 | |
| 9628 | final long identity = Binder.clearCallingIdentity(); |
| 9629 | try { |
| 9630 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9631 | } finally { |
| 9632 | Binder.restoreCallingIdentity(identity); |
| 9633 | } |
| 9634 | } |
| 9635 | |
| 9636 | @Override |
| 9637 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9639 | mApp, subId, "setCdmaRoamingMode"); |
| 9640 | |
| 9641 | final long identity = Binder.clearCallingIdentity(); |
| 9642 | try { |
| 9643 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9644 | } finally { |
| 9645 | Binder.restoreCallingIdentity(identity); |
| 9646 | } |
| 9647 | } |
| 9648 | |
| 9649 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9650 | public int getCdmaSubscriptionMode(int subId) { |
| 9651 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9652 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9653 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9654 | |
| 9655 | final long identity = Binder.clearCallingIdentity(); |
| 9656 | try { |
| 9657 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9658 | } finally { |
| 9659 | Binder.restoreCallingIdentity(identity); |
| 9660 | } |
| 9661 | } |
| 9662 | |
| 9663 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9664 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9666 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9667 | |
| 9668 | final long identity = Binder.clearCallingIdentity(); |
| 9669 | try { |
| 9670 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9671 | } finally { |
| 9672 | Binder.restoreCallingIdentity(identity); |
| 9673 | } |
| 9674 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9675 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9676 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9677 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9678 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9679 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9680 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9681 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9682 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9683 | } |
| 9684 | final long identity = Binder.clearCallingIdentity(); |
| 9685 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9686 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9687 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9688 | if (phone.getEmergencyNumberTracker() != null |
| 9689 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9690 | emergencyNumberListInternal.put( |
| 9691 | phone.getSubId(), |
| 9692 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9693 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9694 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9695 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9696 | } finally { |
| 9697 | Binder.restoreCallingIdentity(identity); |
| 9698 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9699 | } |
| 9700 | |
| 9701 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9702 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9703 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9704 | if (!exactMatch) { |
| 9705 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9706 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9707 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9708 | } |
| 9709 | final long identity = Binder.clearCallingIdentity(); |
| 9710 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9711 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9712 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9713 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9714 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9715 | && phone.getEmergencyNumberTracker() |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9716 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9717 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9718 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9719 | } |
| 9720 | return false; |
| 9721 | } finally { |
| 9722 | Binder.restoreCallingIdentity(identity); |
| 9723 | } |
| 9724 | } |
| 9725 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9726 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9727 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9728 | */ |
| 9729 | @Override |
| 9730 | public void startEmergencyCallbackMode() { |
| 9731 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9732 | "startEmergencyCallbackMode"); |
| 9733 | enforceModifyPermission(); |
| 9734 | final long identity = Binder.clearCallingIdentity(); |
| 9735 | try { |
| 9736 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9737 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9738 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9739 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9740 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9741 | gsmCdmaPhone.obtainMessage( |
| 9742 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9743 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9744 | } |
| 9745 | } |
| 9746 | } finally { |
| 9747 | Binder.restoreCallingIdentity(identity); |
| 9748 | } |
| 9749 | } |
| 9750 | |
| 9751 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9752 | * Update emergency number list for test mode. |
| 9753 | */ |
| 9754 | @Override |
| 9755 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9756 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9757 | "updateEmergencyNumberListTestMode"); |
| 9758 | |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
| 9760 | try { |
| 9761 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9762 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9763 | if (tracker != null) { |
| 9764 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9765 | } |
| 9766 | } |
| 9767 | } finally { |
| 9768 | Binder.restoreCallingIdentity(identity); |
| 9769 | } |
| 9770 | } |
| 9771 | |
| 9772 | /** |
| 9773 | * Get the full emergency number list for test mode. |
| 9774 | */ |
| 9775 | @Override |
| 9776 | public List<String> getEmergencyNumberListTestMode() { |
| 9777 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9778 | "getEmergencyNumberListTestMode"); |
| 9779 | |
| 9780 | final long identity = Binder.clearCallingIdentity(); |
| 9781 | try { |
| 9782 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9783 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9784 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9785 | if (tracker != null) { |
| 9786 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9787 | emergencyNumbers.add(num.getNumber()); |
| 9788 | } |
| 9789 | } |
| 9790 | } |
| 9791 | return new ArrayList<>(emergencyNumbers); |
| 9792 | } finally { |
| 9793 | Binder.restoreCallingIdentity(identity); |
| 9794 | } |
| 9795 | } |
| 9796 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9797 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9798 | public int getEmergencyNumberDbVersion(int subId) { |
| 9799 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9800 | |
| 9801 | final long identity = Binder.clearCallingIdentity(); |
| 9802 | try { |
| 9803 | final Phone phone = getPhone(subId); |
| 9804 | if (phone == null) { |
| 9805 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9806 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9807 | } |
| 9808 | return phone.getEmergencyNumberDbVersion(); |
| 9809 | } finally { |
| 9810 | Binder.restoreCallingIdentity(identity); |
| 9811 | } |
| 9812 | } |
| 9813 | |
| 9814 | @Override |
| 9815 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9816 | enforceModifyPermission(); |
| 9817 | |
| 9818 | final long identity = Binder.clearCallingIdentity(); |
| 9819 | try { |
| 9820 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9821 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9822 | if (tracker != null) { |
| 9823 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9824 | } |
| 9825 | } |
| 9826 | } finally { |
| 9827 | Binder.restoreCallingIdentity(identity); |
| 9828 | } |
| 9829 | } |
| 9830 | |
| 9831 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9832 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9833 | enforceActiveEmergencySessionPermission(); |
| 9834 | |
| 9835 | final long identity = Binder.clearCallingIdentity(); |
| 9836 | try { |
| 9837 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9838 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9839 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9840 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9841 | } |
| 9842 | } |
| 9843 | } finally { |
| 9844 | Binder.restoreCallingIdentity(identity); |
| 9845 | } |
| 9846 | } |
| 9847 | |
| 9848 | @Override |
| 9849 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9850 | enforceActiveEmergencySessionPermission(); |
| 9851 | |
| 9852 | final long identity = Binder.clearCallingIdentity(); |
| 9853 | try { |
| 9854 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9855 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9856 | if (tracker != null) { |
| 9857 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9858 | } |
| 9859 | } |
| 9860 | } finally { |
| 9861 | Binder.restoreCallingIdentity(identity); |
| 9862 | } |
| 9863 | } |
| 9864 | |
| 9865 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9866 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9867 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9868 | Phone phone = getPhone(subId); |
| 9869 | if (phone == null) { |
| 9870 | return null; |
| 9871 | } |
| 9872 | final long identity = Binder.clearCallingIdentity(); |
| 9873 | try { |
| 9874 | UiccProfile profile = UiccController.getInstance() |
| 9875 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9876 | if (profile != null) { |
| 9877 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9878 | } |
| 9879 | } finally { |
| 9880 | Binder.restoreCallingIdentity(identity); |
| 9881 | } |
| 9882 | return null; |
| 9883 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9884 | |
| 9885 | /** |
| 9886 | * Enable or disable a modem stack. |
| 9887 | */ |
| 9888 | @Override |
| 9889 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9890 | enforceModifyPermission(); |
| 9891 | |
| 9892 | final long identity = Binder.clearCallingIdentity(); |
| 9893 | try { |
| 9894 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9895 | if (phone == null) { |
| 9896 | return false; |
| 9897 | } else { |
| 9898 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9899 | } |
| 9900 | } finally { |
| 9901 | Binder.restoreCallingIdentity(identity); |
| 9902 | } |
| 9903 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9904 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9905 | /** |
| 9906 | * Whether a modem stack is enabled or not. |
| 9907 | */ |
| 9908 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9909 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9910 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9911 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9912 | if (phone == null) return false; |
| 9913 | |
| 9914 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9915 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9916 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9917 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9918 | } |
| 9919 | |
| 9920 | final long identity = Binder.clearCallingIdentity(); |
| 9921 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9922 | try { |
| 9923 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9924 | } catch (NoSuchElementException ex) { |
| 9925 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9926 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9927 | } finally { |
| 9928 | Binder.restoreCallingIdentity(identity); |
| 9929 | } |
| 9930 | } |
| 9931 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9932 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9933 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9934 | enforceModifyPermission(); |
| 9935 | |
| 9936 | final long identity = Binder.clearCallingIdentity(); |
| 9937 | try { |
| 9938 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9939 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9940 | .commit(); |
| 9941 | } finally { |
| 9942 | Binder.restoreCallingIdentity(identity); |
| 9943 | } |
| 9944 | } |
| 9945 | |
| 9946 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9947 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9948 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9949 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9950 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9951 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9952 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9953 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9954 | |
| 9955 | final long identity = Binder.clearCallingIdentity(); |
| 9956 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9957 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9958 | } finally { |
| 9959 | Binder.restoreCallingIdentity(identity); |
| 9960 | } |
| 9961 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9962 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9963 | @TelephonyManager.IsMultiSimSupportedResult |
| 9964 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9965 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9966 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9967 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9968 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9969 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9970 | } |
| 9971 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9972 | // supported by the modem, indicate that it is restricted. |
| 9973 | PhoneCapability staticCapability = |
| 9974 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9975 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9976 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9977 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9978 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9979 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9980 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9981 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9982 | } |
| 9983 | // Check if support of multiple SIMs is restricted by carrier |
| 9984 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9985 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9986 | } |
| 9987 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9988 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9989 | } |
| 9990 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9991 | /** |
| 9992 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9993 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9994 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9995 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9996 | * @param numOfSims number of active sims we want to switch to |
| 9997 | */ |
| 9998 | @Override |
| 9999 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 10000 | if (numOfSims == 1) { |
| 10001 | enforceModifyPermission(); |
| 10002 | } else { |
| 10003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10004 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 10005 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10006 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10007 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10008 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10009 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10010 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10011 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 10012 | return; |
| 10013 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10014 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 10015 | } finally { |
| 10016 | Binder.restoreCallingIdentity(identity); |
| 10017 | } |
| 10018 | } |
| 10019 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10020 | @Override |
| 10021 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 10022 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 10023 | Phone phone = getPhone(subId); |
| 10024 | if (phone == null) { |
| 10025 | return false; |
| 10026 | } |
| 10027 | final long identity = Binder.clearCallingIdentity(); |
| 10028 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10029 | UiccPort uiccPort = phone.getUiccPort(); |
| 10030 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10031 | return false; |
| 10032 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10033 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10034 | if (uiccProfile == null) { |
| 10035 | return false; |
| 10036 | } |
| 10037 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 10038 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 10039 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 10040 | } |
| 10041 | return false; |
| 10042 | } finally { |
| 10043 | Binder.restoreCallingIdentity(identity); |
| 10044 | } |
| 10045 | } |
| 10046 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10047 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10048 | * Get whether making changes to modem configurations will trigger reboot. |
| 10049 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10050 | */ |
| 10051 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10052 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 10053 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10054 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10055 | mApp, subId, callingPackage, callingFeatureId, |
| 10056 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10057 | return false; |
| 10058 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10059 | final long identity = Binder.clearCallingIdentity(); |
| 10060 | try { |
| 10061 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 10062 | } finally { |
| 10063 | Binder.restoreCallingIdentity(identity); |
| 10064 | } |
| 10065 | } |
| 10066 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10067 | private void updateModemStateMetrics() { |
| 10068 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 10069 | // TODO: check the state for each modem if the api is ready. |
| 10070 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 10071 | } |
| 10072 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10073 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10074 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10075 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10076 | // Verify that the callingPackage belongs to the calling UID |
| 10077 | mApp.getSystemService(AppOpsManager.class) |
| 10078 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10079 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10080 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10081 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10082 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 10083 | if (slotInfos != null) { |
| 10084 | for (int i = 0; i < slotInfos.length; i++) { |
| 10085 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 10086 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 10087 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 10088 | portInfo.getLogicalSlotIndex())); |
| 10089 | } |
| 10090 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10091 | } |
| 10092 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10093 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10094 | } finally { |
| 10095 | Binder.restoreCallingIdentity(identity); |
| 10096 | } |
| 10097 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10098 | |
| 10099 | /** |
| 10100 | * Get the IRadio HAL Version |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10101 | * @deprecated use getHalVersion instead |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10102 | */ |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10103 | @Deprecated |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10104 | @Override |
| 10105 | public int getRadioHalVersion() { |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10106 | return getHalVersion(HAL_SERVICE_RADIO); |
| 10107 | } |
| 10108 | |
| 10109 | /** |
| 10110 | * Get the HAL Version of a specific service |
| 10111 | */ |
| 10112 | @Override |
| 10113 | public int getHalVersion(int service) { |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10114 | Phone phone = getDefaultPhone(); |
| 10115 | if (phone == null) return -1; |
jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10116 | HalVersion hv = phone.getHalVersion(service); |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10117 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 10118 | return hv.major * 100 + hv.minor; |
| 10119 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10120 | |
| 10121 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10122 | * Get the current calling package name. |
| 10123 | * @return the current calling package name |
| 10124 | */ |
| 10125 | @Override |
| 10126 | public String getCurrentPackageName() { |
| 10127 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 10128 | } |
| 10129 | |
| 10130 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10131 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 10132 | * corresponding network requests on a subId. |
| 10133 | * |
| 10134 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10135 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10136 | * 2) APN is un-metered for this subscription, or |
| 10137 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10138 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10139 | * |
| 10140 | * @return whether data is allowed for a apn type. |
| 10141 | * |
| 10142 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10143 | */ |
| 10144 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10145 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10146 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 10147 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10148 | |
| 10149 | // Now that all security checks passes, perform the operation as ourselves. |
| 10150 | final long identity = Binder.clearCallingIdentity(); |
| 10151 | try { |
| 10152 | Phone phone = getPhone(subId); |
| 10153 | if (phone == null) return false; |
| 10154 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10155 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10156 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10157 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 10158 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 10159 | phone.getServiceState().getDataRoaming()); |
| 10160 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10161 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10162 | } finally { |
| 10163 | Binder.restoreCallingIdentity(identity); |
| 10164 | } |
| 10165 | } |
| 10166 | |
| 10167 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10168 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10169 | enforceReadPrivilegedPermission("isApnMetered"); |
| 10170 | |
| 10171 | // Now that all security checks passes, perform the operation as ourselves. |
| 10172 | final long identity = Binder.clearCallingIdentity(); |
| 10173 | try { |
| 10174 | Phone phone = getPhone(subId); |
| 10175 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10176 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 10177 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 10178 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10179 | } finally { |
| 10180 | Binder.restoreCallingIdentity(identity); |
| 10181 | } |
| 10182 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10183 | |
| 10184 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10185 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 10186 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 10187 | enforceModifyPermission(); |
| 10188 | long token = Binder.clearCallingIdentity(); |
| 10189 | try { |
| 10190 | Phone phone = getPhone(subscriptionId); |
| 10191 | if (phone == null) { |
| 10192 | try { |
| 10193 | if (resultCallback != null) { |
| 10194 | resultCallback.accept(false); |
| 10195 | } |
| 10196 | } catch (RemoteException e) { |
| 10197 | // ignore |
| 10198 | } |
| 10199 | return; |
| 10200 | } |
| 10201 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 10202 | Pair.create(specifiers, (x) -> { |
| 10203 | try { |
| 10204 | if (resultCallback != null) { |
| 10205 | resultCallback.accept(x); |
| 10206 | } |
| 10207 | } catch (RemoteException e) { |
| 10208 | // ignore |
| 10209 | } |
| 10210 | }); |
| 10211 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 10212 | } finally { |
| 10213 | Binder.restoreCallingIdentity(token); |
| 10214 | } |
| 10215 | } |
| 10216 | |
| 10217 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10218 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 10219 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10220 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10221 | mApp, subId, "getSystemSelectionChannels"); |
| 10222 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10223 | final long identity = Binder.clearCallingIdentity(); |
| 10224 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10225 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 10226 | if (result instanceof IllegalStateException) { |
| 10227 | throw (IllegalStateException) result; |
| 10228 | } |
| 10229 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10230 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 10231 | return specifiers; |
| 10232 | } finally { |
| 10233 | Binder.restoreCallingIdentity(identity); |
| 10234 | } |
| 10235 | } |
| 10236 | |
| 10237 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10238 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10239 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10240 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10241 | } |
| 10242 | |
| 10243 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10244 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 10245 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10246 | if (callingPackage == null) { |
| 10247 | callingPackage = getCurrentPackageName(); |
| 10248 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10249 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 10250 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10251 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 10252 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10253 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 10254 | } |
| 10255 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 10256 | Intent intent = new Intent(); |
| 10257 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 10258 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10259 | // Bring up choose default SMS subscription dialog right now |
| 10260 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 10261 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 10262 | mApp.startActivity(intent); |
| 10263 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10264 | |
| 10265 | @Override |
Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10266 | public void showSwitchToManagedProfileDialog() { |
| 10267 | enforceModifyPermission(); |
| 10268 | |
| 10269 | Intent intent = new Intent(); |
| 10270 | intent.setClass(mApp, ErrorDialogActivity.class); |
| 10271 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 10272 | mApp.startActivity(intent); |
| 10273 | } |
| 10274 | |
| 10275 | @Override |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10276 | public String getMmsUAProfUrl(int subId) { |
| 10277 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10278 | final long identity = Binder.clearCallingIdentity(); |
| 10279 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10280 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 10281 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 10282 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 10283 | return carrierUAProfUrl; |
| 10284 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10285 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10286 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10287 | } finally { |
| 10288 | Binder.restoreCallingIdentity(identity); |
| 10289 | } |
| 10290 | } |
| 10291 | |
| 10292 | @Override |
| 10293 | public String getMmsUserAgent(int subId) { |
| 10294 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 10295 | final long identity = Binder.clearCallingIdentity(); |
| 10296 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10297 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 10298 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 10299 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 10300 | return carrierUserAgent; |
| 10301 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10302 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 10303 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10304 | } finally { |
| 10305 | Binder.restoreCallingIdentity(identity); |
| 10306 | } |
| 10307 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10308 | |
| 10309 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10310 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 10311 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10312 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10313 | final long identity = Binder.clearCallingIdentity(); |
| 10314 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10315 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10316 | if (phone == null) return false; |
| 10317 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10318 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10319 | } finally { |
| 10320 | Binder.restoreCallingIdentity(identity); |
| 10321 | } |
| 10322 | } |
| 10323 | |
| 10324 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10325 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10326 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10327 | enforceModifyPermission(); |
| 10328 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10329 | final long identity = Binder.clearCallingIdentity(); |
| 10330 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10331 | Phone phone = getPhone(subscriptionId); |
| 10332 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10333 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10334 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10335 | } finally { |
| 10336 | Binder.restoreCallingIdentity(identity); |
| 10337 | } |
| 10338 | } |
| 10339 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10340 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10341 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10342 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10343 | * otherwise. |
| 10344 | */ |
| 10345 | @Override |
| 10346 | public void setCepEnabled(boolean isCepEnabled) { |
| 10347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10348 | |
| 10349 | final long identity = Binder.clearCallingIdentity(); |
| 10350 | try { |
| 10351 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10352 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10353 | Phone defaultPhone = phone.getImsPhone(); |
| 10354 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10355 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10356 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10357 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10358 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10359 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10360 | + imsPhone.getMsisdn()); |
| 10361 | } |
| 10362 | } |
| 10363 | } finally { |
| 10364 | Binder.restoreCallingIdentity(identity); |
| 10365 | } |
| 10366 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10367 | |
| 10368 | /** |
| 10369 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10370 | * |
| 10371 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10372 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10373 | * before being read. |
| 10374 | */ |
| 10375 | @Override |
| 10376 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10377 | isCompressed) { |
| 10378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10379 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10380 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10381 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10382 | } |
| 10383 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10384 | // ProvisioningManager can not handle ServiceSpecificException. |
| 10385 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 10386 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10387 | } |
| 10388 | |
| 10389 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10390 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10391 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10392 | } finally { |
| 10393 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10394 | } |
| 10395 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10396 | |
| 10397 | @Override |
| 10398 | public boolean isIccLockEnabled(int subId) { |
| 10399 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10400 | |
| 10401 | // Now that all security checks passes, perform the operation as ourselves. |
| 10402 | final long identity = Binder.clearCallingIdentity(); |
| 10403 | try { |
| 10404 | Phone phone = getPhone(subId); |
| 10405 | if (phone != null && phone.getIccCard() != null) { |
| 10406 | return phone.getIccCard().getIccLockEnabled(); |
| 10407 | } else { |
| 10408 | return false; |
| 10409 | } |
| 10410 | } finally { |
| 10411 | Binder.restoreCallingIdentity(identity); |
| 10412 | } |
| 10413 | } |
| 10414 | |
| 10415 | /** |
| 10416 | * Set the ICC pin lock enabled or disabled. |
| 10417 | * |
| 10418 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10419 | * three cases: |
| 10420 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10421 | * successfully. |
| 10422 | * - Positive number and zero for remaining password attempts. |
| 10423 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10424 | * |
| 10425 | */ |
| 10426 | @Override |
| 10427 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10428 | enforceModifyPermission(); |
| 10429 | |
| 10430 | Phone phone = getPhone(subId); |
| 10431 | if (phone == null) { |
| 10432 | return 0; |
| 10433 | } |
| 10434 | // Now that all security checks passes, perform the operation as ourselves. |
| 10435 | final long identity = Binder.clearCallingIdentity(); |
| 10436 | try { |
| 10437 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10438 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10439 | return attemptsRemaining; |
| 10440 | |
| 10441 | } catch (Exception e) { |
| 10442 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10443 | } finally { |
| 10444 | Binder.restoreCallingIdentity(identity); |
| 10445 | } |
| 10446 | return 0; |
| 10447 | } |
| 10448 | |
| 10449 | /** |
| 10450 | * Change the ICC password used in ICC pin lock. |
| 10451 | * |
| 10452 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10453 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10454 | * - Positive number and zero for remaining password attempts. |
| 10455 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10456 | * |
| 10457 | */ |
| 10458 | @Override |
| 10459 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10460 | enforceModifyPermission(); |
| 10461 | |
| 10462 | Phone phone = getPhone(subId); |
| 10463 | if (phone == null) { |
| 10464 | return 0; |
| 10465 | } |
| 10466 | // Now that all security checks passes, perform the operation as ourselves. |
| 10467 | final long identity = Binder.clearCallingIdentity(); |
| 10468 | try { |
| 10469 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10470 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10471 | return attemptsRemaining; |
| 10472 | |
| 10473 | } catch (Exception e) { |
| 10474 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10475 | } finally { |
| 10476 | Binder.restoreCallingIdentity(identity); |
| 10477 | } |
| 10478 | return 0; |
| 10479 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10480 | |
| 10481 | /** |
| 10482 | * Request for receiving user activity notification |
| 10483 | */ |
| 10484 | @Override |
| 10485 | public void requestUserActivityNotification() { |
| 10486 | if (!mNotifyUserActivity.get() |
| 10487 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10488 | mNotifyUserActivity.set(true); |
| 10489 | } |
| 10490 | } |
| 10491 | |
| 10492 | /** |
| 10493 | * Called when userActivity is signalled in the power manager. |
| 10494 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10495 | */ |
| 10496 | @Override |
| 10497 | public void userActivity() { |
| 10498 | // *************************************** |
| 10499 | // * Inherited from PhoneWindowManager * |
| 10500 | // *************************************** |
| 10501 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10502 | // WITH ITS LOCKS HELD. |
| 10503 | // |
| 10504 | // This code must be VERY careful about the locks |
| 10505 | // it acquires. |
| 10506 | // In fact, the current code acquires way too many, |
| 10507 | // and probably has lurking deadlocks. |
| 10508 | |
| 10509 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10510 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10511 | } |
| 10512 | |
| 10513 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10514 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10515 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10516 | } |
| 10517 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10518 | |
| 10519 | @Override |
| 10520 | public boolean canConnectTo5GInDsdsMode() { |
| 10521 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10522 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10523 | |
| 10524 | @Override |
| 10525 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10526 | String callingFeatureId) { |
| 10527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10528 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10529 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10530 | } |
| 10531 | |
| 10532 | Phone phone = getPhone(subId); |
| 10533 | if (phone == null) { |
| 10534 | throw new RuntimeException("phone is not available"); |
| 10535 | } |
| 10536 | // Now that all security checks passes, perform the operation as ourselves. |
| 10537 | final long identity = Binder.clearCallingIdentity(); |
| 10538 | try { |
| 10539 | return phone.getEquivalentHomePlmns(); |
| 10540 | } finally { |
| 10541 | Binder.restoreCallingIdentity(identity); |
| 10542 | } |
| 10543 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10544 | |
| 10545 | @Override |
| 10546 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10547 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10548 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10549 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10550 | if (radioInterfaceCapabilities == null) { |
| 10551 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10552 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10553 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10554 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10555 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10556 | @Override |
| 10557 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10558 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10559 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10560 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10561 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10562 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10563 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10564 | if (DBG) { |
| 10565 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10566 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10567 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10568 | } |
| 10569 | |
| 10570 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10571 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10572 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10573 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10574 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10575 | if (callback != null) { |
| 10576 | try { |
| 10577 | callback.onAuthenticationFailure( |
| 10578 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10579 | } catch (RemoteException exception) { |
| 10580 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10581 | } |
| 10582 | return; |
| 10583 | } |
| 10584 | } |
| 10585 | |
| 10586 | final long token = Binder.clearCallingIdentity(); |
| 10587 | try { |
| 10588 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10589 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10590 | forceBootStrapping, callback)); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10591 | } finally { |
| 10592 | Binder.restoreCallingIdentity(token); |
| 10593 | } |
| 10594 | } |
| 10595 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10596 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10597 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10598 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10599 | * requested radio power state will actually be set. See {@link |
| 10600 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10601 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10602 | * @param enable {@code true} if trying to turn radio on. |
| 10603 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10604 | * false}. |
| 10605 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10606 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10607 | boolean isPhoneAvailable = false; |
| 10608 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10609 | Phone phone = PhoneFactory.getPhone(i); |
| 10610 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10611 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10612 | isPhoneAvailable = true; |
| 10613 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10614 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10615 | |
| 10616 | // return true if successfully informed the phone object about the thermal radio power |
| 10617 | // request. |
| 10618 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10619 | } |
| 10620 | |
| 10621 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10622 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10623 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10624 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10625 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10626 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10627 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10628 | } |
| 10629 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10630 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10631 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10632 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10633 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10634 | } |
| 10635 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10636 | setDataEnabledForReason( |
| 10637 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10638 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10639 | if (isDataThrottlingSupported) { |
| 10640 | int thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10641 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10642 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10643 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10644 | } else if (thermalMitigationResult |
| 10645 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10646 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10647 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10648 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10649 | } |
| 10650 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10651 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10652 | |
| 10653 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10654 | } |
| 10655 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10656 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10657 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10658 | for (String pckg : context.getResources() |
| 10659 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10660 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10661 | } |
| 10662 | } |
| 10663 | |
| 10664 | return sThermalMitigationAllowlistedPackages; |
| 10665 | } |
| 10666 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10667 | private boolean isAnyPhoneInEmergencyState() { |
| 10668 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10669 | if (tm.isInEmergencyCall()) { |
| 10670 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10671 | return true; |
| 10672 | } |
| 10673 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10674 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10675 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10676 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10677 | + phone.isInEcm()); |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10678 | return true; |
| 10679 | } |
| 10680 | } |
| 10681 | |
| 10682 | return false; |
| 10683 | } |
| 10684 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10685 | /** |
| 10686 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10687 | * @param packageName name of package to be allowlisted |
| 10688 | * @param context |
| 10689 | */ |
| 10690 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10691 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10692 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10693 | } |
| 10694 | |
| 10695 | /** |
| 10696 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10697 | * @param packageName name of package to remove from allowlist |
| 10698 | * @param context |
| 10699 | */ |
| 10700 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10701 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10702 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10703 | } |
| 10704 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10705 | /** |
| 10706 | * Thermal mitigation request to control functionalities at modem. |
| 10707 | * |
| 10708 | * @param subId the id of the subscription. |
| 10709 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10710 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10711 | * |
| 10712 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10713 | */ |
| 10714 | @Override |
| 10715 | @ThermalMitigationResult |
| 10716 | public int sendThermalMitigationRequest( |
| 10717 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10718 | ThermalMitigationRequest thermalMitigationRequest, |
| 10719 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10720 | enforceModifyPermission(); |
| 10721 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10722 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10723 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10724 | .contains(callingPackage)) { |
| 10725 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10726 | + "calling package: " + callingPackage); |
| 10727 | } |
| 10728 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10730 | final long identity = Binder.clearCallingIdentity(); |
| 10731 | |
| 10732 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10733 | try { |
| 10734 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10735 | switch (thermalMitigationAction) { |
| 10736 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10737 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10738 | handleDataThrottlingRequest(subId, |
| 10739 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10740 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10741 | break; |
| 10742 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10743 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10744 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10745 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10746 | } |
| 10747 | |
| 10748 | // Ensure that radio is on. If not able to power on due to phone being |
| 10749 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10750 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10751 | thermalMitigationResult = |
| 10752 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10753 | break; |
| 10754 | } |
| 10755 | |
| 10756 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10757 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10758 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10759 | break; |
| 10760 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10761 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10762 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10763 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10764 | } |
| 10765 | |
| 10766 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10767 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10768 | Phone phone = getPhone(subId); |
| 10769 | if (phone == null) { |
| 10770 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10771 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10772 | break; |
| 10773 | } |
| 10774 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10775 | TelephonyConnectionService service = |
| 10776 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10777 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10778 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10779 | thermalMitigationResult = |
| 10780 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10781 | break; |
| 10782 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10783 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10784 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10785 | break; |
| 10786 | } |
| 10787 | } else { |
| 10788 | thermalMitigationResult = |
| 10789 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10790 | break; |
| 10791 | } |
| 10792 | |
| 10793 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10794 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10795 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10796 | thermalMitigationResult = |
| 10797 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10798 | break; |
| 10799 | } |
| 10800 | thermalMitigationResult = |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10801 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10802 | break; |
| 10803 | default: |
| 10804 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10805 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10806 | } |
| 10807 | } catch (IllegalArgumentException e) { |
| 10808 | throw e; |
| 10809 | } catch (Exception e) { |
| 10810 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10811 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10812 | } finally { |
| 10813 | Binder.restoreCallingIdentity(identity); |
| 10814 | } |
| 10815 | |
| 10816 | if (DBG) { |
| 10817 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10818 | + thermalMitigationResult); |
| 10819 | } |
| 10820 | |
| 10821 | return thermalMitigationResult; |
| 10822 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10823 | |
| 10824 | /** |
| 10825 | * Set the GbaService Package Name that Telephony will bind to. |
| 10826 | * |
| 10827 | * @param subId The sim that the GbaService is associated with. |
| 10828 | * @param packageName The name of the package to be replaced with. |
| 10829 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10830 | */ |
| 10831 | @Override |
| 10832 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10833 | enforceModifyPermission(); |
| 10834 | |
| 10835 | final long identity = Binder.clearCallingIdentity(); |
| 10836 | try { |
| 10837 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10838 | } finally { |
| 10839 | Binder.restoreCallingIdentity(identity); |
| 10840 | } |
| 10841 | } |
| 10842 | |
| 10843 | /** |
| 10844 | * Return the package name of the currently bound GbaService. |
| 10845 | * |
| 10846 | * @param subId The sim that the GbaService is associated with. |
| 10847 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10848 | */ |
| 10849 | @Override |
| 10850 | public String getBoundGbaService(int subId) { |
| 10851 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10852 | |
| 10853 | final long identity = Binder.clearCallingIdentity(); |
| 10854 | try { |
| 10855 | return getGbaManager(subId).getServicePackage(); |
| 10856 | } finally { |
| 10857 | Binder.restoreCallingIdentity(identity); |
| 10858 | } |
| 10859 | } |
| 10860 | |
| 10861 | /** |
| 10862 | * Set the release time for telephony to unbind GbaService. |
| 10863 | * |
| 10864 | * @param subId The sim that the GbaService is associated with. |
| 10865 | * @param interval The release time to unbind GbaService by millisecond. |
| 10866 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10867 | */ |
| 10868 | @Override |
| 10869 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10870 | enforceModifyPermission(); |
| 10871 | |
| 10872 | final long identity = Binder.clearCallingIdentity(); |
| 10873 | try { |
| 10874 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10875 | } finally { |
| 10876 | Binder.restoreCallingIdentity(identity); |
| 10877 | } |
| 10878 | } |
| 10879 | |
| 10880 | /** |
| 10881 | * Return the release time for telephony to unbind GbaService. |
| 10882 | * |
| 10883 | * @param subId The sim that the GbaService is associated with. |
| 10884 | * @return The release time to unbind GbaService by millisecond. |
| 10885 | */ |
| 10886 | @Override |
| 10887 | public int getGbaReleaseTime(int subId) { |
| 10888 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10889 | |
| 10890 | final long identity = Binder.clearCallingIdentity(); |
| 10891 | try { |
| 10892 | return getGbaManager(subId).getReleaseTime(); |
| 10893 | } finally { |
| 10894 | Binder.restoreCallingIdentity(identity); |
| 10895 | } |
| 10896 | } |
| 10897 | |
| 10898 | private GbaManager getGbaManager(int subId) { |
| 10899 | GbaManager instance = GbaManager.getInstance(subId); |
| 10900 | if (instance == null) { |
| 10901 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10902 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10903 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10904 | } |
| 10905 | return instance; |
| 10906 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10907 | |
| 10908 | /** |
| 10909 | * indicate whether the device and the carrier can support |
| 10910 | * RCS VoLTE single registration. |
| 10911 | */ |
| 10912 | @Override |
| 10913 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10914 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10915 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10916 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10917 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10918 | |
| 10919 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10920 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10921 | } |
| 10922 | |
| 10923 | final long identity = Binder.clearCallingIdentity(); |
| 10924 | try { |
| 10925 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10926 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10927 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10928 | if (isCapable != null) { |
| 10929 | return isCapable; |
| 10930 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10931 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10932 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10933 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10934 | } finally { |
| 10935 | Binder.restoreCallingIdentity(identity); |
| 10936 | } |
| 10937 | } |
| 10938 | |
| 10939 | /** |
| 10940 | * Register RCS provisioning callback. |
| 10941 | */ |
| 10942 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10943 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10944 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10945 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10946 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10947 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10948 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10949 | |
| 10950 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10951 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10952 | } |
| 10953 | if (!isImsAvailableOnDevice()) { |
| 10954 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10955 | "IMS not available on device."); |
| 10956 | } |
| 10957 | |
| 10958 | final long identity = Binder.clearCallingIdentity(); |
| 10959 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10960 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10961 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10962 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10963 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10964 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10965 | } finally { |
| 10966 | Binder.restoreCallingIdentity(identity); |
| 10967 | } |
| 10968 | } |
| 10969 | |
| 10970 | /** |
| 10971 | * Unregister RCS provisioning callback. |
| 10972 | */ |
| 10973 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10974 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10975 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10976 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10977 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10978 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10979 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10980 | |
| 10981 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10982 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10983 | } |
| 10984 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10985 | // operation failed silently |
| 10986 | Rlog.w(LOG_TAG, "IMS not available on device."); |
| 10987 | return; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10988 | } |
| 10989 | |
| 10990 | final long identity = Binder.clearCallingIdentity(); |
| 10991 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10992 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10993 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10994 | } finally { |
| 10995 | Binder.restoreCallingIdentity(identity); |
| 10996 | } |
| 10997 | } |
| 10998 | |
| 10999 | /** |
| 11000 | * trigger RCS reconfiguration. |
| 11001 | */ |
| 11002 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11003 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11004 | "triggerRcsReconfiguration", |
| 11005 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11006 | |
| 11007 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11008 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11009 | } |
| 11010 | if (!isImsAvailableOnDevice()) { |
joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11011 | // ProvisioningManager can not handle ServiceSpecificException. |
| 11012 | // Throw the IllegalStateException and annotate ProvisioningManager. |
| 11013 | throw new IllegalStateException("IMS not available on device."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11014 | } |
| 11015 | |
| 11016 | final long identity = Binder.clearCallingIdentity(); |
| 11017 | try { |
| 11018 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 11019 | } finally { |
| 11020 | Binder.restoreCallingIdentity(identity); |
| 11021 | } |
| 11022 | } |
| 11023 | |
| 11024 | /** |
| 11025 | * Provide the client configuration parameters of the RCS application. |
| 11026 | */ |
| 11027 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11028 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 11029 | "setRcsClientConfiguration", |
| 11030 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11031 | |
| 11032 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 11033 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 11034 | } |
| 11035 | if (!isImsAvailableOnDevice()) { |
| 11036 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11037 | "IMS not available on device."); |
| 11038 | } |
| 11039 | |
| 11040 | final long identity = Binder.clearCallingIdentity(); |
| 11041 | |
| 11042 | try { |
| 11043 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 11044 | if (configBinder == null) { |
| 11045 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11046 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 11047 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11048 | } else { |
| 11049 | configBinder.setRcsClientConfiguration(rcc); |
| 11050 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11051 | |
| 11052 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 11053 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11054 | } catch (RemoteException e) { |
| 11055 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11056 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 11057 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11058 | } finally { |
| 11059 | Binder.restoreCallingIdentity(identity); |
| 11060 | } |
| 11061 | } |
| 11062 | |
| 11063 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11064 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 11065 | */ |
| 11066 | @Override |
| 11067 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 11068 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11069 | "setRcsSingleRegistrationTestModeEnabled"); |
| 11070 | |
| 11071 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 11072 | } |
| 11073 | |
| 11074 | /** |
| 11075 | * Gets the test mode for RCS VoLTE single registration. |
| 11076 | */ |
| 11077 | @Override |
| 11078 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 11079 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11080 | "getRcsSingleRegistrationTestModeEnabled"); |
| 11081 | |
| 11082 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 11083 | } |
| 11084 | |
| 11085 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11086 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 11087 | */ |
| 11088 | @Override |
| 11089 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 11090 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11091 | "setDeviceSingleRegistrationEnabledOverride"); |
| 11092 | enforceModifyPermission(); |
| 11093 | |
| 11094 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11095 | : Boolean.parseBoolean(enabledStr); |
| 11096 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11097 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11098 | } |
| 11099 | |
| 11100 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11101 | * Sends a device to device communication message. Only usable via shell. |
| 11102 | * @param message message to send. |
| 11103 | * @param value message value. |
| 11104 | */ |
| 11105 | @Override |
| 11106 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 11107 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11108 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11109 | enforceModifyPermission(); |
| 11110 | |
| 11111 | final long identity = Binder.clearCallingIdentity(); |
| 11112 | try { |
| 11113 | TelephonyConnectionService service = |
| 11114 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11115 | if (service == null) { |
| 11116 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 11117 | return; |
| 11118 | } |
| 11119 | service.sendTestDeviceToDeviceMessage(message, value); |
| 11120 | } finally { |
| 11121 | Binder.restoreCallingIdentity(identity); |
| 11122 | } |
| 11123 | } |
| 11124 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11125 | /** |
| 11126 | * Sets the specified device to device transport active. |
| 11127 | * @param transport The transport to set active. |
| 11128 | */ |
| 11129 | @Override |
| 11130 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 11131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11132 | "setActiveDeviceToDeviceTransport"); |
| 11133 | enforceModifyPermission(); |
| 11134 | |
| 11135 | final long identity = Binder.clearCallingIdentity(); |
| 11136 | try { |
| 11137 | TelephonyConnectionService service = |
| 11138 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 11139 | if (service == null) { |
| 11140 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 11141 | return; |
| 11142 | } |
| 11143 | service.setActiveDeviceToDeviceTransport(transport); |
| 11144 | } finally { |
| 11145 | Binder.restoreCallingIdentity(identity); |
| 11146 | } |
| 11147 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11148 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11149 | @Override |
| 11150 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 11151 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11152 | "setDeviceToDeviceForceEnabled"); |
| 11153 | |
| 11154 | final long identity = Binder.clearCallingIdentity(); |
| 11155 | try { |
| 11156 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 11157 | p -> { |
| 11158 | Phone thePhone = p.getImsPhone(); |
| 11159 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 11160 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 11161 | CallTracker tracker = imsPhone.getCallTracker(); |
| 11162 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 11163 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 11164 | (ImsPhoneCallTracker) tracker; |
| 11165 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 11166 | } |
| 11167 | } |
| 11168 | } |
| 11169 | ); |
| 11170 | } finally { |
| 11171 | Binder.restoreCallingIdentity(identity); |
| 11172 | } |
| 11173 | } |
| 11174 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11175 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11176 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 11177 | */ |
| 11178 | @Override |
| 11179 | public boolean getDeviceSingleRegistrationEnabled() { |
| 11180 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 11181 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 11182 | } |
| 11183 | |
| 11184 | /** |
| 11185 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11186 | */ |
| 11187 | @Override |
| 11188 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 11189 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11190 | "setCarrierSingleRegistrationEnabledOverride"); |
| 11191 | enforceModifyPermission(); |
| 11192 | |
| 11193 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11194 | : Boolean.parseBoolean(enabledStr); |
| 11195 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 11196 | subId, enabled); |
| 11197 | } |
| 11198 | |
| 11199 | /** |
| 11200 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 11201 | */ |
| 11202 | @Override |
| 11203 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 11204 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 11205 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 11206 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11207 | |
| 11208 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11209 | * Overrides the ims feature validation result |
| 11210 | */ |
| 11211 | @Override |
| 11212 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 11213 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11214 | "setImsFeatureValidationOverride"); |
| 11215 | |
| 11216 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 11217 | : Boolean.parseBoolean(enabledStr); |
| 11218 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 11219 | subId, enabled); |
| 11220 | } |
| 11221 | |
| 11222 | /** |
| 11223 | * Gets the ims feature validation override value |
| 11224 | */ |
| 11225 | @Override |
| 11226 | public boolean getImsFeatureValidationOverride(int subId) { |
| 11227 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11228 | "getImsFeatureValidationOverride"); |
| 11229 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 11230 | } |
| 11231 | |
| 11232 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11233 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 11234 | * their mobile plan. |
| 11235 | */ |
| 11236 | @Override |
| 11237 | public String getMobileProvisioningUrl() { |
| 11238 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 11239 | final long identity = Binder.clearCallingIdentity(); |
| 11240 | try { |
| 11241 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 11242 | } finally { |
| 11243 | Binder.restoreCallingIdentity(identity); |
| 11244 | } |
| 11245 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11246 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11247 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11248 | * Get the EAB contact from the EAB database. |
| 11249 | */ |
| 11250 | @Override |
| 11251 | public String getContactFromEab(String contact) { |
| 11252 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 11253 | enforceModifyPermission(); |
| 11254 | final long identity = Binder.clearCallingIdentity(); |
| 11255 | try { |
| 11256 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 11257 | } finally { |
| 11258 | Binder.restoreCallingIdentity(identity); |
| 11259 | } |
| 11260 | } |
| 11261 | |
| 11262 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11263 | * Get the EAB capability from the EAB database. |
| 11264 | */ |
| 11265 | @Override |
| 11266 | public String getCapabilityFromEab(String contact) { |
| 11267 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 11268 | enforceModifyPermission(); |
| 11269 | final long identity = Binder.clearCallingIdentity(); |
| 11270 | try { |
| 11271 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 11272 | } finally { |
| 11273 | Binder.restoreCallingIdentity(identity); |
| 11274 | } |
| 11275 | } |
| 11276 | |
| 11277 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11278 | * Remove the EAB contacts from the EAB database. |
| 11279 | */ |
| 11280 | @Override |
| 11281 | public int removeContactFromEab(int subId, String contacts) { |
| 11282 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 11283 | enforceModifyPermission(); |
| 11284 | final long identity = Binder.clearCallingIdentity(); |
| 11285 | try { |
| 11286 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 11287 | } finally { |
| 11288 | Binder.restoreCallingIdentity(identity); |
| 11289 | } |
| 11290 | } |
| 11291 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11292 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11293 | public boolean getDeviceUceEnabled() { |
| 11294 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 11295 | final long identity = Binder.clearCallingIdentity(); |
| 11296 | try { |
| 11297 | return mApp.getDeviceUceEnabled(); |
| 11298 | } finally { |
| 11299 | Binder.restoreCallingIdentity(identity); |
| 11300 | } |
| 11301 | } |
| 11302 | |
| 11303 | @Override |
| 11304 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 11305 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 11306 | final long identity = Binder.clearCallingIdentity(); |
| 11307 | try { |
| 11308 | mApp.setDeviceUceEnabled(isEnabled); |
| 11309 | } finally { |
| 11310 | Binder.restoreCallingIdentity(identity); |
| 11311 | } |
| 11312 | } |
| 11313 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11314 | /** |
| 11315 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11316 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11317 | */ |
| 11318 | // Used for SHELL command only right now. |
| 11319 | @Override |
| 11320 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 11321 | List<String> featureTags) { |
| 11322 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11323 | "addUceRegistrationOverrideShell"); |
| 11324 | final long identity = Binder.clearCallingIdentity(); |
| 11325 | try { |
| 11326 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 11327 | new ArraySet<>(featureTags)); |
| 11328 | } catch (ImsException e) { |
| 11329 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11330 | } finally { |
| 11331 | Binder.restoreCallingIdentity(identity); |
| 11332 | } |
| 11333 | } |
| 11334 | |
| 11335 | /** |
| 11336 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11337 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11338 | */ |
| 11339 | // Used for SHELL command only right now. |
| 11340 | @Override |
| 11341 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11342 | List<String> featureTags) { |
| 11343 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11344 | "removeUceRegistrationOverrideShell"); |
| 11345 | final long identity = Binder.clearCallingIdentity(); |
| 11346 | try { |
| 11347 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11348 | new ArraySet<>(featureTags)); |
| 11349 | } catch (ImsException e) { |
| 11350 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11351 | } finally { |
| 11352 | Binder.restoreCallingIdentity(identity); |
| 11353 | } |
| 11354 | } |
| 11355 | |
| 11356 | /** |
| 11357 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11358 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11359 | */ |
| 11360 | // Used for SHELL command only right now. |
| 11361 | @Override |
| 11362 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11363 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11364 | "clearUceRegistrationOverrideShell"); |
| 11365 | final long identity = Binder.clearCallingIdentity(); |
| 11366 | try { |
| 11367 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11368 | } catch (ImsException e) { |
| 11369 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11370 | } finally { |
| 11371 | Binder.restoreCallingIdentity(identity); |
| 11372 | } |
| 11373 | } |
| 11374 | |
| 11375 | /** |
| 11376 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11377 | */ |
| 11378 | // Used for SHELL command only right now. |
| 11379 | @Override |
| 11380 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11381 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11382 | "getLatestRcsContactUceCapabilityShell"); |
| 11383 | final long identity = Binder.clearCallingIdentity(); |
| 11384 | try { |
| 11385 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11386 | } catch (ImsException e) { |
| 11387 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11388 | } finally { |
| 11389 | Binder.restoreCallingIdentity(identity); |
| 11390 | } |
| 11391 | } |
| 11392 | |
| 11393 | /** |
| 11394 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11395 | * device does not have an active PUBLISH. |
| 11396 | */ |
| 11397 | // Used for SHELL command only right now. |
| 11398 | @Override |
| 11399 | public String getLastUcePidfXmlShell(int subId) { |
| 11400 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11401 | final long identity = Binder.clearCallingIdentity(); |
| 11402 | try { |
| 11403 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11404 | } catch (ImsException e) { |
| 11405 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11406 | } finally { |
| 11407 | Binder.restoreCallingIdentity(identity); |
| 11408 | } |
| 11409 | } |
| 11410 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11411 | /** |
| 11412 | * Remove UCE requests cannot be sent to the network status. |
| 11413 | */ |
| 11414 | // Used for SHELL command only right now. |
| 11415 | @Override |
| 11416 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11417 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11418 | final long identity = Binder.clearCallingIdentity(); |
| 11419 | try { |
| 11420 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11421 | } catch (ImsException e) { |
| 11422 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11423 | } finally { |
| 11424 | Binder.restoreCallingIdentity(identity); |
| 11425 | } |
| 11426 | } |
| 11427 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11428 | /** |
| 11429 | * Remove UCE requests cannot be sent to the network status. |
| 11430 | */ |
| 11431 | // Used for SHELL command only. |
| 11432 | @Override |
| 11433 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11434 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11435 | final long identity = Binder.clearCallingIdentity(); |
| 11436 | try { |
| 11437 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11438 | } catch (ImsException e) { |
| 11439 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11440 | } finally { |
| 11441 | Binder.restoreCallingIdentity(identity); |
| 11442 | } |
| 11443 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11444 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11445 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11446 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11447 | String callingPackage) { |
| 11448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11449 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11450 | |
| 11451 | final int callingUid = Binder.getCallingUid(); |
| 11452 | // Verify that tha callingPackage belongs to the calling UID |
| 11453 | mApp.getSystemService(AppOpsManager.class) |
| 11454 | .checkPackage(callingUid, callingPackage); |
| 11455 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11456 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11457 | |
| 11458 | final long identity = Binder.clearCallingIdentity(); |
| 11459 | try { |
| 11460 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11461 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11462 | |
| 11463 | if (result instanceof IllegalStateException) { |
| 11464 | throw (IllegalStateException) result; |
| 11465 | } |
| 11466 | } finally { |
| 11467 | Binder.restoreCallingIdentity(identity); |
| 11468 | } |
| 11469 | } |
| 11470 | |
| 11471 | @Override |
| 11472 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11473 | String callingPackage) { |
| 11474 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11475 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11476 | |
| 11477 | final int callingUid = Binder.getCallingUid(); |
| 11478 | // Verify that tha callingPackage belongs to the calling UID |
| 11479 | mApp.getSystemService(AppOpsManager.class) |
| 11480 | .checkPackage(callingUid, callingPackage); |
| 11481 | |
| 11482 | final long identity = Binder.clearCallingIdentity(); |
| 11483 | try { |
| 11484 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11485 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11486 | |
| 11487 | if (result instanceof IllegalStateException) { |
| 11488 | throw (IllegalStateException) result; |
| 11489 | } |
| 11490 | } finally { |
| 11491 | Binder.restoreCallingIdentity(identity); |
| 11492 | } |
| 11493 | } |
| 11494 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11495 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11496 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11497 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11498 | // phone/system process do not have further restriction on request |
| 11499 | return; |
| 11500 | } |
| 11501 | |
| 11502 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11503 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11504 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11505 | context.enforceCallingOrSelfPermission( |
| 11506 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11507 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11508 | } |
| 11509 | |
| 11510 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11511 | // Only system caller can set mHysteresisMs/mIsEnabled. |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11512 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11513 | || info.isEnabled()) { |
| 11514 | throw new IllegalArgumentException( |
| 11515 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11516 | } |
| 11517 | |
| 11518 | // Thresholds length for each RAN need in range. This has been validated in |
| 11519 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11520 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11521 | final int[] thresholds = info.getThresholds(); |
| 11522 | Objects.requireNonNull(thresholds); |
| 11523 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11524 | || thresholds.length |
| 11525 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11526 | throw new IllegalArgumentException( |
| 11527 | "thresholds length is out of range: " + thresholds.length); |
| 11528 | } |
| 11529 | } |
| 11530 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11531 | |
| 11532 | /** |
| 11533 | * Gets the current phone capability. |
| 11534 | * |
| 11535 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11536 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11537 | * It's used to evaluate possible phone config change, for example from single |
| 11538 | * SIM device to multi-SIM device. |
| 11539 | */ |
| 11540 | @Override |
| 11541 | public PhoneCapability getPhoneCapability() { |
| 11542 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11543 | final long identity = Binder.clearCallingIdentity(); |
| 11544 | try { |
| 11545 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11546 | } finally { |
| 11547 | Binder.restoreCallingIdentity(identity); |
| 11548 | } |
| 11549 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11550 | |
| 11551 | /** |
| 11552 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11553 | * required to be done shortly after the API is invoked. |
| 11554 | */ |
| 11555 | @Override |
| 11556 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11557 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11558 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11559 | enforceRebootPermission(); |
| 11560 | |
| 11561 | final long identity = Binder.clearCallingIdentity(); |
| 11562 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11563 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11564 | } finally { |
| 11565 | Binder.restoreCallingIdentity(identity); |
| 11566 | } |
| 11567 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11568 | |
| 11569 | /** |
| 11570 | * Request to get the current slicing configuration including URSP rules and |
| 11571 | * NSSAIs (configured, allowed and rejected). |
| 11572 | * |
| 11573 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11574 | */ |
| 11575 | @Override |
| 11576 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11577 | TelephonyPermissions |
| 11578 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11579 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11580 | |
| 11581 | final long identity = Binder.clearCallingIdentity(); |
| 11582 | try { |
| 11583 | Phone phone = getDefaultPhone(); |
| 11584 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11585 | } finally { |
| 11586 | Binder.restoreCallingIdentity(identity); |
| 11587 | } |
| 11588 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11589 | |
| 11590 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11591 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11592 | * |
| 11593 | * @param capability The premium capability to check. |
| 11594 | * @param subId The subId to check the premium capability for. |
| 11595 | * |
| 11596 | * @return Whether the given premium capability is available to purchase. |
| 11597 | */ |
| 11598 | @Override |
| 11599 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11600 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11601 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11602 | log("Premium capability " |
| 11603 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11604 | + " is not available for purchase due to missing permissions."); |
| 11605 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11606 | + "permission READ_BASIC_PHONE_STATE."); |
| 11607 | } |
| 11608 | |
| 11609 | Phone phone = getPhone(subId); |
Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11610 | if (phone == null) { |
| 11611 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); |
| 11612 | return false; |
| 11613 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11614 | final long identity = Binder.clearCallingIdentity(); |
| 11615 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11616 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11617 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11618 | } finally { |
| 11619 | Binder.restoreCallingIdentity(identity); |
| 11620 | } |
| 11621 | } |
| 11622 | |
| 11623 | /** |
| 11624 | * Purchase the given premium capability from the carrier. |
| 11625 | * |
| 11626 | * @param capability The premium capability to purchase. |
| 11627 | * @param callback The result of the purchase request. |
| 11628 | * @param subId The subId to purchase the premium capability for. |
| 11629 | */ |
| 11630 | @Override |
| 11631 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11632 | log("purchasePremiumCapability: capability=" |
| 11633 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11634 | + getCurrentPackageName()); |
| 11635 | |
| 11636 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11637 | mApp, "purchasePremiumCapability")) { |
| 11638 | log("purchasePremiumCapability " |
| 11639 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11640 | + " failed due to missing permissions."); |
| 11641 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11642 | + "READ_BASIC_PHONE_STATE."); |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11643 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( |
| 11644 | mApp, "purchasePremiumCapability")) { |
| 11645 | log("purchasePremiumCapability " |
| 11646 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11647 | + " failed due to missing permissions."); |
| 11648 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11649 | } |
| 11650 | |
| 11651 | Phone phone = getPhone(subId); |
Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11652 | if (phone == null) { |
| 11653 | try { |
| 11654 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; |
| 11655 | callback.accept(result); |
| 11656 | loge("purchasePremiumCapability: phone is null, subId=" + subId); |
| 11657 | } catch (RemoteException e) { |
| 11658 | String logStr = "Purchase premium capability " |
| 11659 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11660 | + " failed due to RemoteException handling null phone: " + e; |
| 11661 | if (DBG) log(logStr); |
| 11662 | AnomalyReporter.reportAnomaly( |
| 11663 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11664 | } |
| 11665 | return; |
| 11666 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11667 | |
| 11668 | String callingProcess; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11669 | try { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11670 | callingProcess = mApp.getPackageManager().getApplicationInfo( |
| 11671 | getCurrentPackageName(), 0).processName; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11672 | } catch (PackageManager.NameNotFoundException e) { |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11673 | callingProcess = getCurrentPackageName(); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11674 | } |
Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11675 | |
| 11676 | boolean isVisible = false; |
| 11677 | ActivityManager am = mApp.getSystemService(ActivityManager.class); |
| 11678 | if (am != null) { |
| 11679 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); |
| 11680 | if (processes != null) { |
| 11681 | for (ActivityManager.RunningAppProcessInfo process : processes) { |
| 11682 | log("purchasePremiumCapability: process " + process.processName |
| 11683 | + "has importance " + process.importance); |
| 11684 | if (process.processName.equals(callingProcess) && process.importance |
| 11685 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { |
| 11686 | isVisible = true; |
| 11687 | break; |
| 11688 | } |
| 11689 | } |
| 11690 | } |
| 11691 | } |
| 11692 | |
| 11693 | if (!isVisible) { |
| 11694 | try { |
| 11695 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; |
| 11696 | callback.accept(result); |
| 11697 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); |
| 11698 | } catch (RemoteException e) { |
| 11699 | String logStr = "Purchase premium capability " |
| 11700 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11701 | + " failed due to RemoteException handling background application: " + e; |
| 11702 | if (DBG) log(logStr); |
| 11703 | AnomalyReporter.reportAnomaly( |
| 11704 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 11705 | } |
| 11706 | return; |
| 11707 | } |
| 11708 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11709 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11710 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11711 | } |
| 11712 | |
| 11713 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11714 | * Register an IMS connection state callback |
| 11715 | */ |
| 11716 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11717 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11718 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11719 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11720 | // ImsMmTelManager |
| 11721 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11722 | TelephonyPermissions |
| 11723 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11724 | mApp, subId, "registerImsStateCallback"); |
| 11725 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11726 | // ImsRcsManager or SipDelegateManager |
| 11727 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11728 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11729 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11730 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11731 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11732 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11733 | } |
| 11734 | |
| 11735 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11736 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11737 | "IMS not available on device."); |
| 11738 | } |
| 11739 | |
| 11740 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11742 | } |
| 11743 | |
| 11744 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11745 | if (controller == null) { |
| 11746 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11747 | "IMS not available on device."); |
| 11748 | } |
| 11749 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11750 | if (callingPackage == null) { |
| 11751 | callingPackage = getCurrentPackageName(); |
| 11752 | } |
| 11753 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11754 | final long token = Binder.clearCallingIdentity(); |
| 11755 | try { |
| 11756 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11757 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11758 | } catch (ImsException e) { |
| 11759 | throw new ServiceSpecificException(e.getCode()); |
| 11760 | } finally { |
| 11761 | Binder.restoreCallingIdentity(token); |
| 11762 | } |
| 11763 | } |
| 11764 | |
| 11765 | /** |
| 11766 | * Unregister an IMS connection state callback |
| 11767 | */ |
| 11768 | @Override |
| 11769 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11770 | final long token = Binder.clearCallingIdentity(); |
| 11771 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11772 | if (controller == null) { |
| 11773 | return; |
| 11774 | } |
| 11775 | try { |
| 11776 | controller.unregisterImsStateCallback(cb); |
| 11777 | } finally { |
| 11778 | Binder.restoreCallingIdentity(token); |
| 11779 | } |
| 11780 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11781 | |
| 11782 | /** |
| 11783 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11784 | * |
| 11785 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11786 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11787 | * SecurityException. |
| 11788 | * If there is current registered network this value will be same as the registered cell |
| 11789 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11790 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11791 | * it will be cleared and null will be returned. |
| 11792 | * |
| 11793 | */ |
| 11794 | @Override |
| 11795 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11796 | String callingFeatureId) { |
| 11797 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11798 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11799 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11800 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11801 | .setCallingPackage(callingPackage) |
| 11802 | .setCallingFeatureId(callingFeatureId) |
| 11803 | .setCallingPid(Binder.getCallingPid()) |
| 11804 | .setCallingUid(Binder.getCallingUid()) |
| 11805 | .setMethod("getLastKnownCellIdentity") |
| 11806 | .setLogAsInfo(true) |
| 11807 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11808 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11809 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11810 | .build()); |
| 11811 | |
| 11812 | boolean hasFinePermission = |
| 11813 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11814 | if (!hasFinePermission |
| 11815 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11816 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11817 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11818 | } |
| 11819 | |
| 11820 | final long identity = Binder.clearCallingIdentity(); |
| 11821 | try { |
Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11822 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11823 | if (sst == null) return null; |
| 11824 | return sst.getLastKnownCellIdentity(); |
| 11825 | } finally { |
| 11826 | Binder.restoreCallingIdentity(identity); |
| 11827 | } |
| 11828 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11829 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11830 | /** |
| 11831 | * Sets the modem service class Name that Telephony will bind to. |
| 11832 | * |
| 11833 | * @param serviceName The class name of the modem service. |
| 11834 | * @return true if the operation is succeed, otherwise false. |
| 11835 | */ |
| 11836 | public boolean setModemService(String serviceName) { |
| 11837 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11838 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11840 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11841 | "setModemService"); |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11842 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11843 | } |
| 11844 | |
| 11845 | /** |
| 11846 | * Return the class name of the currently bounded modem service. |
| 11847 | * |
| 11848 | * @return the class name of the modem service. |
| 11849 | */ |
| 11850 | public String getModemService() { |
| 11851 | String result; |
| 11852 | Log.d(LOG_TAG, "getModemService"); |
| 11853 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11854 | TelephonyPermissions |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11855 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11856 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11857 | "getModemService"); |
| 11858 | result = mPhoneConfigurationManager.getModemService(); |
| 11859 | Log.d(LOG_TAG, "result = " + result); |
| 11860 | return result; |
| 11861 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11862 | |
| 11863 | @Override |
| 11864 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11865 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11866 | mApp.enforceCallingOrSelfPermission( |
| 11867 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11868 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11869 | |
| 11870 | final long identity = Binder.clearCallingIdentity(); |
| 11871 | try { |
| 11872 | Phone phone = getPhone(subId); |
| 11873 | if (phone == null) return; |
Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11874 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone |
| 11875 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11876 | phone.setVoiceServiceStateOverride(hasService); |
| 11877 | } finally { |
| 11878 | Binder.restoreCallingIdentity(identity); |
| 11879 | } |
| 11880 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11881 | |
| 11882 | /** |
| 11883 | * set removable eSIM as default eUICC. |
| 11884 | * |
| 11885 | * @hide |
| 11886 | */ |
| 11887 | @Override |
| 11888 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11889 | enforceModifyPermission(); |
| 11890 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11891 | |
| 11892 | final long identity = Binder.clearCallingIdentity(); |
| 11893 | try { |
| 11894 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11895 | } finally { |
| 11896 | Binder.restoreCallingIdentity(identity); |
| 11897 | } |
| 11898 | } |
| 11899 | |
| 11900 | /** |
| 11901 | * Returns whether the removable eSIM is default eUICC or not. |
| 11902 | * |
| 11903 | * @hide |
| 11904 | */ |
| 11905 | @Override |
| 11906 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11907 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11909 | |
| 11910 | final long identity = Binder.clearCallingIdentity(); |
| 11911 | try { |
| 11912 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11913 | } finally { |
| 11914 | Binder.restoreCallingIdentity(identity); |
| 11915 | } |
| 11916 | } |
| 11917 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11918 | /** |
| 11919 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11920 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11921 | * application currently configured for this user. |
| 11922 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11923 | * {@code null} if the functionality is not supported. |
| 11924 | * @hide |
| 11925 | */ |
| 11926 | @Override |
| 11927 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11928 | boolean updateIfNeeded) { |
| 11929 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11930 | |
Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11931 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); |
| 11932 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11933 | UserHandle userHandle = null; |
| 11934 | final long identity = Binder.clearCallingIdentity(); |
| 11935 | try { |
| 11936 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11937 | } finally { |
| 11938 | Binder.restoreCallingIdentity(identity); |
| 11939 | } |
| 11940 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11941 | updateIfNeeded, userHandle); |
| 11942 | } |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11943 | |
| 11944 | /** |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11945 | * Set whether the device is able to connect with null ciphering or integrity |
| 11946 | * algorithms. This is a global setting and will apply to all active subscriptions |
| 11947 | * and all new subscriptions after this. |
| 11948 | * |
| 11949 | * @param enabled when true, null cipher and integrity algorithms are allowed. |
| 11950 | * @hide |
| 11951 | */ |
| 11952 | @Override |
| 11953 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 11954 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { |
| 11955 | enforceModifyPermission(); |
| 11956 | checkForNullCipherAndIntegritySupport(); |
| 11957 | |
| 11958 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible |
| 11959 | // for listening to these preference changes and applying them immediately. |
| 11960 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 11961 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); |
| 11962 | editor.apply(); |
| 11963 | |
| 11964 | for (Phone phone: PhoneFactory.getPhones()) { |
| 11965 | phone.handleNullCipherEnabledChange(); |
| 11966 | } |
| 11967 | } |
| 11968 | |
| 11969 | |
| 11970 | /** |
| 11971 | * Get whether the device is able to connect with null ciphering or integrity |
| 11972 | * algorithms. Note that this retrieves the phone-global preference and not |
| 11973 | * the state of the radio. |
| 11974 | * |
| 11975 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied |
| 11976 | * @throws UnsupportedOperationException if the device does not support the minimum HAL |
| 11977 | * version for this feature. |
| 11978 | * @hide |
| 11979 | */ |
| 11980 | @Override |
| 11981 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) |
| 11982 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { |
| 11983 | enforceReadPermission(); |
| 11984 | checkForNullCipherAndIntegritySupport(); |
| 11985 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); |
| 11986 | } |
| 11987 | |
| 11988 | private void checkForNullCipherAndIntegritySupport() { |
| 11989 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { |
| 11990 | throw new UnsupportedOperationException( |
| 11991 | "Null cipher and integrity operations require HAL 2.1 or above"); |
| 11992 | } |
Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11993 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { |
| 11994 | throw new UnsupportedOperationException( |
| 11995 | "Null cipher and integrity operations unsupported by modem"); |
| 11996 | } |
Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11997 | } |
| 11998 | |
| 11999 | /** |
Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 12000 | * Get the SIM state for the slot index. |
| 12001 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} |
| 12002 | * |
| 12003 | * @return SIM state as the ordinal of {@link IccCardConstants.State} |
| 12004 | */ |
| 12005 | @Override |
| 12006 | @SimState |
| 12007 | public int getSimStateForSlotIndex(int slotIndex) { |
| 12008 | IccCardConstants.State simState; |
| 12009 | if (slotIndex < 0) { |
| 12010 | simState = IccCardConstants.State.UNKNOWN; |
| 12011 | } else { |
| 12012 | Phone phone = null; |
| 12013 | try { |
| 12014 | phone = PhoneFactory.getPhone(slotIndex); |
| 12015 | } catch (IllegalStateException e) { |
| 12016 | // ignore |
| 12017 | } |
| 12018 | if (phone == null) { |
| 12019 | simState = IccCardConstants.State.UNKNOWN; |
| 12020 | } else { |
| 12021 | IccCard icc = phone.getIccCard(); |
| 12022 | if (icc == null) { |
| 12023 | simState = IccCardConstants.State.UNKNOWN; |
| 12024 | } else { |
| 12025 | simState = icc.getState(); |
| 12026 | } |
| 12027 | } |
| 12028 | } |
| 12029 | return simState.ordinal(); |
| 12030 | } |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12031 | |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12032 | private void persistEmergencyCallDiagnosticDataInternal(@NonNull String dropboxTag, |
| 12033 | boolean enableLogcat, |
| 12034 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12035 | boolean enableTelephonyDump) { |
Chinmay Dhodapkar | 66262c4 | 2023-03-10 15:47:41 -0800 | [diff] [blame] | 12036 | DropBoxManager db = mApp.getSystemService(DropBoxManager.class); |
| 12037 | TelephonyManager.EmergencyCallDiagnosticParams edp = |
| 12038 | new TelephonyManager.EmergencyCallDiagnosticParams(); |
| 12039 | edp.setLogcatCollection(enableLogcat, logcatStartTimestampMillis); |
| 12040 | edp.setTelephonyDumpSysCollection(enableTelephonyDump); |
| 12041 | edp.setTelecomDumpSysCollection(enableTelecomDump); |
| 12042 | Log.d(LOG_TAG, "persisting with Params " + edp.toString()); |
| 12043 | DiagnosticDataCollector ddc = new DiagnosticDataCollector(Runtime.getRuntime(), |
| 12044 | Executors.newCachedThreadPool(), db, |
| 12045 | mApp.getSystemService(ActivityManager.class).isLowRamDevice()); |
| 12046 | ddc.persistEmergencyDianosticData(new DataCollectorConfig.Adapter(), edp, dropboxTag); |
Chinmay Dhodapkar | 3e11ced | 2023-03-03 19:44:00 -0800 | [diff] [blame] | 12047 | } |
| 12048 | |
| 12049 | /** |
| 12050 | * Request telephony to persist state for debugging emergency call failures. |
| 12051 | * |
| 12052 | * @param dropBoxTag Tag to use when persisting data to dropbox service. |
| 12053 | * @param enableLogcat whether to collect logcat output |
| 12054 | * @param logcatStartTimestampMillis timestamp from when logcat buffers would be persisted |
| 12055 | * @param enableTelecomDump whether to collect telecom dumpsys |
| 12056 | * @param enableTelephonyDump whether to collect telephony dumpsys |
| 12057 | */ |
| 12058 | @Override |
| 12059 | @RequiresPermission(android.Manifest.permission.DUMP) |
| 12060 | public void persistEmergencyCallDiagnosticData(@NonNull String dropboxTag, boolean enableLogcat, |
| 12061 | long logcatStartTimestampMillis, boolean enableTelecomDump, |
| 12062 | boolean enableTelephonyDump) { |
| 12063 | mApp.enforceCallingPermission(android.Manifest.permission.DUMP, |
| 12064 | "persistEmergencyCallDiagnosticData"); |
| 12065 | final long identity = Binder.clearCallingIdentity(); |
| 12066 | try { |
| 12067 | persistEmergencyCallDiagnosticDataInternal(dropboxTag, enableLogcat, |
| 12068 | logcatStartTimestampMillis, enableTelecomDump, enableTelephonyDump); |
| 12069 | |
| 12070 | } finally { |
| 12071 | Binder.restoreCallingIdentity(identity); |
| 12072 | } |
| 12073 | } |
| 12074 | |
Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12075 | /** |
| 12076 | * Get current cell broadcast ranges. |
| 12077 | */ |
| 12078 | @Override |
| 12079 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12080 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { |
| 12081 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12082 | "getCellBroadcastIdRanges"); |
| 12083 | final long identity = Binder.clearCallingIdentity(); |
| 12084 | try { |
| 12085 | return getPhone(subId).getCellBroadcastIdRanges(); |
| 12086 | } finally { |
| 12087 | Binder.restoreCallingIdentity(identity); |
| 12088 | } |
| 12089 | } |
| 12090 | |
| 12091 | /** |
| 12092 | * Set reception of cell broadcast messages with the list of the given ranges |
| 12093 | * |
| 12094 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled |
| 12095 | */ |
| 12096 | @Override |
| 12097 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) |
| 12098 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, |
| 12099 | @Nullable IIntegerConsumer callback) { |
| 12100 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, |
| 12101 | "setCellBroadcastIdRanges"); |
| 12102 | final long identity = Binder.clearCallingIdentity(); |
| 12103 | try { |
| 12104 | Phone phone = getPhoneFromSubId(subId); |
| 12105 | if (DBG) { |
| 12106 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); |
| 12107 | } |
| 12108 | phone.setCellBroadcastIdRanges(ranges, result -> { |
| 12109 | if (callback != null) { |
| 12110 | try { |
| 12111 | callback.accept(result); |
| 12112 | } catch (RemoteException e) { |
| 12113 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); |
| 12114 | } |
| 12115 | } |
| 12116 | }); |
| 12117 | } finally { |
| 12118 | Binder.restoreCallingIdentity(identity); |
| 12119 | } |
| 12120 | } |
Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12121 | |
| 12122 | /** |
| 12123 | * Returns whether the device supports the domain selection service. |
| 12124 | * |
| 12125 | * @return {@code true} if the device supports the domain selection service. |
| 12126 | */ |
| 12127 | @Override |
| 12128 | public boolean isDomainSelectionSupported() { |
| 12129 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 12130 | "isDomainSelectionSupported"); |
| 12131 | |
| 12132 | final long identity = Binder.clearCallingIdentity(); |
| 12133 | try { |
| 12134 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); |
| 12135 | } finally { |
| 12136 | Binder.restoreCallingIdentity(identity); |
| 12137 | } |
| 12138 | } |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12139 | |
| 12140 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12141 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is |
| 12142 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, |
| 12143 | * this may also re-enable the cellular modem. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12144 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12145 | * @param subId The subId of the subscription to set satellite enabled for. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12146 | * @param enableSatellite {@code true} to enable the satellite modem and |
| 12147 | * {@code false} to disable. |
| 12148 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. |
| 12149 | * @param callback The callback to get the result of the request. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12150 | * |
| 12151 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12152 | */ |
| 12153 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12154 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, |
| 12155 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12156 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12157 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, |
| 12158 | callback); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12159 | } |
| 12160 | |
| 12161 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12162 | * Request to get whether the satellite modem is enabled. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12163 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12164 | * @param subId The subId of the subscription to check whether satellite is enabled for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12165 | * @param result The result receiver that returns whether the satellite modem is enabled |
| 12166 | * if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12167 | * |
| 12168 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12169 | */ |
| 12170 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12171 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { |
| 12172 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12173 | mSatelliteController.requestIsSatelliteEnabled(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12174 | } |
| 12175 | |
| 12176 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12177 | * Request to get whether the satellite service demo mode is enabled. |
| 12178 | * |
| 12179 | * @param subId The subId of the subscription to check whether the satellite demo mode |
| 12180 | * is enabled for. |
| 12181 | * @param result The result receiver that returns whether the satellite demo mode is enabled |
| 12182 | * if the request is successful or an error code if the request failed. |
| 12183 | * |
| 12184 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12185 | */ |
| 12186 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12187 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { |
| 12188 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); |
| 12189 | mSatelliteController.requestIsDemoModeEnabled(subId, result); |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12190 | } |
| 12191 | |
| 12192 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12193 | * Request to get whether the satellite service is supported on the device. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12194 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12195 | * @param subId The subId of the subscription to check satellite service support for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12196 | * @param result The result receiver that returns whether the satellite service is supported on |
| 12197 | * the device if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12198 | */ |
| 12199 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12200 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12201 | mSatelliteController.requestIsSatelliteSupported(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12202 | } |
| 12203 | |
| 12204 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12205 | * Request to get the {@link SatelliteCapabilities} of the satellite service. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12206 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12207 | * @param subId The subId of the subscription to get the satellite capabilities for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12208 | * @param result The result receiver that returns the {@link SatelliteCapabilities} |
| 12209 | * if the request is successful or an error code if the request failed. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12210 | * |
| 12211 | * @throws SecurityException if the caller doesn't have required permission. |
| 12212 | */ |
| 12213 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12214 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { |
| 12215 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12216 | mSatelliteController.requestSatelliteCapabilities(subId, result); |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12217 | } |
| 12218 | |
| 12219 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12220 | * Start receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12221 | * This can be called by the pointing UI when the user starts pointing to the satellite. |
| 12222 | * Modem should continue to report the pointing input as the device or satellite moves. |
| 12223 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12224 | * @param subId The subId of the subscription to start satellite transmission updates for. |
| 12225 | * @param resultCallback The callback to get the result of the request. |
| 12226 | * @param callback The callback to notify of satellite transmission updates. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12227 | * |
| 12228 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12229 | */ |
| 12230 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12231 | public void startSatelliteTransmissionUpdates(int subId, |
| 12232 | @NonNull IIntegerConsumer resultCallback, |
| 12233 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12234 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); |
| 12235 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12236 | } |
| 12237 | |
| 12238 | /** |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12239 | * Stop receiving satellite transmission updates. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12240 | * This can be called by the pointing UI when the user stops pointing to the satellite. |
| 12241 | * |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12242 | * @param subId The subId of the subscription to stop satellite transmission updates for. |
| 12243 | * @param resultCallback The callback to get the result of the request. |
| 12244 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( |
| 12245 | * int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. |
Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12246 | * |
| 12247 | * @throws SecurityException if the caller doesn't have the required permission. |
Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12248 | */ |
| 12249 | @Override |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12250 | public void stopSatelliteTransmissionUpdates(int subId, |
| 12251 | @NonNull IIntegerConsumer resultCallback, |
| 12252 | @NonNull ISatelliteTransmissionUpdateCallback callback) { |
| 12253 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); |
| 12254 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); |
Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12255 | } |
| 12256 | |
| 12257 | /** |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12258 | * Register the subscription with a satellite provider. |
| 12259 | * This is needed to register the subscription if the provider allows dynamic registration. |
| 12260 | * |
| 12261 | * @param subId The subId of the subscription to be provisioned. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12262 | * @param token The token to be used as a unique identifier for provisioning with satellite |
| 12263 | * gateway. |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame^] | 12264 | * @param provisionData Data from the provisioning app that can be used by provisioning server |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12265 | * @param callback The callback to get the result of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12266 | * |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12267 | * @return The signal transport used by the caller to cancel the provision request, |
| 12268 | * or {@code null} if the request failed. |
| 12269 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12270 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12271 | */ |
| 12272 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12273 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame^] | 12274 | @NonNull String token, @NonNull byte[] provisionData, |
| 12275 | @NonNull IIntegerConsumer callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12276 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); |
Aishwarya Mallampati | 8b2310c | 2023-03-28 22:01:43 +0000 | [diff] [blame^] | 12277 | return mSatelliteController.provisionSatelliteService(subId, token, provisionData, |
| 12278 | callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12279 | } |
| 12280 | |
| 12281 | /** |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12282 | * Unregister the device/subscription with the satellite provider. |
| 12283 | * This is needed if the provider allows dynamic registration. Once deprovisioned, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12284 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12285 | * should report as deprovisioned. |
| 12286 | * |
| 12287 | * @param subId The subId of the subscription to be deprovisioned. |
| 12288 | * @param token The token of the device/subscription to be deprovisioned. |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12289 | * @param callback The callback to get the result of the request. |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12290 | * |
| 12291 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12292 | */ |
| 12293 | @Override |
| 12294 | public void deprovisionSatelliteService(int subId, |
| 12295 | @NonNull String token, @NonNull IIntegerConsumer callback) { |
| 12296 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12297 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); |
Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12298 | } |
| 12299 | |
| 12300 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12301 | * Registers for the satellite provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12302 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12303 | * @param subId The subId of the subscription to register for provision state changed. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12304 | * @param callback The callback to handle the satellite provision state changed event. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12305 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12306 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12307 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12308 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12309 | */ |
| 12310 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12311 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12312 | @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12313 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12314 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12315 | } |
| 12316 | |
| 12317 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12318 | * Unregisters for the satellite provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12319 | * If callback was not registered before, the request will be ignored. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12320 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12321 | * @param subId The subId of the subscription to unregister for provision state changed. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12322 | * @param callback The callback that was passed to |
| 12323 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12324 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12325 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12326 | */ |
| 12327 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12328 | public void unregisterForSatelliteProvisionStateChanged( |
| 12329 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12330 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12331 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12332 | } |
| 12333 | |
| 12334 | /** |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12335 | * Request to get whether the device is provisioned with a satellite provider. |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12336 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12337 | * @param subId The subId of the subscription to get whether the device is provisioned for. |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12338 | * @param result The result receiver that returns whether the device is provisioned with a |
| 12339 | * satellite provider if the request is successful or an error code if the |
| 12340 | * request failed. |
| 12341 | * |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12342 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12343 | */ |
| 12344 | @Override |
Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12345 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { |
| 12346 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12347 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12348 | } |
| 12349 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12350 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12351 | * Registers for modem state changed from satellite modem. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12352 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12353 | * @param subId The subId of the subscription to register for satellite modem state changed. |
| 12354 | * @param callback The callback to handle the satellite modem state changed event. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12355 | * |
| 12356 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12357 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12358 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12359 | */ |
| 12360 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12361 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12362 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12363 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12364 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12365 | } |
| 12366 | |
| 12367 | /** |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12368 | * Unregisters for modem state changed from satellite modem. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12369 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12370 | * |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12371 | * @param subId The subId of the subscription to unregister for satellite modem state changed. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12372 | * @param callback The callback that was passed to |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12373 | * {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12374 | * |
| 12375 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12376 | */ |
| 12377 | @Override |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12378 | public void unregisterForSatelliteModemStateChanged(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12379 | @NonNull ISatelliteStateCallback callback) { |
Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12380 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12381 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12382 | } |
| 12383 | |
| 12384 | /** |
| 12385 | * Register to receive incoming datagrams over satellite. |
| 12386 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12387 | * @param subId The subId of the subscription to register for incoming satellite datagrams. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12388 | * @param callback The callback to handle incoming datagrams over satellite. |
| 12389 | * |
| 12390 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. |
| 12391 | * |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12392 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12393 | */ |
| 12394 | @Override |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12395 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12396 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12397 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12398 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12399 | } |
| 12400 | |
| 12401 | /** |
| 12402 | * Unregister to stop receiving incoming datagrams over satellite. |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12403 | * If callback was not registered before, the request will be ignored. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12404 | * |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12405 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. |
| 12406 | * @param callback The callback that was passed to |
Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12407 | * {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12408 | * |
| 12409 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12410 | */ |
| 12411 | @Override |
Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12412 | public void unregisterForSatelliteDatagram(int subId, |
| 12413 | @NonNull ISatelliteDatagramCallback callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12414 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12415 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12416 | } |
| 12417 | |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12418 | /** |
| 12419 | * Poll pending satellite datagrams over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12420 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12421 | * This method requests modem to check if there are any pending datagrams to be received over |
| 12422 | * satellite. If there are any incoming datagrams, they will be received via |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12423 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12424 | * ILongConsumer)})} |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12425 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12426 | * @param subId The subId of the subscription used for receiving datagrams. |
| 12427 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12428 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12429 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12430 | */ |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12431 | @Override |
| 12432 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12433 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12434 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); |
Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12435 | } |
| 12436 | |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12437 | /** |
| 12438 | * Send datagram over satellite. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12439 | * |
Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12440 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as |
| 12441 | * input to this method. Datagram received here will be passed down to modem without any |
| 12442 | * encoding or encryption. |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12443 | * |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12444 | * @param subId The subId of the subscription to send satellite datagrams for. |
| 12445 | * @param datagramType datagram type indicating whether the datagram is of type |
| 12446 | * SOS_SMS or LOCATION_SHARING. |
| 12447 | * @param datagram encoded gateway datagram which is encrypted by the caller. |
| 12448 | * Datagram will be passed down to modem without any encoding or encryption. |
Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12449 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in |
| 12450 | * full screen mode. |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12451 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. |
Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12452 | * |
| 12453 | * @throws SecurityException if the caller doesn't have required permission. |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12454 | */ |
| 12455 | @Override |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12456 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, |
| 12457 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, |
| 12458 | @NonNull IIntegerConsumer callback) { |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12459 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); |
Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12460 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, |
| 12461 | needFullScreenPointingUI, callback); |
Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12462 | } |
| 12463 | |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12464 | /** |
| 12465 | * Request to get whether satellite communication is allowed for the current location. |
| 12466 | * |
| 12467 | * @param subId The subId of the subscription to check whether satellite communication is |
| 12468 | * allowed for the current location for. |
| 12469 | * @param result The result receiver that returns whether satellite communication is allowed |
| 12470 | * for the current location if the request is successful or an error code |
| 12471 | * if the request failed. |
| 12472 | * |
| 12473 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12474 | */ |
| 12475 | @Override |
| 12476 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, |
| 12477 | @NonNull ResultReceiver result) { |
| 12478 | enforceSatelliteCommunicationPermission( |
| 12479 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12480 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, |
| 12481 | result); |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12482 | } |
| 12483 | |
| 12484 | /** |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12485 | * Request to get the time after which the satellite will be visible |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12486 | * |
Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12487 | * @param subId The subId to get the time after which the satellite will be visible for. |
| 12488 | * @param result The result receiver that returns the time after which the satellite will |
Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12489 | * be visible if the request is successful or an error code if the request failed. |
| 12490 | * |
| 12491 | * @throws SecurityException if the caller doesn't have the required permission. |
| 12492 | */ |
| 12493 | @Override |
| 12494 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { |
| 12495 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); |
Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12496 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12497 | } |
| 12498 | |
Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12499 | /** |
arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12500 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. |
| 12501 | * |
| 12502 | * <p>This method behaves in one of the following ways: |
| 12503 | * <ul> |
| 12504 | * <li>return true : if the calling package has the appop permission {@link |
| 12505 | * Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> |
| 12506 | * <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE |
| 12507 | * permission, the calling package passes a DevicePolicyManager Device Owner / Profile |
| 12508 | * Owner device identifier access check, or the calling package has carrier privileges</> |
| 12509 | * <li>throw SecurityException: if the caller does not meet any of the requirements. |
| 12510 | * </ul> |
| 12511 | */ |
| 12512 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, |
| 12513 | String callingPackage, @Nullable String callingFeatureId, String message) { |
| 12514 | for (Phone phone : PhoneFactory.getPhones()) { |
| 12515 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, |
| 12516 | phone.getSubId(), callingPackage, callingFeatureId, message)) { |
| 12517 | return true; |
| 12518 | } |
| 12519 | } |
| 12520 | return false; |
| 12521 | } |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12522 | |
| 12523 | /** |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12524 | * @return The subscription manager service instance. |
| 12525 | */ |
| 12526 | public SubscriptionManagerService getSubscriptionManagerService() { |
| 12527 | return SubscriptionManagerService.getInstance(); |
| 12528 | } |
| 12529 | |
| 12530 | /** |
arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12531 | * Class binds the consumer[callback] and carrierId. |
| 12532 | */ |
| 12533 | private static class CallerCallbackInfo { |
| 12534 | private final Consumer<Integer> mConsumer; |
| 12535 | private final int mCarrierId; |
| 12536 | |
| 12537 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { |
| 12538 | mConsumer = consumer; |
| 12539 | mCarrierId = carrierId; |
| 12540 | } |
| 12541 | |
| 12542 | public Consumer<Integer> getConsumer() { |
| 12543 | return mConsumer; |
| 12544 | } |
| 12545 | |
| 12546 | public int getCarrierId() { |
| 12547 | return mCarrierId; |
| 12548 | } |
| 12549 | } |
Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12550 | } |