| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | package com.android.phone; | 
|  | 18 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 20 | import static android.telephony.TelephonyManager.HAL_SERVICE_NETWORK; | 
| jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 21 | import static android.telephony.TelephonyManager.HAL_SERVICE_RADIO; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 22 |  | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; | 
|  | 24 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 25 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; | 
| joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 27 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 28 |  | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 29 | import android.Manifest; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 30 | import android.Manifest.permission; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 31 | import android.annotation.NonNull; | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 33 | import android.annotation.RequiresPermission; | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 34 | import android.app.ActivityManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 35 | import android.app.AppOpsManager; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 36 | import android.app.PendingIntent; | 
| Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 37 | import android.app.PropertyInvalidatedCache; | 
| Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 38 | import android.app.compat.CompatChanges; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 39 | import android.app.role.RoleManager; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 40 | import android.compat.annotation.ChangeId; | 
|  | 41 | import android.compat.annotation.EnabledSince; | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 42 | import android.content.ComponentName; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 43 | import android.content.ContentResolver; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 44 | import android.content.Context; | 
|  | 45 | import android.content.Intent; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 46 | import android.content.SharedPreferences; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 47 | import android.content.pm.ComponentInfo; | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 48 | import android.content.pm.PackageManager; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.net.Uri; | 
|  | 50 | import android.os.AsyncResult; | 
|  | 51 | import android.os.Binder; | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 52 | import android.os.Build; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Bundle; | 
|  | 54 | import android.os.Handler; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.IBinder; | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 56 | import android.os.ICancellationSignal; | 
| tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 57 | import android.os.LocaleList; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 58 | import android.os.Looper; | 
|  | 59 | import android.os.Message; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 60 | import android.os.Messenger; | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 61 | import android.os.ParcelFileDescriptor; | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 62 | import android.os.ParcelUuid; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 63 | import android.os.PersistableBundle; | 
| Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 64 | import android.os.Process; | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 65 | import android.os.RemoteException; | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 66 | import android.os.ResultReceiver; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 67 | import android.os.ServiceSpecificException; | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 68 | import android.os.SystemClock; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 69 | import android.os.UserHandle; | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 70 | import android.os.UserManager; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 71 | import android.os.WorkSource; | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 72 | import android.preference.PreferenceManager; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 73 | import android.provider.DeviceConfig; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 74 | import android.provider.Settings; | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 75 | import android.provider.Telephony; | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 76 | import android.service.carrier.CarrierIdentifier; | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 77 | import android.sysprop.TelephonyProperties; | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 78 | import android.telecom.PhoneAccount; | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 79 | import android.telecom.PhoneAccountHandle; | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 80 | import android.telecom.TelecomManager; | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 81 | import android.telephony.AccessNetworkConstants; | 
|  | 82 | import android.telephony.ActivityStatsTechSpecificInfo; | 
| Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 83 | import android.telephony.Annotation.ApnType; | 
| Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 84 | import android.telephony.Annotation.DataActivityType; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 85 | import android.telephony.Annotation.ThermalMitigationResult; | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 86 | import android.telephony.AnomalyReporter; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 87 | import android.telephony.CallForwardingInfo; | 
| Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 88 | import android.telephony.CarrierConfigManager; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 89 | import android.telephony.CarrierRestrictionRules; | 
| Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 90 | import android.telephony.CellBroadcastIdRange; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 91 | import android.telephony.CellIdentity; | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 92 | import android.telephony.CellIdentityCdma; | 
|  | 93 | import android.telephony.CellIdentityGsm; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 94 | import android.telephony.CellInfo; | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 95 | import android.telephony.CellInfoGsm; | 
|  | 96 | import android.telephony.CellInfoWcdma; | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 97 | import android.telephony.ClientRequestStats; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 98 | import android.telephony.DataThrottlingRequest; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 99 | import android.telephony.IBootstrapAuthenticationCallback; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 100 | import android.telephony.ICellInfoCallback; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 101 | import android.telephony.IccOpenLogicalChannelResponse; | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 102 | import android.telephony.LocationAccessPolicy; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 103 | import android.telephony.ModemActivityInfo; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 104 | import android.telephony.NeighboringCellInfo; | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 105 | import android.telephony.NetworkScanRequest; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 106 | import android.telephony.PhoneCapability; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 107 | import android.telephony.PhoneNumberRange; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 108 | import android.telephony.RadioAccessFamily; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 109 | import android.telephony.RadioAccessSpecifier; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 110 | import android.telephony.ServiceState; | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 111 | import android.telephony.SignalStrength; | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 112 | import android.telephony.SignalStrengthUpdateRequest; | 
|  | 113 | import android.telephony.SignalThresholdInfo; | 
| Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 114 | import android.telephony.SubscriptionInfo; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 115 | import android.telephony.SubscriptionManager; | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 116 | import android.telephony.TelephonyFrameworkInitializer; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 117 | import android.telephony.TelephonyHistogram; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 118 | import android.telephony.TelephonyManager; | 
| Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 119 | import android.telephony.TelephonyManager.SimState; | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 120 | import android.telephony.TelephonyScanManager; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 121 | import android.telephony.ThermalMitigationRequest; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 122 | import android.telephony.UiccCardInfo; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 123 | import android.telephony.UiccPortInfo; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 124 | import android.telephony.UiccSlotInfo; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 125 | import android.telephony.UiccSlotMapping; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 126 | import android.telephony.UssdResponse; | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 127 | import android.telephony.VisualVoicemailSmsFilterSettings; | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 128 | import android.telephony.data.NetworkSlicingConfig; | 
| Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 129 | import android.telephony.emergency.EmergencyNumber; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 130 | import android.telephony.gba.GbaAuthRequest; | 
|  | 131 | import android.telephony.gba.UaSecurityProtocolIdentifier; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 132 | import android.telephony.ims.ImsException; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 133 | import android.telephony.ims.ProvisioningManager; | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 134 | import android.telephony.ims.RcsClientConfiguration; | 
| Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 135 | import android.telephony.ims.RcsContactUceCapability; | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 136 | import android.telephony.ims.RegistrationManager; | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 137 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 138 | import android.telephony.ims.aidl.IImsCapabilityCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 139 | import android.telephony.ims.aidl.IImsConfig; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 140 | import android.telephony.ims.aidl.IImsConfigCallback; | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 141 | import android.telephony.ims.aidl.IImsRegistration; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 142 | import android.telephony.ims.aidl.IImsRegistrationCallback; | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 143 | import android.telephony.ims.aidl.IRcsConfigCallback; | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 144 | import android.telephony.ims.feature.ImsFeature; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 145 | import android.telephony.ims.stub.ImsConfigImplBase; | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 146 | import android.telephony.ims.stub.ImsRegistrationImplBase; | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 147 | import android.telephony.satellite.ISatelliteDatagramCallback; | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 148 | import android.telephony.satellite.ISatelliteProvisionStateCallback; | 
|  | 149 | import android.telephony.satellite.ISatelliteStateCallback; | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 150 | import android.telephony.satellite.ISatelliteTransmissionUpdateCallback; | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 151 | import android.telephony.satellite.SatelliteCapabilities; | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 152 | import android.telephony.satellite.SatelliteDatagram; | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 153 | import android.telephony.satellite.SatelliteDatagramCallback; | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 154 | import android.telephony.satellite.SatelliteManager; | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 155 | import android.telephony.satellite.SatelliteProvisionStateCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 156 | import android.text.TextUtils; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 157 | import android.util.ArraySet; | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 158 | import android.util.EventLog; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import android.util.Log; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 160 | import android.util.Pair; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 161 |  | 
| Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 162 | import com.android.ims.ImsManager; | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 163 | import com.android.ims.internal.IImsServiceFeatureCallback; | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 164 | import com.android.ims.rcs.uce.eab.EabUtil; | 
| SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 165 | import com.android.internal.annotations.VisibleForTesting; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.CallForwardInfo; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.CallManager; | 
| Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.CallStateException; | 
| Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.CallTracker; | 
| Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.CarrierPrivilegesTracker; | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.CarrierResolver; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.CellNetworkScanResult; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.CommandException; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.CommandsInterface; | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.GbaManager; | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.GsmCdmaPhone; | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.HalVersion; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.IBooleanConsumer; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.ICallForwardingInfoCallback; | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 180 | import com.android.internal.telephony.IImsStateCallback; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.IIntegerConsumer; | 
| Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.ILongConsumer; | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.INumberVerificationCallback; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.ITelephony; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.IccCard; | 
| Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.IccCardConstants; | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.IccLogicalChannelRequest; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.LocaleTracker; | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.NetworkScanRequestTracker; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.OperatorInfo; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.Phone; | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.PhoneConfigurationManager; | 
| Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.PhoneConstantConversions; | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.PhoneConstants; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.PhoneFactory; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.ProxyController; | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.RIL; | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 198 | import com.android.internal.telephony.RILConstants; | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.RadioInterfaceCapabilityController; | 
| Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.ServiceStateTracker; | 
| Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.SmsApplication; | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.SmsController; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.SmsPermissions; | 
| Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.SubscriptionController; | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.TelephonyIntents; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.TelephonyPermissions; | 
| Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.data.DataUtils; | 
| Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 208 | import com.android.internal.telephony.domainselection.DomainSelectionResolver; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 209 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 210 | import com.android.internal.telephony.euicc.EuiccConnector; | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 211 | import com.android.internal.telephony.ims.ImsResolver; | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 212 | import com.android.internal.telephony.imsphone.ImsPhone; | 
|  | 213 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; | 
| joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 214 | import com.android.internal.telephony.metrics.RcsStats; | 
| Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 215 | import com.android.internal.telephony.metrics.TelephonyMetrics; | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 216 | import com.android.internal.telephony.satellite.SatelliteController; | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 217 | import com.android.internal.telephony.subscription.SubscriptionInfoInternal; | 
|  | 218 | import com.android.internal.telephony.subscription.SubscriptionManagerService; | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 219 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 220 | import com.android.internal.telephony.uicc.IccIoResult; | 
|  | 221 | import com.android.internal.telephony.uicc.IccUtils; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 222 | import com.android.internal.telephony.uicc.SIMRecords; | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 223 | import com.android.internal.telephony.uicc.UiccCard; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 224 | import com.android.internal.telephony.uicc.UiccCardApplication; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 225 | import com.android.internal.telephony.uicc.UiccController; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 226 | import com.android.internal.telephony.uicc.UiccPort; | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 227 | import com.android.internal.telephony.uicc.UiccProfile; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 228 | import com.android.internal.telephony.uicc.UiccSlot; | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 229 | import com.android.internal.telephony.util.LocaleUtils; | 
| Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 230 | import com.android.internal.telephony.util.TelephonyUtils; | 
| fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 231 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 232 | import com.android.internal.util.FunctionalUtils; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | import com.android.internal.util.HexDump; | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 234 | import com.android.phone.callcomposer.CallComposerPictureManager; | 
|  | 235 | import com.android.phone.callcomposer.CallComposerPictureTransfer; | 
|  | 236 | import com.android.phone.callcomposer.ImageData; | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 237 | import com.android.phone.settings.PickSmsSubscriptionActivity; | 
| Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 238 | import com.android.phone.slice.SlicePurchaseController; | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 239 | import com.android.phone.utils.CarrierAllowListInfo; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 240 | import com.android.phone.vvm.PhoneAccountHandleConverter; | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 241 | import com.android.phone.vvm.RemoteVvmTaskManager; | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 242 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; | 
| Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 243 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 244 | import com.android.services.telephony.TelecomAccountRegistry; | 
|  | 245 | import com.android.services.telephony.TelephonyConnectionService; | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 246 | import com.android.telephony.Rlog; | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 247 |  | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 248 | import java.io.ByteArrayOutputStream; | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 249 | import java.io.FileDescriptor; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 250 | import java.io.IOException; | 
|  | 251 | import java.io.InputStream; | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 252 | import java.io.PrintWriter; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | import java.util.ArrayList; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 254 | import java.util.Arrays; | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 255 | import java.util.Collection; | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 256 | import java.util.Collections; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 257 | import java.util.HashMap; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 258 | import java.util.HashSet; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 259 | import java.util.List; | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 260 | import java.util.Locale; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 261 | import java.util.Map; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 262 | import java.util.NoSuchElementException; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 263 | import java.util.Objects; | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 264 | import java.util.Set; | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 265 | import java.util.UUID; | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 266 | import java.util.concurrent.Executors; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 267 | import java.util.concurrent.atomic.AtomicBoolean; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 268 | import java.util.function.Consumer; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 269 |  | 
|  | 270 | /** | 
|  | 271 | * Implementation of the ITelephony interface. | 
|  | 272 | */ | 
| Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 273 | public class PhoneInterfaceManager extends ITelephony.Stub { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | private static final String LOG_TAG = "PhoneInterfaceManager"; | 
|  | 275 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); | 
|  | 276 | private static final boolean DBG_LOC = false; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 277 | private static final boolean DBG_MERGE = false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 278 |  | 
|  | 279 | // Message codes used with mMainThreadHandler | 
|  | 280 | private static final int CMD_HANDLE_PIN_MMI = 1; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 281 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; | 
|  | 282 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 283 | private static final int CMD_OPEN_CHANNEL = 9; | 
|  | 284 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; | 
|  | 285 | private static final int CMD_CLOSE_CHANNEL = 11; | 
|  | 286 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 287 | private static final int CMD_NV_READ_ITEM = 13; | 
|  | 288 | private static final int EVENT_NV_READ_ITEM_DONE = 14; | 
|  | 289 | private static final int CMD_NV_WRITE_ITEM = 15; | 
|  | 290 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; | 
|  | 291 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; | 
|  | 292 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 293 | private static final int CMD_RESET_MODEM_CONFIG = 19; | 
|  | 294 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 295 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; | 
|  | 296 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; | 
| Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 297 | private static final int CMD_SEND_ENVELOPE = 25; | 
|  | 298 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 299 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; | 
|  | 300 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; | 
| Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 301 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; | 
|  | 302 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; | 
|  | 303 | private static final int CMD_EXCHANGE_SIM_IO = 31; | 
|  | 304 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 305 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; | 
|  | 306 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 307 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; | 
|  | 308 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; | 
|  | 310 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 311 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; | 
|  | 312 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; | 
|  | 313 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; | 
|  | 314 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 315 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; | 
|  | 316 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; | 
|  | 317 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; | 
|  | 318 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 319 | private static final int CMD_HANDLE_USSD_REQUEST = 47; | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 320 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; | 
|  | 321 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 322 | private static final int CMD_SWITCH_SLOTS = 50; | 
|  | 323 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 324 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; | 
|  | 325 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; | 
|  | 326 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; | 
|  | 327 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; | 
|  | 328 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; | 
|  | 329 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; | 
|  | 330 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; | 
|  | 331 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 332 | private static final int CMD_GET_ALL_CELL_INFO = 60; | 
|  | 333 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; | 
|  | 334 | private static final int CMD_GET_CELL_LOCATION = 62; | 
|  | 335 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 336 | private static final int CMD_MODEM_REBOOT = 64; | 
|  | 337 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 338 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; | 
|  | 339 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 340 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; | 
|  | 341 | private static final int EVENT_ENABLE_MODEM_DONE = 69; | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 342 | private static final int CMD_GET_MODEM_STATUS = 70; | 
|  | 343 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 344 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; | 
|  | 345 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 346 | private static final int CMD_ERASE_MODEM_CONFIG = 74; | 
|  | 347 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 348 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; | 
|  | 349 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; | 
|  | 350 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; | 
|  | 351 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 352 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; | 
|  | 353 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 354 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 355 | private static final int CMD_GET_CALL_FORWARDING = 83; | 
|  | 356 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; | 
|  | 357 | private static final int CMD_SET_CALL_FORWARDING = 85; | 
|  | 358 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; | 
|  | 359 | private static final int CMD_GET_CALL_WAITING = 87; | 
|  | 360 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; | 
|  | 361 | private static final int CMD_SET_CALL_WAITING = 89; | 
|  | 362 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 363 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; | 
|  | 364 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; | 
|  | 365 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; | 
|  | 366 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 367 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; | 
|  | 368 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 369 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; | 
|  | 370 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 371 | private static final int CMD_SET_DATA_THROTTLING = 99; | 
|  | 372 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 373 | private static final int CMD_SET_SIM_POWER = 101; | 
|  | 374 | private static final int EVENT_SET_SIM_POWER_DONE = 102; | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 375 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; | 
|  | 376 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; | 
|  | 377 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; | 
|  | 378 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 379 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; | 
|  | 380 | 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] | 381 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 382 | private static final int CMD_GET_SLICING_CONFIG = 110; | 
|  | 383 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 384 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 385 | private static final int CMD_ENABLE_VONR = 113; | 
|  | 386 | private static final int EVENT_ENABLE_VONR_DONE = 114; | 
|  | 387 | private static final int CMD_IS_VONR_ENABLED = 115; | 
|  | 388 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 389 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; | 
|  | 390 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 391 |  | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 392 | // Parameters of select command. | 
|  | 393 | private static final int SELECT_COMMAND = 0xA4; | 
|  | 394 | private static final int SELECT_P1 = 0x04; | 
|  | 395 | private static final int SELECT_P2 = 0; | 
|  | 396 | private static final int SELECT_P3 = 0x10; | 
|  | 397 |  | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 398 | // Toggling null cipher and integrity support was added in IRadioNetwork 2.1 | 
|  | 399 | private static final int MIN_NULL_CIPHER_AND_INTEGRITY_VERSION = 201; | 
|  | 400 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | /** The singleton instance. */ | 
|  | 402 | private static PhoneInterfaceManager sInstance; | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 403 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 404 |  | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 405 | private final PhoneGlobals mApp; | 
|  | 406 | private final CallManager mCM; | 
|  | 407 | private final ImsResolver mImsResolver; | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 408 |  | 
|  | 409 | private final SatelliteController mSatelliteController; | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 410 | private final UserManager mUserManager; | 
|  | 411 | private final AppOpsManager mAppOps; | 
|  | 412 | private final MainThreadHandler mMainThreadHandler; | 
| Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 413 | private final SubscriptionController mSubscriptionController; | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 414 | private final SharedPreferences mTelephonySharedPreferences; | 
|  | 415 | private final PhoneConfigurationManager mPhoneConfigurationManager; | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 416 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 418 | /** User Activity */ | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 419 | private final AtomicBoolean mNotifyUserActivity; | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 420 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; | 
|  | 421 |  | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 422 | private final Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 423 |  | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 424 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; | 
|  | 425 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 426 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 427 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 428 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 429 | // String to store multi SIM allowed | 
|  | 430 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; | 
|  | 431 |  | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 432 | // The AID of ISD-R. | 
|  | 433 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; | 
|  | 434 |  | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 435 | private NetworkScanRequestTracker mNetworkScanRequestTracker; | 
|  | 436 |  | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 437 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; | 
|  | 438 | private static final int MANUFACTURER_CODE_LENGTH = 8; | 
|  | 439 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 440 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 441 | 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] | 442 |  | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 443 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = | 
|  | 444 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; | 
|  | 445 |  | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 446 | /** | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 447 | * Experiment flag to enable erase modem config on reset network, default value is false | 
|  | 448 | */ | 
|  | 449 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = | 
|  | 450 | "reset_network_erase_modem_config_enabled"; | 
|  | 451 |  | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 452 | 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] | 453 |  | 
| Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 454 | private static final int MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS = 50; | 
|  | 455 |  | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 456 | /** | 
|  | 457 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than | 
|  | 458 | * one ICCID active at the same time. | 
|  | 459 | * Apps should use below API signatures if targeting SDK is T and beyond. | 
|  | 460 | * | 
|  | 461 | * @hide | 
|  | 462 | */ | 
|  | 463 | @ChangeId | 
|  | 464 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) | 
|  | 465 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 466 |  | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 467 | /** | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 468 | * Apps targeting on Android T and beyond will get exception whenever icc close channel | 
|  | 469 | * operation fails. | 
|  | 470 | */ | 
|  | 471 | @ChangeId | 
|  | 472 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) | 
|  | 473 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; | 
|  | 474 |  | 
|  | 475 | /** | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 476 | * A request object to use for transmitting data to an ICC. | 
|  | 477 | */ | 
|  | 478 | private static final class IccAPDUArgument { | 
|  | 479 | public int channel, cla, command, p1, p2, p3; | 
|  | 480 | public String data; | 
|  | 481 |  | 
|  | 482 | public IccAPDUArgument(int channel, int cla, int command, | 
|  | 483 | int p1, int p2, int p3, String data) { | 
|  | 484 | this.channel = channel; | 
|  | 485 | this.cla = cla; | 
|  | 486 | this.command = command; | 
|  | 487 | this.p1 = p1; | 
|  | 488 | this.p2 = p2; | 
|  | 489 | this.p3 = p3; | 
|  | 490 | this.data = data; | 
|  | 491 | } | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | /** | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 495 | * A request object to use for transmitting data to an ICC. | 
|  | 496 | */ | 
|  | 497 | private static final class ManualNetworkSelectionArgument { | 
|  | 498 | public OperatorInfo operatorInfo; | 
|  | 499 | public boolean persistSelection; | 
|  | 500 |  | 
|  | 501 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { | 
|  | 502 | this.operatorInfo = operatorInfo; | 
|  | 503 | this.persistSelection = persistSelection; | 
|  | 504 | } | 
|  | 505 | } | 
|  | 506 |  | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 507 | private static final class PurchasePremiumCapabilityArgument { | 
|  | 508 | public @TelephonyManager.PremiumCapability int capability; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 509 | public @NonNull IIntegerConsumer callback; | 
|  | 510 |  | 
|  | 511 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, | 
| Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 512 | @NonNull IIntegerConsumer callback) { | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 513 | this.capability = capability; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 514 | this.callback = callback; | 
|  | 515 | } | 
|  | 516 | } | 
|  | 517 |  | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 518 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the | 
|  | 520 | * request after sending. The main thread will notify the request when it is complete. | 
|  | 521 | */ | 
|  | 522 | private static final class MainThreadRequest { | 
|  | 523 | /** The argument to use for the request */ | 
|  | 524 | public Object argument; | 
|  | 525 | /** The result of the request that is run on the main thread */ | 
|  | 526 | public Object result; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 527 | // The subscriber id that this request applies to. Defaults to | 
|  | 528 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID | 
|  | 529 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 530 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 531 | // In cases where subId is unavailable, the caller needs to specify the phone. | 
|  | 532 | public Phone phone; | 
|  | 533 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 534 | public WorkSource workSource; | 
|  | 535 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 536 | public MainThreadRequest(Object argument) { | 
|  | 537 | this.argument = argument; | 
|  | 538 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 539 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 540 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { | 
|  | 541 | this.argument = argument; | 
|  | 542 | if (phone != null) { | 
|  | 543 | this.phone = phone; | 
|  | 544 | } | 
|  | 545 | this.workSource = workSource; | 
|  | 546 | } | 
|  | 547 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 548 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 549 | this.argument = argument; | 
| Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 550 | if (subId != null) { | 
|  | 551 | this.subId = subId; | 
|  | 552 | } | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 553 | this.workSource = workSource; | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 554 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 555 | } | 
|  | 556 |  | 
| Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 557 | private static final class IncomingThirdPartyCallArgs { | 
|  | 558 | public final ComponentName component; | 
|  | 559 | public final String callId; | 
|  | 560 | public final String callerDisplayName; | 
|  | 561 |  | 
|  | 562 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, | 
|  | 563 | String callerDisplayName) { | 
|  | 564 | this.component = component; | 
|  | 565 | this.callId = callId; | 
|  | 566 | this.callerDisplayName = callerDisplayName; | 
|  | 567 | } | 
|  | 568 | } | 
|  | 569 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 570 | /** | 
|  | 571 | * A handler that processes messages on the main thread in the phone process. Since many | 
|  | 572 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the | 
|  | 573 | * inbound binder threads to the main thread in the phone process.  The Binder thread | 
|  | 574 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting | 
|  | 575 | * on, which will be notified when the operation completes and will contain the result of the | 
|  | 576 | * request. | 
|  | 577 | * | 
|  | 578 | * <p>If a MainThreadRequest object is provided in the msg.obj field, | 
|  | 579 | * note that request.result must be set to something non-null for the calling thread to | 
|  | 580 | * unblock. | 
|  | 581 | */ | 
|  | 582 | private final class MainThreadHandler extends Handler { | 
|  | 583 | @Override | 
|  | 584 | public void handleMessage(Message msg) { | 
|  | 585 | MainThreadRequest request; | 
|  | 586 | Message onCompleted; | 
|  | 587 | AsyncResult ar; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 588 | UiccPort uiccPort; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 589 | IccAPDUArgument iccArgument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 590 | final Phone defaultPhone = getDefaultPhone(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 591 |  | 
|  | 592 | switch (msg.what) { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | case CMD_HANDLE_USSD_REQUEST: { | 
|  | 594 | request = (MainThreadRequest) msg.obj; | 
|  | 595 | final Phone phone = getPhoneFromRequest(request); | 
|  | 596 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 597 | String ussdRequest = ussdObject.first; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | ResultReceiver wrappedCallback = ussdObject.second; | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 599 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | if (!isUssdApiAllowed(request.subId)) { | 
|  | 601 | // Carrier does not support use of this API, return failure. | 
|  | 602 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); | 
|  | 603 | UssdResponse response = new UssdResponse(ussdRequest, null); | 
|  | 604 | Bundle returnData = new Bundle(); | 
|  | 605 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); | 
|  | 606 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 607 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | request.result = true; | 
|  | 609 | notifyRequester(request); | 
|  | 610 | return; | 
|  | 611 | } | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 612 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | try { | 
|  | 614 | request.result = phone != null | 
|  | 615 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; | 
|  | 616 | } catch (CallStateException cse) { | 
|  | 617 | request.result = false; | 
|  | 618 | } | 
|  | 619 | // Wake up the requesting thread | 
|  | 620 | notifyRequester(request); | 
|  | 621 | break; | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 622 | } | 
|  | 623 |  | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 624 | case CMD_HANDLE_PIN_MMI: { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 625 | request = (MainThreadRequest) msg.obj; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 626 | final Phone phone = getPhoneFromRequest(request); | 
|  | 627 | request.result = phone != null ? | 
|  | 628 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) | 
|  | 629 | : false; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 630 | // Wake up the requesting thread | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | notifyRequester(request); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 632 | break; | 
| Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 633 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 634 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | iccArgument = (IccAPDUArgument) request.argument; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 638 | uiccPort = getUiccPortFromRequest(request); | 
|  | 639 | if (uiccPort == null) { | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | loge("iccTransmitApduLogicalChannel: No UICC"); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 641 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 642 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 643 | } else { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | request); | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 646 | uiccPort.iccTransmitApduLogicalChannel( | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 647 | iccArgument.channel, iccArgument.cla, iccArgument.command, | 
|  | 648 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, | 
|  | 649 | onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 650 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | break; | 
|  | 652 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 653 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | ar = (AsyncResult) msg.obj; | 
|  | 655 | request = (MainThreadRequest) ar.userObj; | 
|  | 656 | if (ar.exception == null && ar.result != null) { | 
|  | 657 | request.result = ar.result; | 
|  | 658 | } else { | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 659 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | if (ar.result == null) { | 
|  | 661 | loge("iccTransmitApduLogicalChannel: Empty response"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 662 | } else if (ar.exception instanceof CommandException) { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | loge("iccTransmitApduLogicalChannel: CommandException: " + | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 664 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } else { | 
|  | 666 | loge("iccTransmitApduLogicalChannel: Unknown exception"); | 
|  | 667 | } | 
|  | 668 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 670 | break; | 
|  | 671 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: | 
|  | 673 | request = (MainThreadRequest) msg.obj; | 
|  | 674 | iccArgument = (IccAPDUArgument) request.argument; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 675 | uiccPort = getUiccPortFromRequest(request); | 
|  | 676 | if (uiccPort == null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | loge("iccTransmitApduBasicChannel: No UICC"); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 678 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 679 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 680 | } else { | 
|  | 681 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request); | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort.iccTransmitApduBasicChannel( | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | iccArgument.cla, iccArgument.command, iccArgument.p1, | 
|  | 685 | iccArgument.p2, | 
|  | 686 | iccArgument.p3, iccArgument.data, onCompleted); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 687 | } | 
|  | 688 | break; | 
|  | 689 |  | 
|  | 690 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: | 
|  | 691 | ar = (AsyncResult) msg.obj; | 
|  | 692 | request = (MainThreadRequest) ar.userObj; | 
|  | 693 | if (ar.exception == null && ar.result != null) { | 
|  | 694 | request.result = ar.result; | 
|  | 695 | } else { | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 696 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 697 | if (ar.result == null) { | 
|  | 698 | loge("iccTransmitApduBasicChannel: Empty response"); | 
|  | 699 | } else if (ar.exception instanceof CommandException) { | 
|  | 700 | loge("iccTransmitApduBasicChannel: CommandException: " + | 
|  | 701 | ar.exception); | 
|  | 702 | } else { | 
|  | 703 | loge("iccTransmitApduBasicChannel: Unknown exception"); | 
|  | 704 | } | 
|  | 705 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | break; | 
|  | 708 |  | 
|  | 709 | case CMD_EXCHANGE_SIM_IO: | 
|  | 710 | request = (MainThreadRequest) msg.obj; | 
|  | 711 | iccArgument = (IccAPDUArgument) request.argument; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 712 | uiccPort = getUiccPortFromRequest(request); | 
|  | 713 | if (uiccPort == null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 714 | loge("iccExchangeSimIO: No UICC"); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 715 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 717 | } else { | 
|  | 718 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, | 
|  | 719 | request); | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 721 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, | 
|  | 722 | iccArgument.data, onCompleted); | 
|  | 723 | } | 
|  | 724 | break; | 
|  | 725 |  | 
|  | 726 | case EVENT_EXCHANGE_SIM_IO_DONE: | 
|  | 727 | ar = (AsyncResult) msg.obj; | 
|  | 728 | request = (MainThreadRequest) ar.userObj; | 
|  | 729 | if (ar.exception == null && ar.result != null) { | 
|  | 730 | request.result = ar.result; | 
|  | 731 | } else { | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 732 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 733 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 734 | notifyRequester(request); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 735 | break; | 
|  | 736 |  | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 737 | case CMD_SEND_ENVELOPE: | 
|  | 738 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 739 | uiccPort = getUiccPortFromRequest(request); | 
|  | 740 | if (uiccPort == null) { | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 741 | loge("sendEnvelopeWithStatus: No UICC"); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 742 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 743 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 744 | } else { | 
|  | 745 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 746 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 747 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 748 | break; | 
|  | 749 |  | 
|  | 750 | case EVENT_SEND_ENVELOPE_DONE: | 
|  | 751 | ar = (AsyncResult) msg.obj; | 
|  | 752 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 753 | if (ar.exception == null && ar.result != null) { | 
|  | 754 | request.result = ar.result; | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 755 | } else { | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 756 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); | 
| Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 757 | if (ar.result == null) { | 
|  | 758 | loge("sendEnvelopeWithStatus: Empty response"); | 
|  | 759 | } else if (ar.exception instanceof CommandException) { | 
|  | 760 | loge("sendEnvelopeWithStatus: CommandException: " + | 
|  | 761 | ar.exception); | 
|  | 762 | } else { | 
|  | 763 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); | 
|  | 764 | } | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 765 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 766 | notifyRequester(request); | 
| Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 767 | break; | 
|  | 768 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | case CMD_OPEN_CHANNEL: | 
|  | 770 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 771 | uiccPort = getUiccPortFromRequest(request); | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 772 | IccLogicalChannelRequest openChannelRequest = | 
|  | 773 | (IccLogicalChannelRequest) request.argument; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 774 | if (uiccPort == null) { | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 775 | loge("iccOpenLogicalChannel: No UICC"); | 
| Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 776 | request.result = new IccOpenLogicalChannelResponse(-1, | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 777 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 778 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 779 | } else { | 
|  | 780 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 781 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, | 
|  | 782 | openChannelRequest.p2, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 783 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | break; | 
|  | 785 |  | 
|  | 786 | case EVENT_OPEN_CHANNEL_DONE: | 
|  | 787 | ar = (AsyncResult) msg.obj; | 
|  | 788 | request = (MainThreadRequest) ar.userObj; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 789 | IccOpenLogicalChannelResponse openChannelResp; | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 790 | if (ar.exception == null && ar.result != null) { | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 791 | int[] result = (int[]) ar.result; | 
|  | 792 | int channelId = result[0]; | 
|  | 793 | byte[] selectResponse = null; | 
|  | 794 | if (result.length > 1) { | 
|  | 795 | selectResponse = new byte[result.length - 1]; | 
|  | 796 | for (int i = 1; i < result.length; ++i) { | 
|  | 797 | selectResponse[i - 1] = (byte) result[i]; | 
|  | 798 | } | 
|  | 799 | } | 
|  | 800 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 801 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); | 
| Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 802 |  | 
|  | 803 | uiccPort = getUiccPortFromRequest(request); | 
| Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 804 | if (uiccPort == null) { | 
|  | 805 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); | 
|  | 806 | } else { | 
|  | 807 | IccLogicalChannelRequest channelRequest = | 
|  | 808 | (IccLogicalChannelRequest) request.argument; | 
|  | 809 | channelRequest.channel = channelId; | 
|  | 810 | uiccPort.onLogicalChannelOpened(channelRequest); | 
|  | 811 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 812 | } else { | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 813 | if (ar.result == null) { | 
|  | 814 | loge("iccOpenLogicalChannel: Empty response"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 815 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 816 | if (ar.exception != null) { | 
|  | 817 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); | 
|  | 818 | } | 
|  | 819 |  | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 820 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 821 | if (ar.exception instanceof CommandException) { | 
|  | 822 | CommandException.Error error = | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 823 | ((CommandException) (ar.exception)).getCommandError(); | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 824 | if (error == CommandException.Error.MISSING_RESOURCE) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 825 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; | 
| Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 826 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { | 
| Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 827 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 828 | } | 
|  | 829 | } | 
|  | 830 | openChannelResp = new IccOpenLogicalChannelResponse( | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 831 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 832 | } | 
| Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 833 | request.result = openChannelResp; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 834 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 835 | break; | 
|  | 836 |  | 
|  | 837 | case CMD_CLOSE_CHANNEL: | 
|  | 838 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 839 | uiccPort = getUiccPortFromRequest(request); | 
|  | 840 | if (uiccPort == null) { | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 841 | loge("iccCloseLogicalChannel: No UICC"); | 
| Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 842 | request.result = new IllegalArgumentException( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 843 | "iccCloseLogicalChannel: No UICC"); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 844 | notifyRequester(request); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 845 | } else { | 
|  | 846 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 847 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 848 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | break; | 
|  | 850 |  | 
|  | 851 | case EVENT_CLOSE_CHANNEL_DONE: | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 852 | ar = (AsyncResult) msg.obj; | 
|  | 853 | request = (MainThreadRequest) ar.userObj; | 
|  | 854 | if (ar.exception == null) { | 
|  | 855 | request.result = true; | 
| Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 856 | uiccPort = getUiccPortFromRequest(request); | 
| Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 857 | if (uiccPort == null) { | 
|  | 858 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); | 
|  | 859 | } else { | 
|  | 860 | final int channelId = (Integer) request.argument; | 
|  | 861 | uiccPort.onLogicalChannelClosed(channelId); | 
|  | 862 | } | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 863 | } else { | 
|  | 864 | request.result = false; | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 865 | Exception exception = null; | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 866 | if (ar.exception instanceof CommandException) { | 
|  | 867 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); | 
|  | 868 | CommandException.Error error = | 
|  | 869 | ((CommandException) (ar.exception)).getCommandError(); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 870 | if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 871 | // should only throw exceptions from the binder threads. | 
|  | 872 | exception = new IllegalArgumentException( | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 873 | "iccCloseLogicalChannel: invalid argument "); | 
|  | 874 | } | 
|  | 875 | } else { | 
|  | 876 | loge("iccCloseLogicalChannel: Unknown exception"); | 
|  | 877 | } | 
| Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 878 | request.result = (exception != null) ? exception : | 
|  | 879 | new IllegalStateException( | 
|  | 880 | "exception from modem to close iccLogical Channel"); | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 881 | } | 
|  | 882 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 883 | break; | 
|  | 884 |  | 
|  | 885 | case CMD_NV_READ_ITEM: | 
|  | 886 | request = (MainThreadRequest) msg.obj; | 
|  | 887 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 888 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, | 
|  | 889 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | break; | 
|  | 891 |  | 
|  | 892 | case EVENT_NV_READ_ITEM_DONE: | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 893 | ar = (AsyncResult) msg.obj; | 
|  | 894 | request = (MainThreadRequest) ar.userObj; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 895 | if (ar.exception == null && ar.result != null) { | 
|  | 896 | request.result = ar.result;     // String | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 897 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | request.result = ""; | 
|  | 899 | if (ar.result == null) { | 
|  | 900 | loge("nvReadItem: Empty response"); | 
|  | 901 | } else if (ar.exception instanceof CommandException) { | 
|  | 902 | loge("nvReadItem: CommandException: " + | 
|  | 903 | ar.exception); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 904 | } else { | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 905 | loge("nvReadItem: Unknown exception"); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 906 | } | 
|  | 907 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 908 | notifyRequester(request); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 909 | break; | 
|  | 910 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | case CMD_NV_WRITE_ITEM: | 
|  | 912 | request = (MainThreadRequest) msg.obj; | 
|  | 913 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); | 
|  | 914 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 915 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 916 | request.workSource); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 917 | break; | 
|  | 918 |  | 
|  | 919 | case EVENT_NV_WRITE_ITEM_DONE: | 
|  | 920 | handleNullReturnEvent(msg, "nvWriteItem"); | 
|  | 921 | break; | 
|  | 922 |  | 
|  | 923 | case CMD_NV_WRITE_CDMA_PRL: | 
|  | 924 | request = (MainThreadRequest) msg.obj; | 
|  | 925 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 926 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 927 | break; | 
|  | 928 |  | 
|  | 929 | case EVENT_NV_WRITE_CDMA_PRL_DONE: | 
|  | 930 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); | 
|  | 931 | break; | 
|  | 932 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 933 | case CMD_RESET_MODEM_CONFIG: | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 934 | request = (MainThreadRequest) msg.obj; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 935 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 936 | defaultPhone.resetModemConfig(onCompleted); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 937 | break; | 
|  | 938 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 939 | case EVENT_RESET_MODEM_CONFIG_DONE: | 
|  | 940 | handleNullReturnEvent(msg, "resetModemConfig"); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 941 | break; | 
|  | 942 |  | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 943 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { | 
|  | 944 | request = (MainThreadRequest) msg.obj; | 
|  | 945 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, | 
|  | 946 | request); | 
|  | 947 | Phone phone = getPhoneFromRequest(request); | 
|  | 948 | if (phone != null) { | 
|  | 949 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); | 
|  | 950 | } else { | 
|  | 951 | loge("isNRDualConnectivityEnabled: No phone object"); | 
|  | 952 | request.result = false; | 
|  | 953 | notifyRequester(request); | 
|  | 954 | } | 
|  | 955 | break; | 
|  | 956 | } | 
|  | 957 |  | 
|  | 958 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: | 
|  | 959 | ar = (AsyncResult) msg.obj; | 
|  | 960 | request = (MainThreadRequest) ar.userObj; | 
|  | 961 | if (ar.exception == null && ar.result != null) { | 
|  | 962 | request.result = ar.result; | 
|  | 963 | } else { | 
|  | 964 | // request.result must be set to something non-null | 
|  | 965 | // for the calling thread to unblock | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 966 | if (ar.result != null) { | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 967 | request.result = ar.result; | 
|  | 968 | } else { | 
|  | 969 | request.result = false; | 
|  | 970 | } | 
|  | 971 | if (ar.result == null) { | 
|  | 972 | loge("isNRDualConnectivityEnabled: Empty response"); | 
|  | 973 | } else if (ar.exception instanceof CommandException) { | 
|  | 974 | loge("isNRDualConnectivityEnabled: CommandException: " | 
|  | 975 | + ar.exception); | 
|  | 976 | } else { | 
|  | 977 | loge("isNRDualConnectivityEnabled: Unknown exception"); | 
|  | 978 | } | 
|  | 979 | } | 
|  | 980 | notifyRequester(request); | 
|  | 981 | break; | 
|  | 982 |  | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 983 | case CMD_IS_VONR_ENABLED: { | 
|  | 984 | request = (MainThreadRequest) msg.obj; | 
|  | 985 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, | 
|  | 986 | request); | 
|  | 987 | Phone phone = getPhoneFromRequest(request); | 
|  | 988 | if (phone != null) { | 
|  | 989 | phone.isVoNrEnabled(onCompleted, request.workSource); | 
|  | 990 | } else { | 
|  | 991 | loge("isVoNrEnabled: No phone object"); | 
|  | 992 | request.result = false; | 
|  | 993 | notifyRequester(request); | 
|  | 994 | } | 
|  | 995 | break; | 
|  | 996 | } | 
|  | 997 |  | 
|  | 998 | case EVENT_IS_VONR_ENABLED_DONE: | 
|  | 999 | ar = (AsyncResult) msg.obj; | 
|  | 1000 | request = (MainThreadRequest) ar.userObj; | 
|  | 1001 | if (ar.exception == null && ar.result != null) { | 
|  | 1002 | request.result = ar.result; | 
|  | 1003 | } else { | 
|  | 1004 | // request.result must be set to something non-null | 
|  | 1005 | // for the calling thread to unblock | 
|  | 1006 | if (ar.result != null) { | 
|  | 1007 | request.result = ar.result; | 
|  | 1008 | } else { | 
|  | 1009 | request.result = false; | 
|  | 1010 | } | 
|  | 1011 | if (ar.result == null) { | 
|  | 1012 | loge("isVoNrEnabled: Empty response"); | 
|  | 1013 | } else if (ar.exception instanceof CommandException) { | 
|  | 1014 | loge("isVoNrEnabled: CommandException: " | 
|  | 1015 | + ar.exception); | 
|  | 1016 | } else { | 
|  | 1017 | loge("isVoNrEnabled: Unknown exception"); | 
|  | 1018 | } | 
|  | 1019 | } | 
|  | 1020 | notifyRequester(request); | 
|  | 1021 | break; | 
|  | 1022 |  | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1023 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { | 
|  | 1024 | request = (MainThreadRequest) msg.obj; | 
|  | 1025 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); | 
|  | 1026 | Phone phone = getPhoneFromRequest(request); | 
|  | 1027 | if (phone != null) { | 
|  | 1028 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, | 
|  | 1029 | request.workSource); | 
|  | 1030 | } else { | 
|  | 1031 | loge("enableNrDualConnectivity: No phone object"); | 
|  | 1032 | request.result = | 
|  | 1033 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
|  | 1034 | notifyRequester(request); | 
|  | 1035 | } | 
|  | 1036 | break; | 
|  | 1037 | } | 
|  | 1038 |  | 
|  | 1039 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { | 
|  | 1040 | ar = (AsyncResult) msg.obj; | 
|  | 1041 | request = (MainThreadRequest) ar.userObj; | 
|  | 1042 | if (ar.exception == null) { | 
|  | 1043 | request.result = | 
|  | 1044 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; | 
|  | 1045 | } else { | 
|  | 1046 | request.result = | 
|  | 1047 | TelephonyManager | 
|  | 1048 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; | 
|  | 1049 | if (ar.exception instanceof CommandException) { | 
|  | 1050 | CommandException.Error error = | 
|  | 1051 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1052 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1053 | request.result = | 
|  | 1054 | TelephonyManager | 
|  | 1055 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; | 
| Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1056 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1057 | request.result = | 
|  | 1058 | TelephonyManager | 
|  | 1059 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1060 | } | 
|  | 1061 | loge("enableNrDualConnectivity" + ": CommandException: " | 
|  | 1062 | + ar.exception); | 
|  | 1063 | } else { | 
|  | 1064 | loge("enableNrDualConnectivity" + ": Unknown exception"); | 
|  | 1065 | } | 
|  | 1066 | } | 
|  | 1067 | notifyRequester(request); | 
|  | 1068 | break; | 
|  | 1069 | } | 
|  | 1070 |  | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1071 | case CMD_ENABLE_VONR: { | 
|  | 1072 | request = (MainThreadRequest) msg.obj; | 
|  | 1073 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); | 
|  | 1074 | Phone phone = getPhoneFromRequest(request); | 
|  | 1075 | if (phone != null) { | 
|  | 1076 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, | 
|  | 1077 | request.workSource); | 
|  | 1078 | } else { | 
|  | 1079 | loge("setVoNrEnabled: No phone object"); | 
|  | 1080 | request.result = | 
|  | 1081 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; | 
|  | 1082 | notifyRequester(request); | 
|  | 1083 | } | 
|  | 1084 | break; | 
|  | 1085 | } | 
|  | 1086 |  | 
|  | 1087 | case EVENT_ENABLE_VONR_DONE: { | 
|  | 1088 | ar = (AsyncResult) msg.obj; | 
|  | 1089 | request = (MainThreadRequest) ar.userObj; | 
|  | 1090 | if (ar.exception == null) { | 
|  | 1091 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; | 
|  | 1092 | } else { | 
|  | 1093 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; | 
|  | 1094 | if (ar.exception instanceof CommandException) { | 
|  | 1095 | CommandException.Error error = | 
|  | 1096 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1097 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1098 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; | 
|  | 1099 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1100 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; | 
|  | 1101 | } else { | 
|  | 1102 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; | 
|  | 1103 | } | 
|  | 1104 | loge("setVoNrEnabled" + ": CommandException: " | 
|  | 1105 | + ar.exception); | 
|  | 1106 | } else { | 
|  | 1107 | loge("setVoNrEnabled" + ": Unknown exception"); | 
|  | 1108 | } | 
|  | 1109 | } | 
|  | 1110 | notifyRequester(request); | 
|  | 1111 | break; | 
|  | 1112 | } | 
|  | 1113 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1114 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1115 | request = (MainThreadRequest) msg.obj; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1116 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, | 
|  | 1117 | request); | 
|  | 1118 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1119 | break; | 
|  | 1120 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1121 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1122 | ar = (AsyncResult) msg.obj; | 
|  | 1123 | request = (MainThreadRequest) ar.userObj; | 
|  | 1124 | if (ar.exception == null && ar.result != null) { | 
|  | 1125 | request.result = ar.result;     // Integer | 
|  | 1126 | } else { | 
| Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1127 | // request.result must be set to something non-null | 
|  | 1128 | // for the calling thread to unblock | 
|  | 1129 | request.result = new int[]{-1}; | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | if (ar.result == null) { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1131 | loge("getAllowedNetworkTypesBitmask: Empty response"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1132 | } else if (ar.exception instanceof CommandException) { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1133 | loge("getAllowedNetworkTypesBitmask: CommandException: " | 
|  | 1134 | + ar.exception); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1135 | } else { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1136 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1137 | } | 
|  | 1138 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1139 | notifyRequester(request); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1140 | break; | 
|  | 1141 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1142 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1143 | request = (MainThreadRequest) msg.obj; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1144 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, | 
|  | 1145 | request); | 
|  | 1146 | Pair<Integer, Long> reasonWithNetworkTypes = | 
|  | 1147 | (Pair<Integer, Long>) request.argument; | 
|  | 1148 | getPhoneFromRequest(request).setAllowedNetworkTypes( | 
|  | 1149 | reasonWithNetworkTypes.first, | 
|  | 1150 | reasonWithNetworkTypes.second, | 
|  | 1151 | onCompleted); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1152 | break; | 
|  | 1153 |  | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1154 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: | 
|  | 1155 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1156 | break; | 
|  | 1157 |  | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1158 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: | 
|  | 1159 | request = (MainThreadRequest)msg.obj; | 
|  | 1160 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1161 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1162 | break; | 
|  | 1163 |  | 
|  | 1164 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: | 
|  | 1165 | ar = (AsyncResult)msg.obj; | 
|  | 1166 | request = (MainThreadRequest)ar.userObj; | 
|  | 1167 | request.result = ar; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1168 | notifyRequester(request); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1169 | break; | 
|  | 1170 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1171 | case CMD_SET_VOICEMAIL_NUMBER: | 
|  | 1172 | request = (MainThreadRequest) msg.obj; | 
|  | 1173 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); | 
|  | 1174 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1175 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, | 
|  | 1176 | onCompleted); | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1177 | break; | 
|  | 1178 |  | 
|  | 1179 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: | 
|  | 1180 | handleNullReturnEvent(msg, "setVoicemailNumber"); | 
|  | 1181 | break; | 
|  | 1182 |  | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1183 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: | 
|  | 1184 | request = (MainThreadRequest) msg.obj; | 
|  | 1185 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, | 
|  | 1186 | request); | 
|  | 1187 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); | 
|  | 1188 | break; | 
|  | 1189 |  | 
|  | 1190 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: | 
|  | 1191 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); | 
|  | 1192 | break; | 
|  | 1193 |  | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1194 | case CMD_PERFORM_NETWORK_SCAN: | 
|  | 1195 | request = (MainThreadRequest) msg.obj; | 
|  | 1196 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); | 
|  | 1197 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); | 
|  | 1198 | break; | 
|  | 1199 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1200 | case CMD_GET_CALL_FORWARDING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | request = (MainThreadRequest) msg.obj; | 
|  | 1202 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = | 
|  | 1204 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 1205 | request.argument; | 
|  | 1206 | int callForwardingReason = args.first; | 
|  | 1207 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | } | 
|  | 1210 | case EVENT_GET_CALL_FORWARDING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | ar = (AsyncResult) msg.obj; | 
|  | 1212 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | TelephonyManager.CallForwardingInfoCallback callback = | 
|  | 1214 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) | 
|  | 1215 | request.argument).second; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | if (ar.exception == null && ar.result != null) { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | CallForwardingInfo callForwardingInfo = null; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; | 
|  | 1219 | for (CallForwardInfo callForwardInfo : callForwardInfos) { | 
|  | 1220 | // Service Class is a bit mask per 3gpp 27.007. Search for | 
|  | 1221 | // any service for voice call. | 
|  | 1222 | if ((callForwardInfo.serviceClass | 
|  | 1223 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { | 
| Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1224 | callForwardingInfo = new CallForwardingInfo( | 
|  | 1225 | callForwardInfo.status | 
|  | 1226 | == CommandsInterface.CF_ACTION_ENABLE, | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1227 | callForwardInfo.reason, | 
|  | 1228 | callForwardInfo.number, | 
|  | 1229 | callForwardInfo.timeSeconds); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | break; | 
|  | 1231 | } | 
|  | 1232 | } | 
|  | 1233 | // Didn't find a call forward info for voice call. | 
|  | 1234 | if (callForwardingInfo == null) { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, | 
|  | 1236 | 0 /* reason */, null /* number */, 0 /* timeout */); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | callback.onCallForwardingInfoAvailable(callForwardingInfo); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | } else { | 
|  | 1240 | if (ar.result == null) { | 
|  | 1241 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); | 
|  | 1242 | } | 
|  | 1243 | if (ar.exception != null) { | 
|  | 1244 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); | 
|  | 1245 | } | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | int errorCode = TelephonyManager | 
|  | 1247 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1248 | if (ar.exception instanceof CommandException) { | 
|  | 1249 | CommandException.Error error = | 
|  | 1250 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1251 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1252 | errorCode = TelephonyManager | 
|  | 1253 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1255 | errorCode = TelephonyManager | 
|  | 1256 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | } | 
|  | 1258 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | callback.onError(errorCode); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | case CMD_SET_CALL_FORWARDING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | request = (MainThreadRequest) msg.obj; | 
|  | 1266 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | request = (MainThreadRequest) msg.obj; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | CallForwardingInfo callForwardingInfoToSet = | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1270 | request.argument).first; | 
|  | 1271 | request.phone.setCallForwardingOption( | 
|  | 1272 | callForwardingInfoToSet.isEnabled() | 
| Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1273 | ? CommandsInterface.CF_ACTION_REGISTRATION | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | : CommandsInterface.CF_ACTION_DISABLE, | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | callForwardingInfoToSet.getReason(), | 
|  | 1276 | callForwardingInfoToSet.getNumber(), | 
|  | 1277 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); | 
|  | 1278 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | case EVENT_SET_CALL_FORWARDING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | ar = (AsyncResult) msg.obj; | 
|  | 1283 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | Consumer<Integer> callback = | 
|  | 1285 | ((Pair<CallForwardingInfo, Consumer<Integer>>) | 
|  | 1286 | request.argument).second; | 
|  | 1287 | if (ar.exception != null) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | loge("setCallForwarding exception: " + ar.exception); | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1289 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1290 | .RESULT_ERROR_UNKNOWN; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1291 | if (ar.exception instanceof CommandException) { | 
|  | 1292 | CommandException.Error error = | 
|  | 1293 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1294 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1295 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1296 | .RESULT_ERROR_FDN_CHECK_FAILURE; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1297 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1298 | errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 1299 | .RESULT_ERROR_NOT_SUPPORTED; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | } | 
|  | 1301 | } | 
|  | 1302 | callback.accept(errorCode); | 
|  | 1303 | } else { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1304 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | case CMD_GET_CALL_WAITING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | request = (MainThreadRequest) msg.obj; | 
|  | 1311 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); | 
|  | 1312 | getPhoneFromRequest(request).getCallWaiting(onCompleted); | 
|  | 1313 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | case EVENT_GET_CALL_WAITING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | ar = (AsyncResult) msg.obj; | 
|  | 1318 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1319 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1320 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1322 | int[] callForwardResults = (int[]) ar.result; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | // Service Class is a bit mask per 3gpp 27.007. | 
|  | 1324 | // Search for any service for voice call. | 
| Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1325 | if (callForwardResults.length > 1 | 
|  | 1326 | && ((callForwardResults[1] | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1327 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1328 | callWaitingStatus = callForwardResults[0] == 0 | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED | 
|  | 1330 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1331 | } else { | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1332 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | } | 
|  | 1334 | } else { | 
|  | 1335 | if (ar.result == null) { | 
|  | 1336 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); | 
|  | 1337 | } | 
|  | 1338 | if (ar.exception != null) { | 
|  | 1339 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); | 
|  | 1340 | } | 
|  | 1341 | if (ar.exception instanceof CommandException) { | 
|  | 1342 | CommandException.Error error = | 
|  | 1343 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1344 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1345 | callWaitingStatus = | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1347 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
|  | 1348 | callWaitingStatus = | 
|  | 1349 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1350 | } | 
|  | 1351 | } | 
|  | 1352 | } | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1353 | callback.accept(callWaitingStatus); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1354 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1356 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1357 | case CMD_SET_CALL_WAITING: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1358 | request = (MainThreadRequest) msg.obj; | 
|  | 1359 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1360 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1361 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1362 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1363 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 |  | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1365 | case EVENT_SET_CALL_WAITING_DONE: { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1366 | ar = (AsyncResult) msg.obj; | 
|  | 1367 | request = (MainThreadRequest) ar.userObj; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1368 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; | 
|  | 1369 | Consumer<Integer> callback = | 
|  | 1370 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; | 
|  | 1371 | if (ar.exception != null) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1372 | loge("setCallWaiting exception: " + ar.exception); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1373 | if (ar.exception instanceof CommandException) { | 
|  | 1374 | CommandException.Error error = | 
|  | 1375 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1376 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1377 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); | 
| SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1378 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { | 
|  | 1379 | callback.accept( | 
|  | 1380 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1381 | } else { | 
|  | 1382 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1383 | } | 
|  | 1384 | } else { | 
|  | 1385 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 1386 | } | 
|  | 1387 | } else { | 
|  | 1388 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED | 
|  | 1389 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1390 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1391 | break; | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1392 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1393 | case EVENT_PERFORM_NETWORK_SCAN_DONE: | 
|  | 1394 | ar = (AsyncResult) msg.obj; | 
|  | 1395 | request = (MainThreadRequest) ar.userObj; | 
|  | 1396 | CellNetworkScanResult cellScanResult; | 
|  | 1397 | if (ar.exception == null && ar.result != null) { | 
|  | 1398 | cellScanResult = new CellNetworkScanResult( | 
|  | 1399 | CellNetworkScanResult.STATUS_SUCCESS, | 
|  | 1400 | (List<OperatorInfo>) ar.result); | 
|  | 1401 | } else { | 
|  | 1402 | if (ar.result == null) { | 
|  | 1403 | loge("getCellNetworkScanResults: Empty response"); | 
|  | 1404 | } | 
|  | 1405 | if (ar.exception != null) { | 
|  | 1406 | loge("getCellNetworkScanResults: Exception: " + ar.exception); | 
|  | 1407 | } | 
|  | 1408 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; | 
|  | 1409 | if (ar.exception instanceof CommandException) { | 
|  | 1410 | CommandException.Error error = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1411 | ((CommandException) (ar.exception)).getCommandError(); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1412 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 1413 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; | 
|  | 1414 | } else if (error == CommandException.Error.GENERIC_FAILURE) { | 
|  | 1415 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; | 
|  | 1416 | } | 
|  | 1417 | } | 
|  | 1418 | cellScanResult = new CellNetworkScanResult(errorCode, null); | 
|  | 1419 | } | 
|  | 1420 | request.result = cellScanResult; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1421 | notifyRequester(request); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1422 | break; | 
|  | 1423 |  | 
|  | 1424 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: | 
|  | 1425 | request = (MainThreadRequest) msg.obj; | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1426 | ManualNetworkSelectionArgument selArg = | 
|  | 1427 | (ManualNetworkSelectionArgument) request.argument; | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1428 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, | 
|  | 1429 | request); | 
| Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1430 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, | 
|  | 1431 | selArg.persistSelection, onCompleted); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1432 | break; | 
|  | 1433 |  | 
|  | 1434 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: | 
| Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1435 | ar = (AsyncResult) msg.obj; | 
|  | 1436 | request = (MainThreadRequest) ar.userObj; | 
|  | 1437 | if (ar.exception == null) { | 
|  | 1438 | request.result = true; | 
|  | 1439 | } else { | 
|  | 1440 | request.result = false; | 
|  | 1441 | loge("setNetworkSelectionModeManual " + ar.exception); | 
|  | 1442 | } | 
|  | 1443 | notifyRequester(request); | 
|  | 1444 | mApp.onNetworkSelectionChanged(request.subId); | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1445 | break; | 
|  | 1446 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | case CMD_GET_MODEM_ACTIVITY_INFO: | 
|  | 1448 | request = (MainThreadRequest) msg.obj; | 
|  | 1449 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1450 | if (defaultPhone != null) { | 
|  | 1451 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1452 | } else { | 
|  | 1453 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 1454 | Bundle bundle = new Bundle(); | 
|  | 1455 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1456 | new ModemActivityInfo(0, 0, 0, | 
|  | 1457 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | result.send(0, bundle); | 
| James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1459 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1460 | break; | 
|  | 1461 |  | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1462 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1463 | ar = (AsyncResult) msg.obj; | 
|  | 1464 | request = (MainThreadRequest) ar.userObj; | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | ResultReceiver result = (ResultReceiver) request.argument; | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1466 | int error = 0; | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1467 | ModemActivityInfo ret = null; | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1468 | if (mLastModemActivityInfo == null) { | 
|  | 1469 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; | 
|  | 1470 | mLastModemActivitySpecificInfo[0] = | 
|  | 1471 | new ActivityStatsTechSpecificInfo( | 
|  | 1472 | 0, | 
|  | 1473 | 0, | 
|  | 1474 | new int[ModemActivityInfo.getNumTxPowerLevels()], | 
|  | 1475 | 0); | 
|  | 1476 | mLastModemActivityInfo = | 
|  | 1477 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); | 
|  | 1478 | } | 
|  | 1479 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1480 | if (ar.exception == null && ar.result != null) { | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1481 | // Update the last modem activity info and the result of the request. | 
|  | 1482 | ModemActivityInfo info = (ModemActivityInfo) ar.result; | 
|  | 1483 | if (isModemActivityInfoValid(info)) { | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1484 | mergeModemActivityInfo(info); | 
| Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 1485 | } else { | 
|  | 1486 | loge("queryModemActivityInfo: invalid response"); | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1487 | } | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1488 | // This is needed to decouple ret from mLastModemActivityInfo | 
|  | 1489 | // We don't want to return mLastModemActivityInfo which is updated | 
|  | 1490 | // inside mergeModemActivityInfo() | 
|  | 1491 | ret = new ModemActivityInfo( | 
|  | 1492 | mLastModemActivityInfo.getTimestampMillis(), | 
|  | 1493 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 1494 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 1495 | deepCopyModemActivitySpecificInfo(mLastModemActivitySpecificInfo)); | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1496 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1497 | } else { | 
|  | 1498 | if (ar.result == null) { | 
|  | 1499 | loge("queryModemActivityInfo: Empty response"); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1500 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1501 | .ERROR_INVALID_INFO_RECEIVED; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1502 | } else if (ar.exception instanceof CommandException) { | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1503 | loge("queryModemActivityInfo: CommandException: " + ar.exception); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1504 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1505 | .ERROR_MODEM_RESPONSE_ERROR; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1506 | } else { | 
|  | 1507 | loge("queryModemActivityInfo: Unknown exception"); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1508 | error = TelephonyManager.ModemActivityInfoException | 
|  | 1509 | .ERROR_UNKNOWN; | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1510 | } | 
|  | 1511 | } | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1512 | Bundle bundle = new Bundle(); | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1513 | if (ret != null) { | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1514 | bundle.putParcelable( | 
|  | 1515 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 1516 | ret); | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1517 | } else { | 
|  | 1518 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); | 
|  | 1519 | } | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1520 | result.send(0, bundle); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1521 | notifyRequester(request); | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1522 | break; | 
| Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1523 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1524 |  | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1525 | case CMD_SET_ALLOWED_CARRIERS: { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1526 | request = (MainThreadRequest) msg.obj; | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1527 | CarrierRestrictionRules argument = | 
|  | 1528 | (CarrierRestrictionRules) request.argument; | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1529 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1530 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | break; | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1532 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1533 |  | 
|  | 1534 | case EVENT_SET_ALLOWED_CARRIERS_DONE: | 
|  | 1535 | ar = (AsyncResult) msg.obj; | 
|  | 1536 | request = (MainThreadRequest) ar.userObj; | 
|  | 1537 | if (ar.exception == null && ar.result != null) { | 
|  | 1538 | request.result = ar.result; | 
|  | 1539 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1540 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; | 
|  | 1541 | if (ar.exception instanceof CommandException) { | 
|  | 1542 | loge("setAllowedCarriers: CommandException: " + ar.exception); | 
|  | 1543 | CommandException.Error error = | 
|  | 1544 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 1545 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 1546 | request.result = | 
|  | 1547 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; | 
|  | 1548 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1549 | } else { | 
|  | 1550 | loge("setAllowedCarriers: Unknown exception"); | 
|  | 1551 | } | 
|  | 1552 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1553 | notifyRequester(request); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1554 | break; | 
|  | 1555 |  | 
|  | 1556 | case CMD_GET_ALLOWED_CARRIERS: | 
|  | 1557 | request = (MainThreadRequest) msg.obj; | 
|  | 1558 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1559 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1560 | break; | 
|  | 1561 |  | 
|  | 1562 | case EVENT_GET_ALLOWED_CARRIERS_DONE: | 
|  | 1563 | ar = (AsyncResult) msg.obj; | 
|  | 1564 | request = (MainThreadRequest) ar.userObj; | 
|  | 1565 | if (ar.exception == null && ar.result != null) { | 
|  | 1566 | request.result = ar.result; | 
|  | 1567 | } else { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1568 | request.result = new IllegalStateException( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1569 | "Failed to get carrier restrictions"); | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1570 | if (ar.result == null) { | 
|  | 1571 | loge("getAllowedCarriers: Empty response"); | 
|  | 1572 | } else if (ar.exception instanceof CommandException) { | 
|  | 1573 | loge("getAllowedCarriers: CommandException: " + | 
|  | 1574 | ar.exception); | 
|  | 1575 | } else { | 
|  | 1576 | loge("getAllowedCarriers: Unknown exception"); | 
|  | 1577 | } | 
|  | 1578 | } | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1579 | if (request.argument != null) { | 
|  | 1580 | // This is for the implementation of carrierRestrictionStatus. | 
|  | 1581 | CallerCallbackInfo callbackInfo = (CallerCallbackInfo) request.argument; | 
|  | 1582 | Consumer<Integer> callback = callbackInfo.getConsumer(); | 
|  | 1583 | int callerCarrierId = callbackInfo.getCarrierId(); | 
|  | 1584 | int lockStatus = TelephonyManager.CARRIER_RESTRICTION_STATUS_UNKNOWN; | 
|  | 1585 | if (ar.exception == null && ar.result instanceof CarrierRestrictionRules) { | 
|  | 1586 | CarrierRestrictionRules carrierRestrictionRules = | 
|  | 1587 | (CarrierRestrictionRules) ar.result; | 
|  | 1588 | int carrierId = -1; | 
|  | 1589 | try { | 
|  | 1590 | CarrierIdentifier carrierIdentifier = | 
|  | 1591 | carrierRestrictionRules.getAllowedCarriers().get(0); | 
|  | 1592 | carrierId = CarrierResolver.getCarrierIdFromIdentifier(mApp, | 
|  | 1593 | carrierIdentifier); | 
|  | 1594 | } catch (NullPointerException | IndexOutOfBoundsException ex) { | 
|  | 1595 | Rlog.e(LOG_TAG, "CarrierIdentifier exception = " + ex); | 
|  | 1596 | } | 
|  | 1597 | lockStatus = carrierRestrictionRules.getCarrierRestrictionStatus(); | 
|  | 1598 | if (carrierId != -1 && callerCarrierId == carrierId && lockStatus | 
|  | 1599 | == TelephonyManager.CARRIER_RESTRICTION_STATUS_RESTRICTED) { | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1600 | lockStatus = TelephonyManager | 
|  | 1601 | .CARRIER_RESTRICTION_STATUS_RESTRICTED_TO_CALLER; | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 1602 | } | 
|  | 1603 | } else { | 
|  | 1604 | Rlog.e(LOG_TAG, | 
|  | 1605 | "getCarrierRestrictionStatus: exception ex = " + ar.exception); | 
|  | 1606 | } | 
|  | 1607 | callback.accept(lockStatus); | 
|  | 1608 | } else { | 
|  | 1609 | // This is for the implementation of getAllowedCarriers. | 
|  | 1610 | notifyRequester(request); | 
|  | 1611 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1612 | break; | 
|  | 1613 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1614 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: | 
|  | 1615 | ar = (AsyncResult) msg.obj; | 
|  | 1616 | request = (MainThreadRequest) ar.userObj; | 
|  | 1617 | if (ar.exception == null && ar.result != null) { | 
|  | 1618 | request.result = ar.result; | 
|  | 1619 | } else { | 
|  | 1620 | request.result = new IllegalArgumentException( | 
|  | 1621 | "Failed to retrieve Forbidden Plmns"); | 
|  | 1622 | if (ar.result == null) { | 
|  | 1623 | loge("getForbiddenPlmns: Empty response"); | 
|  | 1624 | } else { | 
|  | 1625 | loge("getForbiddenPlmns: Unknown exception"); | 
|  | 1626 | } | 
|  | 1627 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1628 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1629 | break; | 
|  | 1630 |  | 
|  | 1631 | case CMD_GET_FORBIDDEN_PLMNS: | 
|  | 1632 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1633 | uiccPort = getUiccPortFromRequest(request); | 
|  | 1634 | if (uiccPort == null) { | 
|  | 1635 | loge("getForbiddenPlmns() UiccPort is null"); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1636 | request.result = new IllegalArgumentException( | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1637 | "getForbiddenPlmns() UiccPort is null"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1638 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1639 | break; | 
|  | 1640 | } | 
|  | 1641 | Integer appType = (Integer) request.argument; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1642 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1643 | if (uiccApp == null) { | 
|  | 1644 | loge("getForbiddenPlmns() no app with specified type -- " | 
|  | 1645 | + appType); | 
|  | 1646 | request.result = new IllegalArgumentException("Failed to get UICC App"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1647 | notifyRequester(request); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1648 | break; | 
|  | 1649 | } else { | 
|  | 1650 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() | 
|  | 1651 | + " specified type -- " + appType); | 
|  | 1652 | } | 
|  | 1653 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1654 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 1655 | onCompleted); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1656 | break; | 
|  | 1657 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1658 | case CMD_SWITCH_SLOTS: | 
|  | 1659 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1660 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1661 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1662 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1663 | break; | 
|  | 1664 |  | 
|  | 1665 | case EVENT_SWITCH_SLOTS_DONE: | 
|  | 1666 | ar = (AsyncResult) msg.obj; | 
|  | 1667 | request = (MainThreadRequest) ar.userObj; | 
|  | 1668 | request.result = (ar.exception == null); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1669 | notifyRequester(request); | 
|  | 1670 | break; | 
|  | 1671 | case CMD_GET_NETWORK_SELECTION_MODE: | 
|  | 1672 | request = (MainThreadRequest) msg.obj; | 
|  | 1673 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); | 
|  | 1674 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); | 
|  | 1675 | break; | 
|  | 1676 |  | 
|  | 1677 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: | 
|  | 1678 | ar = (AsyncResult) msg.obj; | 
|  | 1679 | request = (MainThreadRequest) ar.userObj; | 
|  | 1680 | if (ar.exception != null) { | 
|  | 1681 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 1682 | } else { | 
|  | 1683 | int mode = ((int[]) ar.result)[0]; | 
|  | 1684 | if (mode == 0) { | 
|  | 1685 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; | 
|  | 1686 | } else { | 
|  | 1687 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; | 
|  | 1688 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1689 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1690 | notifyRequester(request); | 
|  | 1691 | break; | 
|  | 1692 | case CMD_GET_CDMA_ROAMING_MODE: | 
|  | 1693 | request = (MainThreadRequest) msg.obj; | 
|  | 1694 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1695 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); | 
|  | 1696 | break; | 
|  | 1697 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: | 
|  | 1698 | ar = (AsyncResult) msg.obj; | 
|  | 1699 | request = (MainThreadRequest) ar.userObj; | 
|  | 1700 | if (ar.exception != null) { | 
|  | 1701 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; | 
|  | 1702 | } else { | 
|  | 1703 | request.result = ((int[]) ar.result)[0]; | 
|  | 1704 | } | 
|  | 1705 | notifyRequester(request); | 
|  | 1706 | break; | 
|  | 1707 | case CMD_SET_CDMA_ROAMING_MODE: | 
|  | 1708 | request = (MainThreadRequest) msg.obj; | 
|  | 1709 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); | 
|  | 1710 | int mode = (int) request.argument; | 
|  | 1711 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); | 
|  | 1712 | break; | 
|  | 1713 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: | 
|  | 1714 | ar = (AsyncResult) msg.obj; | 
|  | 1715 | request = (MainThreadRequest) ar.userObj; | 
|  | 1716 | request.result = ar.exception == null; | 
|  | 1717 | notifyRequester(request); | 
|  | 1718 | break; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1719 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1720 | request = (MainThreadRequest) msg.obj; | 
|  | 1721 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1722 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); | 
|  | 1723 | break; | 
|  | 1724 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1725 | ar = (AsyncResult) msg.obj; | 
|  | 1726 | request = (MainThreadRequest) ar.userObj; | 
|  | 1727 | if (ar.exception != null) { | 
|  | 1728 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; | 
|  | 1729 | } else { | 
|  | 1730 | request.result = ((int[]) ar.result)[0]; | 
|  | 1731 | } | 
|  | 1732 | notifyRequester(request); | 
|  | 1733 | break; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1734 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: | 
|  | 1735 | request = (MainThreadRequest) msg.obj; | 
|  | 1736 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); | 
|  | 1737 | int subscriptionMode = (int) request.argument; | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1738 | getPhoneFromRequest(request).setCdmaSubscriptionMode( | 
|  | 1739 | subscriptionMode, onCompleted); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1740 | break; | 
|  | 1741 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: | 
|  | 1742 | ar = (AsyncResult) msg.obj; | 
|  | 1743 | request = (MainThreadRequest) ar.userObj; | 
|  | 1744 | request.result = ar.exception == null; | 
|  | 1745 | notifyRequester(request); | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1746 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1747 | case CMD_GET_ALL_CELL_INFO: | 
|  | 1748 | request = (MainThreadRequest) msg.obj; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1749 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1750 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1751 | break; | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1752 | case EVENT_GET_ALL_CELL_INFO_DONE: | 
|  | 1753 | ar = (AsyncResult) msg.obj; | 
|  | 1754 | request = (MainThreadRequest) ar.userObj; | 
| Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1755 | // If a timeout occurs, the response will be null | 
|  | 1756 | request.result = (ar.exception == null && ar.result != null) | 
|  | 1757 | ? ar.result : new ArrayList<CellInfo>(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1758 | synchronized (request) { | 
|  | 1759 | request.notifyAll(); | 
|  | 1760 | } | 
|  | 1761 | break; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1762 | case CMD_REQUEST_CELL_INFO_UPDATE: | 
|  | 1763 | request = (MainThreadRequest) msg.obj; | 
|  | 1764 | request.phone.requestCellInfoUpdate(request.workSource, | 
|  | 1765 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); | 
|  | 1766 | break; | 
|  | 1767 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: | 
|  | 1768 | ar = (AsyncResult) msg.obj; | 
|  | 1769 | request = (MainThreadRequest) ar.userObj; | 
|  | 1770 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; | 
|  | 1771 | try { | 
|  | 1772 | if (ar.exception != null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1773 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1774 | cb.onError( | 
|  | 1775 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, | 
|  | 1776 | ar.exception.getClass().getName(), | 
|  | 1777 | ar.exception.toString()); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1778 | } else if (ar.result == null) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1779 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); | 
| Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1780 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1781 | } else { | 
|  | 1782 | // use the result as returned | 
|  | 1783 | cb.onCellInfo((List<CellInfo>) ar.result); | 
|  | 1784 | } | 
|  | 1785 | } catch (RemoteException re) { | 
|  | 1786 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); | 
|  | 1787 | } | 
|  | 1788 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1789 | case CMD_GET_CELL_LOCATION: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1790 | request = (MainThreadRequest) msg.obj; | 
|  | 1791 | WorkSource ws = (WorkSource) request.argument; | 
|  | 1792 | Phone phone = getPhoneFromRequest(request); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1793 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1794 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | } | 
|  | 1796 | case EVENT_GET_CELL_LOCATION_DONE: { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1797 | ar = (AsyncResult) msg.obj; | 
|  | 1798 | request = (MainThreadRequest) ar.userObj; | 
|  | 1799 | if (ar.exception == null) { | 
|  | 1800 | request.result = ar.result; | 
|  | 1801 | } else { | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1802 | Phone phone = getPhoneFromRequest(request); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1803 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1804 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1805 | } | 
|  | 1806 |  | 
|  | 1807 | synchronized (request) { | 
|  | 1808 | request.notifyAll(); | 
|  | 1809 | } | 
|  | 1810 | break; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1811 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1812 | case CMD_MODEM_REBOOT: | 
|  | 1813 | request = (MainThreadRequest) msg.obj; | 
|  | 1814 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1815 | defaultPhone.rebootModem(onCompleted); | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1816 | break; | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1817 | case EVENT_CMD_MODEM_REBOOT_DONE: | 
|  | 1818 | handleNullReturnEvent(msg, "rebootModem"); | 
|  | 1819 | break; | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1820 | case CMD_REQUEST_ENABLE_MODEM: { | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1821 | request = (MainThreadRequest) msg.obj; | 
|  | 1822 | boolean enable = (boolean) request.argument; | 
|  | 1823 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1824 | onCompleted.arg1 = enable ? 1 : 0; | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1825 | PhoneConfigurationManager.getInstance() | 
|  | 1826 | .enablePhone(request.phone, enable, onCompleted); | 
|  | 1827 | break; | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 1828 | } | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1829 | case EVENT_ENABLE_MODEM_DONE: { | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1830 | ar = (AsyncResult) msg.obj; | 
|  | 1831 | request = (MainThreadRequest) ar.userObj; | 
|  | 1832 | request.result = (ar.exception == null); | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1833 | int phoneId = request.phone.getPhoneId(); | 
| Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1834 | //update the cache as modem status has changed | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1835 | if ((boolean) request.result) { | 
|  | 1836 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); | 
|  | 1837 | updateModemStateMetrics(); | 
|  | 1838 | } else { | 
|  | 1839 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1840 | + ar.exception); | 
|  | 1841 | } | 
|  | 1842 | notifyRequester(request); | 
|  | 1843 | break; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1844 | } | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1845 | case CMD_GET_MODEM_STATUS: | 
|  | 1846 | request = (MainThreadRequest) msg.obj; | 
|  | 1847 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); | 
|  | 1848 | PhoneConfigurationManager.getInstance() | 
|  | 1849 | .getPhoneStatusFromModem(request.phone, onCompleted); | 
|  | 1850 | break; | 
|  | 1851 | case EVENT_GET_MODEM_STATUS_DONE: | 
|  | 1852 | ar = (AsyncResult) msg.obj; | 
|  | 1853 | request = (MainThreadRequest) ar.userObj; | 
|  | 1854 | int id = request.phone.getPhoneId(); | 
|  | 1855 | if (ar.exception == null && ar.result != null) { | 
|  | 1856 | request.result = ar.result; | 
|  | 1857 | //update the cache as modem status has changed | 
|  | 1858 | mPhoneConfigurationManager.addToPhoneStatusCache(id, | 
|  | 1859 | (boolean) request.result); | 
|  | 1860 | } else { | 
|  | 1861 | // Return true if modem status cannot be retrieved. For most cases, | 
|  | 1862 | // modem status is on. And for older version modems, GET_MODEM_STATUS | 
|  | 1863 | // and disable modem are not supported. Modem is always on. | 
|  | 1864 | // TODO: this should be fixed in R to support a third | 
|  | 1865 | // status UNKNOWN b/131631629 | 
|  | 1866 | request.result = true; | 
|  | 1867 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." | 
|  | 1868 | + ar.exception); | 
|  | 1869 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1870 | notifyRequester(request); | 
|  | 1871 | break; | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1872 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1873 | request = (MainThreadRequest) msg.obj; | 
|  | 1874 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1875 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1876 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1877 | request.phone.setSystemSelectionChannels(args.first, onCompleted); | 
|  | 1878 | break; | 
|  | 1879 | } | 
|  | 1880 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { | 
|  | 1881 | ar = (AsyncResult) msg.obj; | 
|  | 1882 | request = (MainThreadRequest) ar.userObj; | 
|  | 1883 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = | 
|  | 1884 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; | 
|  | 1885 | args.second.accept(ar.exception == null); | 
|  | 1886 | notifyRequester(request); | 
|  | 1887 | break; | 
|  | 1888 | } | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1889 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { | 
|  | 1890 | request = (MainThreadRequest) msg.obj; | 
|  | 1891 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); | 
|  | 1892 | Phone phone = getPhoneFromRequest(request); | 
|  | 1893 | if (phone != null) { | 
|  | 1894 | phone.getSystemSelectionChannels(onCompleted); | 
|  | 1895 | } else { | 
|  | 1896 | loge("getSystemSelectionChannels: No phone object"); | 
|  | 1897 | request.result = new ArrayList<RadioAccessSpecifier>(); | 
|  | 1898 | notifyRequester(request); | 
|  | 1899 | } | 
|  | 1900 | break; | 
|  | 1901 | } | 
|  | 1902 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: | 
|  | 1903 | ar = (AsyncResult) msg.obj; | 
|  | 1904 | request = (MainThreadRequest) ar.userObj; | 
|  | 1905 | if (ar.exception == null && ar.result != null) { | 
|  | 1906 | request.result = ar.result; | 
|  | 1907 | } else { | 
| Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1908 | request.result = new IllegalStateException( | 
|  | 1909 | "Failed to retrieve system selecton channels"); | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1910 | if (ar.result == null) { | 
|  | 1911 | loge("getSystemSelectionChannels: Empty response"); | 
|  | 1912 | } else { | 
|  | 1913 | loge("getSystemSelectionChannels: Unknown exception"); | 
|  | 1914 | } | 
|  | 1915 | } | 
|  | 1916 | notifyRequester(request); | 
|  | 1917 | break; | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1918 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: | 
|  | 1919 | ar = (AsyncResult) msg.obj; | 
|  | 1920 | request = (MainThreadRequest) ar.userObj; | 
|  | 1921 | if (ar.exception == null && ar.result != null) { | 
|  | 1922 | request.result = ar.result; | 
|  | 1923 | } else { | 
|  | 1924 | request.result = -1; | 
|  | 1925 | loge("Failed to set Forbidden Plmns"); | 
|  | 1926 | if (ar.result == null) { | 
|  | 1927 | loge("setForbidenPlmns: Empty response"); | 
|  | 1928 | } else if (ar.exception != null) { | 
|  | 1929 | loge("setForbiddenPlmns: Exception: " + ar.exception); | 
|  | 1930 | request.result = -1; | 
|  | 1931 | } else { | 
|  | 1932 | loge("setForbiddenPlmns: Unknown exception"); | 
|  | 1933 | } | 
|  | 1934 | } | 
|  | 1935 | notifyRequester(request); | 
|  | 1936 | break; | 
|  | 1937 | case CMD_SET_FORBIDDEN_PLMNS: | 
|  | 1938 | request = (MainThreadRequest) msg.obj; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1939 | uiccPort = getUiccPortFromRequest(request); | 
|  | 1940 | if (uiccPort == null) { | 
|  | 1941 | loge("setForbiddenPlmns: UiccPort is null"); | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1942 | request.result = -1; | 
|  | 1943 | notifyRequester(request); | 
|  | 1944 | break; | 
|  | 1945 | } | 
|  | 1946 | Pair<Integer, List<String>> setFplmnsArgs = | 
|  | 1947 | (Pair<Integer, List<String>>) request.argument; | 
|  | 1948 | appType = setFplmnsArgs.first; | 
|  | 1949 | List<String> fplmns = setFplmnsArgs.second; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1950 | uiccApp = uiccPort.getApplicationByType(appType); | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1951 | if (uiccApp == null) { | 
|  | 1952 | loge("setForbiddenPlmns: no app with specified type -- " + appType); | 
|  | 1953 | request.result = -1; | 
|  | 1954 | loge("Failed to get UICC App"); | 
|  | 1955 | notifyRequester(request); | 
|  | 1956 | } else { | 
|  | 1957 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); | 
|  | 1958 | ((SIMRecords) uiccApp.getIccRecords()) | 
|  | 1959 | .setForbiddenPlmns(onCompleted, fplmns); | 
|  | 1960 | } | 
| yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1961 | break; | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1962 | case CMD_ERASE_MODEM_CONFIG: | 
|  | 1963 | request = (MainThreadRequest) msg.obj; | 
|  | 1964 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); | 
|  | 1965 | defaultPhone.eraseModemConfig(onCompleted); | 
|  | 1966 | break; | 
|  | 1967 | case EVENT_ERASE_MODEM_CONFIG_DONE: | 
|  | 1968 | handleNullReturnEvent(msg, "eraseModemConfig"); | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1969 | break; | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1970 |  | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1971 | case CMD_ERASE_DATA_SHARED_PREFERENCES: | 
|  | 1972 | request = (MainThreadRequest) msg.obj; | 
|  | 1973 | request.result = defaultPhone.eraseDataInSharedPreferences(); | 
|  | 1974 | notifyRequester(request); | 
|  | 1975 | break; | 
|  | 1976 |  | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1977 | case CMD_CHANGE_ICC_LOCK_PASSWORD: | 
|  | 1978 | request = (MainThreadRequest) msg.obj; | 
|  | 1979 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); | 
|  | 1980 | Pair<String, String> changed = (Pair<String, String>) request.argument; | 
|  | 1981 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( | 
|  | 1982 | changed.first, changed.second, onCompleted); | 
|  | 1983 | break; | 
|  | 1984 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: | 
|  | 1985 | ar = (AsyncResult) msg.obj; | 
|  | 1986 | request = (MainThreadRequest) ar.userObj; | 
|  | 1987 | if (ar.exception == null) { | 
|  | 1988 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1989 | // If the operation is successful, update the PIN storage | 
|  | 1990 | Pair<String, String> passwords = (Pair<String, String>) request.argument; | 
|  | 1991 | int phoneId = getPhoneFromRequest(request).getPhoneId(); | 
| Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1992 | UiccController.getInstance().getPinStorage() | 
|  | 1993 | .storePin(passwords.second, phoneId); | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1994 | } else { | 
|  | 1995 | request.result = msg.arg1; | 
|  | 1996 | } | 
|  | 1997 | notifyRequester(request); | 
|  | 1998 | break; | 
|  | 1999 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2000 | case CMD_SET_ICC_LOCK_ENABLED: { | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2001 | request = (MainThreadRequest) msg.obj; | 
|  | 2002 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); | 
|  | 2003 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
|  | 2004 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( | 
|  | 2005 | enabled.first, enabled.second, onCompleted); | 
|  | 2006 | break; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2007 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2008 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: | 
|  | 2009 | ar = (AsyncResult) msg.obj; | 
|  | 2010 | request = (MainThreadRequest) ar.userObj; | 
|  | 2011 | if (ar.exception == null) { | 
|  | 2012 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2013 | // If the operation is successful, update the PIN storage | 
|  | 2014 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; | 
|  | 2015 | int phoneId = getPhoneFromRequest(request).getPhoneId(); | 
|  | 2016 | if (enabled.first) { | 
| Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2017 | UiccController.getInstance().getPinStorage() | 
|  | 2018 | .storePin(enabled.second, phoneId); | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2019 | } else { | 
|  | 2020 | UiccController.getInstance().getPinStorage().clearPin(phoneId); | 
|  | 2021 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2022 | } else { | 
|  | 2023 | request.result = msg.arg1; | 
|  | 2024 | } | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2025 |  | 
|  | 2026 |  | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 2027 | notifyRequester(request); | 
|  | 2028 | break; | 
|  | 2029 |  | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2030 | case MSG_NOTIFY_USER_ACTIVITY: | 
|  | 2031 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); | 
| Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 2032 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 2033 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); | 
|  | 2034 | getDefaultPhone().getContext().sendBroadcastAsUser( | 
|  | 2035 | intent, UserHandle.ALL, permission.USER_ACTIVITY); | 
|  | 2036 | break; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2037 |  | 
|  | 2038 | case CMD_SET_DATA_THROTTLING: { | 
|  | 2039 | request = (MainThreadRequest) msg.obj; | 
|  | 2040 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); | 
|  | 2041 | DataThrottlingRequest dataThrottlingRequest = | 
|  | 2042 | (DataThrottlingRequest) request.argument; | 
|  | 2043 | Phone phone = getPhoneFromRequest(request); | 
|  | 2044 | if (phone != null) { | 
|  | 2045 | phone.setDataThrottling(onCompleted, | 
|  | 2046 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), | 
|  | 2047 | dataThrottlingRequest.getCompletionDurationMillis()); | 
|  | 2048 | } else { | 
|  | 2049 | loge("setDataThrottling: No phone object"); | 
|  | 2050 | request.result = | 
|  | 2051 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 2052 | notifyRequester(request); | 
|  | 2053 | } | 
|  | 2054 |  | 
|  | 2055 | break; | 
|  | 2056 | } | 
|  | 2057 | case EVENT_SET_DATA_THROTTLING_DONE: | 
|  | 2058 | ar = (AsyncResult) msg.obj; | 
|  | 2059 | request = (MainThreadRequest) ar.userObj; | 
|  | 2060 |  | 
|  | 2061 | if (ar.exception == null) { | 
|  | 2062 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 2063 | } else if (ar.exception instanceof CommandException) { | 
|  | 2064 | loge("setDataThrottling: CommandException: " + ar.exception); | 
|  | 2065 | CommandException.Error error = | 
|  | 2066 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 2067 |  | 
|  | 2068 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { | 
|  | 2069 | request.result = TelephonyManager | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2070 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2071 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 2072 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2073 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 2074 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2075 | } else { | 
|  | 2076 | request.result = | 
|  | 2077 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 2078 | } | 
|  | 2079 | } else { | 
|  | 2080 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 2081 | } | 
|  | 2082 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); | 
|  | 2083 | notifyRequester(request); | 
|  | 2084 | break; | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2085 |  | 
|  | 2086 | case CMD_SET_SIM_POWER: { | 
|  | 2087 | request = (MainThreadRequest) msg.obj; | 
|  | 2088 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); | 
|  | 2089 | request = (MainThreadRequest) msg.obj; | 
|  | 2090 | int stateToSet = | 
|  | 2091 | ((Pair<Integer, IIntegerConsumer>) | 
|  | 2092 | request.argument).first; | 
|  | 2093 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); | 
|  | 2094 | break; | 
|  | 2095 | } | 
|  | 2096 | case EVENT_SET_SIM_POWER_DONE: { | 
|  | 2097 | ar = (AsyncResult) msg.obj; | 
|  | 2098 | request = (MainThreadRequest) ar.userObj; | 
|  | 2099 | IIntegerConsumer callback = | 
|  | 2100 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; | 
|  | 2101 | if (ar.exception != null) { | 
|  | 2102 | loge("setSimPower exception: " + ar.exception); | 
|  | 2103 | int errorCode = TelephonyManager.CallForwardingInfoCallback | 
|  | 2104 | .RESULT_ERROR_UNKNOWN; | 
|  | 2105 | if (ar.exception instanceof CommandException) { | 
|  | 2106 | CommandException.Error error = | 
|  | 2107 | ((CommandException) (ar.exception)).getCommandError(); | 
|  | 2108 | if (error == CommandException.Error.SIM_ERR) { | 
|  | 2109 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; | 
|  | 2110 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { | 
|  | 2111 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; | 
|  | 2112 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { | 
|  | 2113 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; | 
|  | 2114 | } else { | 
|  | 2115 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; | 
|  | 2116 | } | 
|  | 2117 | } | 
|  | 2118 | try { | 
|  | 2119 | callback.accept(errorCode); | 
|  | 2120 | } catch (RemoteException e) { | 
|  | 2121 | // Ignore if the remote process is no longer available to call back. | 
|  | 2122 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 2123 | } | 
|  | 2124 | } else { | 
|  | 2125 | try { | 
|  | 2126 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); | 
|  | 2127 | } catch (RemoteException e) { | 
|  | 2128 | // Ignore if the remote process is no longer available to call back. | 
|  | 2129 | Log.w(LOG_TAG, "setSimPower: callback not available."); | 
|  | 2130 | } | 
|  | 2131 | } | 
|  | 2132 | break; | 
|  | 2133 | } | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2134 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { | 
|  | 2135 | request = (MainThreadRequest) msg.obj; | 
|  | 2136 |  | 
|  | 2137 | final Phone phone = getPhoneFromRequest(request); | 
|  | 2138 | if (phone == null || phone.getServiceStateTracker() == null) { | 
|  | 2139 | request.result = new IllegalStateException("Phone or SST is null"); | 
|  | 2140 | notifyRequester(request); | 
|  | 2141 | break; | 
|  | 2142 | } | 
|  | 2143 |  | 
|  | 2144 | Pair<Integer, SignalStrengthUpdateRequest> pair = | 
|  | 2145 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; | 
|  | 2146 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, | 
|  | 2147 | request); | 
| Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2148 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2149 | request.subId, pair.first /*callingUid*/, | 
|  | 2150 | pair.second /*request*/, onCompleted); | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2151 | break; | 
|  | 2152 | } | 
|  | 2153 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { | 
|  | 2154 | ar = (AsyncResult) msg.obj; | 
|  | 2155 | request = (MainThreadRequest) ar.userObj; | 
|  | 2156 | // request.result will be the exception of ar if present, true otherwise. | 
|  | 2157 | // Be cautious not to leave result null which will wait() forever | 
|  | 2158 | request.result = ar.exception != null ? ar.exception : true; | 
|  | 2159 | notifyRequester(request); | 
|  | 2160 | break; | 
|  | 2161 | } | 
|  | 2162 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { | 
|  | 2163 | request = (MainThreadRequest) msg.obj; | 
|  | 2164 |  | 
|  | 2165 | Phone phone = getPhoneFromRequest(request); | 
|  | 2166 | if (phone == null || phone.getServiceStateTracker() == null) { | 
|  | 2167 | request.result = new IllegalStateException("Phone or SST is null"); | 
|  | 2168 | notifyRequester(request); | 
|  | 2169 | break; | 
|  | 2170 | } | 
|  | 2171 |  | 
|  | 2172 | Pair<Integer, SignalStrengthUpdateRequest> pair = | 
|  | 2173 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; | 
|  | 2174 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, | 
|  | 2175 | request); | 
| Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2176 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2177 | request.subId, pair.first /*callingUid*/, | 
|  | 2178 | pair.second /*request*/, onCompleted); | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2179 | break; | 
|  | 2180 | } | 
|  | 2181 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { | 
|  | 2182 | ar = (AsyncResult) msg.obj; | 
|  | 2183 | request = (MainThreadRequest) ar.userObj; | 
|  | 2184 | request.result = ar.exception != null ? ar.exception : true; | 
|  | 2185 | notifyRequester(request); | 
|  | 2186 | break; | 
|  | 2187 | } | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2188 |  | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2189 | case CMD_GET_SLICING_CONFIG: { | 
|  | 2190 | request = (MainThreadRequest) msg.obj; | 
|  | 2191 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); | 
|  | 2192 | request.phone.getSlicingConfig(onCompleted); | 
|  | 2193 | break; | 
|  | 2194 | } | 
|  | 2195 | case EVENT_GET_SLICING_CONFIG_DONE: { | 
|  | 2196 | ar = (AsyncResult) msg.obj; | 
|  | 2197 | request = (MainThreadRequest) ar.userObj; | 
|  | 2198 | ResultReceiver result = (ResultReceiver) request.argument; | 
|  | 2199 |  | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2200 | NetworkSlicingConfig slicingConfig = null; | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2201 | Bundle bundle = new Bundle(); | 
|  | 2202 | int resultCode = 0; | 
|  | 2203 | if (ar.exception != null) { | 
|  | 2204 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" | 
|  | 2205 | + ar.exception); | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2206 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2207 | } else if (ar.result == null) { | 
|  | 2208 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2209 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2210 | } else { | 
|  | 2211 | // use the result as returned | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2212 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; | 
|  | 2213 | slicingConfig = (NetworkSlicingConfig) ar.result; | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2214 | } | 
|  | 2215 |  | 
|  | 2216 | if (slicingConfig == null) { | 
| Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2217 | slicingConfig = new NetworkSlicingConfig(); | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2218 | } | 
|  | 2219 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); | 
|  | 2220 | result.send(resultCode, bundle); | 
|  | 2221 | notifyRequester(request); | 
|  | 2222 | break; | 
|  | 2223 | } | 
|  | 2224 |  | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2225 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2226 | request = (MainThreadRequest) msg.obj; | 
|  | 2227 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2228 | PurchasePremiumCapabilityArgument arg = | 
|  | 2229 | (PurchasePremiumCapabilityArgument) request.argument; | 
| Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2230 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( | 
| Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 2231 | arg.capability, onCompleted); | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2232 | break; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2233 | } | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2234 |  | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2235 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2236 | ar = (AsyncResult) msg.obj; | 
|  | 2237 | request = (MainThreadRequest) ar.userObj; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2238 | PurchasePremiumCapabilityArgument arg = | 
|  | 2239 | (PurchasePremiumCapabilityArgument) request.argument; | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2240 | try { | 
|  | 2241 | int result = (int) ar.result; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2242 | arg.callback.accept(result); | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2243 | log("purchasePremiumCapability: capability=" | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2244 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2245 | + ", result= " | 
|  | 2246 | + TelephonyManager.convertPurchaseResultToString(result)); | 
|  | 2247 | } catch (RemoteException e) { | 
|  | 2248 | String logStr = "Purchase premium capability " | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2249 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2250 | + " failed: " + e; | 
|  | 2251 | if (DBG) log(logStr); | 
|  | 2252 | AnomalyReporter.reportAnomaly( | 
|  | 2253 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); | 
|  | 2254 | } | 
|  | 2255 | break; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2256 | } | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2257 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2258 | case CMD_PREPARE_UNATTENDED_REBOOT: | 
|  | 2259 | request = (MainThreadRequest) msg.obj; | 
|  | 2260 | request.result = | 
| Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2261 | UiccController.getInstance().getPinStorage() | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2262 | .prepareUnattendedReboot(request.workSource); | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2263 | notifyRequester(request); | 
|  | 2264 | break; | 
|  | 2265 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | default: | 
|  | 2267 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); | 
|  | 2268 | break; | 
|  | 2269 | } | 
|  | 2270 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2271 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2272 | private void notifyRequester(MainThreadRequest request) { | 
|  | 2273 | synchronized (request) { | 
|  | 2274 | request.notifyAll(); | 
|  | 2275 | } | 
|  | 2276 | } | 
|  | 2277 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2278 | private void handleNullReturnEvent(Message msg, String command) { | 
|  | 2279 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 2280 | MainThreadRequest request = (MainThreadRequest) ar.userObj; | 
|  | 2281 | if (ar.exception == null) { | 
|  | 2282 | request.result = true; | 
|  | 2283 | } else { | 
|  | 2284 | request.result = false; | 
|  | 2285 | if (ar.exception instanceof CommandException) { | 
|  | 2286 | loge(command + ": CommandException: " + ar.exception); | 
|  | 2287 | } else { | 
|  | 2288 | loge(command + ": Unknown exception"); | 
|  | 2289 | } | 
|  | 2290 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2291 | notifyRequester(request); | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2292 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | } | 
|  | 2294 |  | 
|  | 2295 | /** | 
|  | 2296 | * Posts the specified command to be executed on the main thread, | 
|  | 2297 | * waits for the request to complete, and returns the result. | 
|  | 2298 | * @see #sendRequestAsync | 
|  | 2299 | */ | 
|  | 2300 | private Object sendRequest(int command, Object argument) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2301 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, | 
|  | 2302 | null, -1 /*timeoutInMs*/); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2303 | } | 
|  | 2304 |  | 
|  | 2305 | /** | 
|  | 2306 | * Posts the specified command to be executed on the main thread, | 
|  | 2307 | * waits for the request to complete, and returns the result. | 
|  | 2308 | * @see #sendRequestAsync | 
|  | 2309 | */ | 
|  | 2310 | private Object sendRequest(int command, Object argument, WorkSource workSource) { | 
|  | 2311 | return sendRequest(command, argument,  SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2312 | null, workSource, -1 /*timeoutInMs*/); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2313 | } | 
|  | 2314 |  | 
|  | 2315 | /** | 
|  | 2316 | * Posts the specified command to be executed on the main thread, | 
|  | 2317 | * waits for the request to complete, and returns the result. | 
|  | 2318 | * @see #sendRequestAsync | 
|  | 2319 | */ | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2320 | private Object sendRequest(int command, Object argument, Integer subId) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2321 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); | 
|  | 2322 | } | 
|  | 2323 |  | 
|  | 2324 | /** | 
|  | 2325 | * Posts the specified command to be executed on the main thread, | 
|  | 2326 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result | 
|  | 2327 | * if not timeout or null otherwise. | 
|  | 2328 | * @see #sendRequestAsync | 
|  | 2329 | */ | 
|  | 2330 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, | 
|  | 2331 | long timeoutInMs) { | 
|  | 2332 | return sendRequest(command, argument, subId, null, null, timeoutInMs); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2333 | } | 
|  | 2334 |  | 
|  | 2335 | /** | 
|  | 2336 | * Posts the specified command to be executed on the main thread, | 
|  | 2337 | * waits for the request to complete, and returns the result. | 
|  | 2338 | * @see #sendRequestAsync | 
|  | 2339 | */ | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2340 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2341 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2342 | } | 
|  | 2343 |  | 
|  | 2344 | /** | 
|  | 2345 | * Posts the specified command to be executed on the main thread, | 
|  | 2346 | * waits for the request to complete, and returns the result. | 
|  | 2347 | * @see #sendRequestAsync | 
|  | 2348 | */ | 
|  | 2349 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2350 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, | 
|  | 2351 | workSource, -1 /*timeoutInMs*/); | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2352 | } | 
|  | 2353 |  | 
|  | 2354 | /** | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2355 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is | 
|  | 2356 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for | 
|  | 2357 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2358 | * @see #sendRequestAsync | 
|  | 2359 | */ | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2360 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, | 
|  | 2361 | WorkSource workSource, long timeoutInMs) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { | 
|  | 2363 | throw new RuntimeException("This method will deadlock if called from the main thread."); | 
|  | 2364 | } | 
|  | 2365 |  | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2366 | MainThreadRequest request = null; | 
|  | 2367 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { | 
|  | 2368 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); | 
|  | 2369 | } else if (phone != null) { | 
|  | 2370 | request = new MainThreadRequest(argument, phone, workSource); | 
|  | 2371 | } else { | 
|  | 2372 | request = new MainThreadRequest(argument, subId, workSource); | 
|  | 2373 | } | 
|  | 2374 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 2376 | msg.sendToTarget(); | 
|  | 2377 |  | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2378 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | synchronized (request) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2380 | if (timeoutInMs >= 0) { | 
|  | 2381 | // Wait for at least timeoutInMs before returning null request result | 
|  | 2382 | long now = SystemClock.elapsedRealtime(); | 
|  | 2383 | long deadline = now + timeoutInMs; | 
| Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2384 | while (request.result == null && now < deadline) { | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2385 | try { | 
|  | 2386 | request.wait(deadline - now); | 
|  | 2387 | } catch (InterruptedException e) { | 
|  | 2388 | // Do nothing, go back and check if request is completed or timeout | 
|  | 2389 | } finally { | 
|  | 2390 | now = SystemClock.elapsedRealtime(); | 
|  | 2391 | } | 
|  | 2392 | } | 
|  | 2393 | } else { | 
|  | 2394 | // Wait for the request to complete | 
|  | 2395 | while (request.result == null) { | 
|  | 2396 | try { | 
|  | 2397 | request.wait(); | 
|  | 2398 | } catch (InterruptedException e) { | 
|  | 2399 | // Do nothing, go back and wait until the request is complete | 
|  | 2400 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2401 | } | 
|  | 2402 | } | 
|  | 2403 | } | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2404 | if (request.result == null) { | 
|  | 2405 | Log.wtf(LOG_TAG, | 
|  | 2406 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); | 
|  | 2407 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | return request.result; | 
|  | 2409 | } | 
|  | 2410 |  | 
|  | 2411 | /** | 
|  | 2412 | * Asynchronous ("fire and forget") version of sendRequest(): | 
|  | 2413 | * Posts the specified command to be executed on the main thread, and | 
|  | 2414 | * returns immediately. | 
|  | 2415 | * @see #sendRequest | 
|  | 2416 | */ | 
|  | 2417 | private void sendRequestAsync(int command) { | 
|  | 2418 | mMainThreadHandler.sendEmptyMessage(command); | 
|  | 2419 | } | 
|  | 2420 |  | 
|  | 2421 | /** | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2422 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2423 | * @see {@link #sendRequest(int)} | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2424 | */ | 
|  | 2425 | private void sendRequestAsync(int command, Object argument) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2426 | sendRequestAsync(command, argument, null, null); | 
|  | 2427 | } | 
|  | 2428 |  | 
|  | 2429 | /** | 
|  | 2430 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. | 
|  | 2431 | * @see {@link #sendRequest(int,Object)} | 
|  | 2432 | */ | 
|  | 2433 | private void sendRequestAsync( | 
|  | 2434 | int command, Object argument, Phone phone, WorkSource workSource) { | 
|  | 2435 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2436 | Message msg = mMainThreadHandler.obtainMessage(command, request); | 
|  | 2437 | msg.sendToTarget(); | 
|  | 2438 | } | 
|  | 2439 |  | 
|  | 2440 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | * Initialize the singleton PhoneInterfaceManager instance. | 
|  | 2442 | * This is only done once, at startup, from PhoneApp.onCreate(). | 
|  | 2443 | */ | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2444 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | synchronized (PhoneInterfaceManager.class) { | 
|  | 2446 | if (sInstance == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2447 | sInstance = new PhoneInterfaceManager(app); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } else { | 
|  | 2449 | Log.wtf(LOG_TAG, "init() called multiple times!  sInstance = " + sInstance); | 
|  | 2450 | } | 
|  | 2451 | return sInstance; | 
|  | 2452 | } | 
|  | 2453 | } | 
|  | 2454 |  | 
|  | 2455 | /** Private constructor; @see init() */ | 
| Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2456 | private PhoneInterfaceManager(PhoneGlobals app) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | mApp = app; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | mCM = PhoneGlobals.getInstance().mCM; | 
| Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2459 | mImsResolver = ImsResolver.getInstance(); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 2460 | mSatelliteController = SatelliteController.getInstance(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2461 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); | 
|  | 2463 | mMainThreadHandler = new MainThreadHandler(); | 
| Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 2464 | if (!PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
|  | 2465 | mSubscriptionController = SubscriptionController.getInstance(); | 
|  | 2466 | } else { | 
|  | 2467 | mSubscriptionController = null; | 
|  | 2468 | } | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 2469 | mTelephonySharedPreferences = PreferenceManager.getDefaultSharedPreferences(mApp); | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2470 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2471 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2472 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); | 
| Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2473 | mNotifyUserActivity = new AtomicBoolean(false); | 
| Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2474 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | publish(); | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 2476 | CarrierAllowListInfo.loadInstance(mApp); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | } | 
|  | 2478 |  | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 2479 | @VisibleForTesting | 
|  | 2480 | public SharedPreferences getSharedPreferences() { | 
|  | 2481 | return mTelephonySharedPreferences; | 
|  | 2482 | } | 
|  | 2483 |  | 
| Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 2484 | /** | 
|  | 2485 | * Get the default phone for this device. | 
|  | 2486 | */ | 
|  | 2487 | @VisibleForTesting | 
|  | 2488 | public Phone getDefaultPhone() { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2489 | Phone thePhone = getPhone(getDefaultSubscription()); | 
|  | 2490 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); | 
|  | 2491 | } | 
|  | 2492 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | private void publish() { | 
|  | 2494 | if (DBG) log("publish: " + this); | 
|  | 2495 |  | 
| Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2496 | TelephonyFrameworkInitializer | 
|  | 2497 | .getTelephonyServiceManager() | 
|  | 2498 | .getTelephonyServiceRegisterer() | 
|  | 2499 | .register(this); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | } | 
|  | 2501 |  | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2502 | private Phone getPhoneFromRequest(MainThreadRequest request) { | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2503 | if (request.phone != null) { | 
|  | 2504 | return request.phone; | 
|  | 2505 | } else { | 
|  | 2506 | return getPhoneFromSubId(request.subId); | 
|  | 2507 | } | 
|  | 2508 | } | 
|  | 2509 |  | 
|  | 2510 | private Phone getPhoneFromSubId(int subId) { | 
|  | 2511 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) | 
|  | 2512 | ? getDefaultPhone() : getPhone(subId); | 
| Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2513 | } | 
|  | 2514 |  | 
| Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2515 | /** | 
|  | 2516 | * Get phone object associated with a subscription. | 
|  | 2517 | * Return default phone if phone object associated with subscription is null | 
|  | 2518 | * @param subId - subscriptionId | 
|  | 2519 | * @return phone object associated with a subscription or default phone if null. | 
|  | 2520 | */ | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2521 | private @NonNull Phone getPhoneFromSubIdOrDefault(int subId) { | 
| Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2522 | Phone phone = getPhoneFromSubId(subId); | 
|  | 2523 | if (phone == null) { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2524 | loge("Called with invalid subId: " + subId + ". Retrying with default phone."); | 
| Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 2525 | phone = getDefaultPhone(); | 
|  | 2526 | } | 
|  | 2527 | return phone; | 
|  | 2528 | } | 
|  | 2529 |  | 
| Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2530 | @Nullable | 
|  | 2531 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2532 | Phone phone = getPhoneFromRequest(request); | 
|  | 2533 | return phone == null ? null : | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2534 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2535 | } | 
|  | 2536 |  | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2537 | /** | 
|  | 2538 | * @param subId The sub Id that associates the phone. If the device has no active SIM, passing | 
|  | 2539 | *              in {@link SubscriptionManager#DEFAULT_SUBSCRIPTION_ID} or any sub <= | 
|  | 2540 | *              {@link SubscriptionManager#INVALID_SUBSCRIPTION_ID} will return {@code null}. | 
|  | 2541 | * @return The Phone associated the sub Id | 
|  | 2542 | */ | 
|  | 2543 | private @Nullable Phone getPhone(int subId) { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 2544 | return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId)); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2545 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 |  | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2547 | private void sendEraseModemConfig(@NonNull Phone phone) { | 
|  | 2548 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); | 
|  | 2549 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 2550 | } | 
|  | 2551 |  | 
|  | 2552 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { | 
|  | 2553 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); | 
|  | 2554 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2555 | } | 
|  | 2556 |  | 
| Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2557 | private boolean isImsAvailableOnDevice() { | 
|  | 2558 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); | 
|  | 2559 | if (pm == null) { | 
|  | 2560 | // For some reason package manger is not available.. This will fail internally anyway, | 
|  | 2561 | // so do not throw error and allow. | 
|  | 2562 | return true; | 
|  | 2563 | } | 
|  | 2564 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); | 
|  | 2565 | } | 
|  | 2566 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | public void dial(String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2568 | dialForSubscriber(getPreferredVoiceSubscription(), number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2569 | } | 
|  | 2570 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public void dialForSubscriber(int subId, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | if (DBG) log("dial: " + number); | 
|  | 2573 | // No permission check needed here: This is just a wrapper around the | 
|  | 2574 | // ACTION_DIAL intent, which is available to any app since it puts up | 
|  | 2575 | // the UI before it does anything. | 
|  | 2576 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2578 | try { | 
|  | 2579 | String url = createTelUrl(number); | 
|  | 2580 | if (url == null) { | 
|  | 2581 | return; | 
|  | 2582 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2584 | // PENDING: should we just silently fail if phone is offhook or ringing? | 
|  | 2585 | PhoneConstants.State state = mCM.getState(subId); | 
|  | 2586 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { | 
|  | 2587 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); | 
|  | 2588 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2589 | mApp.startActivity(intent); | 
|  | 2590 | } | 
|  | 2591 | } finally { | 
|  | 2592 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2593 | } | 
|  | 2594 | } | 
|  | 2595 |  | 
|  | 2596 | public void call(String callingPackage, String number) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2597 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2598 | } | 
|  | 2599 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2600 | public void callForSubscriber(int subId, String callingPackage, String number) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | if (DBG) log("call: " + number); | 
|  | 2602 |  | 
|  | 2603 | // This is just a wrapper around the ACTION_CALL intent, but we still | 
|  | 2604 | // need to do a permission check since we're calling startActivity() | 
|  | 2605 | // from the context of the phone app. | 
|  | 2606 | enforceCallPermission(); | 
|  | 2607 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2608 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2609 | != AppOpsManager.MODE_ALLOWED) { | 
|  | 2610 | return; | 
|  | 2611 | } | 
|  | 2612 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2614 | try { | 
|  | 2615 | String url = createTelUrl(number); | 
|  | 2616 | if (url == null) { | 
|  | 2617 | return; | 
|  | 2618 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2620 | boolean isValid = false; | 
|  | 2621 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); | 
|  | 2622 | if (slist != null) { | 
|  | 2623 | for (SubscriptionInfo subInfoRecord : slist) { | 
|  | 2624 | if (subInfoRecord.getSubscriptionId() == subId) { | 
|  | 2625 | isValid = true; | 
|  | 2626 | break; | 
|  | 2627 | } | 
| Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2628 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2629 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | if (!isValid) { | 
|  | 2631 | return; | 
|  | 2632 | } | 
| Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2633 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2634 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); | 
|  | 2635 | intent.putExtra(SUBSCRIPTION_KEY, subId); | 
|  | 2636 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 2637 | mApp.startActivity(intent); | 
|  | 2638 | } finally { | 
|  | 2639 | Binder.restoreCallingIdentity(identity); | 
|  | 2640 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | } | 
|  | 2642 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2643 | public boolean supplyPinForSubscriber(int subId, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2644 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2645 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2646 | } | 
|  | 2647 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2648 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2649 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2650 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; | 
|  | 2651 | } | 
|  | 2652 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2653 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2654 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 |  | 
|  | 2656 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2657 | try { | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2658 | Phone phone = getPhone(subId); | 
|  | 2659 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2660 | checkSimPin.start(); | 
|  | 2661 | return checkSimPin.unlockSim(null, pin); | 
|  | 2662 | } finally { | 
|  | 2663 | Binder.restoreCallingIdentity(identity); | 
|  | 2664 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | } | 
|  | 2666 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2667 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2668 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 |  | 
|  | 2670 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2671 | try { | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2672 | Phone phone = getPhone(subId); | 
|  | 2673 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | checkSimPuk.start(); | 
|  | 2675 | return checkSimPuk.unlockSim(puk, pin); | 
|  | 2676 | } finally { | 
|  | 2677 | Binder.restoreCallingIdentity(identity); | 
|  | 2678 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | } | 
|  | 2680 |  | 
|  | 2681 | /** | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2682 | * Helper thread to turn async call to SimCard#supplyPin into | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | * a synchronous one. | 
|  | 2684 | */ | 
|  | 2685 | private static class UnlockSim extends Thread { | 
|  | 2686 |  | 
|  | 2687 | private final IccCard mSimCard; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2688 | private final int mPhoneId; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 |  | 
|  | 2690 | private boolean mDone = false; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2691 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2692 | private int mRetryCount = -1; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2693 |  | 
|  | 2694 | // For replies from SimCard interface | 
|  | 2695 | private Handler mHandler; | 
|  | 2696 |  | 
|  | 2697 | // For async handler to identify request type | 
|  | 2698 | private static final int SUPPLY_PIN_COMPLETE = 100; | 
|  | 2699 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2700 | UnlockSim(int phoneId, IccCard simCard) { | 
|  | 2701 | mPhoneId = phoneId; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | mSimCard = simCard; | 
|  | 2703 | } | 
|  | 2704 |  | 
|  | 2705 | @Override | 
|  | 2706 | public void run() { | 
|  | 2707 | Looper.prepare(); | 
|  | 2708 | synchronized (UnlockSim.this) { | 
|  | 2709 | mHandler = new Handler() { | 
|  | 2710 | @Override | 
|  | 2711 | public void handleMessage(Message msg) { | 
|  | 2712 | AsyncResult ar = (AsyncResult) msg.obj; | 
|  | 2713 | switch (msg.what) { | 
|  | 2714 | case SUPPLY_PIN_COMPLETE: | 
|  | 2715 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); | 
|  | 2716 | synchronized (UnlockSim.this) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2717 | mRetryCount = msg.arg1; | 
|  | 2718 | if (ar.exception != null) { | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2719 | CommandException.Error error = null; | 
|  | 2720 | if (ar.exception instanceof CommandException) { | 
|  | 2721 | error = ((CommandException) (ar.exception)) | 
|  | 2722 | .getCommandError(); | 
|  | 2723 | } | 
|  | 2724 | if (error == CommandException.Error.PASSWORD_INCORRECT) { | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2725 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 2726 | } else if (error == CommandException.Error.ABORTED) { | 
|  | 2727 | /* When UiccCardApp dispose, handle message and return | 
|  | 2728 | exception */ | 
| vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2729 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2730 | } else { | 
|  | 2731 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; | 
|  | 2732 | } | 
|  | 2733 | } else { | 
|  | 2734 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; | 
|  | 2735 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | mDone = true; | 
|  | 2737 | UnlockSim.this.notifyAll(); | 
|  | 2738 | } | 
|  | 2739 | break; | 
|  | 2740 | } | 
|  | 2741 | } | 
|  | 2742 | }; | 
|  | 2743 | UnlockSim.this.notifyAll(); | 
|  | 2744 | } | 
|  | 2745 | Looper.loop(); | 
|  | 2746 | } | 
|  | 2747 |  | 
|  | 2748 | /* | 
|  | 2749 | * Use PIN or PUK to unlock SIM card | 
|  | 2750 | * | 
|  | 2751 | * If PUK is null, unlock SIM card with PIN | 
|  | 2752 | * | 
|  | 2753 | * If PUK is not null, unlock SIM card with PUK and set PIN code | 
|  | 2754 | */ | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2755 | synchronized int[] unlockSim(String puk, String pin) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2756 |  | 
|  | 2757 | while (mHandler == null) { | 
|  | 2758 | try { | 
|  | 2759 | wait(); | 
|  | 2760 | } catch (InterruptedException e) { | 
|  | 2761 | Thread.currentThread().interrupt(); | 
|  | 2762 | } | 
|  | 2763 | } | 
|  | 2764 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); | 
|  | 2765 |  | 
|  | 2766 | if (puk == null) { | 
|  | 2767 | mSimCard.supplyPin(pin, callback); | 
|  | 2768 | } else { | 
|  | 2769 | mSimCard.supplyPuk(puk, pin, callback); | 
|  | 2770 | } | 
|  | 2771 |  | 
|  | 2772 | while (!mDone) { | 
|  | 2773 | try { | 
|  | 2774 | Log.d(LOG_TAG, "wait for done"); | 
|  | 2775 | wait(); | 
|  | 2776 | } catch (InterruptedException e) { | 
|  | 2777 | // Restore the interrupted status | 
|  | 2778 | Thread.currentThread().interrupt(); | 
|  | 2779 | } | 
|  | 2780 | } | 
|  | 2781 | Log.d(LOG_TAG, "done"); | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2782 | int[] resultArray = new int[2]; | 
|  | 2783 | resultArray[0] = mResult; | 
|  | 2784 | resultArray[1] = mRetryCount; | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2785 |  | 
|  | 2786 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { | 
| Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2787 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2788 | } | 
|  | 2789 |  | 
| Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2790 | return resultArray; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2791 | } | 
|  | 2792 | } | 
|  | 2793 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2794 | /** | 
|  | 2795 | * This method has been removed due to privacy and stability concerns. | 
|  | 2796 | */ | 
|  | 2797 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2798 | public void updateServiceLocation() { | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2799 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); | 
|  | 2800 | return; | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2801 | } | 
|  | 2802 |  | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2803 | @Override | 
|  | 2804 | public void updateServiceLocationWithPackageName(String callingPackage) { | 
|  | 2805 | mApp.getSystemService(AppOpsManager.class) | 
|  | 2806 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 2807 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2808 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2809 | if (targetSdk > android.os.Build.VERSION_CODES.R) { | 
|  | 2810 | // Callers targeting S have no business invoking this method. | 
|  | 2811 | return; | 
|  | 2812 | } | 
|  | 2813 |  | 
|  | 2814 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 2815 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 2816 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 2817 | .setCallingPackage(callingPackage) | 
|  | 2818 | .setCallingFeatureId(null) | 
|  | 2819 | .setCallingPid(Binder.getCallingPid()) | 
|  | 2820 | .setCallingUid(Binder.getCallingUid()) | 
|  | 2821 | .setMethod("updateServiceLocation") | 
|  | 2822 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 2823 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 2824 | .build()); | 
|  | 2825 | // Apps that lack location permission have no business calling this method; | 
|  | 2826 | // however, because no permission was declared in the public API, denials must | 
|  | 2827 | // all be "soft". | 
|  | 2828 | switch (locationResult) { | 
|  | 2829 | case DENIED_HARD: /* fall through */ | 
|  | 2830 | case DENIED_SOFT: | 
|  | 2831 | return; | 
|  | 2832 | } | 
|  | 2833 |  | 
|  | 2834 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2835 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2836 | try { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 2837 | getPhoneFromSubIdOrDefault(getDefaultSubscription()).updateServiceLocation(workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | } finally { | 
|  | 2839 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2840 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | } | 
|  | 2842 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2843 | @Deprecated | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2844 | @Override | 
|  | 2845 | public boolean isRadioOn(String callingPackage) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2846 | return isRadioOnWithFeature(callingPackage, null); | 
|  | 2847 | } | 
|  | 2848 |  | 
|  | 2849 |  | 
|  | 2850 | @Override | 
|  | 2851 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { | 
|  | 2852 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, | 
|  | 2853 | callingFeatureId); | 
|  | 2854 | } | 
|  | 2855 |  | 
|  | 2856 | @Deprecated | 
|  | 2857 | @Override | 
|  | 2858 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { | 
|  | 2859 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2860 | } | 
|  | 2861 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2862 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2863 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, | 
|  | 2864 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2866 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2867 | return false; | 
|  | 2868 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 |  | 
|  | 2870 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2871 | try { | 
|  | 2872 | return isRadioOnForSubscriber(subId); | 
|  | 2873 | } finally { | 
|  | 2874 | Binder.restoreCallingIdentity(identity); | 
|  | 2875 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2876 | } | 
|  | 2877 |  | 
|  | 2878 | private boolean isRadioOnForSubscriber(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2879 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2880 | try { | 
|  | 2881 | final Phone phone = getPhone(subId); | 
|  | 2882 | if (phone != null) { | 
|  | 2883 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; | 
|  | 2884 | } else { | 
|  | 2885 | return false; | 
|  | 2886 | } | 
|  | 2887 | } finally { | 
|  | 2888 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2889 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2890 | } | 
|  | 2891 |  | 
|  | 2892 | public void toggleRadioOnOff() { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2893 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2894 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2895 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2896 | public void toggleRadioOnOffForSubscriber(int subId) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2898 |  | 
|  | 2899 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2900 | try { | 
|  | 2901 | final Phone phone = getPhone(subId); | 
|  | 2902 | if (phone != null) { | 
|  | 2903 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); | 
|  | 2904 | } | 
|  | 2905 | } finally { | 
|  | 2906 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2907 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2908 | } | 
|  | 2909 |  | 
|  | 2910 | public boolean setRadio(boolean turnOn) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2911 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2912 | } | 
|  | 2913 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2914 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2915 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2916 |  | 
|  | 2917 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2918 | try { | 
|  | 2919 | final Phone phone = getPhone(subId); | 
|  | 2920 | if (phone == null) { | 
|  | 2921 | return false; | 
|  | 2922 | } | 
|  | 2923 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { | 
|  | 2924 | toggleRadioOnOffForSubscriber(subId); | 
|  | 2925 | } | 
|  | 2926 | return true; | 
|  | 2927 | } finally { | 
|  | 2928 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2929 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2930 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2931 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2932 | public boolean needMobileRadioShutdown() { | 
| Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2933 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2934 | /* | 
|  | 2935 | * If any of the Radios are available, it will need to be | 
|  | 2936 | * shutdown. So return true if any Radio is available. | 
|  | 2937 | */ | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2939 | try { | 
|  | 2940 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2941 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 2942 | if (phone != null && phone.isRadioAvailable()) return true; | 
|  | 2943 | } | 
|  | 2944 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); | 
|  | 2945 | return false; | 
|  | 2946 | } finally { | 
|  | 2947 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2948 | } | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2949 | } | 
|  | 2950 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2951 | @Override | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2952 | public void shutdownMobileRadios() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2953 | enforceModifyPermission(); | 
|  | 2954 |  | 
|  | 2955 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2956 | try { | 
|  | 2957 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 2958 | logv("Shutting down Phone " + i); | 
|  | 2959 | shutdownRadioUsingPhoneId(i); | 
|  | 2960 | } | 
|  | 2961 | } finally { | 
|  | 2962 | Binder.restoreCallingIdentity(identity); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2963 | } | 
|  | 2964 | } | 
|  | 2965 |  | 
|  | 2966 | private void shutdownRadioUsingPhoneId(int phoneId) { | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2967 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 2968 | if (phone != null && phone.isRadioAvailable()) { | 
|  | 2969 | phone.shutdownRadio(); | 
|  | 2970 | } | 
|  | 2971 | } | 
|  | 2972 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2973 | public boolean setRadioPower(boolean turnOn) { | 
| Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2974 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2975 |  | 
| Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2976 | if (!turnOn) { | 
|  | 2977 | log("setRadioPower off: callingPackage=" + getCurrentPackageName()); | 
|  | 2978 | } | 
|  | 2979 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2980 | final long identity = Binder.clearCallingIdentity(); | 
|  | 2981 | try { | 
|  | 2982 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); | 
|  | 2983 | if (defaultPhone != null) { | 
|  | 2984 | defaultPhone.setRadioPower(turnOn); | 
|  | 2985 | return true; | 
|  | 2986 | } else { | 
|  | 2987 | loge("There's no default phone."); | 
|  | 2988 | return false; | 
|  | 2989 | } | 
|  | 2990 | } finally { | 
|  | 2991 | Binder.restoreCallingIdentity(identity); | 
| Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2992 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2993 | } | 
|  | 2994 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2995 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2996 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2997 |  | 
| Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 2998 | if (!turnOn) { | 
|  | 2999 | log("setRadioPowerForSubscriber off: subId=" + subId | 
|  | 3000 | + ",callingPackage=" + getCurrentPackageName()); | 
|  | 3001 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3003 | try { | 
|  | 3004 | final Phone phone = getPhone(subId); | 
|  | 3005 | if (phone != null) { | 
|  | 3006 | phone.setRadioPower(turnOn); | 
|  | 3007 | return true; | 
|  | 3008 | } else { | 
|  | 3009 | return false; | 
|  | 3010 | } | 
|  | 3011 | } finally { | 
|  | 3012 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3013 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3014 | } | 
|  | 3015 |  | 
| Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3016 | /** | 
|  | 3017 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is | 
|  | 3018 | * no reason to power it off. When any of the voters want to power it off, it will be turned | 
|  | 3019 | * off. In case of emergency, the radio will be turned on even if there are some reasons for | 
|  | 3020 | * powering it off, and these radio off votes will be cleared. | 
|  | 3021 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is | 
|  | 3022 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is | 
|  | 3023 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call | 
|  | 3024 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make | 
|  | 3025 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to | 
|  | 3026 | * check its vote. | 
|  | 3027 | * | 
|  | 3028 | * @param subId The subscription ID. | 
|  | 3029 | * @param reason The reason for powering off radio. | 
|  | 3030 | * @return true on success and false on failure. | 
|  | 3031 | */ | 
|  | 3032 | public boolean requestRadioPowerOffForReason(int subId, | 
|  | 3033 | @TelephonyManager.RadioPowerReason int reason) { | 
|  | 3034 | enforceModifyPermission(); | 
|  | 3035 |  | 
| Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3036 | log("requestRadioPowerOffForReason: subId=" + subId | 
|  | 3037 | + ",reason=" + reason + ",callingPackage=" + getCurrentPackageName()); | 
| Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 3038 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3039 | try { | 
|  | 3040 | final Phone phone = getPhone(subId); | 
|  | 3041 | if (phone != null) { | 
|  | 3042 | phone.setRadioPowerForReason(false, reason); | 
|  | 3043 | return true; | 
|  | 3044 | } else { | 
|  | 3045 | return false; | 
|  | 3046 | } | 
|  | 3047 | } finally { | 
|  | 3048 | Binder.restoreCallingIdentity(identity); | 
|  | 3049 | } | 
|  | 3050 | } | 
|  | 3051 |  | 
|  | 3052 | /** | 
|  | 3053 | * Remove the vote on powering off the radio for a reason, as requested by | 
|  | 3054 | * {@link requestRadioPowerOffForReason}. | 
|  | 3055 | * | 
|  | 3056 | * @param subId The subscription ID. | 
|  | 3057 | * @param reason The reason for powering off radio. | 
|  | 3058 | * @return true on success and false on failure. | 
|  | 3059 | */ | 
|  | 3060 | public boolean clearRadioPowerOffForReason(int subId, | 
|  | 3061 | @TelephonyManager.RadioPowerReason int reason) { | 
|  | 3062 | enforceModifyPermission(); | 
|  | 3063 |  | 
|  | 3064 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3065 | try { | 
|  | 3066 | final Phone phone = getPhone(subId); | 
|  | 3067 | if (phone != null) { | 
|  | 3068 | phone.setRadioPowerForReason(true, reason); | 
|  | 3069 | return true; | 
|  | 3070 | } else { | 
|  | 3071 | return false; | 
|  | 3072 | } | 
|  | 3073 | } finally { | 
|  | 3074 | Binder.restoreCallingIdentity(identity); | 
|  | 3075 | } | 
|  | 3076 | } | 
|  | 3077 |  | 
|  | 3078 | /** | 
|  | 3079 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. | 
|  | 3080 | * | 
|  | 3081 | * @param subId The subscription ID. | 
|  | 3082 | * @param callingPackage The package making the call. | 
|  | 3083 | * @param callingFeatureId The feature in the package. | 
|  | 3084 | * @return List of reasons for powering off radio. | 
|  | 3085 | */ | 
|  | 3086 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { | 
|  | 3087 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); | 
|  | 3088 |  | 
|  | 3089 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3090 | List result = new ArrayList(); | 
|  | 3091 | try { | 
|  | 3092 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, | 
|  | 3093 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { | 
|  | 3094 | return result; | 
|  | 3095 | } | 
|  | 3096 |  | 
|  | 3097 | final Phone phone = getPhone(subId); | 
|  | 3098 | if (phone != null) { | 
|  | 3099 | result.addAll(phone.getRadioPowerOffReasons()); | 
|  | 3100 | } | 
|  | 3101 | } finally { | 
|  | 3102 | Binder.restoreCallingIdentity(identity); | 
|  | 3103 | } | 
|  | 3104 | return result; | 
|  | 3105 | } | 
|  | 3106 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3107 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3108 | @Override | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3109 | public boolean enableDataConnectivity(String callingPackage) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3110 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 |  | 
|  | 3112 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3113 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3114 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3115 | final Phone phone = getPhone(subId); | 
|  | 3116 | if (phone != null) { | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3117 | phone.getDataSettingsManager().setDataEnabled( | 
|  | 3118 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3119 | return true; | 
|  | 3120 | } else { | 
|  | 3121 | return false; | 
|  | 3122 | } | 
|  | 3123 | } finally { | 
|  | 3124 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3125 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3126 | } | 
|  | 3127 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3128 | // FIXME: subId version needed | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3129 | @Override | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3130 | public boolean disableDataConnectivity(String callingPackage) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3131 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3132 |  | 
|  | 3133 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3134 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3135 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | final Phone phone = getPhone(subId); | 
|  | 3137 | if (phone != null) { | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3138 | phone.getDataSettingsManager().setDataEnabled( | 
|  | 3139 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3140 | return true; | 
|  | 3141 | } else { | 
|  | 3142 | return false; | 
|  | 3143 | } | 
|  | 3144 | } finally { | 
|  | 3145 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3146 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3147 | } | 
|  | 3148 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3149 | @Override | 
| Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3150 | public boolean isDataConnectivityPossible(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3151 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3152 | try { | 
|  | 3153 | final Phone phone = getPhone(subId); | 
|  | 3154 | if (phone != null) { | 
| Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3155 | return phone.isDataAllowed(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | } else { | 
|  | 3157 | return false; | 
|  | 3158 | } | 
|  | 3159 | } finally { | 
|  | 3160 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3161 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3162 | } | 
|  | 3163 |  | 
|  | 3164 | public boolean handlePinMmi(String dialString) { | 
| Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3165 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3166 | } | 
|  | 3167 |  | 
| pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3168 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3169 | enforceCallPermission(); | 
|  | 3170 |  | 
|  | 3171 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3172 | try { | 
|  | 3173 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3174 | return; | 
|  | 3175 | } | 
|  | 3176 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); | 
|  | 3177 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); | 
|  | 3178 | } finally { | 
|  | 3179 | Binder.restoreCallingIdentity(identity); | 
|  | 3180 | } | 
| pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3181 | }; | 
|  | 3182 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3183 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3184 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3185 |  | 
|  | 3186 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3187 | try { | 
|  | 3188 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 3189 | return false; | 
|  | 3190 | } | 
|  | 3191 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); | 
|  | 3192 | } finally { | 
|  | 3193 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3195 | } | 
|  | 3196 |  | 
| Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3197 | /** | 
|  | 3198 | * @deprecated  This method is deprecated and is only being kept due to an UnsupportedAppUsage | 
|  | 3199 | * tag on getCallState Binder call. | 
|  | 3200 | */ | 
|  | 3201 | @Deprecated | 
|  | 3202 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | public int getCallState() { | 
| Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3204 | if (CompatChanges.isChangeEnabled( | 
|  | 3205 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, | 
|  | 3206 | Binder.getCallingUid())) { | 
|  | 3207 | // Do not allow this API to be called on API version 31+, it should only be | 
|  | 3208 | // called on old apps using this Binder call directly. | 
|  | 3209 | throw new SecurityException("This method can only be used for applications " | 
|  | 3210 | + "targeting API version 30 or less."); | 
|  | 3211 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3213 | try { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 3214 | Phone phone = getPhoneFromSubIdOrDefault(getDefaultSubscription()); | 
|  | 3215 | return PhoneConstantConversions.convertCallState(phone.getState()); | 
| Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3216 | } finally { | 
|  | 3217 | Binder.restoreCallingIdentity(identity); | 
|  | 3218 | } | 
|  | 3219 | } | 
|  | 3220 |  | 
|  | 3221 | @Override | 
|  | 3222 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { | 
|  | 3223 | if (CompatChanges.isChangeEnabled( | 
|  | 3224 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, | 
|  | 3225 | Binder.getCallingUid())) { | 
|  | 3226 | // Check READ_PHONE_STATE for API version 31+ | 
|  | 3227 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, | 
|  | 3228 | featureId, "getCallStateForSubscription")) { | 
|  | 3229 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " | 
|  | 3230 | + "targeting API level 31+."); | 
|  | 3231 | } | 
|  | 3232 | } | 
|  | 3233 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3234 | try { | 
|  | 3235 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3236 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : | 
|  | 3237 | PhoneConstantConversions.convertCallState(phone.getState()); | 
|  | 3238 | } finally { | 
|  | 3239 | Binder.restoreCallingIdentity(identity); | 
|  | 3240 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3241 | } | 
|  | 3242 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | @Override | 
| Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3244 | public int getDataState() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3245 | return getDataStateForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3246 | } | 
|  | 3247 |  | 
|  | 3248 | @Override | 
|  | 3249 | public int getDataStateForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3251 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3252 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3253 | if (phone != null) { | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3254 | return phone.getDataNetworkController().getInternetDataNetworkState(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3255 | } else { | 
|  | 3256 | return PhoneConstantConversions.convertDataState( | 
|  | 3257 | PhoneConstants.DataState.DISCONNECTED); | 
|  | 3258 | } | 
|  | 3259 | } finally { | 
|  | 3260 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3261 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3262 | } | 
|  | 3263 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3264 | @Override | 
| Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3265 | public @DataActivityType int getDataActivity() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3266 | return getDataActivityForSubId(SubscriptionManager.getDefaultDataSubscriptionId()); | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3267 | } | 
|  | 3268 |  | 
|  | 3269 | @Override | 
| Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3270 | public @DataActivityType int getDataActivityForSubId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3271 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3272 | try { | 
| Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3273 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | if (phone != null) { | 
| Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3275 | return phone.getDataActivityState(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3276 | } else { | 
|  | 3277 | return TelephonyManager.DATA_ACTIVITY_NONE; | 
|  | 3278 | } | 
|  | 3279 | } finally { | 
|  | 3280 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3281 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3282 | } | 
|  | 3283 |  | 
|  | 3284 | @Override | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3285 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3286 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3287 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3288 |  | 
|  | 3289 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 3290 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 3291 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 3292 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3293 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3294 | .setCallingPid(Binder.getCallingPid()) | 
|  | 3295 | .setCallingUid(Binder.getCallingUid()) | 
|  | 3296 | .setMethod("getCellLocation") | 
| Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3297 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3298 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 3299 | .build()); | 
|  | 3300 | switch (locationResult) { | 
|  | 3301 | case DENIED_HARD: | 
|  | 3302 | throw new SecurityException("Not allowed to access cell location"); | 
|  | 3303 | case DENIED_SOFT: | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3304 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) | 
|  | 3305 | ? new CellIdentityCdma() : new CellIdentityGsm(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3306 | } | 
|  | 3307 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3308 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3310 | try { | 
|  | 3311 | if (DBG_LOC) log("getCellLocation: is active user"); | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3312 | int subId = SubscriptionManager.getDefaultDataSubscriptionId(); | 
| Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3313 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3314 | } finally { | 
|  | 3315 | Binder.restoreCallingIdentity(identity); | 
|  | 3316 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3317 | } | 
|  | 3318 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3319 | @Override | 
| Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3320 | public String getNetworkCountryIsoForPhone(int phoneId) { | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3321 | // Reporting the correct network country is ambiguous when IWLAN could conflict with | 
|  | 3322 | // registered cell info, so return a NULL country instead. | 
|  | 3323 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3324 | try { | 
| Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3325 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { | 
|  | 3326 | // Get default phone in this case. | 
|  | 3327 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; | 
|  | 3328 | } | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 3329 | final int subId = SubscriptionManager.getSubscriptionId(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3331 | if (phone == null) return ""; | 
|  | 3332 | ServiceStateTracker sst = phone.getServiceStateTracker(); | 
|  | 3333 | if (sst == null) return ""; | 
|  | 3334 | LocaleTracker lt = sst.getLocaleTracker(); | 
|  | 3335 | if (lt == null) return ""; | 
| Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3336 | return lt.getCurrentCountry(); | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3337 | } finally { | 
|  | 3338 | Binder.restoreCallingIdentity(identity); | 
|  | 3339 | } | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3340 | } | 
|  | 3341 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3342 | /** | 
|  | 3343 | * This method was removed due to potential issues caused by performing partial | 
|  | 3344 | * updates of service state, and lack of a credible use case. | 
|  | 3345 | * | 
|  | 3346 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 3347 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 3348 | */ | 
| Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3349 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3350 | public void enableLocationUpdates() { | 
|  | 3351 | mApp.enforceCallingOrSelfPermission( | 
|  | 3352 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3353 | } | 
|  | 3354 |  | 
| Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3355 | /** | 
|  | 3356 | * This method was removed due to potential issues caused by performing partial | 
|  | 3357 | * updates of service state, and lack of a credible use case. | 
|  | 3358 | * | 
|  | 3359 | * This has the ability to break the telephony implementation by disabling notification of | 
|  | 3360 | * changes in device connectivity. DO NOT USE THIS! | 
|  | 3361 | */ | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3362 | @Override | 
|  | 3363 | public void disableLocationUpdates() { | 
|  | 3364 | mApp.enforceCallingOrSelfPermission( | 
|  | 3365 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | } | 
|  | 3367 |  | 
|  | 3368 | @Override | 
|  | 3369 | @SuppressWarnings("unchecked") | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3370 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, | 
|  | 3371 | String callingFeatureId) { | 
| Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3372 | try { | 
|  | 3373 | mApp.getSystemService(AppOpsManager.class) | 
|  | 3374 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3375 | } catch (SecurityException e) { | 
|  | 3376 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); | 
|  | 3377 | throw e; | 
|  | 3378 | } | 
|  | 3379 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3380 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3381 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 3382 | throw new SecurityException( | 
|  | 3383 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); | 
|  | 3384 | } | 
| Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3385 |  | 
| Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3386 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3387 | callingPackage) != AppOpsManager.MODE_ALLOWED) { | 
|  | 3388 | return null; | 
|  | 3389 | } | 
| Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3390 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3391 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3392 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3393 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3394 | if (info == null) return null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3395 |  | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3396 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); | 
|  | 3397 | for (CellInfo ci : info) { | 
|  | 3398 | if (ci instanceof CellInfoGsm) { | 
|  | 3399 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); | 
|  | 3400 | } else if (ci instanceof CellInfoWcdma) { | 
|  | 3401 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); | 
|  | 3402 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3403 | } | 
| Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3404 | return (neighbors.size()) > 0 ? neighbors : null; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3405 | } | 
|  | 3406 |  | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3407 | private List<CellInfo> getCachedCellInfo() { | 
|  | 3408 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 3409 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 3410 | List<CellInfo> info = phone.getAllCellInfo(); | 
|  | 3411 | if (info != null) cellInfos.addAll(info); | 
|  | 3412 | } | 
|  | 3413 | return cellInfos; | 
|  | 3414 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3415 |  | 
|  | 3416 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3417 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | mApp.getSystemService(AppOpsManager.class) | 
| Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3419 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3420 |  | 
|  | 3421 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 3422 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 3423 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 3424 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3425 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3426 | .setCallingPid(Binder.getCallingPid()) | 
|  | 3427 | .setCallingUid(Binder.getCallingUid()) | 
|  | 3428 | .setMethod("getAllCellInfo") | 
| Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3429 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3430 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 3431 | .build()); | 
|  | 3432 | switch (locationResult) { | 
|  | 3433 | case DENIED_HARD: | 
|  | 3434 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 3435 | case DENIED_SOFT: | 
|  | 3436 | return new ArrayList<>(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3437 | } | 
|  | 3438 |  | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3439 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3440 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { | 
|  | 3441 | return getCachedCellInfo(); | 
|  | 3442 | } | 
|  | 3443 |  | 
| Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3444 | if (DBG_LOC) log("getAllCellInfo: is active user"); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3445 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3447 | try { | 
|  | 3448 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); | 
|  | 3449 | for (Phone phone : PhoneFactory.getPhones()) { | 
| Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3450 | final List<CellInfo> info = (List<CellInfo>) sendRequest( | 
| Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3451 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3452 | if (info != null) cellInfos.addAll(info); | 
|  | 3453 | } | 
|  | 3454 | return cellInfos; | 
|  | 3455 | } finally { | 
|  | 3456 | Binder.restoreCallingIdentity(identity); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3457 | } | 
|  | 3458 | } | 
|  | 3459 |  | 
| Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3460 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3461 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, | 
|  | 3462 | String callingFeatureId) { | 
|  | 3463 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, | 
|  | 3464 | getWorkSource(Binder.getCallingUid())); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3465 | } | 
|  | 3466 |  | 
|  | 3467 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3468 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, | 
|  | 3469 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3470 | enforceModifyPermission(); | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3471 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3472 | } | 
|  | 3473 |  | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3474 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, | 
|  | 3475 | String callingPackage, String callingFeatureId, WorkSource workSource) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3476 | mApp.getSystemService(AppOpsManager.class) | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3477 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3478 |  | 
|  | 3479 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 3480 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 3481 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 3482 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3483 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3484 | .setCallingPid(Binder.getCallingPid()) | 
|  | 3485 | .setCallingUid(Binder.getCallingUid()) | 
|  | 3486 | .setMethod("requestCellInfoUpdate") | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3487 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) | 
|  | 3488 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3489 | .build()); | 
|  | 3490 | switch (locationResult) { | 
|  | 3491 | case DENIED_HARD: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3492 | if (TelephonyPermissions | 
|  | 3493 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3494 | // Safetynet logging for b/154934934 | 
|  | 3495 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 3496 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3497 | throw new SecurityException("Not allowed to access cell info"); | 
|  | 3498 | case DENIED_SOFT: | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3499 | if (TelephonyPermissions | 
|  | 3500 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { | 
| Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3501 | // Safetynet logging for b/154934934 | 
|  | 3502 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); | 
|  | 3503 | } | 
| Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3504 | try { | 
|  | 3505 | cb.onCellInfo(new ArrayList<CellInfo>()); | 
|  | 3506 | } catch (RemoteException re) { | 
|  | 3507 | // Drop without consequences | 
|  | 3508 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3509 | return; | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3510 | } | 
|  | 3511 |  | 
| Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3512 |  | 
|  | 3513 | final Phone phone = getPhoneFromSubId(subId); | 
| Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3514 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
|  | 3515 |  | 
|  | 3516 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); | 
|  | 3517 | } | 
|  | 3518 |  | 
|  | 3519 | @Override | 
| Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3520 | public void setCellInfoListRate(int rateInMillis, int subId) { | 
| Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3521 | enforceModifyPermission(); | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3522 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 |  | 
|  | 3524 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3525 | try { | 
| Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3526 | Phone phone = getPhone(subId); | 
|  | 3527 | if (phone == null) { | 
|  | 3528 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); | 
|  | 3529 | } else { | 
|  | 3530 | phone.setCellInfoListRate(rateInMillis, workSource); | 
|  | 3531 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3532 | } finally { | 
|  | 3533 | Binder.restoreCallingIdentity(identity); | 
|  | 3534 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | } | 
|  | 3536 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3537 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3538 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3539 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3540 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3541 | return null; | 
|  | 3542 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3543 | int subId = phone.getSubId(); | 
| Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3544 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3545 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3546 | callingPackage, callingFeatureId, "getImeiForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3547 | return null; | 
|  | 3548 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3549 |  | 
|  | 3550 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3551 | try { | 
|  | 3552 | return phone.getImei(); | 
|  | 3553 | } finally { | 
|  | 3554 | Binder.restoreCallingIdentity(identity); | 
|  | 3555 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3556 | } | 
|  | 3557 |  | 
|  | 3558 | @Override | 
| arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 3559 | public String getPrimaryImei(String callingPackage, String callingFeatureId) { | 
|  | 3560 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getPrimaryImei"); | 
|  | 3561 | if (!checkCallingOrSelfReadDeviceIdentifiersForAnySub(mApp, callingPackage, | 
|  | 3562 | callingFeatureId, "getPrimaryImei")) { | 
|  | 3563 | throw new SecurityException("Caller does not have permission"); | 
|  | 3564 | } | 
|  | 3565 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3566 | try { | 
|  | 3567 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 3568 | if (phone.getImeiType() == Phone.IMEI_TYPE_PRIMARY) { | 
|  | 3569 | return phone.getImei(); | 
|  | 3570 | } | 
|  | 3571 | } | 
|  | 3572 | throw new UnsupportedOperationException("Operation not supported"); | 
|  | 3573 | } finally { | 
|  | 3574 | Binder.restoreCallingIdentity(identity); | 
|  | 3575 | } | 
|  | 3576 | } | 
|  | 3577 |  | 
|  | 3578 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3579 | public String getTypeAllocationCodeForSlot(int slotIndex) { | 
|  | 3580 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3581 | String tac = null; | 
|  | 3582 | if (phone != null) { | 
|  | 3583 | String imei = phone.getImei(); | 
| Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3584 | try { | 
|  | 3585 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); | 
|  | 3586 | } catch (IndexOutOfBoundsException e) { | 
|  | 3587 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); | 
|  | 3588 | return null; | 
|  | 3589 | } | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3590 | } | 
|  | 3591 | return tac; | 
|  | 3592 | } | 
|  | 3593 |  | 
|  | 3594 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3595 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3596 | try { | 
|  | 3597 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3598 | } catch (SecurityException se) { | 
|  | 3599 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); | 
|  | 3600 | throw new SecurityException("Package " + callingPackage + " does not belong to " | 
|  | 3601 | + Binder.getCallingUid()); | 
|  | 3602 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3603 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3604 | if (phone == null) { | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3605 | return null; | 
|  | 3606 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3607 |  | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3608 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3609 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3610 | callingPackage, callingFeatureId, "getMeidForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3611 | return null; | 
|  | 3612 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3613 |  | 
|  | 3614 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3615 | try { | 
|  | 3616 | return phone.getMeid(); | 
|  | 3617 | } finally { | 
|  | 3618 | Binder.restoreCallingIdentity(identity); | 
|  | 3619 | } | 
| Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3620 | } | 
|  | 3621 |  | 
|  | 3622 | @Override | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3623 | public String getManufacturerCodeForSlot(int slotIndex) { | 
|  | 3624 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3625 | String manufacturerCode = null; | 
|  | 3626 | if (phone != null) { | 
|  | 3627 | String meid = phone.getMeid(); | 
| Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3628 | try { | 
|  | 3629 | manufacturerCode = | 
|  | 3630 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); | 
|  | 3631 | } catch (IndexOutOfBoundsException e) { | 
|  | 3632 | Log.e(LOG_TAG, "MEID length shorter than upper index."); | 
|  | 3633 | return null; | 
|  | 3634 | } | 
| David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3635 | } | 
|  | 3636 | return manufacturerCode; | 
|  | 3637 | } | 
|  | 3638 |  | 
|  | 3639 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3640 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, | 
|  | 3641 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3642 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3643 | if (phone == null) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3644 | return null; | 
|  | 3645 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3646 | int subId = phone.getSubId(); | 
|  | 3647 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3648 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3649 | "getDeviceSoftwareVersionForSlot")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3650 | return null; | 
|  | 3651 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 |  | 
|  | 3653 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3654 | try { | 
|  | 3655 | return phone.getDeviceSvn(); | 
|  | 3656 | } finally { | 
|  | 3657 | Binder.restoreCallingIdentity(identity); | 
|  | 3658 | } | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3659 | } | 
|  | 3660 |  | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3661 | @Override | 
|  | 3662 | public int getSubscriptionCarrierId(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3663 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3664 | try { | 
|  | 3665 | final Phone phone = getPhone(subId); | 
|  | 3666 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); | 
|  | 3667 | } finally { | 
|  | 3668 | Binder.restoreCallingIdentity(identity); | 
|  | 3669 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3670 | } | 
|  | 3671 |  | 
|  | 3672 | @Override | 
|  | 3673 | public String getSubscriptionCarrierName(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3674 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3675 | try { | 
|  | 3676 | final Phone phone = getPhone(subId); | 
|  | 3677 | return phone == null ? null : phone.getCarrierName(); | 
|  | 3678 | } finally { | 
|  | 3679 | Binder.restoreCallingIdentity(identity); | 
|  | 3680 | } | 
| fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3681 | } | 
|  | 3682 |  | 
| calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3683 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3684 | public int getSubscriptionSpecificCarrierId(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3685 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3686 | try { | 
|  | 3687 | final Phone phone = getPhone(subId); | 
|  | 3688 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3689 | : phone.getSpecificCarrierId(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3690 | } finally { | 
|  | 3691 | Binder.restoreCallingIdentity(identity); | 
|  | 3692 | } | 
|  | 3693 | } | 
|  | 3694 |  | 
|  | 3695 | @Override | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3696 | public String getSubscriptionSpecificCarrierName(int subId) { | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3697 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3698 | try { | 
|  | 3699 | final Phone phone = getPhone(subId); | 
| chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3700 | return phone == null ? null : phone.getSpecificCarrierName(); | 
| chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3701 | } finally { | 
|  | 3702 | Binder.restoreCallingIdentity(identity); | 
|  | 3703 | } | 
|  | 3704 | } | 
|  | 3705 |  | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3706 | @Override | 
| chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3707 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { | 
|  | 3708 | if (!isSubscriptionMccMnc) { | 
|  | 3709 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); | 
|  | 3710 | } | 
| chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3711 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3712 | if (phone == null) { | 
|  | 3713 | return TelephonyManager.UNKNOWN_CARRIER_ID; | 
|  | 3714 | } | 
|  | 3715 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3716 | try { | 
|  | 3717 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); | 
|  | 3718 | } finally { | 
|  | 3719 | Binder.restoreCallingIdentity(identity); | 
|  | 3720 | } | 
|  | 3721 | } | 
|  | 3722 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3723 | // | 
|  | 3724 | // Internal helper methods. | 
|  | 3725 | // | 
|  | 3726 |  | 
| Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3727 | /** | 
| Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3728 | * Make sure the caller is the calling package itself | 
|  | 3729 | * | 
|  | 3730 | * @throws SecurityException if the caller is not the calling package | 
|  | 3731 | */ | 
|  | 3732 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { | 
|  | 3733 | int packageUid = -1; | 
| Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3734 | PackageManager pm = mApp.getBaseContext().createContextAsUser( | 
|  | 3735 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); | 
| Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3736 | try { | 
| Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3737 | packageUid = pm.getPackageUid(callingPackage, 0); | 
| Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3738 | } catch (PackageManager.NameNotFoundException e) { | 
|  | 3739 | // packageUid is -1 | 
|  | 3740 | } | 
|  | 3741 | if (packageUid != callingUid) { | 
|  | 3742 | throw new SecurityException(message + ": Package " + callingPackage | 
|  | 3743 | + " does not belong to " + callingUid); | 
|  | 3744 | } | 
|  | 3745 | } | 
|  | 3746 |  | 
|  | 3747 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3748 | * Make sure the caller has the MODIFY_PHONE_STATE permission. | 
|  | 3749 | * | 
|  | 3750 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3751 | */ | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3752 | @VisibleForTesting | 
|  | 3753 | public void enforceModifyPermission() { | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3754 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); | 
|  | 3755 | } | 
|  | 3756 |  | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3757 | /** | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3758 | * Make sure the caller has the READ_PHONE_STATE permission. | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3759 | * | 
|  | 3760 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3761 | */ | 
|  | 3762 | @VisibleForTesting | 
|  | 3763 | public void enforceReadPermission() { | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 3764 | enforceReadPermission(null); | 
|  | 3765 | } | 
|  | 3766 |  | 
|  | 3767 | /** | 
|  | 3768 | * Make sure the caller has the READ_PHONE_STATE permissions. | 
|  | 3769 | * | 
|  | 3770 | * @throws SecurityException if the caller does not have the READ_PHONE_STATE permission. | 
|  | 3771 | */ | 
|  | 3772 | @VisibleForTesting | 
|  | 3773 | public void enforceReadPermission(String msg) { | 
|  | 3774 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, msg); | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 3775 | } | 
|  | 3776 |  | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3777 | private void enforceActiveEmergencySessionPermission() { | 
|  | 3778 | mApp.enforceCallingOrSelfPermission( | 
|  | 3779 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); | 
|  | 3780 | } | 
|  | 3781 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3782 | /** | 
|  | 3783 | * Make sure the caller has the CALL_PHONE permission. | 
|  | 3784 | * | 
|  | 3785 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3786 | */ | 
|  | 3787 | private void enforceCallPermission() { | 
|  | 3788 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); | 
|  | 3789 | } | 
|  | 3790 |  | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3791 | private void enforceSettingsPermission() { | 
|  | 3792 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3793 | } | 
|  | 3794 |  | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3795 | private void enforceRebootPermission() { | 
|  | 3796 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); | 
|  | 3797 | } | 
|  | 3798 |  | 
| Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 3799 | /** | 
|  | 3800 | * Make sure the caller has SATELLITE_COMMUNICATION permission. | 
|  | 3801 | * @param message - log message to print. | 
|  | 3802 | * @throws SecurityException if the caller does not have the required permission | 
|  | 3803 | */ | 
|  | 3804 | private void enforceSatelliteCommunicationPermission(String message) { | 
|  | 3805 | mApp.enforceCallingOrSelfPermission(permission.SATELLITE_COMMUNICATION, message); | 
|  | 3806 | } | 
|  | 3807 |  | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3808 | private String createTelUrl(String number) { | 
|  | 3809 | if (TextUtils.isEmpty(number)) { | 
|  | 3810 | return null; | 
|  | 3811 | } | 
|  | 3812 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3813 | return "tel:" + number; | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3814 | } | 
|  | 3815 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3816 | private static void log(String msg) { | 
| Ling Ma | 83dc5ea | 2023-01-12 15:06:04 -0800 | [diff] [blame] | 3817 | Log.d(LOG_TAG, msg); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3818 | } | 
|  | 3819 |  | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3820 | private static void logv(String msg) { | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3821 | Log.v(LOG_TAG, msg); | 
| Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3822 | } | 
|  | 3823 |  | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3824 | private static void loge(String msg) { | 
| Sarah Chin | 4beb2b7 | 2023-02-14 14:47:54 -0800 | [diff] [blame] | 3825 | Log.e(LOG_TAG, msg); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3826 | } | 
|  | 3827 |  | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3828 | @Override | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3829 | public int getActivePhoneType() { | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3830 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3831 | } | 
|  | 3832 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3833 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3834 | public int getActivePhoneTypeForSlot(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3836 | try { | 
|  | 3837 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 3838 | if (phone == null) { | 
|  | 3839 | return PhoneConstants.PHONE_TYPE_NONE; | 
|  | 3840 | } else { | 
|  | 3841 | return phone.getPhoneType(); | 
|  | 3842 | } | 
|  | 3843 | } finally { | 
|  | 3844 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3845 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3846 | } | 
|  | 3847 |  | 
|  | 3848 | /** | 
|  | 3849 | * Returns the CDMA ERI icon index to display | 
|  | 3850 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3851 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3852 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { | 
|  | 3853 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3854 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3855 | } | 
|  | 3856 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3857 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3858 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, | 
|  | 3859 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3861 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3862 | "getCdmaEriIconIndexForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3863 | return -1; | 
|  | 3864 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3865 |  | 
|  | 3866 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3867 | try { | 
|  | 3868 | final Phone phone = getPhone(subId); | 
|  | 3869 | if (phone != null) { | 
|  | 3870 | return phone.getCdmaEriIconIndex(); | 
|  | 3871 | } else { | 
|  | 3872 | return -1; | 
|  | 3873 | } | 
|  | 3874 | } finally { | 
|  | 3875 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3876 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3877 | } | 
|  | 3878 |  | 
|  | 3879 | /** | 
|  | 3880 | * Returns the CDMA ERI icon mode, | 
|  | 3881 | * 0 - ON | 
|  | 3882 | * 1 - FLASHING | 
|  | 3883 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3884 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3885 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { | 
|  | 3886 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3887 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3888 | } | 
|  | 3889 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3890 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3891 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, | 
|  | 3892 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3894 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3895 | "getCdmaEriIconModeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3896 | return -1; | 
|  | 3897 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 |  | 
|  | 3899 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3900 | try { | 
|  | 3901 | final Phone phone = getPhone(subId); | 
|  | 3902 | if (phone != null) { | 
|  | 3903 | return phone.getCdmaEriIconMode(); | 
|  | 3904 | } else { | 
|  | 3905 | return -1; | 
|  | 3906 | } | 
|  | 3907 | } finally { | 
|  | 3908 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3909 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3910 | } | 
|  | 3911 |  | 
|  | 3912 | /** | 
|  | 3913 | * Returns the CDMA ERI text, | 
|  | 3914 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3915 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3916 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { | 
|  | 3917 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 3918 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3919 | } | 
|  | 3920 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3921 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3922 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, | 
|  | 3923 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3924 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3925 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 3926 | "getCdmaEriIconTextForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3927 | return null; | 
|  | 3928 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3929 |  | 
|  | 3930 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3931 | try { | 
|  | 3932 | final Phone phone = getPhone(subId); | 
|  | 3933 | if (phone != null) { | 
|  | 3934 | return phone.getCdmaEriText(); | 
|  | 3935 | } else { | 
|  | 3936 | return null; | 
|  | 3937 | } | 
|  | 3938 | } finally { | 
|  | 3939 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3940 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3941 | } | 
|  | 3942 |  | 
|  | 3943 | /** | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3944 | * Returns the CDMA MDN. | 
|  | 3945 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3946 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3947 | public String getCdmaMdn(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3948 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3949 | mApp, subId, "getCdmaMdn"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 |  | 
|  | 3951 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3952 | try { | 
|  | 3953 | final Phone phone = getPhone(subId); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3954 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3955 | return phone.getLine1Number(); | 
|  | 3956 | } else { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | return null; | 
|  | 3959 | } | 
|  | 3960 | } finally { | 
|  | 3961 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3962 | } | 
|  | 3963 | } | 
|  | 3964 |  | 
|  | 3965 | /** | 
|  | 3966 | * Returns the CDMA MIN. | 
|  | 3967 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3968 | @Override | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3969 | public String getCdmaMin(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3970 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 3971 | mApp, subId, "getCdmaMin"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 |  | 
|  | 3973 | final long identity = Binder.clearCallingIdentity(); | 
|  | 3974 | try { | 
|  | 3975 | final Phone phone = getPhone(subId); | 
|  | 3976 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { | 
|  | 3977 | return phone.getCdmaMin(); | 
|  | 3978 | } else { | 
|  | 3979 | return null; | 
|  | 3980 | } | 
|  | 3981 | } finally { | 
|  | 3982 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3983 | } | 
|  | 3984 | } | 
|  | 3985 |  | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3986 | @Override | 
|  | 3987 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, | 
|  | 3988 | INumberVerificationCallback callback, String callingPackage) { | 
|  | 3989 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 3990 | != PERMISSION_GRANTED) { | 
|  | 3991 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); | 
|  | 3992 | } | 
|  | 3993 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 3994 |  | 
|  | 3995 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); | 
|  | 3996 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { | 
| Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3997 | throw new SecurityException("Calling package must be configured in the device config: " | 
|  | 3998 | + "calling package: " + callingPackage | 
|  | 3999 | + ", configured package: " + authorizedPackage); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4000 | } | 
|  | 4001 |  | 
|  | 4002 | if (range == null) { | 
|  | 4003 | throw new NullPointerException("Range must be non-null"); | 
|  | 4004 | } | 
|  | 4005 |  | 
|  | 4006 | timeoutMillis = Math.min(timeoutMillis, | 
| Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 4007 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); | 
| Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 4008 |  | 
|  | 4009 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); | 
|  | 4010 | } | 
|  | 4011 |  | 
| Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 4012 | /** | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4013 | * Returns true if CDMA provisioning needs to run. | 
|  | 4014 | */ | 
|  | 4015 | public boolean needsOtaServiceProvisioning() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4017 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4018 | return getDefaultPhone().needsOtaServiceProvisioning(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | } finally { | 
|  | 4020 | Binder.restoreCallingIdentity(identity); | 
|  | 4021 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4022 | } | 
|  | 4023 |  | 
|  | 4024 | /** | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4025 | * Sets the voice mail number of a given subId. | 
|  | 4026 | */ | 
|  | 4027 | @Override | 
|  | 4028 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4029 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 4030 | mApp, subId, "setVoiceMailNumber"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 |  | 
|  | 4032 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4033 | try { | 
|  | 4034 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, | 
|  | 4035 | new Pair<String, String>(alphaTag, number), new Integer(subId)); | 
|  | 4036 | return success; | 
|  | 4037 | } finally { | 
|  | 4038 | Binder.restoreCallingIdentity(identity); | 
|  | 4039 | } | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4040 | } | 
|  | 4041 |  | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4042 | @Override | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4043 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { | 
|  | 4044 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4045 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); | 
|  | 4046 | String systemDialer = tm.getSystemDialerPackage(); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4047 | if (!TextUtils.equals(callingPackage, systemDialer)) { | 
|  | 4048 | throw new SecurityException("caller must be system dialer"); | 
|  | 4049 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4050 |  | 
|  | 4051 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4052 | try { | 
|  | 4053 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); | 
|  | 4054 | if (phoneAccountHandle == null) { | 
|  | 4055 | return null; | 
|  | 4056 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4057 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4058 | } finally { | 
|  | 4059 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4060 | } | 
| Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 4061 | } | 
|  | 4062 |  | 
|  | 4063 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4064 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, | 
|  | 4065 | int subId) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4066 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4068 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4069 | "getVisualVoicemailPackageName")) { | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4070 | return null; | 
|  | 4071 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4072 |  | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4073 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4074 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4075 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); | 
| Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 4076 | } finally { | 
|  | 4077 | Binder.restoreCallingIdentity(identity); | 
|  | 4078 | } | 
| Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 4079 | } | 
|  | 4080 |  | 
|  | 4081 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4082 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, | 
|  | 4083 | VisualVoicemailSmsFilterSettings settings) { | 
|  | 4084 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4085 |  | 
|  | 4086 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4087 | try { | 
|  | 4088 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4089 | mApp, callingPackage, subId, settings); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4090 | } finally { | 
|  | 4091 | Binder.restoreCallingIdentity(identity); | 
|  | 4092 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4093 | } | 
|  | 4094 |  | 
|  | 4095 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4096 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { | 
|  | 4097 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4098 |  | 
|  | 4099 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4100 | try { | 
|  | 4101 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4102 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4103 | } finally { | 
|  | 4104 | Binder.restoreCallingIdentity(identity); | 
|  | 4105 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4106 | } | 
|  | 4107 |  | 
|  | 4108 | @Override | 
| Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 4109 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( | 
|  | 4110 | String callingPackage, int subId) { | 
|  | 4111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 |  | 
|  | 4113 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4114 | try { | 
|  | 4115 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4116 | mApp, callingPackage, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4117 | } finally { | 
|  | 4118 | Binder.restoreCallingIdentity(identity); | 
|  | 4119 | } | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4120 | } | 
|  | 4121 |  | 
|  | 4122 | @Override | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4123 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4124 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4125 |  | 
|  | 4126 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4127 | try { | 
|  | 4128 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4129 | mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | } finally { | 
|  | 4131 | Binder.restoreCallingIdentity(identity); | 
|  | 4132 | } | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4133 | } | 
|  | 4134 |  | 
|  | 4135 | @Override | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4136 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, | 
|  | 4137 | String callingAttributionTag, int subId, String number, int port, String text, | 
|  | 4138 | PendingIntent sentIntent) { | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4139 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 4140 | enforceVisualVoicemailPackage(callingPackage, subId); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 4141 | enforceSendSmsPermission(); | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4142 | SmsController smsController = PhoneFactory.getSmsController(); | 
| Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 4143 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, | 
|  | 4144 | subId, number, port, text, sentIntent); | 
| Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 4145 | } | 
| Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 4146 |  | 
| Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 4147 | /** | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4148 | * Sets the voice activation state of a given subId. | 
|  | 4149 | */ | 
|  | 4150 | @Override | 
|  | 4151 | public void setVoiceActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4153 | mApp, subId, "setVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4154 |  | 
|  | 4155 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4156 | try { | 
|  | 4157 | final Phone phone = getPhone(subId); | 
|  | 4158 | if (phone != null) { | 
|  | 4159 | phone.setVoiceActivationState(activationState); | 
|  | 4160 | } else { | 
|  | 4161 | loge("setVoiceActivationState fails with invalid subId: " + subId); | 
|  | 4162 | } | 
|  | 4163 | } finally { | 
|  | 4164 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4165 | } | 
|  | 4166 | } | 
|  | 4167 |  | 
|  | 4168 | /** | 
|  | 4169 | * Sets the data activation state of a given subId. | 
|  | 4170 | */ | 
|  | 4171 | @Override | 
|  | 4172 | public void setDataActivationState(int subId, int activationState) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4173 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 4174 | mApp, subId, "setDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4175 |  | 
|  | 4176 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4177 | try { | 
|  | 4178 | final Phone phone = getPhone(subId); | 
|  | 4179 | if (phone != null) { | 
|  | 4180 | phone.setDataActivationState(activationState); | 
|  | 4181 | } else { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4182 | loge("setDataActivationState fails with invalid subId: " + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | } | 
|  | 4184 | } finally { | 
|  | 4185 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4186 | } | 
|  | 4187 | } | 
|  | 4188 |  | 
|  | 4189 | /** | 
|  | 4190 | * Returns the voice activation state of a given subId. | 
|  | 4191 | */ | 
|  | 4192 | @Override | 
|  | 4193 | public int getVoiceActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4194 | enforceReadPrivilegedPermission("getVoiceActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4195 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4196 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4197 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4198 | try { | 
|  | 4199 | if (phone != null) { | 
|  | 4200 | return phone.getVoiceActivationState(); | 
|  | 4201 | } else { | 
|  | 4202 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 4203 | } | 
|  | 4204 | } finally { | 
|  | 4205 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4206 | } | 
|  | 4207 | } | 
|  | 4208 |  | 
|  | 4209 | /** | 
|  | 4210 | * Returns the data activation state of a given subId. | 
|  | 4211 | */ | 
|  | 4212 | @Override | 
|  | 4213 | public int getDataActivationState(int subId, String callingPackage) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | enforceReadPrivilegedPermission("getDataActivationState"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4215 |  | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4216 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4217 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4218 | try { | 
|  | 4219 | if (phone != null) { | 
|  | 4220 | return phone.getDataActivationState(); | 
|  | 4221 | } else { | 
|  | 4222 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; | 
|  | 4223 | } | 
|  | 4224 | } finally { | 
|  | 4225 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4226 | } | 
|  | 4227 | } | 
|  | 4228 |  | 
|  | 4229 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4230 | * Returns the unread count of voicemails for a subId | 
|  | 4231 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4232 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4233 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, | 
|  | 4234 | String callingFeatureId) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4236 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 4237 | "getVoiceMessageCountForSubscriber")) { | 
| Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4238 | return 0; | 
|  | 4239 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4241 | try { | 
|  | 4242 | final Phone phone = getPhone(subId); | 
|  | 4243 | if (phone != null) { | 
|  | 4244 | return phone.getVoiceMessageCount(); | 
|  | 4245 | } else { | 
|  | 4246 | return 0; | 
|  | 4247 | } | 
|  | 4248 | } finally { | 
|  | 4249 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4250 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4251 | } | 
|  | 4252 |  | 
|  | 4253 | /** | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4254 | * returns true, if the device is in a state where both voice and data | 
|  | 4255 | * are supported simultaneously. This can change based on location or network condition. | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4256 | */ | 
|  | 4257 | @Override | 
|  | 4258 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4259 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4260 | try { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 4261 | return getPhoneFromSubIdOrDefault(subId).isConcurrentVoiceAndDataAllowed(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4262 | } finally { | 
|  | 4263 | Binder.restoreCallingIdentity(identity); | 
|  | 4264 | } | 
| pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4265 | } | 
|  | 4266 |  | 
|  | 4267 | /** | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4268 | * Send the dialer code if called from the current default dialer or the caller has | 
|  | 4269 | * carrier privilege. | 
|  | 4270 | * @param inputCode The dialer code to send | 
|  | 4271 | */ | 
|  | 4272 | @Override | 
|  | 4273 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4274 | final Phone defaultPhone = getDefaultPhone(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4275 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4276 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 4277 | String defaultDialer = tm.getDefaultDialerPackage(); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4278 | if (!TextUtils.equals(callingPackage, defaultDialer)) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4279 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4280 | getDefaultSubscription(), "sendDialerSpecialCode"); | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4281 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 |  | 
|  | 4283 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4284 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4285 | defaultPhone.sendDialerSpecialCode(inputCode); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4286 | } finally { | 
|  | 4287 | Binder.restoreCallingIdentity(identity); | 
|  | 4288 | } | 
| fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4289 | } | 
|  | 4290 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4291 | @Override | 
|  | 4292 | public int getNetworkSelectionMode(int subId) { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4293 | TelephonyPermissions | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 4294 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4295 | mApp, subId, "getNetworkSelectionMode"); | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4296 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4297 | try { | 
|  | 4298 | if (!isActiveSubscription(subId)) { | 
|  | 4299 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; | 
|  | 4300 | } | 
|  | 4301 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); | 
|  | 4302 | } finally { | 
|  | 4303 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4304 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4305 | } | 
|  | 4306 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | @Override | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4308 | public boolean isInEmergencySmsMode() { | 
|  | 4309 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); | 
|  | 4310 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4311 | try { | 
|  | 4312 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 4313 | if (phone.isInEmergencySmsMode()) { | 
|  | 4314 | return true; | 
|  | 4315 | } | 
|  | 4316 | } | 
|  | 4317 | } finally { | 
|  | 4318 | Binder.restoreCallingIdentity(identity); | 
|  | 4319 | } | 
|  | 4320 | return false; | 
|  | 4321 | } | 
|  | 4322 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4323 | /** | 
|  | 4324 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4325 | * @param subId The subscription to use to check the configuration. | 
|  | 4326 | * @param c The callback that will be used to send the result. | 
|  | 4327 | */ | 
| Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4328 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4329 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) | 
|  | 4330 | throws RemoteException { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4331 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4332 | mApp, subId, "registerImsRegistrationCallback"); | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4333 |  | 
|  | 4334 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 4335 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4336 | "IMS not available on device."); | 
|  | 4337 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4338 | final long token = Binder.clearCallingIdentity(); | 
|  | 4339 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4340 | int slotId = getSlotIndexOrException(subId); | 
|  | 4341 | verifyImsMmTelConfiguredOrThrow(slotId); | 
| joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4342 |  | 
|  | 4343 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4344 | if (controller != null) { | 
|  | 4345 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4346 | if (imsManager != null) { | 
|  | 4347 | imsManager.addRegistrationCallbackForSubscription(c, subId); | 
|  | 4348 | } else { | 
|  | 4349 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); | 
|  | 4350 | } | 
|  | 4351 | } else { | 
|  | 4352 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); | 
|  | 4353 | } | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4354 | } catch (ImsException e) { | 
|  | 4355 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4356 | } finally { | 
|  | 4357 | Binder.restoreCallingIdentity(token); | 
|  | 4358 | } | 
|  | 4359 | } | 
|  | 4360 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4361 | /** | 
|  | 4362 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4363 | * @param subId The subscription to use to check the configuration. | 
|  | 4364 | * @param c The callback that will be used to send the result. | 
|  | 4365 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4366 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4367 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4368 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4369 | mApp, subId, "unregisterImsRegistrationCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4370 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4371 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4372 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4373 | final long token = Binder.clearCallingIdentity(); | 
| joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4374 |  | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4375 | try { | 
| joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4376 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4377 | if (controller != null) { | 
|  | 4378 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4379 | if (imsManager != null) { | 
|  | 4380 | imsManager.removeRegistrationCallbackForSubscription(c, subId); | 
|  | 4381 | } else { | 
|  | 4382 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId | 
|  | 4383 | + "is inactive, ignoring unregister."); | 
|  | 4384 | // If the ImsManager is not valid, just return, since the callback | 
|  | 4385 | // will already have been removed internally. | 
|  | 4386 | } | 
|  | 4387 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4388 | } finally { | 
|  | 4389 | Binder.restoreCallingIdentity(token); | 
|  | 4390 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4391 | } | 
|  | 4392 |  | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4393 | /** | 
|  | 4394 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. | 
|  | 4395 | */ | 
|  | 4396 | @Override | 
|  | 4397 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { | 
|  | 4398 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); | 
|  | 4399 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 4400 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4401 | "IMS not available on device."); | 
|  | 4402 | } | 
|  | 4403 | final long token = Binder.clearCallingIdentity(); | 
|  | 4404 | try { | 
|  | 4405 | Phone phone = getPhone(subId); | 
|  | 4406 | if (phone == null) { | 
|  | 4407 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 4408 | + subId + "'"); | 
|  | 4409 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 4410 | } | 
|  | 4411 | phone.getImsRegistrationState(regState -> { | 
|  | 4412 | try { | 
|  | 4413 | consumer.accept((regState == null) | 
|  | 4414 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); | 
|  | 4415 | } catch (RemoteException e) { | 
|  | 4416 | // Ignore if the remote process is no longer available to call back. | 
|  | 4417 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 4418 | } | 
|  | 4419 | }); | 
|  | 4420 | } finally { | 
|  | 4421 | Binder.restoreCallingIdentity(token); | 
|  | 4422 | } | 
|  | 4423 | } | 
|  | 4424 |  | 
|  | 4425 | /** | 
|  | 4426 | * Get the transport type for the IMS service registration state. | 
|  | 4427 | */ | 
|  | 4428 | @Override | 
|  | 4429 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4430 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4431 | mApp, subId, "getImsMmTelRegistrationTransportType"); | 
| Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4432 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 4433 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4434 | "IMS not available on device."); | 
|  | 4435 | } | 
|  | 4436 | final long token = Binder.clearCallingIdentity(); | 
|  | 4437 | try { | 
|  | 4438 | Phone phone = getPhone(subId); | 
|  | 4439 | if (phone == null) { | 
|  | 4440 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" | 
|  | 4441 | + subId + "'"); | 
|  | 4442 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 4443 | } | 
|  | 4444 | phone.getImsRegistrationTech(regTech -> { | 
|  | 4445 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager | 
|  | 4446 | int regTechConverted = (regTech == null) | 
|  | 4447 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; | 
|  | 4448 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( | 
|  | 4449 | regTechConverted); | 
|  | 4450 | try { | 
|  | 4451 | consumer.accept(regTechConverted); | 
|  | 4452 | } catch (RemoteException e) { | 
|  | 4453 | // Ignore if the remote process is no longer available to call back. | 
|  | 4454 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); | 
|  | 4455 | } | 
|  | 4456 | }); | 
|  | 4457 | } finally { | 
|  | 4458 | Binder.restoreCallingIdentity(token); | 
|  | 4459 | } | 
|  | 4460 | } | 
|  | 4461 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4462 | /** | 
|  | 4463 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4464 | * @param subId The subscription to use to check the configuration. | 
|  | 4465 | * @param c The callback that will be used to send the result. | 
|  | 4466 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4467 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4468 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) | 
|  | 4469 | throws RemoteException { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4470 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4471 | mApp, subId, "registerMmTelCapabilityCallback"); | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4472 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 4473 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4474 | "IMS not available on device."); | 
|  | 4475 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4476 | final long token = Binder.clearCallingIdentity(); | 
|  | 4477 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4478 | int slotId = getSlotIndexOrException(subId); | 
|  | 4479 | verifyImsMmTelConfiguredOrThrow(slotId); | 
| Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4480 |  | 
|  | 4481 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4482 | if (controller != null) { | 
|  | 4483 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4484 | if (imsManager != null) { | 
|  | 4485 | imsManager.addCapabilitiesCallbackForSubscription(c, subId); | 
|  | 4486 | } else { | 
|  | 4487 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); | 
|  | 4488 | } | 
|  | 4489 | } else { | 
|  | 4490 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); | 
|  | 4491 | } | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4492 | } catch (ImsException e) { | 
|  | 4493 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4494 | } finally { | 
|  | 4495 | Binder.restoreCallingIdentity(token); | 
|  | 4496 | } | 
|  | 4497 | } | 
|  | 4498 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4499 | /** | 
|  | 4500 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4501 | * @param subId The subscription to use to check the configuration. | 
|  | 4502 | * @param c The callback that will be used to send the result. | 
|  | 4503 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4504 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4505 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4506 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4507 | mApp, subId, "unregisterMmTelCapabilityCallback"); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4508 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4509 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4510 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4511 |  | 
|  | 4512 | final long token = Binder.clearCallingIdentity(); | 
|  | 4513 | try { | 
| Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4514 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4515 | if (controller != null) { | 
|  | 4516 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4517 | if (imsManager != null) { | 
|  | 4518 | imsManager.removeCapabilitiesCallbackForSubscription(c, subId); | 
|  | 4519 | } else { | 
|  | 4520 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId | 
|  | 4521 | + " is inactive, ignoring unregister."); | 
|  | 4522 | // If the ImsManager is not valid, just return, since the callback | 
|  | 4523 | // will already have been removed internally. | 
|  | 4524 | } | 
|  | 4525 | } | 
| Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4526 | } finally { | 
|  | 4527 | Binder.restoreCallingIdentity(token); | 
|  | 4528 | } | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4529 | } | 
|  | 4530 |  | 
|  | 4531 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4532 | public boolean isCapable(int subId, int capability, int regTech) { | 
|  | 4533 | enforceReadPrivilegedPermission("isCapable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4534 | final long token = Binder.clearCallingIdentity(); | 
|  | 4535 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4536 | int slotId = getSlotIndexOrException(subId); | 
|  | 4537 | verifyImsMmTelConfiguredOrThrow(slotId); | 
|  | 4538 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); | 
|  | 4539 | } catch (com.android.ims.ImsException e) { | 
|  | 4540 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); | 
|  | 4541 | return false; | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4542 | } catch (ImsException e) { | 
| Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4543 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); | 
|  | 4544 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4545 | } finally { | 
|  | 4546 | Binder.restoreCallingIdentity(token); | 
|  | 4547 | } | 
|  | 4548 | } | 
|  | 4549 |  | 
|  | 4550 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4551 | public boolean isAvailable(int subId, int capability, int regTech) { | 
|  | 4552 | enforceReadPrivilegedPermission("isAvailable"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4553 | final long token = Binder.clearCallingIdentity(); | 
|  | 4554 | try { | 
|  | 4555 | Phone phone = getPhone(subId); | 
|  | 4556 | if (phone == null) return false; | 
|  | 4557 | return phone.isImsCapabilityAvailable(capability, regTech); | 
| Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4558 | } catch (com.android.ims.ImsException e) { | 
|  | 4559 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); | 
|  | 4560 | return false; | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4561 | } finally { | 
|  | 4562 | Binder.restoreCallingIdentity(token); | 
|  | 4563 | } | 
|  | 4564 | } | 
|  | 4565 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4566 | /** | 
|  | 4567 | * Determines if the MmTel feature capability is supported by the carrier configuration for this | 
|  | 4568 | * subscription. | 
|  | 4569 | * @param subId The subscription to use to check the configuration. | 
|  | 4570 | * @param callback The callback that will be used to send the result. | 
|  | 4571 | * @param capability The MmTelFeature capability that will be used to send the result. | 
|  | 4572 | * @param transportType The transport type of the MmTelFeature capability. | 
|  | 4573 | */ | 
|  | 4574 | @Override | 
|  | 4575 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, | 
|  | 4576 | int transportType) { | 
|  | 4577 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4578 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 4579 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4580 | "IMS not available on device."); | 
|  | 4581 | } | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4582 | final long token = Binder.clearCallingIdentity(); | 
|  | 4583 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4584 | int slotId = getSlotIndex(subId); | 
|  | 4585 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 4586 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" | 
|  | 4587 | + subId + "'"); | 
|  | 4588 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 4589 | } | 
|  | 4590 | verifyImsMmTelConfiguredOrThrow(slotId); | 
|  | 4591 | ImsManager.getInstance(mApp, slotId).isSupported(capability, | 
|  | 4592 | transportType, aBoolean -> { | 
|  | 4593 | try { | 
|  | 4594 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); | 
|  | 4595 | } catch (RemoteException e) { | 
|  | 4596 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " | 
|  | 4597 | + "running. Ignore"); | 
|  | 4598 | } | 
|  | 4599 | }); | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4600 | } catch (ImsException e) { | 
|  | 4601 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4602 | } finally { | 
|  | 4603 | Binder.restoreCallingIdentity(token); | 
|  | 4604 | } | 
|  | 4605 | } | 
|  | 4606 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4607 | /** | 
|  | 4608 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4609 | * @param subId The subscription to use to check the configuration. | 
|  | 4610 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4611 | @Override | 
|  | 4612 | public boolean isAdvancedCallingSettingEnabled(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4613 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4614 | mApp, subId, "isAdvancedCallingSettingEnabled"); | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4615 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4616 | final long token = Binder.clearCallingIdentity(); | 
|  | 4617 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4618 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4619 | // 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] | 4620 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4621 | } catch (ImsException e) { | 
|  | 4622 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4623 | } finally { | 
|  | 4624 | Binder.restoreCallingIdentity(token); | 
|  | 4625 | } | 
|  | 4626 | } | 
|  | 4627 |  | 
|  | 4628 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4629 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4631 | "setAdvancedCallingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4632 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4633 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4634 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4635 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4636 | // 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] | 4637 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4638 | } catch (ImsException e) { | 
|  | 4639 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4640 | } finally { | 
|  | 4641 | Binder.restoreCallingIdentity(identity); | 
|  | 4642 | } | 
|  | 4643 | } | 
|  | 4644 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4645 | /** | 
|  | 4646 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4647 | * @param subId The subscription to use to check the configuration. | 
|  | 4648 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4649 | @Override | 
| Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4650 | public boolean isVtSettingEnabled(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4651 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4652 | mApp, subId, "isVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4653 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4654 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4655 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4656 | // 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] | 4657 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4658 | } catch (ImsException e) { | 
|  | 4659 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4660 | } finally { | 
|  | 4661 | Binder.restoreCallingIdentity(identity); | 
|  | 4662 | } | 
|  | 4663 | } | 
|  | 4664 |  | 
|  | 4665 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4666 | public void setVtSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4668 | "setVtSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4669 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4670 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4671 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4672 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4673 | // 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] | 4674 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4675 | } catch (ImsException e) { | 
|  | 4676 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4677 | } finally { | 
|  | 4678 | Binder.restoreCallingIdentity(identity); | 
|  | 4679 | } | 
|  | 4680 | } | 
|  | 4681 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4682 | /** | 
|  | 4683 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4684 | * @param subId The subscription to use to check the configuration. | 
|  | 4685 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4686 | @Override | 
|  | 4687 | public boolean isVoWiFiSettingEnabled(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4688 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4689 | mApp, subId, "isVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4690 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4691 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4692 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4693 | // 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] | 4694 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4695 | } catch (ImsException e) { | 
|  | 4696 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4697 | } finally { | 
|  | 4698 | Binder.restoreCallingIdentity(identity); | 
|  | 4699 | } | 
|  | 4700 | } | 
|  | 4701 |  | 
|  | 4702 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4703 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4705 | "setVoWiFiSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4706 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4707 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4708 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4709 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4710 | // 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] | 4711 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4712 | } catch (ImsException e) { | 
|  | 4713 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4714 | } finally { | 
|  | 4715 | Binder.restoreCallingIdentity(identity); | 
|  | 4716 | } | 
|  | 4717 | } | 
|  | 4718 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4719 | /** | 
| Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4720 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not | 
|  | 4721 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4722 | * @param subId The subscription to use to check the configuration. | 
|  | 4723 | */ | 
|  | 4724 | @Override | 
|  | 4725 | public boolean isCrossSimCallingEnabledByUser(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4726 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4727 | mApp, subId, "isCrossSimCallingEnabledByUser"); | 
|  | 4728 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4729 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4730 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4731 | // 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] | 4732 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); | 
| Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4733 | } catch (ImsException e) { | 
|  | 4734 | throw new ServiceSpecificException(e.getCode()); | 
|  | 4735 | } finally { | 
|  | 4736 | Binder.restoreCallingIdentity(identity); | 
|  | 4737 | } | 
|  | 4738 | } | 
|  | 4739 |  | 
|  | 4740 | /** | 
|  | 4741 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. | 
|  | 4742 | * Requires MODIFY_PHONE_STATE permission. | 
|  | 4743 | * @param subId The subscription to use to check the configuration. | 
|  | 4744 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, | 
|  | 4745 | *                 false otherwise | 
|  | 4746 | */ | 
|  | 4747 | @Override | 
|  | 4748 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { | 
|  | 4749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4750 | "setCrossSimCallingEnabled"); | 
|  | 4751 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4752 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4753 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4754 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4755 | // 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] | 4756 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); | 
| Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4757 | } catch (ImsException e) { | 
|  | 4758 | throw new ServiceSpecificException(e.getCode()); | 
|  | 4759 | } finally { | 
|  | 4760 | Binder.restoreCallingIdentity(identity); | 
|  | 4761 | } | 
|  | 4762 | } | 
|  | 4763 |  | 
|  | 4764 | /** | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4765 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4766 | * @param subId The subscription to use to check the configuration. | 
|  | 4767 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4768 | @Override | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4769 |  | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4770 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4771 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4772 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4773 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4774 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4775 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4776 | // This setting doesn't require an active ImsService connection, so do not verify. | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4777 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4778 | } catch (ImsException e) { | 
|  | 4779 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4780 | } finally { | 
|  | 4781 | Binder.restoreCallingIdentity(identity); | 
|  | 4782 | } | 
|  | 4783 | } | 
|  | 4784 |  | 
|  | 4785 | @Override | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4786 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
| Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4788 | "setVoWiFiRoamingSettingEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4789 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4790 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4791 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4792 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4793 | // 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] | 4794 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4795 | } catch (ImsException e) { | 
|  | 4796 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4797 | } finally { | 
|  | 4798 | Binder.restoreCallingIdentity(identity); | 
|  | 4799 | } | 
|  | 4800 | } | 
|  | 4801 |  | 
|  | 4802 | @Override | 
|  | 4803 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { | 
|  | 4804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4805 | "setVoWiFiNonPersistent"); | 
|  | 4806 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4807 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4808 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4809 | // This setting will be ignored if the ImsService isn't up. | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4810 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4811 | } catch (ImsException e) { | 
|  | 4812 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4813 | } finally { | 
|  | 4814 | Binder.restoreCallingIdentity(identity); | 
|  | 4815 | } | 
|  | 4816 | } | 
|  | 4817 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4818 | /** | 
|  | 4819 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4820 | * @param subId The subscription to use to check the configuration. | 
|  | 4821 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4822 | @Override | 
|  | 4823 | public int getVoWiFiModeSetting(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4824 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4825 | mApp, subId, "getVoWiFiModeSetting"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4826 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4827 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4828 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4829 | // 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] | 4830 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4831 | } catch (ImsException e) { | 
|  | 4832 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4833 | } finally { | 
|  | 4834 | Binder.restoreCallingIdentity(identity); | 
|  | 4835 | } | 
|  | 4836 | } | 
|  | 4837 |  | 
|  | 4838 | @Override | 
|  | 4839 | public void setVoWiFiModeSetting(int subId, int mode) { | 
|  | 4840 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4841 | "setVoWiFiModeSetting"); | 
|  | 4842 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4843 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4844 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4845 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4846 | // 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] | 4847 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4848 | } catch (ImsException e) { | 
|  | 4849 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4850 | } finally { | 
|  | 4851 | Binder.restoreCallingIdentity(identity); | 
|  | 4852 | } | 
|  | 4853 | } | 
|  | 4854 |  | 
|  | 4855 | @Override | 
|  | 4856 | public int getVoWiFiRoamingModeSetting(int subId) { | 
|  | 4857 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); | 
|  | 4858 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4859 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4860 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4861 | // 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] | 4862 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4863 | } catch (ImsException e) { | 
|  | 4864 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4865 | } finally { | 
|  | 4866 | Binder.restoreCallingIdentity(identity); | 
|  | 4867 | } | 
|  | 4868 | } | 
|  | 4869 |  | 
|  | 4870 | @Override | 
|  | 4871 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { | 
|  | 4872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4873 | "setVoWiFiRoamingModeSetting"); | 
|  | 4874 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4875 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4876 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4877 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4878 | // 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] | 4879 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4880 | } catch (ImsException e) { | 
|  | 4881 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4882 | } finally { | 
|  | 4883 | Binder.restoreCallingIdentity(identity); | 
|  | 4884 | } | 
|  | 4885 | } | 
|  | 4886 |  | 
|  | 4887 | @Override | 
|  | 4888 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { | 
|  | 4889 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 4890 | "setRttCapabilityEnabled"); | 
|  | 4891 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4892 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4893 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4894 | // This setting doesn't require an active ImsService connection, so do not verify. The | 
|  | 4895 | // 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] | 4896 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4897 | } catch (ImsException e) { | 
|  | 4898 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4899 | } finally { | 
|  | 4900 | Binder.restoreCallingIdentity(identity); | 
|  | 4901 | } | 
|  | 4902 | } | 
|  | 4903 |  | 
| shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4904 | /** | 
|  | 4905 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 4906 | * @param subId The subscription to use to check the configuration. | 
|  | 4907 | */ | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4908 | @Override | 
|  | 4909 | public boolean isTtyOverVolteEnabled(int subId) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4910 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4911 | mApp, subId, "isTtyOverVolteEnabled"); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4912 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4913 | try { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4914 | int slotId = getSlotIndexOrException(subId); | 
| Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4915 | // 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] | 4916 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4917 | } catch (ImsException e) { | 
|  | 4918 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4919 | } finally { | 
|  | 4920 | Binder.restoreCallingIdentity(identity); | 
|  | 4921 | } | 
|  | 4922 | } | 
|  | 4923 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4924 | @Override | 
|  | 4925 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4926 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4927 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4928 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4929 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4930 | if (!isImsAvailableOnDevice()) { | 
|  | 4931 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4932 | "IMS not available on device."); | 
|  | 4933 | } | 
|  | 4934 | int slotId = getSlotIndexOrException(subId); | 
|  | 4935 | verifyImsMmTelConfiguredOrThrow(slotId); | 
| Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4936 |  | 
|  | 4937 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4938 | if (controller != null) { | 
|  | 4939 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4940 | if (imsManager != null) { | 
|  | 4941 | imsManager.addProvisioningCallbackForSubscription(callback, subId); | 
|  | 4942 | } else { | 
|  | 4943 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); | 
|  | 4944 | } | 
|  | 4945 | } else { | 
|  | 4946 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); | 
|  | 4947 | } | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4948 | } catch (ImsException e) { | 
|  | 4949 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4950 | } finally { | 
|  | 4951 | Binder.restoreCallingIdentity(identity); | 
|  | 4952 | } | 
|  | 4953 | } | 
|  | 4954 |  | 
|  | 4955 | @Override | 
|  | 4956 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { | 
|  | 4957 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4958 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4959 | final long identity = Binder.clearCallingIdentity(); | 
| Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4960 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4961 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4962 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4963 | try { | 
| Hwangoo Park | 8646b0d | 2023-01-13 02:42:34 +0000 | [diff] [blame] | 4964 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 4965 | if (controller != null) { | 
|  | 4966 | ImsManager imsManager = controller.getImsManager(subId); | 
|  | 4967 | if (imsManager != null) { | 
|  | 4968 | imsManager.removeProvisioningCallbackForSubscription(callback, subId); | 
|  | 4969 | } else { | 
|  | 4970 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId | 
|  | 4971 | + " is inactive, ignoring unregister."); | 
|  | 4972 | // If the ImsManager is not valid, just return, since the callback will already | 
|  | 4973 | // have been removed internally. | 
|  | 4974 | } | 
|  | 4975 | } | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4976 | } finally { | 
|  | 4977 | Binder.restoreCallingIdentity(identity); | 
|  | 4978 | } | 
|  | 4979 | } | 
|  | 4980 |  | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4981 | @Override | 
|  | 4982 | public void registerFeatureProvisioningChangedCallback(int subId, | 
|  | 4983 | IFeatureProvisioningCallback callback) { | 
|  | 4984 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 4985 | mApp, subId, "registerFeatureProvisioningChangedCallback"); | 
|  | 4986 |  | 
|  | 4987 | final long identity = Binder.clearCallingIdentity(); | 
|  | 4988 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 4989 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 4990 | } | 
|  | 4991 |  | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4992 | try { | 
|  | 4993 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 4994 | if (controller == null) { | 
|  | 4995 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 4996 | "Device does not support IMS"); | 
|  | 4997 | } | 
|  | 4998 | controller.addFeatureProvisioningChangedCallback(subId, callback); | 
|  | 4999 | } finally { | 
|  | 5000 | Binder.restoreCallingIdentity(identity); | 
|  | 5001 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5002 | } | 
|  | 5003 |  | 
|  | 5004 | @Override | 
|  | 5005 | public void unregisterFeatureProvisioningChangedCallback(int subId, | 
|  | 5006 | IFeatureProvisioningCallback callback) { | 
|  | 5007 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5008 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); | 
|  | 5009 |  | 
|  | 5010 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5011 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 5012 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 5013 | } | 
|  | 5014 |  | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5015 | try { | 
|  | 5016 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5017 | if (controller == null) { | 
|  | 5018 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); | 
|  | 5019 | return; | 
|  | 5020 | } | 
|  | 5021 | controller.removeFeatureProvisioningChangedCallback(subId, callback); | 
|  | 5022 | } finally { | 
|  | 5023 | Binder.restoreCallingIdentity(identity); | 
|  | 5024 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5025 | } | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5026 |  | 
|  | 5027 | private void checkModifyPhoneStatePermission(int subId, String message) { | 
|  | 5028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 5029 | message); | 
|  | 5030 | } | 
|  | 5031 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5032 | @Override | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5033 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5034 | boolean isProvisioned) { | 
|  | 5035 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); | 
|  | 5036 |  | 
|  | 5037 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5038 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5039 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5040 | if (controller == null) { | 
|  | 5041 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); | 
|  | 5042 | return; | 
|  | 5043 | } | 
|  | 5044 | controller.setRcsProvisioningStatusForCapability( | 
|  | 5045 | subId, capability, tech, isProvisioned); | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5046 | } finally { | 
|  | 5047 | Binder.restoreCallingIdentity(identity); | 
|  | 5048 | } | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5049 | } | 
|  | 5050 |  | 
|  | 5051 |  | 
|  | 5052 | @Override | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5053 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
|  | 5054 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5055 | mApp, subId, "getRcsProvisioningStatusForCapability"); | 
|  | 5056 |  | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5057 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5058 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5059 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5060 | if (controller == null) { | 
|  | 5061 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); | 
|  | 5062 |  | 
|  | 5063 | // device does not support IMS, this method will return true always. | 
|  | 5064 | return true; | 
|  | 5065 | } | 
|  | 5066 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5067 | } finally { | 
|  | 5068 | Binder.restoreCallingIdentity(identity); | 
|  | 5069 | } | 
|  | 5070 | } | 
|  | 5071 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5072 | @Override | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5073 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, | 
|  | 5074 | boolean isProvisioned) { | 
| allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 5075 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5076 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5078 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5079 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5080 | if (controller == null) { | 
|  | 5081 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); | 
|  | 5082 | return; | 
|  | 5083 | } | 
|  | 5084 | controller.setImsProvisioningStatusForCapability( | 
|  | 5085 | subId, capability, tech, isProvisioned); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5086 | } finally { | 
|  | 5087 | Binder.restoreCallingIdentity(identity); | 
|  | 5088 | } | 
|  | 5089 | } | 
|  | 5090 |  | 
|  | 5091 | @Override | 
|  | 5092 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5093 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5094 | mApp, subId, "getProvisioningStatusForCapability"); | 
|  | 5095 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5096 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5097 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5098 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5099 | if (controller == null) { | 
|  | 5100 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5101 |  | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5102 | // device does not support IMS, this method will return true always. | 
|  | 5103 | return true; | 
|  | 5104 | } | 
|  | 5105 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5106 | } finally { | 
|  | 5107 | Binder.restoreCallingIdentity(identity); | 
|  | 5108 | } | 
|  | 5109 | } | 
|  | 5110 |  | 
|  | 5111 | @Override | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5112 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { | 
|  | 5113 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5114 | mApp, subId, "isProvisioningRequiredForCapability"); | 
|  | 5115 |  | 
|  | 5116 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5117 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5118 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5119 | if (controller == null) { | 
|  | 5120 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); | 
|  | 5121 |  | 
|  | 5122 | // device does not support IMS, this method will return false | 
|  | 5123 | return false; | 
|  | 5124 | } | 
|  | 5125 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5126 | } finally { | 
|  | 5127 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5128 | } | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5129 | } | 
|  | 5130 |  | 
|  | 5131 | @Override | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5132 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { | 
|  | 5133 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5134 | mApp, subId, "isProvisioningRequiredForCapability"); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5135 |  | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5136 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5137 | try { | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5138 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5139 | if (controller == null) { | 
|  | 5140 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); | 
|  | 5141 |  | 
|  | 5142 | // device does not support IMS, this method will return false | 
|  | 5143 | return false; | 
|  | 5144 | } | 
|  | 5145 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5146 | } finally { | 
|  | 5147 | Binder.restoreCallingIdentity(identity); | 
|  | 5148 | } | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5149 | } | 
|  | 5150 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5151 | @Override | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5152 | public int getImsProvisioningInt(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5153 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 5154 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 5155 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5156 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5157 | mApp, subId, "getImsProvisioningInt"); | 
|  | 5158 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5159 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5160 | try { | 
|  | 5161 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5162 | int slotId = getSlotIndex(subId); | 
|  | 5163 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5164 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" | 
|  | 5165 | + subId + "' for key:" + key); | 
|  | 5166 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 5167 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5168 |  | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5169 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5170 | if (controller == null) { | 
|  | 5171 | loge("getImsProvisioningInt: Device does not support IMS"); | 
|  | 5172 |  | 
|  | 5173 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. | 
|  | 5174 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
|  | 5175 | } | 
|  | 5176 | int retVal = controller.getProvisioningValue(subId, key); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5177 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { | 
|  | 5178 | return retVal; | 
|  | 5179 | } | 
|  | 5180 |  | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5181 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5182 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5183 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" | 
|  | 5184 | + subId + "' for key:" + key); | 
|  | 5185 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5186 | } finally { | 
|  | 5187 | Binder.restoreCallingIdentity(identity); | 
|  | 5188 | } | 
|  | 5189 | } | 
|  | 5190 |  | 
|  | 5191 | @Override | 
|  | 5192 | public String getImsProvisioningString(int subId, int key) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5193 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 5194 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 5195 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5196 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 5197 | mApp, subId, "getImsProvisioningString"); | 
|  | 5198 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5199 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5200 | try { | 
|  | 5201 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5202 | int slotId = getSlotIndex(subId); | 
|  | 5203 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5204 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" | 
|  | 5205 | + subId + "' for key:" + key); | 
|  | 5206 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; | 
|  | 5207 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5208 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5209 | } catch (com.android.ims.ImsException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5210 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" | 
|  | 5211 | + subId + "' for key:" + key); | 
|  | 5212 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5213 | } finally { | 
|  | 5214 | Binder.restoreCallingIdentity(identity); | 
|  | 5215 | } | 
|  | 5216 | } | 
|  | 5217 |  | 
|  | 5218 | @Override | 
|  | 5219 | public int setImsProvisioningInt(int subId, int key, int value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5220 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 5221 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 5222 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 5224 | "setImsProvisioningInt"); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5225 |  | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5226 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5227 | try { | 
|  | 5228 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5229 | int slotId = getSlotIndex(subId); | 
|  | 5230 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5231 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" | 
|  | 5232 | + subId + "' for key:" + key); | 
|  | 5233 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 5234 | } | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5235 |  | 
| joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5236 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); | 
|  | 5237 | if (controller == null) { | 
|  | 5238 | loge("setImsProvisioningInt: Device does not support IMS"); | 
|  | 5239 |  | 
|  | 5240 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. | 
|  | 5241 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 5242 | } | 
|  | 5243 | int retVal = controller.setProvisioningValue(subId, key, value); | 
| joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5244 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { | 
|  | 5245 | return retVal; | 
|  | 5246 | } | 
|  | 5247 |  | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5248 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); | 
|  | 5249 | } catch (com.android.ims.ImsException | RemoteException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5250 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5251 | + "' for key:" + key, e); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5252 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5253 | } finally { | 
|  | 5254 | Binder.restoreCallingIdentity(identity); | 
|  | 5255 | } | 
|  | 5256 | } | 
|  | 5257 |  | 
|  | 5258 | @Override | 
|  | 5259 | public int setImsProvisioningString(int subId, int key, String value) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5260 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 5261 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); | 
|  | 5262 | } | 
| Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, | 
|  | 5264 | "setImsProvisioningString"); | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5265 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5266 | try { | 
|  | 5267 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5268 | int slotId = getSlotIndex(subId); | 
|  | 5269 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5270 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" | 
|  | 5271 | + subId + "' for key:" + key); | 
|  | 5272 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
|  | 5273 | } | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5274 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); | 
|  | 5275 | } catch (com.android.ims.ImsException | RemoteException e) { | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5276 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId | 
| calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5277 | + "' for key:" + key, e); | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5278 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; | 
| Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5279 | } finally { | 
|  | 5280 | Binder.restoreCallingIdentity(identity); | 
|  | 5281 | } | 
|  | 5282 | } | 
|  | 5283 |  | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5284 | /** | 
|  | 5285 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL | 
|  | 5286 | * for the given slot ID or no ImsResolver instance has been created. | 
|  | 5287 | * @param slotId The slot ID that the IMS service is created for. | 
|  | 5288 | * @throws ImsException If there is no ImsService configured for this slot. | 
|  | 5289 | */ | 
|  | 5290 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { | 
|  | 5291 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, | 
|  | 5292 | ImsFeature.FEATURE_MMTEL)) { | 
|  | 5293 | throw new ImsException("This subscription does not support MMTEL over IMS", | 
|  | 5294 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); | 
|  | 5295 | } | 
|  | 5296 | } | 
|  | 5297 |  | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5298 | private int getSlotIndexOrException(int subId) throws ImsException { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5299 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 5300 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
| Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5301 | throw new ImsException("Invalid Subscription Id, subId=" + subId, | 
|  | 5302 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5303 | } | 
|  | 5304 | return slotId; | 
|  | 5305 | } | 
|  | 5306 |  | 
| Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5307 | private int getSlotIndex(int subId) { | 
|  | 5308 | int slotId = SubscriptionManager.getSlotIndex(subId); | 
|  | 5309 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { | 
|  | 5310 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; | 
|  | 5311 | } | 
|  | 5312 | return slotId; | 
|  | 5313 | } | 
|  | 5314 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5315 | /** | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5316 | * Returns the data network type for a subId; does not throw SecurityException. | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5317 | */ | 
|  | 5318 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5319 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 5320 | String callingFeatureId) { | 
| Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5321 | try { | 
|  | 5322 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5323 | } catch (SecurityException se) { | 
|  | 5324 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); | 
|  | 5325 | throw new SecurityException("Package " + callingPackage + " does not belong to " | 
|  | 5326 | + Binder.getCallingUid()); | 
|  | 5327 | } | 
| Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5328 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5329 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5330 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); | 
| Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5331 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q | 
| Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5332 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5333 | mApp, subId, callingPackage, callingFeatureId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5334 | "getNetworkTypeForSubscriber")) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5335 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5336 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5337 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5339 | try { | 
|  | 5340 | final Phone phone = getPhone(subId); | 
|  | 5341 | if (phone != null) { | 
|  | 5342 | return phone.getServiceState().getDataNetworkType(); | 
|  | 5343 | } else { | 
|  | 5344 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5345 | } | 
|  | 5346 | } finally { | 
|  | 5347 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5348 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5349 | } | 
|  | 5350 |  | 
|  | 5351 | /** | 
|  | 5352 | * Returns the data network type | 
|  | 5353 | */ | 
|  | 5354 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5355 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5356 | return getDataNetworkTypeForSubscriber(SubscriptionManager.getDefaultDataSubscriptionId(), | 
| Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5357 | callingPackage, callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5358 | } | 
|  | 5359 |  | 
|  | 5360 | /** | 
|  | 5361 | * Returns the data network type for a subId | 
|  | 5362 | */ | 
|  | 5363 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5364 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 5365 | String callingFeatureId) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5366 | String functionName = "getDataNetworkTypeForSubscriber"; | 
|  | 5367 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( | 
|  | 5368 | mApp, functionName)) { | 
|  | 5369 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5370 | mApp, subId, callingPackage, callingFeatureId, functionName)) { | 
|  | 5371 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5372 | } | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5373 | } | 
|  | 5374 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5376 | try { | 
|  | 5377 | final Phone phone = getPhone(subId); | 
|  | 5378 | if (phone != null) { | 
|  | 5379 | return phone.getServiceState().getDataNetworkType(); | 
|  | 5380 | } else { | 
|  | 5381 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5382 | } | 
|  | 5383 | } finally { | 
|  | 5384 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5385 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5386 | } | 
|  | 5387 |  | 
|  | 5388 | /** | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5389 | * Returns the Voice network type for a subId | 
|  | 5390 | */ | 
|  | 5391 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5392 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, | 
|  | 5393 | String callingFeatureId) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5394 | String functionName = "getVoiceNetworkTypeForSubscriber"; | 
|  | 5395 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( | 
|  | 5396 | mApp, functionName)) { | 
|  | 5397 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 5398 | mApp, subId, callingPackage, callingFeatureId, functionName)) { | 
|  | 5399 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5400 | } | 
| Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5401 | } | 
|  | 5402 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5404 | try { | 
|  | 5405 | final Phone phone = getPhone(subId); | 
|  | 5406 | if (phone != null) { | 
|  | 5407 | return phone.getServiceState().getVoiceNetworkType(); | 
|  | 5408 | } else { | 
|  | 5409 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; | 
|  | 5410 | } | 
|  | 5411 | } finally { | 
|  | 5412 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5413 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5414 | } | 
|  | 5415 |  | 
|  | 5416 | /** | 
|  | 5417 | * @return true if a ICC card is present | 
|  | 5418 | */ | 
|  | 5419 | public boolean hasIccCard() { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5420 | // FIXME Make changes to pass defaultSimId of type int | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5421 | return hasIccCardUsingSlotIndex(SubscriptionManager.getSlotIndex( | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5422 | getDefaultSubscription())); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5423 | } | 
|  | 5424 |  | 
|  | 5425 | /** | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5426 | * @return true if a ICC card is present for a slotIndex | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5427 | */ | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5428 | @Override | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5429 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5431 | try { | 
|  | 5432 | final Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5433 | if (phone != null) { | 
|  | 5434 | return phone.getIccCard().hasIccCard(); | 
|  | 5435 | } else { | 
|  | 5436 | return false; | 
|  | 5437 | } | 
|  | 5438 | } finally { | 
|  | 5439 | Binder.restoreCallingIdentity(identity); | 
| Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5440 | } | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5441 | } | 
|  | 5442 |  | 
|  | 5443 | /** | 
|  | 5444 | * Return if the current radio is LTE on CDMA. This | 
|  | 5445 | * is a tri-state return value as for a period of time | 
|  | 5446 | * the mode may be unknown. | 
|  | 5447 | * | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5448 | * @param callingPackage the name of the package making the call. | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5449 | * @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] | 5450 | * or {@link Phone#LTE_ON_CDMA_TRUE} | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5451 | */ | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5452 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5453 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { | 
|  | 5454 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, | 
|  | 5455 | callingFeatureId); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5456 | } | 
|  | 5457 |  | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5458 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5459 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, | 
|  | 5460 | String callingFeatureId) { | 
| Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5461 | try { | 
|  | 5462 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); | 
|  | 5463 | } catch (SecurityException e) { | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5464 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 5465 | } | 
|  | 5466 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5467 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5468 | try { | 
|  | 5469 | final Phone phone = getPhone(subId); | 
|  | 5470 | if (phone == null) { | 
|  | 5471 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; | 
|  | 5472 | } else { | 
| Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5473 | return TelephonyProperties.lte_on_cdma_device() | 
|  | 5474 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | } | 
|  | 5476 | } finally { | 
|  | 5477 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5478 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5479 | } | 
|  | 5480 |  | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5481 | /** | 
|  | 5482 | * {@hide} | 
|  | 5483 | * Returns Default subId, 0 in the case of single standby. | 
|  | 5484 | */ | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5485 | private int getDefaultSubscription() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5486 | return SubscriptionManager.getDefaultSubscriptionId(); | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5487 | } | 
|  | 5488 |  | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5489 | private int getSlotForDefaultSubscription() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5490 | return SubscriptionManager.getPhoneId(getDefaultSubscription()); | 
| Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5491 | } | 
|  | 5492 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5493 | private int getPreferredVoiceSubscription() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5494 | return SubscriptionManager.getDefaultVoiceSubscriptionId(); | 
| Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5495 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5496 |  | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5497 | private boolean isActiveSubscription(int subId) { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5498 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 5499 | return getSubscriptionManagerService().isActiveSubId(subId, | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 5500 | mApp.getOpPackageName(), mApp.getFeatureId()); | 
|  | 5501 | } | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5502 | return mSubscriptionController.isActiveSubId(subId); | 
|  | 5503 | } | 
|  | 5504 |  | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5505 | /** | 
|  | 5506 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 5507 | */ | 
|  | 5508 | public int getWhenToMakeWifiCalls() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5510 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5511 | return Settings.System.getInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, | 
|  | 5513 | getWhenToMakeWifiCallsDefaultPreference()); | 
|  | 5514 | } finally { | 
|  | 5515 | Binder.restoreCallingIdentity(identity); | 
|  | 5516 | } | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5517 | } | 
|  | 5518 |  | 
|  | 5519 | /** | 
|  | 5520 | * @see android.telephony.TelephonyManager.WifiCallingChoices | 
|  | 5521 | */ | 
|  | 5522 | public void setWhenToMakeWifiCalls(int preference) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5524 | try { | 
|  | 5525 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5526 | Settings.System.putInt(mApp.getContentResolver(), | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); | 
|  | 5528 | } finally { | 
|  | 5529 | Binder.restoreCallingIdentity(identity); | 
|  | 5530 | } | 
| Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5531 | } | 
|  | 5532 |  | 
| Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5533 | private static int getWhenToMakeWifiCallsDefaultPreference() { | 
| Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5534 | // TODO: Use a build property to choose this value. | 
| Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5535 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; | 
| Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5536 | } | 
| Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5537 |  | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5538 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { | 
|  | 5539 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, | 
|  | 5540 | portIndex); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5541 | if (phoneId == -1) { | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5542 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5543 | + portIndex + " does not correspond to an active phone"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5544 | } | 
|  | 5545 | return PhoneFactory.getPhone(phoneId); | 
|  | 5546 | } | 
|  | 5547 |  | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5548 | @Override | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5549 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5550 | @NonNull IccLogicalChannelRequest request) { | 
|  | 5551 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, | 
|  | 5552 | /*message=*/ "iccOpenLogicalChannel"); | 
|  | 5553 |  | 
|  | 5554 | if (DBG) log("iccOpenLogicalChannel: request=" + request); | 
|  | 5555 | // Verify that the callingPackage in the request belongs to the calling UID | 
|  | 5556 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); | 
|  | 5557 |  | 
|  | 5558 | return iccOpenLogicalChannelWithPermission(phone, request); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5559 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5560 |  | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5561 | private Phone getPhoneFromValidIccLogicalChannelRequest( | 
|  | 5562 | @NonNull IccLogicalChannelRequest request, String message) { | 
|  | 5563 | Phone phone; | 
|  | 5564 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { | 
|  | 5565 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5566 | mApp, request.subId, message); | 
|  | 5567 | phone = getPhoneFromSubId(request.subId); | 
|  | 5568 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 5569 | enforceModifyPermission(); | 
|  | 5570 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); | 
|  | 5571 | } else { | 
|  | 5572 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5573 | } | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5574 | return phone; | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5575 | } | 
|  | 5576 |  | 
|  | 5577 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5578 | IccLogicalChannelRequest channelRequest) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5580 | try { | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5581 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | // Only allows LPA to open logical channel to ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5583 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 5584 | .getContext().getPackageManager()); | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5585 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, | 
|  | 5586 | bestComponent.packageName)) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5587 | loge("The calling package is not allowed to access ISD-R."); | 
|  | 5588 | throw new SecurityException( | 
|  | 5589 | "The calling package is not allowed to access ISD-R."); | 
|  | 5590 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5591 | } | 
| Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5592 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5594 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); | 
|  | 5595 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5596 | return response; | 
|  | 5597 | } finally { | 
|  | 5598 | Binder.restoreCallingIdentity(identity); | 
|  | 5599 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5600 | } | 
|  | 5601 |  | 
|  | 5602 | @Override | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5603 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { | 
|  | 5604 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, | 
|  | 5605 | /*message=*/"iccCloseLogicalChannel"); | 
|  | 5606 |  | 
|  | 5607 | if (DBG) log("iccCloseLogicalChannel: request=" + request); | 
|  | 5608 |  | 
|  | 5609 | return iccCloseLogicalChannelWithPermission(phone, request); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5610 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5611 |  | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5612 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, | 
|  | 5613 | IccLogicalChannelRequest request) { | 
| Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5614 | // before this feature is enabled, this API should only return false if | 
|  | 5615 | // the operation fails instead of throwing runtime exception for | 
|  | 5616 | // backward-compatibility. | 
|  | 5617 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( | 
|  | 5618 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5620 | try { | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5621 | if (request.channel < 0) { | 
| Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5622 | throw new IllegalArgumentException("request.channel is less than 0"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5623 | } | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5624 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5625 | null /* workSource */); | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5626 | Boolean success = false; | 
|  | 5627 | if (result instanceof RuntimeException) { | 
|  | 5628 | // if there is an exception returned, throw from the binder thread here. | 
| Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5629 | if (shouldThrowExceptionOnFailure) { | 
|  | 5630 | throw (RuntimeException) result; | 
|  | 5631 | } else { | 
|  | 5632 | return false; | 
|  | 5633 | } | 
| Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5634 | } else if (result instanceof Boolean) { | 
|  | 5635 | success = (Boolean) result; | 
|  | 5636 | } else { | 
|  | 5637 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); | 
|  | 5638 | } | 
| Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5639 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | return success; | 
|  | 5641 | } finally { | 
|  | 5642 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5643 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5644 | } | 
|  | 5645 |  | 
|  | 5646 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5647 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5648 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5649 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5650 | mApp, subId, "iccTransmitApduLogicalChannel"); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5651 | if (DBG) { | 
|  | 5652 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel | 
|  | 5653 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" | 
|  | 5654 | + p3 + " data=" + data); | 
|  | 5655 | } | 
|  | 5656 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, | 
|  | 5657 | command, p1, p2, p3, data); | 
|  | 5658 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5659 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5660 | @Override | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5661 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5662 | int cla, int command, int p1, int p2, int p3, String data) { | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5663 | enforceModifyPermission(); | 
|  | 5664 | if (DBG) { | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5665 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5666 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" | 
|  | 5667 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5668 | } | 
|  | 5669 | return iccTransmitApduLogicalChannelWithPermission( | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5670 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, | 
|  | 5671 | command, p1, p2, p3, data); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5672 | } | 
|  | 5673 |  | 
|  | 5674 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, | 
|  | 5675 | int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5677 | try { | 
| Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5678 | if (channel <= 0) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | return ""; | 
|  | 5680 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5681 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5682 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5683 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, | 
|  | 5684 | null /* workSource */); | 
|  | 5685 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5686 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | // Append the returned status code to the end of the response payload. | 
|  | 5688 | String s = Integer.toHexString( | 
|  | 5689 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5690 | if (response.payload != null) { | 
|  | 5691 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5692 | } | 
|  | 5693 | return s; | 
|  | 5694 | } finally { | 
|  | 5695 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5696 | } | 
| Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5697 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5698 |  | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5699 | @Override | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5700 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, | 
|  | 5701 | int command, int p1, int p2, int p3, String data) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5703 | mApp, subId, "iccTransmitApduBasicChannel"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5705 | if (DBG) { | 
|  | 5706 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" | 
|  | 5707 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); | 
|  | 5708 | } | 
|  | 5709 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, | 
|  | 5710 | cla, command, p1, p2, p3, data); | 
|  | 5711 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5712 |  | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5713 | @Override | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5714 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5715 | 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] | 5716 | enforceModifyPermission(); | 
|  | 5717 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 5718 | if (DBG) { | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5719 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 5720 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" | 
|  | 5721 | + p2 + " p3=" + p3 + " data=" + data); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5722 | } | 
|  | 5723 |  | 
|  | 5724 | return iccTransmitApduBasicChannelWithPermission( | 
| Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5725 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, | 
|  | 5726 | cla, command, p1, p2, p3, data); | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5727 | } | 
|  | 5728 |  | 
|  | 5729 | // open APDU basic channel assuming the caller has sufficient permissions | 
|  | 5730 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, | 
|  | 5731 | int cla, int command, int p1, int p2, int p3, String data) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5733 | try { | 
|  | 5734 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 | 
|  | 5735 | && TextUtils.equals(ISDR_AID, data)) { | 
|  | 5736 | // Only allows LPA to select ISD-R. | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5737 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() | 
|  | 5738 | .getContext().getPackageManager()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5739 | if (bestComponent == null | 
|  | 5740 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { | 
|  | 5741 | loge("The calling package is not allowed to select ISD-R."); | 
|  | 5742 | throw new SecurityException( | 
|  | 5743 | "The calling package is not allowed to select ISD-R."); | 
|  | 5744 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5745 | } | 
| Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5746 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, | 
| Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5748 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, | 
|  | 5749 | null /* workSource */); | 
|  | 5750 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5751 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | // Append the returned status code to the end of the response payload. | 
|  | 5753 | String s = Integer.toHexString( | 
|  | 5754 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5755 | if (response.payload != null) { | 
|  | 5756 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5757 | } | 
|  | 5758 | return s; | 
|  | 5759 | } finally { | 
|  | 5760 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5761 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5762 | } | 
|  | 5763 |  | 
|  | 5764 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5765 | 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] | 5766 | String filePath) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5768 | mApp, subId, "iccExchangeSimIO"); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5769 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5770 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5771 | try { | 
|  | 5772 | if (DBG) { | 
|  | 5773 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " | 
|  | 5774 | + p1 + " " + p2 + " " + p3 + ":" + filePath); | 
|  | 5775 | } | 
|  | 5776 |  | 
|  | 5777 | IccIoResult response = | 
|  | 5778 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, | 
|  | 5779 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), | 
|  | 5780 | subId); | 
|  | 5781 |  | 
|  | 5782 | if (DBG) { | 
|  | 5783 | log("Exchange SIM_IO [R]" + response); | 
|  | 5784 | } | 
|  | 5785 |  | 
|  | 5786 | byte[] result = null; | 
|  | 5787 | int length = 2; | 
|  | 5788 | if (response.payload != null) { | 
|  | 5789 | length = 2 + response.payload.length; | 
|  | 5790 | result = new byte[length]; | 
|  | 5791 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); | 
|  | 5792 | } else { | 
|  | 5793 | result = new byte[length]; | 
|  | 5794 | } | 
|  | 5795 |  | 
|  | 5796 | result[length - 1] = (byte) response.sw2; | 
|  | 5797 | result[length - 2] = (byte) response.sw1; | 
|  | 5798 | return result; | 
|  | 5799 | } finally { | 
|  | 5800 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5801 | } | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5802 | } | 
|  | 5803 |  | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5804 | /** | 
|  | 5805 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) | 
|  | 5806 | * on a particular subscription | 
|  | 5807 | */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5808 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, | 
|  | 5809 | String callingFeatureId) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5811 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { | 
| sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5812 | return null; | 
|  | 5813 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 |  | 
|  | 5815 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5816 | try { | 
|  | 5817 | if (appType != TelephonyManager.APPTYPE_USIM | 
|  | 5818 | && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5819 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5820 | return null; | 
|  | 5821 | } | 
|  | 5822 | Object response = sendRequest( | 
|  | 5823 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); | 
|  | 5824 | if (response instanceof String[]) { | 
|  | 5825 | return (String[]) response; | 
|  | 5826 | } | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5827 | // Response is an Exception of some kind | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | // which is signalled to the user as a NULL retval | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5829 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5830 | } finally { | 
|  | 5831 | Binder.restoreCallingIdentity(identity); | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5832 | } | 
| Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5833 | } | 
|  | 5834 |  | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5835 | /** | 
|  | 5836 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular | 
|  | 5837 | * subscription. | 
|  | 5838 | * | 
|  | 5839 | * @param subId the id of the subscription. | 
|  | 5840 | * @param appType the uicc app type, must be USIM or SIM. | 
|  | 5841 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. | 
|  | 5842 | * @param callingPackage the op Package name. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5843 | * @param callingFeatureId the feature in the package. | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5844 | * @return number of fplmns that is successfully written to the SIM. | 
|  | 5845 | */ | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5846 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, | 
|  | 5847 | String callingFeatureId) { | 
| Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5849 | mApp, subId, "setForbiddenPlmns"); | 
|  | 5850 |  | 
| yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5851 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { | 
|  | 5852 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); | 
|  | 5853 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); | 
|  | 5854 | } | 
|  | 5855 | if (fplmns == null) { | 
|  | 5856 | throw new IllegalArgumentException("Fplmn List provided is null"); | 
|  | 5857 | } | 
|  | 5858 | for (String fplmn : fplmns) { | 
|  | 5859 | if (!CellIdentity.isValidPlmn(fplmn)) { | 
|  | 5860 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); | 
|  | 5861 | } | 
|  | 5862 | } | 
|  | 5863 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5864 | try { | 
|  | 5865 | Object response = sendRequest( | 
|  | 5866 | CMD_SET_FORBIDDEN_PLMNS, | 
|  | 5867 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), | 
|  | 5868 | subId); | 
|  | 5869 | return (int) response; | 
|  | 5870 | } finally { | 
|  | 5871 | Binder.restoreCallingIdentity(identity); | 
|  | 5872 | } | 
|  | 5873 | } | 
|  | 5874 |  | 
| Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5875 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5876 | public String sendEnvelopeWithStatus(int subId, String content) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5878 | mApp, subId, "sendEnvelopeWithStatus"); | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5879 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5881 | try { | 
|  | 5882 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); | 
|  | 5883 | if (response.payload == null) { | 
|  | 5884 | return ""; | 
|  | 5885 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5886 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5887 | // Append the returned status code to the end of the response payload. | 
|  | 5888 | String s = Integer.toHexString( | 
|  | 5889 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); | 
|  | 5890 | s = IccUtils.bytesToHexString(response.payload) + s; | 
|  | 5891 | return s; | 
|  | 5892 | } finally { | 
|  | 5893 | Binder.restoreCallingIdentity(identity); | 
|  | 5894 | } | 
| Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5895 | } | 
|  | 5896 |  | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5897 | /** | 
|  | 5898 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5899 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5900 | * | 
|  | 5901 | * @param itemID the ID of the item to read | 
|  | 5902 | * @return the NV item as a String, or null on error. | 
|  | 5903 | */ | 
|  | 5904 | @Override | 
|  | 5905 | public String nvReadItem(int itemID) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5906 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5907 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5908 | mApp, getDefaultSubscription(), "nvReadItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 |  | 
|  | 5910 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5911 | try { | 
|  | 5912 | if (DBG) log("nvReadItem: item " + itemID); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5913 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); | 
|  | 5915 | return value; | 
|  | 5916 | } finally { | 
|  | 5917 | Binder.restoreCallingIdentity(identity); | 
|  | 5918 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5919 | } | 
|  | 5920 |  | 
|  | 5921 | /** | 
|  | 5922 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} | 
|  | 5923 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. | 
|  | 5924 | * | 
|  | 5925 | * @param itemID the ID of the item to read | 
|  | 5926 | * @param itemValue the value to write, as a String | 
|  | 5927 | * @return true on success; false on any failure | 
|  | 5928 | */ | 
|  | 5929 | @Override | 
|  | 5930 | public boolean nvWriteItem(int itemID, String itemValue) { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5933 | mApp, getDefaultSubscription(), "nvWriteItem"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 |  | 
|  | 5935 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5936 | try { | 
|  | 5937 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); | 
|  | 5938 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5939 | new Pair<Integer, String>(itemID, itemValue), workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5940 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); | 
|  | 5941 | return success; | 
|  | 5942 | } finally { | 
|  | 5943 | Binder.restoreCallingIdentity(identity); | 
|  | 5944 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5945 | } | 
|  | 5946 |  | 
|  | 5947 | /** | 
|  | 5948 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. | 
|  | 5949 | * Used for device configuration by some CDMA operators. | 
|  | 5950 | * | 
|  | 5951 | * @param preferredRoamingList byte array containing the new PRL | 
|  | 5952 | * @return true on success; false on any failure | 
|  | 5953 | */ | 
|  | 5954 | @Override | 
|  | 5955 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5957 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 |  | 
|  | 5959 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5960 | try { | 
|  | 5961 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); | 
|  | 5962 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); | 
|  | 5963 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); | 
|  | 5964 | return success; | 
|  | 5965 | } finally { | 
|  | 5966 | Binder.restoreCallingIdentity(identity); | 
|  | 5967 | } | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5968 | } | 
|  | 5969 |  | 
|  | 5970 | /** | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5971 | * 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] | 5972 | * Used for device configuration by some CDMA operators. | 
|  | 5973 | * | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5974 | * @param slotIndex - device slot. | 
|  | 5975 | * | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5976 | * @return true on success; false on any failure | 
|  | 5977 | */ | 
|  | 5978 | @Override | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5979 | public boolean resetModemConfig(int slotIndex) { | 
|  | 5980 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 5981 | if (phone != null) { | 
|  | 5982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 5983 | mApp, phone.getSubId(), "resetModemConfig"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 |  | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5985 | final long identity = Binder.clearCallingIdentity(); | 
|  | 5986 | try { | 
|  | 5987 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); | 
|  | 5988 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); | 
|  | 5989 | return success; | 
|  | 5990 | } finally { | 
|  | 5991 | Binder.restoreCallingIdentity(identity); | 
|  | 5992 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | } | 
| chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5994 | return false; | 
|  | 5995 | } | 
|  | 5996 |  | 
|  | 5997 | /** | 
|  | 5998 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. | 
|  | 5999 | * | 
|  | 6000 | * @param slotIndex - device slot. | 
|  | 6001 | * | 
|  | 6002 | * @return true on success; false on any failure | 
|  | 6003 | */ | 
|  | 6004 | @Override | 
|  | 6005 | public boolean rebootModem(int slotIndex) { | 
|  | 6006 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 6007 | if (phone != null) { | 
|  | 6008 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6009 | mApp, phone.getSubId(), "rebootModem"); | 
|  | 6010 |  | 
|  | 6011 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6012 | try { | 
|  | 6013 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); | 
|  | 6014 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); | 
|  | 6015 | return success; | 
|  | 6016 | } finally { | 
|  | 6017 | Binder.restoreCallingIdentity(identity); | 
|  | 6018 | } | 
|  | 6019 | } | 
|  | 6020 | return false; | 
| Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 6021 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6022 |  | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6023 | /** | 
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6024 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and | 
|  | 6025 | * {@link #disableIms(int)}. | 
|  | 6026 | * @param slotIndex device slot. | 
|  | 6027 | */ | 
|  | 6028 | public void resetIms(int slotIndex) { | 
|  | 6029 | enforceModifyPermission(); | 
|  | 6030 |  | 
|  | 6031 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6032 | try { | 
|  | 6033 | if (mImsResolver == null) { | 
|  | 6034 | // may happen if the does not support IMS. | 
|  | 6035 | return; | 
|  | 6036 | } | 
| Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 6037 | mImsResolver.resetIms(slotIndex); | 
| Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 6038 | } finally { | 
|  | 6039 | Binder.restoreCallingIdentity(identity); | 
|  | 6040 | } | 
|  | 6041 | } | 
|  | 6042 |  | 
|  | 6043 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6044 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability | 
|  | 6045 | * status updates, if not already enabled. | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6046 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6047 | public void enableIms(int slotId) { | 
| Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 6048 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6049 |  | 
|  | 6050 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6051 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6052 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6053 | // may happen if the device does not support IMS. | 
|  | 6054 | return; | 
|  | 6055 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6056 | mImsResolver.enableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6057 | } finally { | 
|  | 6058 | Binder.restoreCallingIdentity(identity); | 
|  | 6059 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6060 | } | 
|  | 6061 |  | 
|  | 6062 | /** | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6063 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature | 
|  | 6064 | * status updates to disabled. | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6065 | */ | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6066 | public void disableIms(int slotId) { | 
|  | 6067 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 |  | 
|  | 6069 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6070 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6071 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6072 | // may happen if the device does not support IMS. | 
|  | 6073 | return; | 
|  | 6074 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6075 | mImsResolver.disableIms(slotId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | } finally { | 
|  | 6077 | Binder.restoreCallingIdentity(identity); | 
|  | 6078 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6079 | } | 
|  | 6080 |  | 
|  | 6081 | /** | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6082 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback | 
|  | 6083 | * callback. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6084 | */ | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6085 | @Override | 
| Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6086 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6087 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 |  | 
|  | 6089 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6090 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6091 | if (mImsResolver == null) { | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6092 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 6093 | "Device does not support IMS"); | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6094 | } | 
| Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 6095 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | } finally { | 
|  | 6097 | Binder.restoreCallingIdentity(identity); | 
|  | 6098 | } | 
| Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 6099 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6100 | /** | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6101 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. | 
|  | 6102 | */ | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6103 | @Override | 
|  | 6104 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6105 | enforceModifyPermission(); | 
|  | 6106 |  | 
|  | 6107 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6108 | try { | 
|  | 6109 | if (mImsResolver == null) return; | 
| Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 6110 | mImsResolver.unregisterImsFeatureCallback(callback); | 
| Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 6111 | } finally { | 
|  | 6112 | Binder.restoreCallingIdentity(identity); | 
|  | 6113 | } | 
|  | 6114 | } | 
|  | 6115 |  | 
|  | 6116 | /** | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6117 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6118 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6119 | */ | 
|  | 6120 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { | 
|  | 6121 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 |  | 
|  | 6123 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6124 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6125 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6126 | // may happen if the device does not support IMS. | 
|  | 6127 | return null; | 
|  | 6128 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6129 | return mImsResolver.getImsRegistration(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6130 | } finally { | 
|  | 6131 | Binder.restoreCallingIdentity(identity); | 
|  | 6132 | } | 
| Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 6133 | } | 
|  | 6134 |  | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6135 | /** | 
|  | 6136 | * Returns the {@link IImsConfig} structure associated with the slotId and feature | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6137 | * specified or null if IMS is not supported on the slot specified. | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6138 | */ | 
|  | 6139 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { | 
|  | 6140 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6141 |  | 
|  | 6142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6143 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6144 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6145 | // may happen if the device does not support IMS. | 
|  | 6146 | return null; | 
|  | 6147 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6148 | return mImsResolver.getImsConfig(slotId, feature); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6149 | } finally { | 
|  | 6150 | Binder.restoreCallingIdentity(identity); | 
|  | 6151 | } | 
| Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 6152 | } | 
|  | 6153 |  | 
| Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 6154 | /** | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6155 | * Sets the ImsService Package Name that Telephony will bind to. | 
|  | 6156 | * | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6157 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 6158 | * @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] | 6159 | *         ImsService is the device default ImsService. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6160 | * @param featureTypes An integer array of feature types associated with a packageName. | 
|  | 6161 | * @param packageName The name of the package that the current configuration will be replaced | 
|  | 6162 | *                    with. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6163 | * @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] | 6164 | */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6165 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, | 
|  | 6166 | int[] featureTypes, String packageName) { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6167 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6168 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
| Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6169 | SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6170 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6172 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6173 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6174 | // may happen if the device does not support IMS. | 
|  | 6175 | return false; | 
|  | 6176 | } | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6177 | Map<Integer, String> featureConfig = new HashMap<>(); | 
|  | 6178 | for (int featureType : featureTypes) { | 
|  | 6179 | featureConfig.put(featureType, packageName); | 
|  | 6180 | } | 
|  | 6181 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, | 
|  | 6182 | featureConfig); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | } finally { | 
|  | 6184 | Binder.restoreCallingIdentity(identity); | 
|  | 6185 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6186 | } | 
|  | 6187 |  | 
|  | 6188 | /** | 
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6189 | * Clears any carrier ImsService overrides for the slot index specified that were previously | 
|  | 6190 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. | 
|  | 6191 | * | 
|  | 6192 | * This should only be used for testing. | 
|  | 6193 | * | 
|  | 6194 | * @param slotIndex the slot ID that the ImsService should bind for. | 
|  | 6195 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. | 
|  | 6196 | */ | 
|  | 6197 | @Override | 
|  | 6198 | public boolean clearCarrierImsServiceOverride(int slotIndex) { | 
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6199 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 6200 | "clearCarrierImsServiceOverride"); | 
|  | 6201 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
| Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6202 | SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride"); | 
| Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6203 |  | 
|  | 6204 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6205 | try { | 
|  | 6206 | if (mImsResolver == null) { | 
|  | 6207 | // may happen if the device does not support IMS. | 
|  | 6208 | return false; | 
|  | 6209 | } | 
|  | 6210 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); | 
|  | 6211 | } finally { | 
|  | 6212 | Binder.restoreCallingIdentity(identity); | 
|  | 6213 | } | 
|  | 6214 | } | 
|  | 6215 |  | 
|  | 6216 | /** | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6217 | * Return the package name of the currently bound ImsService. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6218 | * | 
|  | 6219 | * @param slotId The slot that the ImsService is associated with. | 
|  | 6220 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is | 
|  | 6221 | *         the device default. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6222 | * @param featureType The feature associated with the queried configuration. | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6223 | * @return the package name of the ImsService configuration. | 
|  | 6224 | */ | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6225 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, | 
|  | 6226 | @ImsFeature.FeatureType int featureType) { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6227 | TelephonyPermissions | 
| Jack Yu | 00ece8c | 2022-11-19 22:29:12 -0800 | [diff] [blame] | 6228 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp, | 
|  | 6229 | SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage"); | 
| Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6230 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6231 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6232 | try { | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6233 | if (mImsResolver == null) { | 
| Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6234 | // may happen if the device does not support IMS. | 
|  | 6235 | return ""; | 
|  | 6236 | } | 
| Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6237 | // TODO: change API to query RCS separately. | 
| Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6238 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, | 
|  | 6239 | featureType); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | } finally { | 
|  | 6241 | Binder.restoreCallingIdentity(identity); | 
|  | 6242 | } | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6243 | } | 
|  | 6244 |  | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6245 | /** | 
|  | 6246 | * Get the MmTelFeature state associated with the requested subscription id. | 
|  | 6247 | * @param subId The subscription that the MmTelFeature is associated with. | 
|  | 6248 | * @param callback A callback with an integer containing the | 
|  | 6249 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. | 
|  | 6250 | */ | 
|  | 6251 | @Override | 
|  | 6252 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { | 
|  | 6253 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6254 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 6255 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 6256 | "IMS not available on device."); | 
|  | 6257 | } | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6258 | final long token = Binder.clearCallingIdentity(); | 
|  | 6259 | try { | 
| Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6260 | int slotId = getSlotIndex(subId); | 
|  | 6261 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 6262 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" | 
|  | 6263 | + subId + "'"); | 
|  | 6264 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 6265 | } | 
|  | 6266 | verifyImsMmTelConfiguredOrThrow(slotId); | 
|  | 6267 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { | 
|  | 6268 | try { | 
|  | 6269 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); | 
|  | 6270 | } catch (RemoteException e) { | 
|  | 6271 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " | 
|  | 6272 | + "Ignore"); | 
|  | 6273 | } | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6274 | }); | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6275 | } catch (ImsException e) { | 
|  | 6276 | throw new ServiceSpecificException(e.getCode()); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6277 | } finally { | 
|  | 6278 | Binder.restoreCallingIdentity(token); | 
|  | 6279 | } | 
|  | 6280 | } | 
|  | 6281 |  | 
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6282 | /** | 
|  | 6283 | * Sets the ims registration state on all valid {@link Phone}s. | 
|  | 6284 | */ | 
|  | 6285 | public void setImsRegistrationState(final boolean registered) { | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6286 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 |  | 
|  | 6288 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6289 | try { | 
| Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6290 | // NOTE: Before S, this method only set the default phone. | 
|  | 6291 | for (final Phone phone : PhoneFactory.getPhones()) { | 
|  | 6292 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { | 
|  | 6293 | phone.setImsRegistrationState(registered); | 
|  | 6294 | } | 
|  | 6295 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | } finally { | 
|  | 6297 | Binder.restoreCallingIdentity(identity); | 
|  | 6298 | } | 
| Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6299 | } | 
|  | 6300 |  | 
|  | 6301 | /** | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6302 | * Set the network selection mode to automatic. | 
|  | 6303 | * | 
|  | 6304 | */ | 
|  | 6305 | @Override | 
|  | 6306 | public void setNetworkSelectionModeAutomatic(int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6307 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6308 | mApp, subId, "setNetworkSelectionModeAutomatic"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 |  | 
|  | 6310 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6311 | try { | 
| shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6312 | if (!isActiveSubscription(subId)) { | 
|  | 6313 | return; | 
|  | 6314 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6315 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); | 
| Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6316 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, | 
|  | 6317 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | } finally { | 
|  | 6319 | Binder.restoreCallingIdentity(identity); | 
|  | 6320 | } | 
| Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6321 | } | 
|  | 6322 |  | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6323 | /** | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6324 | * Ask the radio to connect to the input network and change selection mode to manual. | 
|  | 6325 | * | 
|  | 6326 | * @param subId the id of the subscription. | 
|  | 6327 | * @param operatorInfo the operator information, included the PLMN, long name and short name of | 
|  | 6328 | * the operator to attach to. | 
|  | 6329 | * @param persistSelection whether the selection will persist until reboot. If true, only allows | 
|  | 6330 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume | 
|  | 6331 | * normal network selection next time. | 
|  | 6332 | * @return {@code true} on success; {@code true} on any failure. | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6333 | */ | 
|  | 6334 | @Override | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6335 | public boolean setNetworkSelectionModeManual( | 
|  | 6336 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6338 | mApp, subId, "setNetworkSelectionModeManual"); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6339 |  | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6340 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6341 | if (!isActiveSubscription(subId)) { | 
|  | 6342 | return false; | 
|  | 6343 | } | 
|  | 6344 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | try { | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6346 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6347 | persistSelection); | 
| Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6348 | if (DBG) { | 
|  | 6349 | log("setNetworkSelectionModeManual: subId: " + subId | 
|  | 6350 | + " operator: " + operatorInfo); | 
|  | 6351 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); | 
|  | 6353 | } finally { | 
|  | 6354 | Binder.restoreCallingIdentity(identity); | 
|  | 6355 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6356 | } | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6357 | /** | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6358 | * Get the manual network selection | 
|  | 6359 | * | 
|  | 6360 | * @param subId the id of the subscription. | 
|  | 6361 | * | 
|  | 6362 | * @return the previously saved user selected PLMN | 
|  | 6363 | */ | 
|  | 6364 | @Override | 
|  | 6365 | public String getManualNetworkSelectionPlmn(int subId) { | 
|  | 6366 | TelephonyPermissions | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6367 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 6368 | mApp, subId, "getManualNetworkSelectionPlmn"); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6369 |  | 
|  | 6370 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6371 | try { | 
|  | 6372 | if (!isActiveSubscription(subId)) { | 
| shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6373 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6374 | } | 
|  | 6375 |  | 
|  | 6376 | final Phone phone = getPhone(subId); | 
|  | 6377 | if (phone == null) { | 
| shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6378 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6379 | } | 
|  | 6380 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); | 
|  | 6381 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6382 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); | 
| shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6383 | } finally { | 
|  | 6384 | Binder.restoreCallingIdentity(identity); | 
|  | 6385 | } | 
|  | 6386 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6387 |  | 
|  | 6388 | /** | 
|  | 6389 | * Scans for available networks. | 
|  | 6390 | */ | 
|  | 6391 | @Override | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6392 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, | 
|  | 6393 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6395 | mApp, subId, "getCellNetworkScanResults"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6396 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
|  | 6397 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 6398 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 6399 | .setCallingPackage(callingPackage) | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6400 | .setCallingFeatureId(callingFeatureId) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6401 | .setCallingPid(Binder.getCallingPid()) | 
|  | 6402 | .setCallingUid(Binder.getCallingUid()) | 
|  | 6403 | .setMethod("getCellNetworkScanResults") | 
|  | 6404 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
| Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6405 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 6406 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6407 | .build()); | 
|  | 6408 | switch (locationResult) { | 
|  | 6409 | case DENIED_HARD: | 
|  | 6410 | throw new SecurityException("Not allowed to access scan results -- location"); | 
|  | 6411 | case DENIED_SOFT: | 
|  | 6412 | return null; | 
|  | 6413 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6415 | long identity = Binder.clearCallingIdentity(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6416 | try { | 
|  | 6417 | if (DBG) log("getCellNetworkScanResults: subId " + subId); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6418 | return (CellNetworkScanResult) sendRequest( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6419 | CMD_PERFORM_NETWORK_SCAN, null, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | } finally { | 
|  | 6421 | Binder.restoreCallingIdentity(identity); | 
|  | 6422 | } | 
| Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6423 | } | 
|  | 6424 |  | 
|  | 6425 | /** | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6426 | * Get the call forwarding info, given the call forwarding reason. | 
|  | 6427 | */ | 
|  | 6428 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6429 | public void getCallForwarding(int subId, int callForwardingReason, | 
|  | 6430 | ICallForwardingInfoCallback callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6431 | enforceReadPrivilegedPermission("getCallForwarding"); | 
|  | 6432 | long identity = Binder.clearCallingIdentity(); | 
|  | 6433 | try { | 
|  | 6434 | if (DBG) { | 
|  | 6435 | log("getCallForwarding: subId " + subId | 
|  | 6436 | + " callForwardingReason" + callForwardingReason); | 
|  | 6437 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6438 |  | 
|  | 6439 | Phone phone = getPhone(subId); | 
|  | 6440 | if (phone == null) { | 
|  | 6441 | try { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6442 | callback.onError( | 
|  | 6443 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6444 | } catch (RemoteException e) { | 
|  | 6445 | // ignore | 
|  | 6446 | } | 
|  | 6447 | return; | 
|  | 6448 | } | 
|  | 6449 |  | 
|  | 6450 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( | 
|  | 6451 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { | 
|  | 6452 | @Override | 
|  | 6453 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { | 
|  | 6454 | try { | 
|  | 6455 | callback.onCallForwardingInfoAvailable(info); | 
|  | 6456 | } catch (RemoteException e) { | 
|  | 6457 | // ignore | 
|  | 6458 | } | 
|  | 6459 | } | 
|  | 6460 |  | 
|  | 6461 | @Override | 
|  | 6462 | public void onError(int error) { | 
|  | 6463 | try { | 
|  | 6464 | callback.onError(error); | 
|  | 6465 | } catch (RemoteException e) { | 
|  | 6466 | // ignore | 
|  | 6467 | } | 
|  | 6468 | } | 
|  | 6469 | }); | 
|  | 6470 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6471 | } finally { | 
|  | 6472 | Binder.restoreCallingIdentity(identity); | 
|  | 6473 | } | 
|  | 6474 | } | 
|  | 6475 |  | 
|  | 6476 | /** | 
|  | 6477 | * Sets the voice call forwarding info including status (enable/disable), call forwarding | 
|  | 6478 | * reason, the number to forward, and the timeout before the forwarding is attempted. | 
|  | 6479 | */ | 
|  | 6480 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6481 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, | 
|  | 6482 | IIntegerConsumer callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6483 | enforceModifyPermission(); | 
|  | 6484 | long identity = Binder.clearCallingIdentity(); | 
|  | 6485 | try { | 
|  | 6486 | if (DBG) { | 
|  | 6487 | log("setCallForwarding: subId " + subId | 
|  | 6488 | + " callForwardingInfo" + callForwardingInfo); | 
|  | 6489 | } | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6490 |  | 
|  | 6491 | Phone phone = getPhone(subId); | 
|  | 6492 | if (phone == null) { | 
|  | 6493 | try { | 
| Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6494 | callback.accept( | 
|  | 6495 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6496 | } catch (RemoteException e) { | 
|  | 6497 | // ignore | 
|  | 6498 | } | 
|  | 6499 | return; | 
|  | 6500 | } | 
|  | 6501 |  | 
|  | 6502 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, | 
|  | 6503 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 6504 |  | 
|  | 6505 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6506 | } finally { | 
|  | 6507 | Binder.restoreCallingIdentity(identity); | 
|  | 6508 | } | 
|  | 6509 | } | 
|  | 6510 |  | 
|  | 6511 | /** | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6512 | * Get the call waiting status for a subId. | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6513 | */ | 
|  | 6514 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6515 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6516 | enforceReadPrivilegedPermission("getCallWaitingStatus"); | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6517 | long identity = Binder.clearCallingIdentity(); | 
|  | 6518 | try { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6519 | Phone phone = getPhone(subId); | 
|  | 6520 | if (phone == null) { | 
|  | 6521 | try { | 
|  | 6522 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 6523 | } catch (RemoteException e) { | 
|  | 6524 | // ignore | 
|  | 6525 | } | 
|  | 6526 | return; | 
|  | 6527 | } | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6528 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); | 
|  | 6529 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 6530 | boolean requireUssd = c.getBoolean( | 
|  | 6531 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6532 |  | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6533 | if (DBG) log("getCallWaitingStatus: subId " + subId); | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6534 | if (requireUssd) { | 
|  | 6535 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), | 
|  | 6536 | getSubscriptionCarrierId(subId)); | 
|  | 6537 | String newUssdCommand = ""; | 
|  | 6538 | try { | 
|  | 6539 | newUssdCommand = carrierXmlParser.getFeature( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6540 | CarrierXmlParser.FEATURE_CALL_WAITING) | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6541 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); | 
|  | 6542 | } catch (NullPointerException e) { | 
|  | 6543 | loge("Failed to generate USSD number" + e); | 
|  | 6544 | } | 
|  | 6545 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( | 
|  | 6546 | mMainThreadHandler, callback, carrierXmlParser, | 
|  | 6547 | CarrierXmlParser.SsEntry.SSAction.QUERY); | 
|  | 6548 | final String ussdCommand = newUssdCommand; | 
|  | 6549 | Executors.newSingleThreadExecutor().execute(() -> { | 
|  | 6550 | handleUssdRequest(subId, ussdCommand, wrappedCallback); | 
|  | 6551 | }); | 
|  | 6552 | } else { | 
|  | 6553 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( | 
|  | 6554 | callback::accept); | 
|  | 6555 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); | 
|  | 6556 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6557 | } finally { | 
|  | 6558 | Binder.restoreCallingIdentity(identity); | 
|  | 6559 | } | 
|  | 6560 | } | 
|  | 6561 |  | 
|  | 6562 | /** | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6563 | * Sets whether call waiting is enabled for a given subId. | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6564 | */ | 
|  | 6565 | @Override | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6566 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6567 | enforceModifyPermission(); | 
|  | 6568 | long identity = Binder.clearCallingIdentity(); | 
|  | 6569 | try { | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6570 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); | 
|  | 6571 |  | 
|  | 6572 | Phone phone = getPhone(subId); | 
|  | 6573 | if (phone == null) { | 
|  | 6574 | try { | 
|  | 6575 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); | 
|  | 6576 | } catch (RemoteException e) { | 
|  | 6577 | // ignore | 
|  | 6578 | } | 
|  | 6579 | return; | 
|  | 6580 | } | 
|  | 6581 |  | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6582 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); | 
|  | 6583 | PersistableBundle c = configManager.getConfigForSubId(subId); | 
|  | 6584 | boolean requireUssd = c.getBoolean( | 
|  | 6585 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); | 
| Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6586 |  | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6587 | if (DBG) log("getCallWaitingStatus: subId " + subId); | 
|  | 6588 | if (requireUssd) { | 
|  | 6589 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), | 
|  | 6590 | getSubscriptionCarrierId(subId)); | 
|  | 6591 | CarrierXmlParser.SsEntry.SSAction ssAction = | 
|  | 6592 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE | 
|  | 6593 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; | 
|  | 6594 | String newUssdCommand = ""; | 
|  | 6595 | try { | 
|  | 6596 | newUssdCommand = carrierXmlParser.getFeature( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6597 | CarrierXmlParser.FEATURE_CALL_WAITING) | 
| SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6598 | .makeCommand(ssAction, null); | 
|  | 6599 | } catch (NullPointerException e) { | 
|  | 6600 | loge("Failed to generate USSD number" + e); | 
|  | 6601 | } | 
|  | 6602 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( | 
|  | 6603 | mMainThreadHandler, callback, carrierXmlParser, ssAction); | 
|  | 6604 | final String ussdCommand = newUssdCommand; | 
|  | 6605 | Executors.newSingleThreadExecutor().execute(() -> { | 
|  | 6606 | handleUssdRequest(subId, ussdCommand, wrappedCallback); | 
|  | 6607 | }); | 
|  | 6608 | } else { | 
|  | 6609 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, | 
|  | 6610 | FunctionalUtils.ignoreRemoteException(callback::accept)); | 
|  | 6611 |  | 
|  | 6612 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); | 
|  | 6613 | } | 
| Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6614 | } finally { | 
|  | 6615 | Binder.restoreCallingIdentity(identity); | 
|  | 6616 | } | 
|  | 6617 | } | 
|  | 6618 |  | 
|  | 6619 | /** | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6620 | * Starts a new network scan and returns the id of this scan. | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6621 | * | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6622 | * @param subId id of the subscription | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6623 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive | 
|  | 6624 | * location related information which will be sent if the caller already possess | 
|  | 6625 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6626 | * @param request contains the radio access networks with bands/channels to scan | 
|  | 6627 | * @param messenger callback messenger for scan results or errors | 
|  | 6628 | * @param binder for the purpose of auto clean when the user thread crashes | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6629 | * @return the id of the requested scan which can be used to stop the scan. | 
|  | 6630 | */ | 
|  | 6631 | @Override | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6632 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, | 
|  | 6633 | NetworkScanRequest request, Messenger messenger, | 
| Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6634 | IBinder binder, String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6635 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6636 | mApp, subId, "requestNetworkScan"); | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6637 | LocationAccessPolicy.LocationPermissionResult locationResult = | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6638 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; | 
|  | 6639 | if (!renounceFineLocationAccess) { | 
|  | 6640 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6641 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 6642 | .setCallingPackage(callingPackage) | 
|  | 6643 | .setCallingFeatureId(callingFeatureId) | 
|  | 6644 | .setCallingPid(Binder.getCallingPid()) | 
|  | 6645 | .setCallingUid(Binder.getCallingUid()) | 
|  | 6646 | .setMethod("requestNetworkScan") | 
|  | 6647 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 6648 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 6649 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
|  | 6650 | .build()); | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6651 | } | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6652 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { | 
| Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6653 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( | 
|  | 6654 | request, subId, callingPackage); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6655 | if (e != null) { | 
|  | 6656 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { | 
|  | 6657 | throw e; | 
|  | 6658 | } else { | 
| Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6659 | loge(e.getMessage()); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6660 | return TelephonyScanManager.INVALID_SCAN_ID; | 
|  | 6661 | } | 
|  | 6662 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | } | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6664 | int callingUid = Binder.getCallingUid(); | 
|  | 6665 | int callingPid = Binder.getCallingPid(); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6666 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6667 | try { | 
|  | 6668 | return mNetworkScanRequestTracker.startNetworkScan( | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 6669 | renounceFineLocationAccess, request, messenger, binder, | 
|  | 6670 | getPhoneFromSubIdOrDefault(subId), | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6671 | callingUid, callingPid, callingPackage); | 
| Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6672 | } finally { | 
|  | 6673 | Binder.restoreCallingIdentity(identity); | 
|  | 6674 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6675 | } | 
|  | 6676 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6677 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( | 
| Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6678 | NetworkScanRequest request, int subId, String callingPackage) { | 
| Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6679 | boolean hasCarrierPriv; | 
|  | 6680 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6681 | try { | 
|  | 6682 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) | 
|  | 6683 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
|  | 6684 | } finally { | 
|  | 6685 | Binder.restoreCallingIdentity(identity); | 
|  | 6686 | } | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6687 | boolean hasNetworkScanPermission = | 
|  | 6688 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 6689 | == PERMISSION_GRANTED; | 
| Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6690 |  | 
|  | 6691 | if (!hasCarrierPriv && !hasNetworkScanPermission) { | 
|  | 6692 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" | 
|  | 6693 | + " for network scans without location access."); | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6694 | } | 
|  | 6695 |  | 
|  | 6696 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { | 
|  | 6697 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6698 | if (ras.getChannels() != null && ras.getChannels().length > 0) { | 
|  | 6699 | return new SecurityException("Specific channels must not be" | 
|  | 6700 | + " scanned without location access."); | 
|  | 6701 | } | 
|  | 6702 | } | 
|  | 6703 | } | 
|  | 6704 |  | 
| Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6705 | return null; | 
|  | 6706 | } | 
|  | 6707 |  | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6708 | /** | 
|  | 6709 | * Stops an existing network scan with the given scanId. | 
| yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6710 | * | 
|  | 6711 | * @param subId id of the subscription | 
|  | 6712 | * @param scanId id of the scan that needs to be stopped | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6713 | */ | 
|  | 6714 | @Override | 
|  | 6715 | public void stopNetworkScan(int subId, int scanId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6717 | mApp, subId, "stopNetworkScan"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 |  | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6719 | int callingUid = Binder.getCallingUid(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6721 | try { | 
| Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6722 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | } finally { | 
|  | 6724 | Binder.restoreCallingIdentity(identity); | 
|  | 6725 | } | 
| yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6726 | } | 
|  | 6727 |  | 
|  | 6728 | /** | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6729 | * Get the allowed network types bitmask. | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6730 | * | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6731 | * @return the allowed network types bitmask, defined in RILConstants.java. | 
| Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6732 | */ | 
|  | 6733 | @Override | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6734 | public int getAllowedNetworkTypesBitmask(int subId) { | 
| Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6735 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6736 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6737 | mApp, subId, "getAllowedNetworkTypesBitmask"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6738 |  | 
|  | 6739 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6740 | try { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6741 | if (DBG) log("getAllowedNetworkTypesBitmask"); | 
|  | 6742 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); | 
|  | 6743 | int networkTypesBitmask = (result != null ? result[0] : -1); | 
|  | 6744 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); | 
|  | 6745 | return networkTypesBitmask; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6746 | } finally { | 
|  | 6747 | Binder.restoreCallingIdentity(identity); | 
|  | 6748 | } | 
| Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6749 | } | 
|  | 6750 |  | 
|  | 6751 | /** | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6752 | * Get the allowed network types for certain reason. | 
|  | 6753 | * | 
|  | 6754 | * @param subId the id of the subscription. | 
|  | 6755 | * @param reason the reason the allowed network type change is taking place | 
|  | 6756 | * @return the allowed network types. | 
|  | 6757 | */ | 
|  | 6758 | @Override | 
|  | 6759 | public long getAllowedNetworkTypesForReason(int subId, | 
|  | 6760 | @TelephonyManager.AllowedNetworkTypesReason int reason) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6761 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6762 | mApp, subId, "getAllowedNetworkTypesForReason"); | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6763 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6764 | try { | 
| Jack Yu | 7247ac8 | 2023-03-02 23:52:10 -0800 | [diff] [blame] | 6765 | return getPhoneFromSubIdOrDefault(subId).getAllowedNetworkTypes(reason); | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6766 | } finally { | 
|  | 6767 | Binder.restoreCallingIdentity(identity); | 
|  | 6768 | } | 
|  | 6769 | } | 
|  | 6770 |  | 
|  | 6771 | /** | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6772 | * Enable/Disable E-UTRA-NR Dual Connectivity | 
|  | 6773 | * @param subId subscription id of the sim card | 
|  | 6774 | * @param nrDualConnectivityState expected NR dual connectivity state | 
|  | 6775 | * This can be passed following states | 
|  | 6776 | * <ol> | 
|  | 6777 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} | 
|  | 6778 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} | 
|  | 6779 | * <li>Disable NR dual connectivity and force secondary cell to be released | 
|  | 6780 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} | 
|  | 6781 | * </ol> | 
|  | 6782 | * @return operation result. | 
|  | 6783 | */ | 
|  | 6784 | @Override | 
|  | 6785 | public int setNrDualConnectivityState(int subId, | 
|  | 6786 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { | 
|  | 6787 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6788 | mApp, subId, "enableNRDualConnectivity"); | 
| Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6789 | if (!isRadioInterfaceCapabilitySupported( | 
| Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6790 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { | 
|  | 6791 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; | 
|  | 6792 | } | 
|  | 6793 |  | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6794 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6795 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6796 | try { | 
|  | 6797 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, | 
|  | 6798 | nrDualConnectivityState, subId, | 
|  | 6799 | workSource); | 
|  | 6800 | if (DBG) log("enableNRDualConnectivity result: " + result); | 
|  | 6801 | return result; | 
|  | 6802 | } finally { | 
|  | 6803 | Binder.restoreCallingIdentity(identity); | 
|  | 6804 | } | 
|  | 6805 | } | 
|  | 6806 |  | 
|  | 6807 | /** | 
|  | 6808 | * Is E-UTRA-NR Dual Connectivity enabled | 
|  | 6809 | * @return true if dual connectivity is enabled else false | 
|  | 6810 | */ | 
|  | 6811 | @Override | 
|  | 6812 | public boolean isNrDualConnectivityEnabled(int subId) { | 
|  | 6813 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6814 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6815 | mApp, subId, "isNRDualConnectivityEnabled"); | 
| Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6816 | if (!isRadioInterfaceCapabilitySupported( | 
| Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6817 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { | 
|  | 6818 | return false; | 
|  | 6819 | } | 
| Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6820 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 6821 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6822 | try { | 
|  | 6823 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, | 
|  | 6824 | null, subId, workSource); | 
|  | 6825 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); | 
|  | 6826 | return isEnabled; | 
|  | 6827 | } finally { | 
|  | 6828 | Binder.restoreCallingIdentity(identity); | 
|  | 6829 | } | 
|  | 6830 | } | 
|  | 6831 |  | 
|  | 6832 | /** | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6833 | * Set the allowed network types of the device and | 
|  | 6834 | * provide the reason triggering the allowed network change. | 
|  | 6835 | * | 
|  | 6836 | * @param subId the id of the subscription. | 
|  | 6837 | * @param reason the reason the allowed network type change is taking place | 
|  | 6838 | * @param allowedNetworkTypes the allowed network types. | 
|  | 6839 | * @return true on success; false on any failure. | 
|  | 6840 | */ | 
|  | 6841 | @Override | 
|  | 6842 | public boolean setAllowedNetworkTypesForReason(int subId, | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6843 | @TelephonyManager.AllowedNetworkTypesReason int reason, | 
|  | 6844 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 6846 | mApp, subId, "setAllowedNetworkTypesForReason"); | 
| Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6847 | // If the caller only has carrier privileges, then they should not be able to override | 
|  | 6848 | // any network types which were set for security reasons. | 
|  | 6849 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 6850 | != PERMISSION_GRANTED | 
| Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6851 | && reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G) { | 
| Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6852 | throw new SecurityException( | 
|  | 6853 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" | 
| Gil Cukierman | 2a8f48b | 2023-01-26 20:26:20 +0000 | [diff] [blame] | 6854 | + " reason " + reason); | 
| Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame] | 6855 | } | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6856 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { | 
| Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6857 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); | 
| SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6858 | return false; | 
|  | 6859 | } | 
|  | 6860 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { | 
|  | 6861 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6862 | return false; | 
|  | 6863 | } | 
|  | 6864 |  | 
| Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6865 | log("setAllowedNetworkTypesForReason: subId=" + subId + ", reason=" + reason + " value: " | 
|  | 6866 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6867 |  | 
| Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6868 | Phone phone = getPhone(subId); | 
|  | 6869 | if (phone == null) { | 
|  | 6870 | return false; | 
|  | 6871 | } | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6872 |  | 
| Jack Yu | e37dd26 | 2022-12-16 11:53:37 -0800 | [diff] [blame] | 6873 | if (allowedNetworkTypes == phone.getAllowedNetworkTypes(reason)) { | 
| Jack Yu | 5b49433 | 2023-01-23 18:18:04 +0000 | [diff] [blame] | 6874 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6875 | return true; | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6876 | } | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6877 |  | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6878 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6879 | try { | 
| SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6880 | Boolean success = (Boolean) sendRequest( | 
|  | 6881 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, | 
|  | 6882 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); | 
|  | 6883 |  | 
|  | 6884 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); | 
|  | 6885 | return success; | 
| Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6886 | } finally { | 
|  | 6887 | Binder.restoreCallingIdentity(identity); | 
|  | 6888 | } | 
|  | 6889 | } | 
|  | 6890 |  | 
|  | 6891 | /** | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6892 | * Check whether DUN APN is required for tethering with subId. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6893 | * | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6894 | * @param subId the id of the subscription to require tethering. | 
| Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6895 | * @return {@code true} if DUN APN is required for tethering. | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6896 | * @hide | 
|  | 6897 | */ | 
|  | 6898 | @Override | 
| SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6899 | public boolean isTetheringApnRequiredForSubscriber(int subId) { | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6900 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6901 | final long identity = Binder.clearCallingIdentity(); | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6902 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | try { | 
| Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6904 | if (phone != null) { | 
|  | 6905 | return phone.hasMatchedTetherApnSetting(); | 
|  | 6906 | } else { | 
|  | 6907 | return false; | 
|  | 6908 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6909 | } finally { | 
|  | 6910 | Binder.restoreCallingIdentity(identity); | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6911 | } | 
| Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6912 | } | 
|  | 6913 |  | 
|  | 6914 | /** | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6915 | * Get the user enabled state of Mobile Data. | 
|  | 6916 | * | 
|  | 6917 | * TODO: remove and use isUserDataEnabled. | 
|  | 6918 | * This can't be removed now because some vendor codes | 
|  | 6919 | * calls through ITelephony directly while they should | 
|  | 6920 | * use TelephonyManager. | 
|  | 6921 | * | 
|  | 6922 | * @return true on enabled | 
|  | 6923 | */ | 
|  | 6924 | @Override | 
|  | 6925 | public boolean getDataEnabled(int subId) { | 
|  | 6926 | return isUserDataEnabled(subId); | 
|  | 6927 | } | 
|  | 6928 |  | 
|  | 6929 | /** | 
|  | 6930 | * Get whether mobile data is enabled per user setting. | 
|  | 6931 | * | 
|  | 6932 | * There are other factors deciding whether mobile data is actually enabled, but they are | 
|  | 6933 | * not considered here. See {@link #isDataEnabled(int)} for more details. | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6934 | * | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6935 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE | 
|  | 6936 | * or carrier privileges. | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6937 | * | 
|  | 6938 | * @return {@code true} if data is enabled else {@code false} | 
|  | 6939 | */ | 
|  | 6940 | @Override | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6941 | public boolean isUserDataEnabled(int subId) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6942 | String functionName = "isUserDataEnabled"; | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6943 | try { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6944 | try { | 
|  | 6945 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, | 
|  | 6946 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6947 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6948 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); | 
|  | 6949 | } | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6950 | } catch (SecurityException e) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6951 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6952 | mApp, subId, functionName); | 
|  | 6953 |  | 
| Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6954 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6955 |  | 
|  | 6956 | final long identity = Binder.clearCallingIdentity(); | 
|  | 6957 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 6958 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6959 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); | 
|  | 6960 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 6961 | if (phone != null) { | 
|  | 6962 | boolean retVal = phone.isUserDataEnabled(); | 
|  | 6963 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); | 
|  | 6964 | return retVal; | 
|  | 6965 | } else { | 
|  | 6966 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 6967 | return false; | 
|  | 6968 | } | 
|  | 6969 | } finally { | 
|  | 6970 | Binder.restoreCallingIdentity(identity); | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6971 | } | 
|  | 6972 | } | 
|  | 6973 |  | 
|  | 6974 | /** | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6975 | * Checks if the device is capable of mobile data by considering whether whether the | 
|  | 6976 | * user has enabled mobile data, whether the carrier has enabled mobile data, and | 
|  | 6977 | * whether the network policy allows data connections. | 
| Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6978 | * | 
| Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6979 | * @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] | 6980 | */ | 
|  | 6981 | @Override | 
|  | 6982 | public boolean isDataEnabled(int subId) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6983 | String functionName = "isDataEnabled"; | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6984 | try { | 
|  | 6985 | try { | 
|  | 6986 | mApp.enforceCallingOrSelfPermission( | 
|  | 6987 | android.Manifest.permission.ACCESS_NETWORK_STATE, | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6988 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6989 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6990 | try { | 
|  | 6991 | mApp.enforceCallingOrSelfPermission( | 
|  | 6992 | android.Manifest.permission.READ_PHONE_STATE, | 
|  | 6993 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6994 | } catch (SecurityException e2) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6995 | mApp.enforceCallingOrSelfPermission( | 
|  | 6996 | permission.READ_BASIC_PHONE_STATE, functionName); | 
|  | 6997 | } | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6998 | } | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6999 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7000 | enforceReadPrivilegedPermission(functionName); | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7001 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 |  | 
|  | 7003 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7004 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7005 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7006 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 7007 | if (phone != null) { | 
| Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 7008 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); | 
| Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 7009 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7010 | return retVal; | 
|  | 7011 | } else { | 
|  | 7012 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); | 
|  | 7013 | return false; | 
|  | 7014 | } | 
|  | 7015 | } finally { | 
|  | 7016 | Binder.restoreCallingIdentity(identity); | 
| Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 7017 | } | 
| Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 7018 | } | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7019 |  | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7020 | /** | 
|  | 7021 | * Check if data is enabled for a specific reason | 
|  | 7022 | * @param subId Subscription index | 
|  | 7023 | * @param reason the reason the data enable change is taking place | 
|  | 7024 | * @return {@code true} if the overall data is enabled; {@code false} if not. | 
|  | 7025 | */ | 
|  | 7026 | @Override | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7027 | public boolean isDataEnabledForReason(int subId, | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7028 | @TelephonyManager.DataEnabledReason int reason) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7029 | String functionName = "isDataEnabledForReason"; | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7030 | try { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7031 | try { | 
|  | 7032 | mApp.enforceCallingOrSelfPermission( | 
|  | 7033 | android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 7034 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7035 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7036 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, | 
|  | 7037 | functionName); | 
|  | 7038 | } | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7039 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7040 | try { | 
|  | 7041 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7042 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 7043 | } catch (SecurityException e2) { | 
| Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 7045 | mApp, subId, functionName); | 
| Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 7046 | } | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7047 | } | 
|  | 7048 |  | 
|  | 7049 |  | 
|  | 7050 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7051 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7052 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7053 | if (DBG) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7054 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7055 | + " reason=" + reason); | 
|  | 7056 | } | 
|  | 7057 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 7058 | if (phone != null) { | 
|  | 7059 | boolean retVal; | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 7060 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7061 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7062 | return retVal; | 
|  | 7063 | } else { | 
|  | 7064 | if (DBG) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7065 | loge("isDataEnabledForReason: no phone subId=" | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7066 | + subId + " retVal=false"); | 
|  | 7067 | } | 
|  | 7068 | return false; | 
|  | 7069 | } | 
|  | 7070 | } finally { | 
|  | 7071 | Binder.restoreCallingIdentity(identity); | 
|  | 7072 | } | 
|  | 7073 | } | 
|  | 7074 |  | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7075 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7076 | public int getCarrierPrivilegeStatus(int subId) { | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7077 | // No permission needed; this only lets the caller inspect their own status. | 
|  | 7078 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); | 
| Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 7079 | } | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7080 |  | 
|  | 7081 | @Override | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7082 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7083 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7084 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); | 
|  | 7085 | } | 
|  | 7086 |  | 
|  | 7087 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { | 
|  | 7088 | Phone phone = getPhone(subId); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7089 | if (phone == null) { | 
| Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 7090 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7091 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 7092 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7093 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7094 | if (cpt == null) { | 
|  | 7095 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7096 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 7097 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7098 | return cpt.getCarrierPrivilegeStatusForUid(uid); | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7099 | } | 
|  | 7100 |  | 
|  | 7101 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7102 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { | 
| Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7103 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7104 | if (TextUtils.isEmpty(pkgName)) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7105 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7106 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7107 | Phone phone = getPhone(subId); | 
|  | 7108 | if (phone == null) { | 
|  | 7109 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); | 
|  | 7110 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
|  | 7111 | } | 
|  | 7112 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7113 | if (cpt == null) { | 
|  | 7114 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); | 
| Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 7115 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
|  | 7116 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7117 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7118 | } | 
|  | 7119 |  | 
|  | 7120 | @Override | 
|  | 7121 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7122 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); | 
| Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 7123 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); | 
|  | 7124 | } | 
|  | 7125 |  | 
|  | 7126 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7127 | if (TextUtils.isEmpty(pkgName)) { | 
| Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 7128 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7129 | } | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7130 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7131 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { | 
|  | 7132 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 7133 | if (phone == null) { | 
|  | 7134 | continue; | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7135 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7136 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7137 | if (cpt == null) { | 
|  | 7138 | continue; | 
|  | 7139 | } | 
|  | 7140 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7141 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
|  | 7142 | break; | 
|  | 7143 | } | 
|  | 7144 | } | 
| Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 7145 | return result; | 
| Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 7146 | } | 
| Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 7147 |  | 
|  | 7148 | @Override | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7149 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { | 
| Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7150 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); | 
| Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7151 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 7152 | if (phone == null) { | 
|  | 7153 | return Collections.emptyList(); | 
| Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 7154 | } | 
| Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7155 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7156 | if (cpt == null) { | 
|  | 7157 | return Collections.emptyList(); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7158 | } | 
| Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 7159 | return cpt.getCarrierPackageNamesForIntent(intent); | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7160 | } | 
|  | 7161 |  | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7162 | @Override | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7163 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { | 
| Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 7164 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7165 | Phone phone = PhoneFactory.getPhone(phoneId); | 
|  | 7166 | if (phone == null) { | 
|  | 7167 | return Collections.emptyList(); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7168 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7169 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7170 | if (cpt == null) { | 
|  | 7171 | return Collections.emptyList(); | 
|  | 7172 | } | 
|  | 7173 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); | 
| Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 7174 | } | 
|  | 7175 |  | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7176 | @Override | 
|  | 7177 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7178 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7179 | Set<String> privilegedPackages = new ArraySet<>(); | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7180 | final long identity = Binder.clearCallingIdentity(); | 
| Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 7181 | try { | 
|  | 7182 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { | 
|  | 7183 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); | 
|  | 7184 | } | 
|  | 7185 | } finally { | 
|  | 7186 | Binder.restoreCallingIdentity(identity); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7187 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 7188 | return new ArrayList<>(privilegedPackages); | 
| chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 7189 | } | 
|  | 7190 |  | 
| Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 7191 | @Override | 
|  | 7192 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { | 
|  | 7193 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); | 
|  | 7194 |  | 
|  | 7195 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); | 
|  | 7196 | if (phone == null) { | 
|  | 7197 | return null; | 
|  | 7198 | } | 
|  | 7199 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 7200 | if (cpt == null) { | 
|  | 7201 | return null; | 
|  | 7202 | } | 
|  | 7203 | return cpt.getCarrierServicePackageName(); | 
|  | 7204 | } | 
|  | 7205 |  | 
| Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7206 | private String getIccId(int subId) { | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7207 | final Phone phone = getPhone(subId); | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7208 | UiccPort port = phone == null ? null : phone.getUiccPort(); | 
|  | 7209 | if (port == null) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7210 | return null; | 
|  | 7211 | } | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7212 | String iccId = port.getIccId(); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7213 | if (TextUtils.isEmpty(iccId)) { | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7214 | return null; | 
|  | 7215 | } | 
|  | 7216 | return iccId; | 
|  | 7217 | } | 
|  | 7218 |  | 
| Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7219 | @Override | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7220 | public void setCallComposerStatus(int subId, int status) { | 
|  | 7221 | enforceModifyPermission(); | 
|  | 7222 |  | 
|  | 7223 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7224 | try { | 
|  | 7225 | Phone phone = getPhone(subId); | 
|  | 7226 | if (phone != null) { | 
|  | 7227 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 7228 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 7229 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 7230 | imsPhone.setCallComposerStatus(status); | 
| Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7231 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) | 
|  | 7232 | .updateImsServiceConfig(); | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7233 | } | 
|  | 7234 | } | 
| Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7235 | } catch (ImsException e) { | 
|  | 7236 | throw new ServiceSpecificException(e.getCode()); | 
|  | 7237 | }  finally { | 
| Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7238 | Binder.restoreCallingIdentity(identity); | 
|  | 7239 | } | 
|  | 7240 | } | 
|  | 7241 |  | 
|  | 7242 | @Override | 
|  | 7243 | public int getCallComposerStatus(int subId) { | 
|  | 7244 | enforceReadPrivilegedPermission("getCallComposerStatus"); | 
|  | 7245 |  | 
|  | 7246 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7247 | try { | 
|  | 7248 | Phone phone = getPhone(subId); | 
|  | 7249 | if (phone != null) { | 
|  | 7250 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 7251 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 7252 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 7253 | return imsPhone.getCallComposerStatus(); | 
|  | 7254 | } | 
|  | 7255 | } | 
|  | 7256 | } finally { | 
|  | 7257 | Binder.restoreCallingIdentity(identity); | 
|  | 7258 | } | 
|  | 7259 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; | 
|  | 7260 | } | 
|  | 7261 |  | 
|  | 7262 | @Override | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7263 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, | 
|  | 7264 | String number) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7265 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7266 | subId, "setLine1NumberForDisplayForSubscriber"); | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7267 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7268 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7269 | try { | 
|  | 7270 | final String iccId = getIccId(subId); | 
|  | 7271 | final Phone phone = getPhone(subId); | 
|  | 7272 | if (phone == null) { | 
|  | 7273 | return false; | 
|  | 7274 | } | 
|  | 7275 | final String subscriberId = phone.getSubscriberId(); | 
|  | 7276 |  | 
|  | 7277 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7278 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | + subscriberId + " to " + number); | 
|  | 7280 | } | 
|  | 7281 |  | 
|  | 7282 | if (TextUtils.isEmpty(iccId)) { | 
|  | 7283 | return false; | 
|  | 7284 | } | 
|  | 7285 |  | 
|  | 7286 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 7287 |  | 
|  | 7288 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 7289 | if (alphaTag == null) { | 
|  | 7290 | editor.remove(alphaTagPrefKey); | 
|  | 7291 | } else { | 
|  | 7292 | editor.putString(alphaTagPrefKey, alphaTag); | 
|  | 7293 | } | 
|  | 7294 |  | 
|  | 7295 | // Record both the line number and IMSI for this ICCID, since we need to | 
|  | 7296 | // track all merged IMSIs based on line number | 
|  | 7297 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 7298 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 7299 | if (number == null) { | 
|  | 7300 | editor.remove(numberPrefKey); | 
|  | 7301 | editor.remove(subscriberPrefKey); | 
|  | 7302 | } else { | 
|  | 7303 | editor.putString(numberPrefKey, number); | 
|  | 7304 | editor.putString(subscriberPrefKey, subscriberId); | 
|  | 7305 | } | 
|  | 7306 |  | 
|  | 7307 | editor.commit(); | 
|  | 7308 | return true; | 
|  | 7309 | } finally { | 
|  | 7310 | Binder.restoreCallingIdentity(identity); | 
| Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7311 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7312 | } | 
|  | 7313 |  | 
|  | 7314 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7315 | public String getLine1NumberForDisplay(int subId, String callingPackage, | 
|  | 7316 | String callingFeatureId) { | 
| Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7317 | // This is open to apps with WRITE_SMS. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7318 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7319 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7320 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7321 | return null; | 
|  | 7322 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7323 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7324 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7325 | try { | 
|  | 7326 | String iccId = getIccId(subId); | 
|  | 7327 | if (iccId != null) { | 
|  | 7328 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 7329 | if (DBG_MERGE) { | 
|  | 7330 | log("getLine1NumberForDisplay returning " | 
|  | 7331 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); | 
|  | 7332 | } | 
|  | 7333 | return mTelephonySharedPreferences.getString(numberPrefKey, null); | 
| Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7334 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); | 
|  | 7336 | return null; | 
|  | 7337 | } finally { | 
|  | 7338 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7339 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7340 | } | 
|  | 7341 |  | 
|  | 7342 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7343 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, | 
|  | 7344 | String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7346 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7347 | return null; | 
|  | 7348 | } | 
| Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7349 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7351 | try { | 
|  | 7352 | String iccId = getIccId(subId); | 
|  | 7353 | if (iccId != null) { | 
|  | 7354 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; | 
|  | 7355 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); | 
|  | 7356 | } | 
|  | 7357 | return null; | 
|  | 7358 | } finally { | 
|  | 7359 | Binder.restoreCallingIdentity(identity); | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7360 | } | 
| Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7361 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7362 |  | 
|  | 7363 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7364 | public String[] getMergedSubscriberIds(int subId, String callingPackage, | 
|  | 7365 | String callingFeatureId) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7366 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried | 
|  | 7367 | // about carrier-privileged callers not having access. | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7368 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7369 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7370 | callingFeatureId, "getMergedSubscriberIds")) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7371 | return null; | 
|  | 7372 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7373 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7374 | // Clear calling identity, when calling TelephonyManager, because callerUid must be | 
|  | 7375 | // the process, where TelephonyManager was instantiated. | 
|  | 7376 | // Otherwise AppOps check will fail. | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7377 | final long identity  = Binder.clearCallingIdentity(); | 
|  | 7378 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7379 | final Context context = mApp; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7380 | final TelephonyManager tele = TelephonyManager.from(context); | 
|  | 7381 | final SubscriptionManager sub = SubscriptionManager.from(context); | 
|  | 7382 |  | 
|  | 7383 | // Figure out what subscribers are currently active | 
|  | 7384 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 |  | 
| Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7386 | // Only consider subs which match the current subId | 
|  | 7387 | // This logic can be simplified. See b/131189269 for progress. | 
|  | 7388 | if (isActiveSubscription(subId)) { | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7389 | activeSubscriberIds.add(tele.getSubscriberId(subId)); | 
|  | 7390 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 |  | 
|  | 7392 | // First pass, find a number override for an active subscriber | 
|  | 7393 | String mergeNumber = null; | 
|  | 7394 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); | 
|  | 7395 | for (String key : prefs.keySet()) { | 
|  | 7396 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { | 
|  | 7397 | final String subscriberId = (String) prefs.get(key); | 
|  | 7398 | if (activeSubscriberIds.contains(subscriberId)) { | 
|  | 7399 | final String iccId = key.substring( | 
|  | 7400 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); | 
|  | 7401 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; | 
|  | 7402 | mergeNumber = (String) prefs.get(numberKey); | 
|  | 7403 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7404 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | + " for active subscriber " + subscriberId); | 
|  | 7406 | } | 
|  | 7407 | if (!TextUtils.isEmpty(mergeNumber)) { | 
|  | 7408 | break; | 
|  | 7409 | } | 
|  | 7410 | } | 
|  | 7411 | } | 
|  | 7412 | } | 
|  | 7413 |  | 
|  | 7414 | // Shortcut when no active merged subscribers | 
|  | 7415 | if (TextUtils.isEmpty(mergeNumber)) { | 
|  | 7416 | return null; | 
|  | 7417 | } | 
|  | 7418 |  | 
|  | 7419 | // Second pass, find all subscribers under that line override | 
|  | 7420 | final ArraySet<String> result = new ArraySet<>(); | 
|  | 7421 | for (String key : prefs.keySet()) { | 
|  | 7422 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { | 
|  | 7423 | final String number = (String) prefs.get(key); | 
|  | 7424 | if (mergeNumber.equals(number)) { | 
|  | 7425 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); | 
|  | 7426 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; | 
|  | 7427 | final String subscriberId = (String) prefs.get(subscriberKey); | 
|  | 7428 | if (!TextUtils.isEmpty(subscriberId)) { | 
|  | 7429 | result.add(subscriberId); | 
|  | 7430 | } | 
|  | 7431 | } | 
|  | 7432 | } | 
|  | 7433 | } | 
|  | 7434 |  | 
|  | 7435 | final String[] resultArray = result.toArray(new String[result.size()]); | 
|  | 7436 | Arrays.sort(resultArray); | 
|  | 7437 | if (DBG_MERGE) { | 
| Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7438 | Rlog.d(LOG_TAG, | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); | 
|  | 7440 | } | 
|  | 7441 | return resultArray; | 
| Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7442 | } finally { | 
|  | 7443 | Binder.restoreCallingIdentity(identity); | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7444 | } | 
| Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7445 | } | 
|  | 7446 |  | 
|  | 7447 | @Override | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7448 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { | 
|  | 7449 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7450 |  | 
|  | 7451 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7452 | try { | 
|  | 7453 | final TelephonyManager telephonyManager = mApp.getSystemService( | 
|  | 7454 | TelephonyManager.class); | 
|  | 7455 | String subscriberId = telephonyManager.getSubscriberId(subId); | 
|  | 7456 | if (subscriberId == null) { | 
|  | 7457 | if (DBG) { | 
| zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7458 | log("getMergedImsisFromGroup can't find subscriberId for subId " | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7459 | + subId); | 
|  | 7460 | } | 
|  | 7461 | return null; | 
|  | 7462 | } | 
|  | 7463 |  | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7464 | ParcelUuid groupUuid; | 
|  | 7465 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7466 | final SubscriptionInfo info = getSubscriptionManagerService() | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7467 | .getSubscriptionInfo(subId); | 
|  | 7468 | groupUuid = info.getGroupUuid(); | 
|  | 7469 | } else { | 
|  | 7470 | final SubscriptionInfo info = mSubscriptionController | 
|  | 7471 | .getSubscriptionInfo(subId); | 
|  | 7472 | groupUuid = info.getGroupUuid(); | 
|  | 7473 | } | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7474 | // If it doesn't belong to any group, return just subscriberId of itself. | 
|  | 7475 | if (groupUuid == null) { | 
|  | 7476 | return new String[]{subscriberId}; | 
|  | 7477 | } | 
|  | 7478 |  | 
|  | 7479 | // Get all subscriberIds from the group. | 
|  | 7480 | final List<String> mergedSubscriberIds = new ArrayList<>(); | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7481 | List<SubscriptionInfo> groupInfos; | 
|  | 7482 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 7483 | groupInfos = getSubscriptionManagerService() | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 7484 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), | 
|  | 7485 | mApp.getAttributionTag()); | 
|  | 7486 | } else { | 
|  | 7487 | groupInfos = mSubscriptionController | 
|  | 7488 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), | 
|  | 7489 | mApp.getAttributionTag()); | 
|  | 7490 | } | 
| Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7491 | for (SubscriptionInfo subInfo : groupInfos) { | 
|  | 7492 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); | 
|  | 7493 | if (subscriberId != null) { | 
|  | 7494 | mergedSubscriberIds.add(subscriberId); | 
|  | 7495 | } | 
|  | 7496 | } | 
|  | 7497 |  | 
|  | 7498 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); | 
|  | 7499 | } finally { | 
|  | 7500 | Binder.restoreCallingIdentity(identity); | 
|  | 7501 |  | 
|  | 7502 | } | 
|  | 7503 | } | 
|  | 7504 |  | 
|  | 7505 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7506 | public boolean setOperatorBrandOverride(int subId, String brand) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7507 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7508 | subId, "setOperatorBrandOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7509 |  | 
|  | 7510 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7511 | try { | 
|  | 7512 | final Phone phone = getPhone(subId); | 
|  | 7513 | return phone == null ? false : phone.setOperatorBrandOverride(brand); | 
|  | 7514 | } finally { | 
|  | 7515 | Binder.restoreCallingIdentity(identity); | 
|  | 7516 | } | 
| Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7517 | } | 
| Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7518 |  | 
|  | 7519 | @Override | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7520 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7521 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, | 
|  | 7522 | List<String> cdmaNonRoamingList) { | 
| Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7523 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
|  | 7524 | mApp, subId, "setRoamingOverride"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 |  | 
|  | 7526 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7527 | try { | 
|  | 7528 | final Phone phone = getPhone(subId); | 
|  | 7529 | if (phone == null) { | 
|  | 7530 | return false; | 
|  | 7531 | } | 
|  | 7532 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, | 
|  | 7533 | cdmaNonRoamingList); | 
|  | 7534 | } finally { | 
|  | 7535 | Binder.restoreCallingIdentity(identity); | 
| Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7536 | } | 
| Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7537 | } | 
|  | 7538 |  | 
|  | 7539 | @Override | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7540 | @Deprecated | 
|  | 7541 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { | 
|  | 7542 | enforceModifyPermission(); | 
|  | 7543 |  | 
|  | 7544 | int returnValue = 0; | 
|  | 7545 | try { | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7546 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); | 
| Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7547 | if(result.exception == null) { | 
|  | 7548 | if (result.result != null) { | 
|  | 7549 | byte[] responseData = (byte[])(result.result); | 
|  | 7550 | if(responseData.length > oemResp.length) { | 
|  | 7551 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + | 
|  | 7552 | responseData.length +  "bytes. Buffer Size is " + | 
|  | 7553 | oemResp.length + "bytes."); | 
|  | 7554 | } | 
|  | 7555 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); | 
|  | 7556 | returnValue = responseData.length; | 
|  | 7557 | } | 
|  | 7558 | } else { | 
|  | 7559 | CommandException ex = (CommandException) result.exception; | 
|  | 7560 | returnValue = ex.getCommandError().ordinal(); | 
|  | 7561 | if(returnValue > 0) returnValue *= -1; | 
|  | 7562 | } | 
|  | 7563 | } catch (RuntimeException e) { | 
|  | 7564 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); | 
|  | 7565 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); | 
|  | 7566 | if(returnValue > 0) returnValue *= -1; | 
|  | 7567 | } | 
|  | 7568 |  | 
|  | 7569 | return returnValue; | 
|  | 7570 | } | 
|  | 7571 |  | 
|  | 7572 | @Override | 
| Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7573 | public int getRadioAccessFamily(int phoneId, String callingPackage) { | 
| Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7574 | int raf = RadioAccessFamily.RAF_UNKNOWN; | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7575 | Phone phone = PhoneFactory.getPhone(phoneId); | 
| Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7576 | if (phone == null) { | 
|  | 7577 | return raf; | 
|  | 7578 | } | 
|  | 7579 |  | 
| Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7580 | try { | 
|  | 7581 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7582 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7583 | mApp, phone.getSubId(), "getRadioAccessFamily"); | 
|  | 7584 | } catch (SecurityException e) { | 
|  | 7585 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); | 
|  | 7586 | throw e; | 
|  | 7587 | } | 
| Aishwarya Mallampati | 11e8287 | 2023-03-13 21:04:00 +0000 | [diff] [blame] | 7588 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7589 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7590 | try { | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7591 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7592 | } finally { | 
|  | 7593 | Binder.restoreCallingIdentity(identity); | 
|  | 7594 | } | 
| chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7595 | return raf; | 
| Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7596 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7597 |  | 
|  | 7598 | @Override | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7599 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, | 
| Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7600 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7601 | try { | 
|  | 7602 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), | 
|  | 7603 | Binder.getCallingUid())) { | 
| Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7604 | throw new SecurityException("Invalid package:" + callingPackage); | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7605 | } | 
|  | 7606 | } catch (PackageManager.NameNotFoundException e) { | 
| Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7607 | throw new SecurityException("Invalid package:" + callingPackage); | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7608 | } | 
|  | 7609 | RoleManager rm = mApp.getSystemService(RoleManager.class); | 
|  | 7610 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); | 
|  | 7611 | if (!dialerRoleHolders.contains(callingPackage)) { | 
|  | 7612 | throw new SecurityException("App must be the dialer role holder to" | 
|  | 7613 | + " upload a call composer pic"); | 
|  | 7614 | } | 
|  | 7615 |  | 
|  | 7616 | Executors.newSingleThreadExecutor().execute(() -> { | 
|  | 7617 | ByteArrayOutputStream output = new ByteArrayOutputStream( | 
|  | 7618 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); | 
|  | 7619 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); | 
|  | 7620 | boolean readUntilEnd = false; | 
|  | 7621 | int totalBytesRead = 0; | 
|  | 7622 | byte[] buffer = new byte[16 * 1024]; | 
|  | 7623 | while (true) { | 
|  | 7624 | int numRead; | 
|  | 7625 | try { | 
|  | 7626 | numRead = input.read(buffer); | 
|  | 7627 | } catch (IOException e) { | 
|  | 7628 | try { | 
|  | 7629 | fd.checkError(); | 
|  | 7630 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, | 
|  | 7631 | null); | 
|  | 7632 | } catch (IOException e1) { | 
|  | 7633 | // This means that the other side closed explicitly with an error. If this | 
|  | 7634 | // happens, log and ignore. | 
|  | 7635 | loge("Remote end of call composer picture pipe closed: " + e1); | 
|  | 7636 | } | 
|  | 7637 | break; | 
|  | 7638 | } | 
|  | 7639 | if (numRead == -1) { | 
|  | 7640 | readUntilEnd = true; | 
|  | 7641 | break; | 
|  | 7642 | } | 
|  | 7643 | totalBytesRead += numRead; | 
|  | 7644 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { | 
|  | 7645 | loge("Too many bytes read for call composer picture: " + totalBytesRead); | 
|  | 7646 | try { | 
|  | 7647 | input.close(); | 
|  | 7648 | } catch (IOException e) { | 
|  | 7649 | // ignore | 
|  | 7650 | } | 
|  | 7651 | break; | 
|  | 7652 | } | 
|  | 7653 | output.write(buffer, 0, numRead); | 
|  | 7654 | } | 
|  | 7655 | // Generally, the remote end will close the file descriptors. The only case where we | 
|  | 7656 | // close is above, where the picture size is too big. | 
|  | 7657 |  | 
|  | 7658 | try { | 
|  | 7659 | fd.checkError(); | 
|  | 7660 | } catch (IOException e) { | 
|  | 7661 | loge("Remote end for call composer closed with an error: " + e); | 
|  | 7662 | return; | 
|  | 7663 | } | 
|  | 7664 |  | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7665 | if (!readUntilEnd) { | 
|  | 7666 | loge("Did not finish reading entire image; aborting"); | 
|  | 7667 | return; | 
|  | 7668 | } | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7669 |  | 
| Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7670 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); | 
|  | 7671 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( | 
|  | 7672 | new CallComposerPictureTransfer.Factory() {}, | 
|  | 7673 | imageData, | 
|  | 7674 | (result) -> { | 
|  | 7675 | if (result.first != null) { | 
|  | 7676 | ParcelUuid parcelUuid = new ParcelUuid(result.first); | 
|  | 7677 | Bundle outputResult = new Bundle(); | 
|  | 7678 | outputResult.putParcelable( | 
|  | 7679 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); | 
|  | 7680 | callback.send(TelephonyManager.CallComposerException.SUCCESS, | 
|  | 7681 | outputResult); | 
|  | 7682 | } else { | 
|  | 7683 | callback.send(result.second, null); | 
|  | 7684 | } | 
|  | 7685 | } | 
|  | 7686 | ); | 
| Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7687 | }); | 
|  | 7688 | } | 
|  | 7689 |  | 
|  | 7690 | @Override | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7691 | public void enableVideoCalling(boolean enable) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7692 | final Phone defaultPhone = getDefaultPhone(); | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7693 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 |  | 
|  | 7695 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7696 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7697 | ImsManager.getInstance(defaultPhone.getContext(), | 
|  | 7698 | defaultPhone.getPhoneId()).setVtSetting(enable); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | } finally { | 
|  | 7700 | Binder.restoreCallingIdentity(identity); | 
|  | 7701 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7702 | } | 
|  | 7703 |  | 
|  | 7704 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7705 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7706 | final Phone defaultPhone = getDefaultPhone(); | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), | 
|  | 7708 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7709 | return false; | 
|  | 7710 | } | 
| Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7711 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7713 | try { | 
|  | 7714 | // Check the user preference and the  system-level IMS setting. Even if the user has | 
|  | 7715 | // enabled video calling, if IMS is disabled we aren't able to support video calling. | 
|  | 7716 | // In the long run, we may instead need to check if there exists a connection service | 
|  | 7717 | // which can support video calling. | 
|  | 7718 | ImsManager imsManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7719 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7720 | return imsManager.isVtEnabledByPlatform() | 
|  | 7721 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() | 
|  | 7722 | && imsManager.isVtEnabledByUser(); | 
|  | 7723 | } finally { | 
|  | 7724 | Binder.restoreCallingIdentity(identity); | 
|  | 7725 | } | 
| Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7726 | } | 
| Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7727 |  | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7728 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7729 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, | 
|  | 7730 | String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7731 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7732 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 7733 | "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | return false; | 
|  | 7735 | } | 
|  | 7736 |  | 
|  | 7737 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7738 | try { | 
|  | 7739 | CarrierConfigManager configManager = | 
|  | 7740 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); | 
|  | 7743 | } finally { | 
|  | 7744 | Binder.restoreCallingIdentity(identity); | 
|  | 7745 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7746 | } | 
|  | 7747 |  | 
|  | 7748 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7749 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7750 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7751 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | return false; | 
|  | 7753 | } | 
|  | 7754 |  | 
|  | 7755 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7756 | try { | 
|  | 7757 | CarrierConfigManager configManager = | 
|  | 7758 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7759 | return configManager.getConfigForSubId(subId) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7760 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); | 
|  | 7761 | } finally { | 
|  | 7762 | Binder.restoreCallingIdentity(identity); | 
|  | 7763 | } | 
| Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7764 | } | 
|  | 7765 |  | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7766 | @Override | 
|  | 7767 | public boolean isTtyModeSupported() { | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7768 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); | 
| Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7769 | return telecomManager.isTtySupported(); | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7770 | } | 
|  | 7771 |  | 
|  | 7772 | @Override | 
|  | 7773 | public boolean isHearingAidCompatibilitySupported() { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7774 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7775 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7776 | return mApp.getResources().getBoolean(R.bool.hac_enabled); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7777 | } finally { | 
|  | 7778 | Binder.restoreCallingIdentity(identity); | 
|  | 7779 | } | 
| Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7780 | } | 
|  | 7781 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7782 | /** | 
|  | 7783 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier | 
|  | 7784 | * support for the feature and device firmware support. | 
|  | 7785 | * | 
|  | 7786 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. | 
|  | 7787 | */ | 
|  | 7788 | @Override | 
|  | 7789 | public boolean isRttSupported(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7790 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7791 | final Phone phone = getPhone(subscriptionId); | 
|  | 7792 | if (phone == null) { | 
|  | 7793 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); | 
|  | 7794 | return false; | 
|  | 7795 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | try { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7797 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7798 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); | 
|  | 7799 | boolean isDeviceSupported = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7800 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | return isCarrierSupported && isDeviceSupported; | 
|  | 7802 | } finally { | 
|  | 7803 | Binder.restoreCallingIdentity(identity); | 
|  | 7804 | } | 
| Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7805 | } | 
|  | 7806 |  | 
| Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7807 | /** | 
| Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7808 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set | 
|  | 7809 | * RTT setting, will return true if the device and carrier both support RTT. | 
|  | 7810 | * 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] | 7811 | */ | 
|  | 7812 | public boolean isRttEnabled(int subscriptionId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7813 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7814 | try { | 
| Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7815 | boolean isRttSupported = isRttSupported(subscriptionId); | 
|  | 7816 | boolean isUserRttSettingOn = Settings.Secure.getInt( | 
|  | 7817 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; | 
|  | 7818 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) | 
|  | 7819 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); | 
|  | 7820 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7821 | } finally { | 
|  | 7822 | Binder.restoreCallingIdentity(identity); | 
|  | 7823 | } | 
| Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7824 | } | 
|  | 7825 |  | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7826 | @Deprecated | 
|  | 7827 | @Override | 
|  | 7828 | public String getDeviceId(String callingPackage) { | 
|  | 7829 | return getDeviceIdWithFeature(callingPackage, null); | 
|  | 7830 | } | 
|  | 7831 |  | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7832 | /** | 
|  | 7833 | * Returns the unique device ID of phone, for example, the IMEI for | 
|  | 7834 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. | 
|  | 7835 | * | 
|  | 7836 | * <p>Requires Permission: | 
|  | 7837 | *   {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} | 
|  | 7838 | */ | 
|  | 7839 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7840 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7841 | try { | 
|  | 7842 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 7843 | } catch (SecurityException se) { | 
|  | 7844 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); | 
|  | 7845 | throw new SecurityException("Package " + callingPackage + " does not belong to " | 
|  | 7846 | + Binder.getCallingUid()); | 
|  | 7847 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7848 | final Phone phone = PhoneFactory.getPhone(0); | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7849 | if (phone == null) { | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7850 | return null; | 
|  | 7851 | } | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7852 | int subId = phone.getSubId(); | 
| Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7853 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7854 | callingPackage, callingFeatureId, "getDeviceId")) { | 
| Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7855 | return null; | 
|  | 7856 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7857 |  | 
|  | 7858 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7859 | try { | 
|  | 7860 | return phone.getDeviceId(); | 
|  | 7861 | } finally { | 
|  | 7862 | Binder.restoreCallingIdentity(identity); | 
|  | 7863 | } | 
| Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7864 | } | 
|  | 7865 |  | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7866 | /** | 
|  | 7867 | * {@hide} | 
|  | 7868 | * Returns the IMS Registration Status on a particular subid | 
|  | 7869 | * | 
|  | 7870 | * @param subId | 
|  | 7871 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7872 | public boolean isImsRegistered(int subId) { | 
| Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7873 | Phone phone = getPhone(subId); | 
|  | 7874 | if (phone != null) { | 
|  | 7875 | return phone.isImsRegistered(); | 
|  | 7876 | } else { | 
|  | 7877 | return false; | 
|  | 7878 | } | 
|  | 7879 | } | 
|  | 7880 |  | 
| Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7881 | @Override | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7882 | public int getSubIdForPhoneAccountHandle( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7883 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7884 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7885 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { | 
| Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7886 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 7887 | } | 
|  | 7888 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7889 | try { | 
|  | 7890 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); | 
|  | 7891 | } finally { | 
|  | 7892 | Binder.restoreCallingIdentity(identity); | 
|  | 7893 | } | 
|  | 7894 | } | 
|  | 7895 |  | 
|  | 7896 | @Override | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7897 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { | 
| Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7898 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7899 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 7900 | mApp, | 
|  | 7901 | subscriptionId, | 
|  | 7902 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " | 
|  | 7903 | + subscriptionId); | 
| Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7904 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7905 | try { | 
|  | 7906 | Phone phone = getPhone(subscriptionId); | 
|  | 7907 | if (phone == null) { | 
|  | 7908 | return null; | 
|  | 7909 | } | 
|  | 7910 | return PhoneUtils.makePstnPhoneAccountHandle(phone); | 
|  | 7911 | } finally { | 
|  | 7912 | Binder.restoreCallingIdentity(identity); | 
|  | 7913 | } | 
|  | 7914 | } | 
|  | 7915 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7916 | /** | 
|  | 7917 | * @return the VoWiFi calling availability. | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7918 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7919 | public boolean isWifiCallingAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7920 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7921 | try { | 
|  | 7922 | Phone phone = getPhone(subId); | 
|  | 7923 | if (phone != null) { | 
|  | 7924 | return phone.isWifiCallingEnabled(); | 
|  | 7925 | } else { | 
|  | 7926 | return false; | 
|  | 7927 | } | 
|  | 7928 | } finally { | 
|  | 7929 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7930 | } | 
| Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7931 | } | 
|  | 7932 |  | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7933 | /** | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7934 | * @return the VT calling availability. | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7935 | */ | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7936 | public boolean isVideoTelephonyAvailable(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7937 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7938 | try { | 
|  | 7939 | Phone phone = getPhone(subId); | 
|  | 7940 | if (phone != null) { | 
|  | 7941 | return phone.isVideoEnabled(); | 
|  | 7942 | } else { | 
|  | 7943 | return false; | 
|  | 7944 | } | 
|  | 7945 | } finally { | 
|  | 7946 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7947 | } | 
|  | 7948 | } | 
|  | 7949 |  | 
|  | 7950 | /** | 
|  | 7951 | * @return the IMS registration technology for the MMTEL feature. Valid return values are | 
|  | 7952 | * defined in {@link ImsRegistrationImplBase}. | 
|  | 7953 | */ | 
|  | 7954 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7955 | final long identity = Binder.clearCallingIdentity(); | 
|  | 7956 | try { | 
|  | 7957 | Phone phone = getPhone(subId); | 
|  | 7958 | if (phone != null) { | 
|  | 7959 | return phone.getImsRegistrationTech(); | 
|  | 7960 | } else { | 
|  | 7961 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; | 
|  | 7962 | } | 
|  | 7963 | } finally { | 
|  | 7964 | Binder.restoreCallingIdentity(identity); | 
| Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7965 | } | 
| Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7966 | } | 
|  | 7967 |  | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7968 | @Override | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7969 | public void factoryReset(int subId, String callingPackage) { | 
| paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7970 | enforceSettingsPermission(); | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7971 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { | 
|  | 7972 | return; | 
|  | 7973 | } | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7974 | Phone defaultPhone = getDefaultPhone(); | 
|  | 7975 | if (defaultPhone != null) { | 
|  | 7976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 7977 | mApp, getDefaultPhone().getSubId(), "factoryReset"); | 
|  | 7978 | } | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7979 | final long identity = Binder.clearCallingIdentity(); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7980 |  | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7981 | try { | 
| Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7982 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( | 
|  | 7983 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7984 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7985 | getDefaultDataEnabled(), callingPackage); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7986 | setNetworkSelectionModeAutomatic(subId); | 
| SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7987 | Phone phone = getPhone(subId); | 
| SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7988 | cleanUpAllowedNetworkTypes(phone, subId); | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7989 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); | 
| Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7990 | getPhone(subId).resetCarrierKeysForImsiEncryption(); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7991 | } | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7992 | // There has been issues when Sms raw table somehow stores orphan | 
|  | 7993 | // fragments. They lead to garbled message when new fragments come | 
|  | 7994 | // in and combined with those stale ones. In case this happens again, | 
|  | 7995 | // user can reset all network settings which will clean up this table. | 
|  | 7996 | cleanUpSmsRawTable(getDefaultPhone().getContext()); | 
| Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7997 | // Clean up IMS settings as well here. | 
|  | 7998 | int slotId = getSlotIndex(subId); | 
|  | 7999 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { | 
|  | 8000 | ImsManager.getInstance(mApp, slotId).factoryReset(); | 
|  | 8001 | } | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8002 |  | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8003 | if (defaultPhone == null) { | 
|  | 8004 | return; | 
|  | 8005 | } | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8006 | // Erase modem config if erase modem on network setting is enabled. | 
|  | 8007 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, | 
|  | 8008 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); | 
|  | 8009 | if (configValue != null && Boolean.parseBoolean(configValue)) { | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8010 | sendEraseModemConfig(defaultPhone); | 
| Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 8011 | } | 
| Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 8012 |  | 
|  | 8013 | sendEraseDataInSharedPreferences(defaultPhone); | 
| Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 8014 | } finally { | 
|  | 8015 | Binder.restoreCallingIdentity(identity); | 
| Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 8016 | } | 
|  | 8017 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8018 |  | 
| SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 8019 | @VisibleForTesting | 
|  | 8020 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { | 
|  | 8021 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { | 
|  | 8022 | return; | 
|  | 8023 | } | 
|  | 8024 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( | 
|  | 8025 | RILConstants.PREFERRED_NETWORK_MODE); | 
|  | 8026 | SubscriptionManager.setSubscriptionProperty(subId, | 
|  | 8027 | SubscriptionManager.ALLOWED_NETWORK_TYPES, | 
|  | 8028 | "user=" + defaultNetworkType); | 
|  | 8029 | phone.loadAllowedNetworksFromSubscriptionDatabase(); | 
|  | 8030 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, | 
|  | 8031 | defaultNetworkType, null); | 
|  | 8032 | } | 
|  | 8033 |  | 
| Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 8034 | private void cleanUpSmsRawTable(Context context) { | 
|  | 8035 | ContentResolver resolver = context.getContentResolver(); | 
|  | 8036 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); | 
|  | 8037 | resolver.delete(uri, null, null); | 
|  | 8038 | } | 
|  | 8039 |  | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8040 | @Override | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8041 | public String getSimLocaleForSubscriber(int subId) { | 
|  | 8042 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); | 
|  | 8043 | final Phone phone = getPhone(subId); | 
|  | 8044 | if (phone == null) { | 
|  | 8045 | log("getSimLocaleForSubscriber, invalid subId"); | 
| chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 8046 | return null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8047 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8049 | try { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8050 | SubscriptionInfo info; | 
|  | 8051 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8052 | info = getSubscriptionManagerService().getActiveSubscriptionInfo(subId, | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8053 | phone.getContext().getOpPackageName(), | 
|  | 8054 | phone.getContext().getAttributionTag()); | 
|  | 8055 | if (info == null) { | 
|  | 8056 | log("getSimLocaleForSubscriber, inactive subId: " + subId); | 
|  | 8057 | return null; | 
|  | 8058 | } | 
|  | 8059 | } else { | 
|  | 8060 | info = mSubscriptionController.getActiveSubscriptionInfo(subId, | 
|  | 8061 | phone.getContext().getOpPackageName(), | 
|  | 8062 | phone.getContext().getAttributionTag()); | 
|  | 8063 | if (info == null) { | 
|  | 8064 | log("getSimLocaleForSubscriber, inactive subId: " + subId); | 
|  | 8065 | return null; | 
|  | 8066 | } | 
| chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 8067 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8068 | // Try and fetch the locale from the carrier properties or from the SIM language | 
|  | 8069 | // preferences (EF-PL and EF-LI)... | 
|  | 8070 | final int mcc = info.getMcc(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8071 | String simLanguage = null; | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8072 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); | 
|  | 8073 | if (localeFromDefaultSim != null) { | 
|  | 8074 | if (!localeFromDefaultSim.getCountry().isEmpty()) { | 
|  | 8075 | if (DBG) log("Using locale from subId: " + subId + " locale: " | 
|  | 8076 | + localeFromDefaultSim); | 
| tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8077 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8078 | } else { | 
|  | 8079 | simLanguage = localeFromDefaultSim.getLanguage(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8080 | } | 
|  | 8081 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8082 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | // The SIM language preferences only store a language (e.g. fr = French), not an | 
|  | 8084 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from | 
|  | 8085 | // the SIM and carrier preferences does not include a country we add the country | 
|  | 8086 | // determined from the SIM MCC to provide an exact locale. | 
| zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 8087 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8088 | if (mccLocale != null) { | 
| chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 8089 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); | 
| tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8090 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | } | 
|  | 8092 |  | 
|  | 8093 | if (DBG) log("No locale found - returning null"); | 
|  | 8094 | return null; | 
|  | 8095 | } finally { | 
|  | 8096 | Binder.restoreCallingIdentity(identity); | 
|  | 8097 | } | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8098 | } | 
|  | 8099 |  | 
| tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8100 | @VisibleForTesting | 
| tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8101 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { | 
| tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8102 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( | 
| tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8103 | phone.getContext()); | 
| tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8104 | for (String localeTag : supportedLocale) { | 
| tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 8105 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) | 
|  | 8106 | && TextUtils.equals(inputLocale.getCountry(), | 
| tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 8107 | Locale.forLanguageTag(localeTag).getCountry())) { | 
|  | 8108 | return localeTag; | 
|  | 8109 | } | 
|  | 8110 | } | 
|  | 8111 | return inputLocale.toLanguageTag(); | 
|  | 8112 | } | 
|  | 8113 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | /** | 
|  | 8115 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. | 
|  | 8116 | */ | 
|  | 8117 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8118 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8119 | return getSubscriptionManagerService().getActiveSubscriptionInfoList( | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8120 | mApp.getOpPackageName(), mApp.getAttributionTag()); | 
|  | 8121 | } | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8122 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), | 
| Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 8123 | mApp.getAttributionTag()); | 
| Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 8124 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8125 |  | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8126 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; | 
|  | 8127 | private ModemActivityInfo mLastModemActivityInfo = null; | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8128 |  | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8129 | /** | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8130 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object | 
|  | 8131 | * representing the state of the modem. | 
|  | 8132 | * | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8133 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one | 
|  | 8134 | * caller to it. Everyone should call this class to get cumulative data. | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8135 | * @hide | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8136 | */ | 
|  | 8137 | @Override | 
| Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 8138 | public void requestModemActivityInfo(ResultReceiver result) { | 
|  | 8139 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8140 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 |  | 
|  | 8142 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8143 | try { | 
| Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 8144 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8145 | } finally { | 
|  | 8146 | Binder.restoreCallingIdentity(identity); | 
| Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 8147 | } | 
| Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 8148 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8149 |  | 
| Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8150 | // Checks that ModemActivityInfo is valid. Sleep time and Idle time should be | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8151 | // less than total activity duration. | 
|  | 8152 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { | 
|  | 8153 | if (info == null) { | 
|  | 8154 | return false; | 
|  | 8155 | } | 
|  | 8156 | int activityDurationMs = | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8157 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); | 
| Gary Jian | 76280a4 | 2022-12-07 16:18:33 +0800 | [diff] [blame] | 8158 | activityDurationMs += MODEM_ACTIVITY_TIME_OFFSET_CORRECTION_MS; | 
|  | 8159 |  | 
| Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 8160 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); | 
|  | 8161 |  | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8162 | return (info.isValid() | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8163 | && (info.getSleepTimeMillis() <= activityDurationMs) | 
|  | 8164 | && (info.getIdleTimeMillis() <= activityDurationMs)); | 
| Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 8165 | } | 
|  | 8166 |  | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8167 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { | 
|  | 8168 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; | 
|  | 8169 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); | 
|  | 8170 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); | 
|  | 8171 |  | 
|  | 8172 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { | 
|  | 8173 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; | 
|  | 8174 | } | 
|  | 8175 |  | 
|  | 8176 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); | 
|  | 8177 | mLastModemActivityInfo.setReceiveTimeMillis( | 
|  | 8178 | rat, | 
|  | 8179 | freq, | 
|  | 8180 | info.getReceiveTimeMillis(rat, freq) | 
|  | 8181 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); | 
|  | 8182 | } | 
|  | 8183 |  | 
|  | 8184 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { | 
|  | 8185 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; | 
|  | 8186 | int[] txTimeMs = info.getTransmitTimeMillis(rat); | 
|  | 8187 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); | 
|  | 8188 |  | 
|  | 8189 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { | 
|  | 8190 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; | 
|  | 8191 | } | 
|  | 8192 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); | 
|  | 8193 | mLastModemActivityInfo.setReceiveTimeMillis( | 
|  | 8194 | rat, | 
|  | 8195 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); | 
|  | 8196 | } | 
|  | 8197 |  | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8198 | /** | 
|  | 8199 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo | 
|  | 8200 | * @param info recent ModemActivityInfo | 
|  | 8201 | */ | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8202 | private void mergeModemActivityInfo(ModemActivityInfo info) { | 
|  | 8203 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8204 | ActivityStatsTechSpecificInfo deltaSpecificInfo; | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8205 | boolean matched; | 
|  | 8206 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { | 
|  | 8207 | matched = false; | 
|  | 8208 | int rat = info.getSpecificInfoRat(i); | 
|  | 8209 | int freq = info.getSpecificInfoFrequencyRange(i); | 
|  | 8210 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns | 
|  | 8211 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original | 
|  | 8212 | //if it already exists | 
|  | 8213 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { | 
|  | 8214 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { | 
|  | 8215 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G | 
|  | 8216 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { | 
|  | 8217 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { | 
|  | 8218 | updateLastModemActivityInfo(info, rat, freq); | 
|  | 8219 | matched = true; | 
|  | 8220 | } | 
|  | 8221 | } else { | 
|  | 8222 | updateLastModemActivityInfo(info, rat); | 
|  | 8223 | matched = true; | 
|  | 8224 | } | 
|  | 8225 | } | 
|  | 8226 | } | 
|  | 8227 |  | 
|  | 8228 | if (!matched) { | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8229 | deltaSpecificInfo = | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8230 | new ActivityStatsTechSpecificInfo( | 
|  | 8231 | rat, | 
|  | 8232 | freq, | 
|  | 8233 | info.getTransmitTimeMillis(rat, freq), | 
|  | 8234 | (int) info.getReceiveTimeMillis(rat, freq)); | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8235 | merged.addAll(Arrays.asList(deltaSpecificInfo)); | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8236 | } | 
|  | 8237 | } | 
|  | 8238 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); | 
|  | 8239 | mLastModemActivitySpecificInfo = | 
|  | 8240 | new ActivityStatsTechSpecificInfo[merged.size()]; | 
|  | 8241 | merged.toArray(mLastModemActivitySpecificInfo); | 
|  | 8242 |  | 
|  | 8243 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); | 
|  | 8244 | mLastModemActivityInfo.setSleepTimeMillis( | 
|  | 8245 | info.getSleepTimeMillis() | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8246 | + mLastModemActivityInfo.getSleepTimeMillis()); | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8247 | mLastModemActivityInfo.setIdleTimeMillis( | 
|  | 8248 | info.getIdleTimeMillis() | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8249 | + mLastModemActivityInfo.getIdleTimeMillis()); | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8250 |  | 
|  | 8251 | mLastModemActivityInfo = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8252 | new ModemActivityInfo( | 
|  | 8253 | mLastModemActivityInfo.getTimestampMillis(), | 
|  | 8254 | mLastModemActivityInfo.getSleepTimeMillis(), | 
|  | 8255 | mLastModemActivityInfo.getIdleTimeMillis(), | 
|  | 8256 | mLastModemActivitySpecificInfo); | 
| Kai Shi | 917fdc6 | 2022-11-28 14:01:02 -0800 | [diff] [blame] | 8257 | } | 
|  | 8258 |  | 
|  | 8259 | private ActivityStatsTechSpecificInfo[] deepCopyModemActivitySpecificInfo( | 
|  | 8260 | ActivityStatsTechSpecificInfo[] info) { | 
|  | 8261 | int infoSize = info.length; | 
|  | 8262 | ActivityStatsTechSpecificInfo[] ret = new ActivityStatsTechSpecificInfo[infoSize]; | 
|  | 8263 | for (int i = 0; i < infoSize; i++) { | 
|  | 8264 | ret[i] = new ActivityStatsTechSpecificInfo( | 
|  | 8265 | info[i].getRat(), info[i].getFrequencyRange(), | 
|  | 8266 | info[i].getTransmitTimeMillis(), | 
|  | 8267 | (int) info[i].getReceiveTimeMillis()); | 
|  | 8268 | } | 
|  | 8269 | return ret; | 
| Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 8270 | } | 
|  | 8271 |  | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8272 | /** | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8273 | * Returns the service state information on specified subscription. | 
|  | 8274 | */ | 
|  | 8275 | @Override | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8276 | public ServiceState getServiceStateForSubscriber(int subId, | 
|  | 8277 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, | 
|  | 8278 | String callingPackage, String callingFeatureId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8280 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8281 | return null; | 
|  | 8282 | } | 
|  | 8283 |  | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8284 | boolean hasFinePermission = false; | 
|  | 8285 | boolean hasCoarsePermission = false; | 
|  | 8286 | if (!renounceFineLocationAccess) { | 
|  | 8287 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 8288 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 8289 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 8290 | .setCallingPackage(callingPackage) | 
|  | 8291 | .setCallingFeatureId(callingFeatureId) | 
|  | 8292 | .setCallingPid(Binder.getCallingPid()) | 
|  | 8293 | .setCallingUid(Binder.getCallingUid()) | 
|  | 8294 | .setMethod("getServiceStateForSubscriber") | 
|  | 8295 | .setLogAsInfo(true) | 
|  | 8296 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 8297 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 8298 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
|  | 8299 | .build()); | 
|  | 8300 | hasFinePermission = | 
|  | 8301 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 8302 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8303 |  | 
| Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8304 | if (!renounceCoarseLocationAccess) { | 
|  | 8305 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = | 
|  | 8306 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 8307 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 8308 | .setCallingPackage(callingPackage) | 
|  | 8309 | .setCallingFeatureId(callingFeatureId) | 
|  | 8310 | .setCallingPid(Binder.getCallingPid()) | 
|  | 8311 | .setCallingUid(Binder.getCallingUid()) | 
|  | 8312 | .setMethod("getServiceStateForSubscriber") | 
|  | 8313 | .setLogAsInfo(true) | 
|  | 8314 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 8315 | .setMinSdkVersionForFine(Integer.MAX_VALUE) | 
|  | 8316 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
|  | 8317 | .build()); | 
|  | 8318 | hasCoarsePermission = | 
|  | 8319 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 8320 | } | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8321 |  | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8322 | final Phone phone = getPhone(subId); | 
|  | 8323 | if (phone == null) { | 
|  | 8324 | return null; | 
|  | 8325 | } | 
|  | 8326 |  | 
| Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8327 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8328 |  | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8329 | boolean isCallingPackageDataService = phone.getDataServicePackages() | 
|  | 8330 | .contains(callingPackage); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8331 | try { | 
| Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8332 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8333 | if (PhoneFactory.isSubscriptionManagerServiceEnabled()) { | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 8334 | SubscriptionInfoInternal subInfo = getSubscriptionManagerService() | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 8335 | .getSubscriptionInfoInternal(subId); | 
|  | 8336 | if (subInfo == null || !subInfo.isActive()) { | 
|  | 8337 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " | 
|  | 8338 | + "subId=" + subId); | 
|  | 8339 | return null; | 
|  | 8340 | } | 
|  | 8341 | } else { | 
|  | 8342 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, | 
|  | 8343 | callingFeatureId)) { | 
|  | 8344 | Rlog.d(LOG_TAG, "getServiceStateForSubscriber returning null for inactive " | 
|  | 8345 | + "subId=" + subId); | 
|  | 8346 | return null; | 
|  | 8347 | } | 
| Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8348 | } | 
|  | 8349 |  | 
| Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8350 | ServiceState ss = phone.getServiceState(); | 
|  | 8351 |  | 
|  | 8352 | // Scrub out the location info in ServiceState depending on what level of access | 
|  | 8353 | // the caller has. | 
| Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8354 | if (hasFinePermission || isCallingPackageDataService) return ss; | 
| Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8355 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); | 
|  | 8356 | return ss.createLocationInfoSanitizedCopy(true); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8357 | } finally { | 
|  | 8358 | Binder.restoreCallingIdentity(identity); | 
|  | 8359 | } | 
| Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8360 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8361 |  | 
|  | 8362 | /** | 
|  | 8363 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. | 
|  | 8364 | * | 
|  | 8365 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 8366 | * voicemail ringtone. | 
|  | 8367 | * @return The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 8368 | * PhoneAccount. | 
|  | 8369 | */ | 
|  | 8370 | @Override | 
|  | 8371 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8373 | try { | 
|  | 8374 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 8375 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8376 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8378 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8379 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); | 
|  | 8380 | } finally { | 
|  | 8381 | Binder.restoreCallingIdentity(identity); | 
|  | 8382 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8383 | } | 
|  | 8384 |  | 
|  | 8385 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8386 | * Sets the per-account voicemail ringtone. | 
|  | 8387 | * | 
|  | 8388 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 8389 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 8390 | * | 
|  | 8391 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 8392 | * voicemail ringtone. | 
|  | 8393 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific | 
|  | 8394 | * PhoneAccount. | 
|  | 8395 | */ | 
|  | 8396 | @Override | 
|  | 8397 | public void setVoicemailRingtoneUri(String callingPackage, | 
|  | 8398 | PhoneAccountHandle phoneAccountHandle, Uri uri) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8399 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8400 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8401 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 8402 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8403 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8404 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 8405 | "setVoicemailRingtoneUri"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8406 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 |  | 
|  | 8408 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8409 | try { | 
|  | 8410 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 8411 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8412 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8413 | } | 
|  | 8414 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); | 
|  | 8415 | } finally { | 
|  | 8416 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8417 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8418 | } | 
|  | 8419 |  | 
|  | 8420 | /** | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8421 | * Returns whether vibration is set for voicemail notification in Phone settings. | 
|  | 8422 | * | 
|  | 8423 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the | 
|  | 8424 | * voicemail vibration setting. | 
|  | 8425 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. | 
|  | 8426 | */ | 
|  | 8427 | @Override | 
|  | 8428 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8429 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8430 | try { | 
|  | 8431 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); | 
|  | 8432 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8433 | phone = getDefaultPhone(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8434 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8435 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8436 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); | 
|  | 8437 | } finally { | 
|  | 8438 | Binder.restoreCallingIdentity(identity); | 
|  | 8439 | } | 
| Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8440 | } | 
|  | 8441 |  | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8442 | /** | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8443 | * Sets the per-account voicemail vibration. | 
|  | 8444 | * | 
|  | 8445 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or | 
|  | 8446 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 8447 | * | 
|  | 8448 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the | 
|  | 8449 | * voicemail vibration setting. | 
|  | 8450 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a | 
|  | 8451 | * specific PhoneAccount. | 
|  | 8452 | */ | 
|  | 8453 | @Override | 
|  | 8454 | public void setVoicemailVibrationEnabled(String callingPackage, | 
|  | 8455 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8456 | final Phone defaultPhone = getDefaultPhone(); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8457 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
| Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8458 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); | 
|  | 8459 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8461 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), | 
|  | 8462 | "setVoicemailVibrationEnabled"); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8463 | } | 
|  | 8464 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8465 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8466 | try { | 
|  | 8467 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); | 
|  | 8468 | if (phone == null) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8469 | phone = defaultPhone; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8470 | } | 
|  | 8471 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); | 
|  | 8472 | } finally { | 
|  | 8473 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8474 | } | 
| Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8475 | } | 
|  | 8476 |  | 
|  | 8477 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8478 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. | 
|  | 8479 | * | 
|  | 8480 | * @throws SecurityException if the caller does not have the required permission | 
|  | 8481 | */ | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8482 | @VisibleForTesting | 
|  | 8483 | public void enforceReadPrivilegedPermission(String message) { | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8484 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8485 | message); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8486 | } | 
|  | 8487 |  | 
|  | 8488 | /** | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8489 | * Make sure either called from same process as self (phone) or IPC caller has send SMS | 
|  | 8490 | * permission. | 
|  | 8491 | * | 
|  | 8492 | * @throws SecurityException if the caller does not have the required permission | 
|  | 8493 | */ | 
|  | 8494 | private void enforceSendSmsPermission() { | 
|  | 8495 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); | 
|  | 8496 | } | 
|  | 8497 |  | 
|  | 8498 | /** | 
| Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 8499 | * Make sure either called from same process as self (phone) or IPC caller has interact across | 
|  | 8500 | * users permission. | 
|  | 8501 | * | 
|  | 8502 | * @throws SecurityException if the caller does not have the required permission | 
|  | 8503 | */ | 
|  | 8504 | private void enforceInteractAcrossUsersPermission(String message) { | 
|  | 8505 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); | 
|  | 8506 | } | 
|  | 8507 |  | 
|  | 8508 | /** | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8509 | * Make sure called from the package in charge of visual voicemail. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8510 | * | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8511 | * @throws SecurityException if the caller is not the visual voicemail package. | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8512 | */ | 
| Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8513 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8514 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8515 | try { | 
|  | 8516 | ComponentName componentName = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8517 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8518 | if (componentName == null) { | 
|  | 8519 | throw new SecurityException( | 
|  | 8520 | "Caller not current active visual voicemail package[null]"); | 
|  | 8521 | } | 
|  | 8522 | String vvmPackage = componentName.getPackageName(); | 
|  | 8523 | if (!callingPackage.equals(vvmPackage)) { | 
| Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8524 | throw new SecurityException("Caller not current active visual voicemail package"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8525 | } | 
|  | 8526 | } finally { | 
|  | 8527 | Binder.restoreCallingIdentity(identity); | 
| Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8528 | } | 
|  | 8529 | } | 
|  | 8530 |  | 
|  | 8531 | /** | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8532 | * Return the application ID for the app type. | 
|  | 8533 | * | 
|  | 8534 | * @param subId the subscription ID that this request applies to. | 
|  | 8535 | * @param appType the uicc app type. | 
|  | 8536 | * @return Application ID for specificied app type, or null if no uicc. | 
|  | 8537 | */ | 
|  | 8538 | @Override | 
|  | 8539 | public String getAidForAppType(int subId, int appType) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8540 | enforceReadPrivilegedPermission("getAidForAppType"); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8541 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8542 |  | 
|  | 8543 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8544 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8545 | if (phone == null) { | 
|  | 8546 | return null; | 
|  | 8547 | } | 
|  | 8548 | String aid = null; | 
|  | 8549 | try { | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8550 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8551 | .getApplicationByType(appType).getAid(); | 
|  | 8552 | } catch (Exception e) { | 
|  | 8553 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); | 
|  | 8554 | } | 
|  | 8555 | return aid; | 
|  | 8556 | } finally { | 
|  | 8557 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8558 | } | 
| Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8559 | } | 
|  | 8560 |  | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8561 | /** | 
|  | 8562 | * Return the Electronic Serial Number. | 
|  | 8563 | * | 
|  | 8564 | * @param subId the subscription ID that this request applies to. | 
|  | 8565 | * @return ESN or null if error. | 
|  | 8566 | */ | 
|  | 8567 | @Override | 
|  | 8568 | public String getEsn(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8569 | enforceReadPrivilegedPermission("getEsn"); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8570 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8571 |  | 
|  | 8572 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8573 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8574 | if (phone == null) { | 
|  | 8575 | return null; | 
|  | 8576 | } | 
|  | 8577 | String esn = null; | 
|  | 8578 | try { | 
|  | 8579 | esn = phone.getEsn(); | 
|  | 8580 | } catch (Exception e) { | 
|  | 8581 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); | 
|  | 8582 | } | 
|  | 8583 | return esn; | 
|  | 8584 | } finally { | 
|  | 8585 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8586 | } | 
| Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8587 | } | 
|  | 8588 |  | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8589 | /** | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8590 | * Return the Preferred Roaming List Version. | 
|  | 8591 | * | 
|  | 8592 | * @param subId the subscription ID that this request applies to. | 
|  | 8593 | * @return PRLVersion or null if error. | 
|  | 8594 | */ | 
|  | 8595 | @Override | 
|  | 8596 | public String getCdmaPrlVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8597 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8598 | Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8599 |  | 
|  | 8600 | final long identity = Binder.clearCallingIdentity(); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8601 | try { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8602 | if (phone == null) { | 
|  | 8603 | return null; | 
|  | 8604 | } | 
|  | 8605 | String cdmaPrlVersion = null; | 
|  | 8606 | try { | 
|  | 8607 | cdmaPrlVersion = phone.getCdmaPrlVersion(); | 
|  | 8608 | } catch (Exception e) { | 
|  | 8609 | Log.e(LOG_TAG, "Not getting PRLVersion", e); | 
|  | 8610 | } | 
|  | 8611 | return cdmaPrlVersion; | 
|  | 8612 | } finally { | 
|  | 8613 | Binder.restoreCallingIdentity(identity); | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8614 | } | 
| Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8615 | } | 
|  | 8616 |  | 
|  | 8617 | /** | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8618 | * Get snapshot of Telephony histograms | 
|  | 8619 | * @return List of Telephony histograms | 
|  | 8620 | * @hide | 
|  | 8621 | */ | 
|  | 8622 | @Override | 
|  | 8623 | public List<TelephonyHistogram> getTelephonyHistograms() { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8624 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 8625 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8626 |  | 
|  | 8627 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8628 | try { | 
|  | 8629 | return RIL.getTelephonyRILTimingHistograms(); | 
|  | 8630 | } finally { | 
|  | 8631 | Binder.restoreCallingIdentity(identity); | 
|  | 8632 | } | 
| Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8633 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8634 |  | 
|  | 8635 | /** | 
|  | 8636 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8637 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between | 
|  | 8638 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8639 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 8640 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8641 | * @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] | 8642 | */ | 
|  | 8643 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8644 | @TelephonyManager.SetCarrierRestrictionResult | 
|  | 8645 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8646 | enforceModifyPermission(); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8647 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8648 |  | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8649 | if (carrierRestrictionRules == null) { | 
|  | 8650 | throw new NullPointerException("carrier restriction cannot be null"); | 
| Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8651 | } | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8652 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8653 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8654 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8655 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8656 | workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8657 | } finally { | 
|  | 8658 | Binder.restoreCallingIdentity(identity); | 
|  | 8659 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8660 | } | 
|  | 8661 |  | 
|  | 8662 | /** | 
|  | 8663 | * {@hide} | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8664 | * Get the allowed carrier list and the excluded carrier list, including the priority between | 
|  | 8665 | * the two lists. | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8666 | * Require system privileges. In the future we may add this to carrier APIs. | 
|  | 8667 | * | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8668 | * @return {@link android.telephony.CarrierRestrictionRules} | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8669 | */ | 
|  | 8670 | @Override | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8671 | public CarrierRestrictionRules getAllowedCarriers() { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8672 | enforceReadPrivilegedPermission("getAllowedCarriers"); | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8673 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8674 |  | 
|  | 8675 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8676 | try { | 
| Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8677 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); | 
|  | 8678 | if (response instanceof CarrierRestrictionRules) { | 
|  | 8679 | return (CarrierRestrictionRules) response; | 
|  | 8680 | } | 
|  | 8681 | // Response is an Exception of some kind, | 
|  | 8682 | // which is signalled to the user as a NULL retval | 
|  | 8683 | return null; | 
|  | 8684 | } catch (Exception e) { | 
|  | 8685 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); | 
|  | 8686 | return null; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8687 | } finally { | 
|  | 8688 | Binder.restoreCallingIdentity(identity); | 
|  | 8689 | } | 
| Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8690 | } | 
|  | 8691 |  | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8692 | /** | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 8693 | * Fetches the carrier restriction status of the device and sends the status to the caller | 
|  | 8694 | * through the callback. | 
|  | 8695 | * | 
|  | 8696 | * @param callback The callback that will be used to send the result. | 
|  | 8697 | * @throws SecurityException if the caller does not have the required permission/privileges or | 
|  | 8698 | *                           the caller is not allowlisted. | 
|  | 8699 | */ | 
|  | 8700 | @Override | 
|  | 8701 | public void getCarrierRestrictionStatus(IIntegerConsumer callback, String packageName) { | 
|  | 8702 | enforceReadPermission("getCarrierRestrictionStatus"); | 
|  | 8703 | int carrierId = validateCallerAndGetCarrierId(packageName); | 
|  | 8704 | if (carrierId == CarrierAllowListInfo.INVALID_CARRIER_ID) { | 
|  | 8705 | Rlog.e(LOG_TAG, "getCarrierRestrictionStatus: caller is not registered"); | 
|  | 8706 | throw new SecurityException("Not an authorized caller"); | 
|  | 8707 | } | 
|  | 8708 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8709 | try { | 
|  | 8710 | Consumer<Integer> consumer = FunctionalUtils.ignoreRemoteException(callback::accept); | 
|  | 8711 | CallerCallbackInfo callbackInfo = new CallerCallbackInfo(consumer, carrierId); | 
|  | 8712 | sendRequestAsync(CMD_GET_ALLOWED_CARRIERS, callbackInfo); | 
|  | 8713 | } finally { | 
|  | 8714 | Binder.restoreCallingIdentity(identity); | 
|  | 8715 | } | 
|  | 8716 | } | 
|  | 8717 |  | 
|  | 8718 | @VisibleForTesting | 
|  | 8719 | public int validateCallerAndGetCarrierId(String packageName) { | 
|  | 8720 | CarrierAllowListInfo allowListInfo = CarrierAllowListInfo.loadInstance(mApp); | 
|  | 8721 | return allowListInfo.validateCallerAndGetCarrierId(packageName); | 
|  | 8722 | } | 
|  | 8723 |  | 
|  | 8724 | /** | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8725 | * Action set from carrier signalling broadcast receivers to enable/disable radio | 
|  | 8726 | * @param subId the subscription ID that this action applies to. | 
|  | 8727 | * @param enabled control enable or disable radio. | 
|  | 8728 | * {@hide} | 
|  | 8729 | */ | 
|  | 8730 | @Override | 
|  | 8731 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { | 
|  | 8732 | enforceModifyPermission(); | 
|  | 8733 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8734 |  | 
|  | 8735 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8736 | if (phone == null) { | 
|  | 8737 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); | 
|  | 8738 | return; | 
|  | 8739 | } | 
|  | 8740 | try { | 
|  | 8741 | phone.carrierActionSetRadioEnabled(enabled); | 
|  | 8742 | } catch (Exception e) { | 
|  | 8743 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8744 | } finally { | 
|  | 8745 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8746 | } | 
|  | 8747 | } | 
|  | 8748 |  | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8749 | /** | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8750 | * Enable or disable Voice over NR (VoNR) | 
|  | 8751 | * @param subId the subscription ID that this action applies to. | 
|  | 8752 | * @param enabled enable or disable VoNR. | 
|  | 8753 | * @return operation result. | 
|  | 8754 | */ | 
|  | 8755 | @Override | 
|  | 8756 | public int setVoNrEnabled(int subId, boolean enabled) { | 
|  | 8757 | enforceModifyPermission(); | 
|  | 8758 | final Phone phone = getPhone(subId); | 
|  | 8759 |  | 
|  | 8760 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8761 | if (phone == null) { | 
|  | 8762 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); | 
|  | 8763 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; | 
|  | 8764 | } | 
|  | 8765 |  | 
|  | 8766 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8767 | try { | 
|  | 8768 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, | 
|  | 8769 | workSource); | 
|  | 8770 | if (DBG) log("setVoNrEnabled result: " + result); | 
| Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8771 |  | 
|  | 8772 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { | 
|  | 8773 | if (DBG) { | 
|  | 8774 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); | 
|  | 8775 | } | 
|  | 8776 | SubscriptionManager.setSubscriptionProperty( | 
|  | 8777 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, | 
|  | 8778 | (enabled ? "1" : "0")); | 
|  | 8779 | } | 
|  | 8780 |  | 
| Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8781 | return result; | 
|  | 8782 | } finally { | 
|  | 8783 | Binder.restoreCallingIdentity(identity); | 
|  | 8784 | } | 
|  | 8785 | } | 
|  | 8786 |  | 
|  | 8787 | /** | 
|  | 8788 | * Is voice over NR enabled | 
|  | 8789 | * @return true if VoNR is enabled else false | 
|  | 8790 | */ | 
|  | 8791 | @Override | 
|  | 8792 | public boolean isVoNrEnabled(int subId) { | 
|  | 8793 | enforceReadPrivilegedPermission("isVoNrEnabled"); | 
|  | 8794 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8795 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8796 | try { | 
|  | 8797 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, | 
|  | 8798 | null, subId, workSource); | 
|  | 8799 | if (DBG) log("isVoNrEnabled: " + isEnabled); | 
|  | 8800 | return isEnabled; | 
|  | 8801 | } finally { | 
|  | 8802 | Binder.restoreCallingIdentity(identity); | 
|  | 8803 | } | 
|  | 8804 | } | 
|  | 8805 |  | 
|  | 8806 | /** | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8807 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default | 
|  | 8808 | * network status based on which carrier apps could apply actions accordingly, | 
|  | 8809 | * enable/disable default url handler for example. | 
|  | 8810 | * | 
|  | 8811 | * @param subId the subscription ID that this action applies to. | 
|  | 8812 | * @param report control start/stop reporting the default network status. | 
|  | 8813 | * {@hide} | 
|  | 8814 | */ | 
|  | 8815 | @Override | 
|  | 8816 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { | 
|  | 8817 | enforceModifyPermission(); | 
|  | 8818 | final Phone phone = getPhone(subId); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8819 |  | 
|  | 8820 | final long identity = Binder.clearCallingIdentity(); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8821 | if (phone == null) { | 
|  | 8822 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); | 
|  | 8823 | return; | 
|  | 8824 | } | 
|  | 8825 | try { | 
|  | 8826 | phone.carrierActionReportDefaultNetworkStatus(report); | 
|  | 8827 | } catch (Exception e) { | 
|  | 8828 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8829 | } finally { | 
|  | 8830 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8831 | } | 
|  | 8832 | } | 
|  | 8833 |  | 
|  | 8834 | /** | 
| fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8835 | * Action set from carrier signalling broadcast receivers to reset all carrier actions | 
|  | 8836 | * @param subId the subscription ID that this action applies to. | 
|  | 8837 | * {@hide} | 
|  | 8838 | */ | 
|  | 8839 | @Override | 
|  | 8840 | public void carrierActionResetAll(int subId) { | 
|  | 8841 | enforceModifyPermission(); | 
|  | 8842 | final Phone phone = getPhone(subId); | 
|  | 8843 | if (phone == null) { | 
|  | 8844 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); | 
|  | 8845 | return; | 
|  | 8846 | } | 
|  | 8847 | try { | 
|  | 8848 | phone.carrierActionResetAll(); | 
|  | 8849 | } catch (Exception e) { | 
|  | 8850 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); | 
|  | 8851 | } | 
|  | 8852 | } | 
|  | 8853 |  | 
|  | 8854 | /** | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8855 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a | 
|  | 8856 | * bug report is being generated. | 
|  | 8857 | */ | 
|  | 8858 | @Override | 
| Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8859 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8860 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) | 
|  | 8861 | != PackageManager.PERMISSION_GRANTED) { | 
| dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8862 | writer.println("Permission Denial: can't dump Phone from pid=" | 
|  | 8863 | + Binder.getCallingPid() | 
|  | 8864 | + ", uid=" + Binder.getCallingUid() | 
|  | 8865 | + "without permission " | 
|  | 8866 | + android.Manifest.permission.DUMP); | 
|  | 8867 | return; | 
|  | 8868 | } | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8869 | DumpsysHandler.dump(mApp, fd, writer, args); | 
| Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8870 | } | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8871 |  | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8872 | @Override | 
| Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8873 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, | 
|  | 8874 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, | 
|  | 8875 | @NonNull String[] args) { | 
|  | 8876 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( | 
|  | 8877 | this, in.getFileDescriptor(), out.getFileDescriptor(), | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 8878 | err.getFileDescriptor(), args); | 
| Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8879 | } | 
|  | 8880 |  | 
| Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8881 | /** | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8882 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} | 
| Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8883 | * @param subId Subscription index | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8884 | * @param reason The reason the data enable change is taking place. | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8885 | * @param enabled True if enabling the data, otherwise disabling. | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8886 | * @param callingPackage The package that changed the data enabled state. | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8887 | * @hide | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8888 | */ | 
|  | 8889 | @Override | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8890 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8891 | boolean enabled, String callingPackage) { | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8892 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER | 
|  | 8893 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 8894 | try { | 
|  | 8895 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( | 
| Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8896 | mApp, subId, "setDataEnabledForReason"); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8897 | } catch (SecurityException se) { | 
|  | 8898 | enforceModifyPermission(); | 
|  | 8899 | } | 
|  | 8900 | } else { | 
|  | 8901 | enforceModifyPermission(); | 
|  | 8902 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8903 |  | 
|  | 8904 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8905 | try { | 
|  | 8906 | Phone phone = getPhone(subId); | 
|  | 8907 | if (phone != null) { | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8908 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { | 
|  | 8909 | phone.carrierActionSetMeteredApnsEnabled(enabled); | 
|  | 8910 | } else { | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8911 | phone.getDataSettingsManager().setDataEnabled( | 
|  | 8912 | reason, enabled, callingPackage); | 
| Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8913 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8914 | } | 
|  | 8915 | } finally { | 
|  | 8916 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8917 | } | 
|  | 8918 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8919 |  | 
|  | 8920 | /** | 
|  | 8921 | * Get Client request stats | 
|  | 8922 | * @return List of Client Request Stats | 
|  | 8923 | * @hide | 
|  | 8924 | */ | 
|  | 8925 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8926 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, | 
|  | 8927 | String callingFeatureId, int subId) { | 
| Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8928 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8929 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8930 | return null; | 
|  | 8931 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8932 | Phone phone = getPhone(subId); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8933 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8934 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8935 | try { | 
|  | 8936 | if (phone != null) { | 
|  | 8937 | return phone.getClientRequestStats(); | 
|  | 8938 | } | 
|  | 8939 |  | 
|  | 8940 | return null; | 
|  | 8941 | } finally { | 
|  | 8942 | Binder.restoreCallingIdentity(identity); | 
|  | 8943 | } | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8944 | } | 
|  | 8945 |  | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8946 | private WorkSource getWorkSource(int uid) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8947 | String packageName = mApp.getPackageManager().getNameForUid(uid); | 
| Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8948 | if (uid == Process.ROOT_UID && packageName == null) { | 
|  | 8949 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name | 
|  | 8950 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime | 
|  | 8951 | // exception. ROOT_UID seems not to have a valid package name returned by | 
|  | 8952 | // PackageManager, so just fake it here to avoid issues when running telephony shell | 
|  | 8953 | // commands that plumb through the RIL as root, like so: | 
|  | 8954 | // $ adb root | 
|  | 8955 | // $ adb shell cmd phone ... | 
|  | 8956 | packageName = "root"; | 
|  | 8957 | } | 
| Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8958 | return new WorkSource(uid, packageName); | 
| Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8959 | } | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8960 |  | 
|  | 8961 | /** | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8962 | * Set SIM card power state. | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8963 | * | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8964 | * @param slotIndex SIM slot id. | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8965 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 8966 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 8967 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 8968 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8969 | * | 
|  | 8970 | **/ | 
|  | 8971 | @Override | 
| Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8972 | public void setSimPowerStateForSlot(int slotIndex, int state) { | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8973 | enforceModifyPermission(); | 
| Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8974 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 8975 |  | 
| vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8976 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 8977 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | final long identity = Binder.clearCallingIdentity(); | 
|  | 8979 | try { | 
|  | 8980 | if (phone != null) { | 
| Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8981 | phone.setSimPowerState(state, null, workSource); | 
|  | 8982 | } | 
|  | 8983 | } finally { | 
|  | 8984 | Binder.restoreCallingIdentity(identity); | 
|  | 8985 | } | 
|  | 8986 | } | 
|  | 8987 |  | 
|  | 8988 | /** | 
|  | 8989 | * Set SIM card power state. | 
|  | 8990 | * | 
|  | 8991 | * @param slotIndex SIM slot id. | 
|  | 8992 | * @param state  State of SIM (power down, power up, pass through) | 
|  | 8993 | * @param callback  callback to trigger after success or failure | 
|  | 8994 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} | 
|  | 8995 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} | 
|  | 8996 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} | 
|  | 8997 | * | 
|  | 8998 | **/ | 
|  | 8999 | @Override | 
|  | 9000 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, | 
|  | 9001 | IIntegerConsumer callback) { | 
|  | 9002 | enforceModifyPermission(); | 
|  | 9003 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 9004 |  | 
|  | 9005 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 9006 |  | 
|  | 9007 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9008 | try { | 
|  | 9009 | if (phone != null) { | 
|  | 9010 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); | 
|  | 9011 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9012 | } | 
|  | 9013 | } finally { | 
|  | 9014 | Binder.restoreCallingIdentity(identity); | 
| Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 9015 | } | 
|  | 9016 | } | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9017 |  | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9018 | private boolean isUssdApiAllowed(int subId) { | 
|  | 9019 | CarrierConfigManager configManager = | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9020 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 9021 | if (configManager == null) { | 
|  | 9022 | return false; | 
|  | 9023 | } | 
|  | 9024 | PersistableBundle pb = configManager.getConfigForSubId(subId); | 
|  | 9025 | if (pb == null) { | 
|  | 9026 | return false; | 
|  | 9027 | } | 
|  | 9028 | return pb.getBoolean( | 
|  | 9029 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); | 
|  | 9030 | } | 
|  | 9031 |  | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9032 | /** | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9033 | * Check if phone is in emergency callback mode. | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9034 | * @return true if phone is in emergency callback mode | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9035 | * @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] | 9036 | */ | 
| goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 9037 | @Override | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9038 | public boolean getEmergencyCallbackMode(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9039 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9040 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9041 | try { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 9042 | return getPhoneFromSubIdOrDefault(subId).isInEcm(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9043 | } finally { | 
|  | 9044 | Binder.restoreCallingIdentity(identity); | 
| Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 9045 | } | 
|  | 9046 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9047 |  | 
|  | 9048 | /** | 
|  | 9049 | * Get the current signal strength information for the given subscription. | 
|  | 9050 | * Because this information is not updated when the device is in a low power state | 
|  | 9051 | * it should not be relied-upon to be current. | 
|  | 9052 | * @param subId Subscription index | 
|  | 9053 | * @return the most recent cached signal strength info from the modem | 
|  | 9054 | */ | 
|  | 9055 | @Override | 
|  | 9056 | public SignalStrength getSignalStrength(int subId) { | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9057 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9058 | try { | 
|  | 9059 | Phone p = getPhone(subId); | 
|  | 9060 | if (p == null) { | 
|  | 9061 | return null; | 
|  | 9062 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9063 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9064 | return p.getSignalStrength(); | 
|  | 9065 | } finally { | 
|  | 9066 | Binder.restoreCallingIdentity(identity); | 
|  | 9067 | } | 
| Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 9068 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9069 |  | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9070 | /** | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9071 | * Get the current modem radio state for the given slot. | 
|  | 9072 | * @param slotIndex slot index. | 
|  | 9073 | * @param callingPackage the name of the package making the call. | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9074 | * @param callingFeatureId The feature in the package. | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9075 | * @return the current radio power state from the modem | 
|  | 9076 | */ | 
|  | 9077 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9078 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9079 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 9080 | if (phone != null) { | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9081 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), | 
|  | 9082 | callingPackage, callingFeatureId, "getRadioPowerState")) { | 
| Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 9083 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 9084 | } | 
|  | 9085 |  | 
|  | 9086 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9087 | try { | 
|  | 9088 | return phone.getRadioPowerState(); | 
|  | 9089 | } finally { | 
|  | 9090 | Binder.restoreCallingIdentity(identity); | 
|  | 9091 | } | 
|  | 9092 | } | 
|  | 9093 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; | 
|  | 9094 | } | 
|  | 9095 |  | 
|  | 9096 | /** | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9097 | * Checks if data roaming is enabled on the subscription with id {@code subId}. | 
|  | 9098 | * | 
|  | 9099 | * <p>Requires one of the following permissions: | 
|  | 9100 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9101 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9102 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier | 
|  | 9103 | * privileges. | 
|  | 9104 | * | 
|  | 9105 | * @param subId subscription id | 
|  | 9106 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return | 
|  | 9107 | * {@code false}. | 
|  | 9108 | */ | 
|  | 9109 | @Override | 
|  | 9110 | public boolean isDataRoamingEnabled(int subId) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9111 | String functionName = "isDataRoamingEnabled"; | 
| Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9112 | try { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9113 | try { | 
|  | 9114 | mApp.enforceCallingOrSelfPermission( | 
|  | 9115 | android.Manifest.permission.ACCESS_NETWORK_STATE, | 
|  | 9116 | functionName); | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9117 | } catch (SecurityException e) { | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9118 | mApp.enforceCallingOrSelfPermission( | 
|  | 9119 | permission.READ_BASIC_PHONE_STATE, functionName); | 
|  | 9120 | } | 
| Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 9121 | } catch (SecurityException e) { | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9122 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( | 
| Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 9123 | mApp, subId, functionName); | 
| Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 9124 | } | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9125 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9126 | boolean isEnabled = false; | 
|  | 9127 | final long identity = Binder.clearCallingIdentity(); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9128 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9129 | Phone phone = getPhone(subId); | 
|  | 9130 | isEnabled =  phone != null ? phone.getDataRoamingEnabled() : false; | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9131 | } finally { | 
|  | 9132 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9133 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9134 | return isEnabled; | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9135 | } | 
|  | 9136 |  | 
|  | 9137 |  | 
|  | 9138 | /** | 
|  | 9139 | * Enables/Disables the data roaming on the subscription with id {@code subId}. | 
|  | 9140 | * | 
|  | 9141 | * <p> Requires permission: | 
|  | 9142 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier | 
|  | 9143 | * privileges. | 
|  | 9144 | * | 
|  | 9145 | * @param subId subscription id | 
|  | 9146 | * @param isEnabled {@code true} means enable, {@code false} means disable. | 
|  | 9147 | */ | 
|  | 9148 | @Override | 
|  | 9149 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9151 | mApp, subId, "setDataRoamingEnabled"); | 
|  | 9152 |  | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9153 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9154 | try { | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9155 | Phone phone = getPhone(subId); | 
|  | 9156 | if (phone != null) { | 
|  | 9157 | phone.setDataRoamingEnabled(isEnabled); | 
|  | 9158 | } | 
|  | 9159 | } finally { | 
|  | 9160 | Binder.restoreCallingIdentity(identity); | 
| Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 9161 | } | 
|  | 9162 | } | 
|  | 9163 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9164 | @Override | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9165 | public boolean isManualNetworkSelectionAllowed(int subId) { | 
| tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 9166 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9167 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9168 | mApp, subId, "isManualNetworkSelectionAllowed"); | 
| Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 9169 |  | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9170 | boolean isAllowed = true; | 
|  | 9171 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9172 | try { | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9173 | Phone phone = getPhone(subId); | 
|  | 9174 | if (phone != null) { | 
|  | 9175 | isAllowed = phone.isCspPlmnEnabled(); | 
|  | 9176 | } | 
|  | 9177 | } finally { | 
|  | 9178 | Binder.restoreCallingIdentity(identity); | 
|  | 9179 | } | 
|  | 9180 | return isAllowed; | 
|  | 9181 | } | 
|  | 9182 |  | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9183 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { | 
|  | 9184 | UiccProfile profile = port.getUiccProfile(); | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9185 | if (profile == null) { | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9186 | return false; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9187 | } | 
| Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 9188 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); | 
|  | 9189 | if (phone == null) { | 
|  | 9190 | return false; | 
|  | 9191 | } | 
|  | 9192 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 9193 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) | 
|  | 9194 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9195 | } | 
|  | 9196 |  | 
| Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 9197 | @Override | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9198 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9199 | // Verify that the callingPackage belongs to the calling UID | 
| Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 9200 | mApp.getSystemService(AppOpsManager.class) | 
|  | 9201 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 9202 |  | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9203 | boolean hasReadPermission = false; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9204 | boolean isIccIdAccessRestricted = false; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9205 | try { | 
|  | 9206 | enforceReadPrivilegedPermission("getUiccCardsInfo"); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9207 | hasReadPermission = true; | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9208 | } catch (SecurityException e) { | 
|  | 9209 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller | 
|  | 9210 | // has carrier privileges on an active UICC | 
| Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 9211 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9212 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9213 | throw new SecurityException("Caller does not have permission."); | 
| Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 9214 | } | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9215 | } | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9216 | // checking compatibility, if calling app's target SDK is T and beyond. | 
|  | 9217 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, | 
|  | 9218 | Binder.getCallingUid())) { | 
|  | 9219 | isIccIdAccessRestricted = true; | 
|  | 9220 | } | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9221 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9222 | try { | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9223 | UiccController uiccController = UiccController.getInstance(); | 
|  | 9224 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9225 | if (hasReadPermission) { | 
|  | 9226 | return cardInfos; | 
| Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 9227 | } | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9228 |  | 
|  | 9229 | // Remove private info if the caller doesn't have access | 
|  | 9230 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); | 
|  | 9231 | for (UiccCardInfo cardInfo : cardInfos) { | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9232 | //setting the value after compatibility check | 
|  | 9233 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9234 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo | 
|  | 9235 | // is available | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9236 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9237 | if (card == null) { | 
|  | 9238 | // assume no access if the card is unavailable | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9239 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9240 | continue; | 
|  | 9241 | } | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9242 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); | 
|  | 9243 | if (portInfos.isEmpty()) { | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9244 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9245 | continue; | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9246 | } | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9247 | List<UiccPortInfo> uiccPortInfos = new  ArrayList<>(); | 
|  | 9248 | for (UiccPortInfo portInfo : portInfos) { | 
|  | 9249 | UiccPort port = uiccController.getUiccPortForSlot( | 
|  | 9250 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); | 
|  | 9251 | if (port == null) { | 
|  | 9252 | // assume no access if port is null | 
|  | 9253 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); | 
|  | 9254 | continue; | 
|  | 9255 | } | 
|  | 9256 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { | 
|  | 9257 | uiccPortInfos.add(portInfo); | 
|  | 9258 | } else { | 
|  | 9259 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); | 
|  | 9260 | } | 
|  | 9261 | } | 
|  | 9262 | filteredInfos.add(new UiccCardInfo( | 
|  | 9263 | cardInfo.isEuicc(), | 
|  | 9264 | cardInfo.getCardId(), | 
|  | 9265 | null, | 
|  | 9266 | cardInfo.getPhysicalSlotIndex(), | 
|  | 9267 | cardInfo.isRemovable(), | 
|  | 9268 | cardInfo.isMultipleEnabledProfilesSupported(), | 
|  | 9269 | uiccPortInfos)); | 
| Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 9270 | } | 
|  | 9271 | return filteredInfos; | 
| Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 9272 | } finally { | 
|  | 9273 | Binder.restoreCallingIdentity(identity); | 
|  | 9274 | } | 
|  | 9275 | } | 
|  | 9276 |  | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9277 | /** | 
|  | 9278 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are | 
|  | 9279 | * generally private and require carrier privileges to view. | 
|  | 9280 | * | 
|  | 9281 | * @hide | 
|  | 9282 | */ | 
|  | 9283 | @NonNull | 
|  | 9284 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { | 
|  | 9285 | List<UiccPortInfo> portinfo = new  ArrayList<>(); | 
|  | 9286 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { | 
|  | 9287 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); | 
|  | 9288 | } | 
|  | 9289 | return new UiccCardInfo( | 
|  | 9290 | cardInfo.isEuicc(), | 
|  | 9291 | cardInfo.getCardId(), | 
|  | 9292 | null, | 
|  | 9293 | cardInfo.getPhysicalSlotIndex(), | 
|  | 9294 | cardInfo.isRemovable(), | 
|  | 9295 | cardInfo.isMultipleEnabledProfilesSupported(), | 
|  | 9296 | portinfo | 
|  | 9297 | ); | 
|  | 9298 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9299 |  | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9300 | /** | 
|  | 9301 | * @hide | 
|  | 9302 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. | 
|  | 9303 | * These values are generally private and require carrier privileges to view. | 
|  | 9304 | */ | 
|  | 9305 | @NonNull | 
|  | 9306 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { | 
|  | 9307 | return new UiccPortInfo( | 
|  | 9308 | UiccPortInfo.ICCID_REDACTED, | 
|  | 9309 | portInfo.getPortIndex(), | 
|  | 9310 | portInfo.getLogicalSlotIndex(), | 
|  | 9311 | portInfo.isActive() | 
|  | 9312 | ); | 
|  | 9313 | } | 
|  | 9314 | @Override | 
|  | 9315 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9316 | // Verify that the callingPackage belongs to the calling UID | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9317 | mApp.getSystemService(AppOpsManager.class) | 
|  | 9318 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 9319 |  | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9320 | boolean isLogicalSlotAccessRestricted = false; | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9321 |  | 
| Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9322 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as | 
|  | 9323 | // we are reading iccId which is PII data. | 
|  | 9324 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9325 |  | 
|  | 9326 | // checking compatibility, if calling app's target SDK is T and beyond. | 
|  | 9327 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, | 
|  | 9328 | Binder.getCallingUid())) { | 
|  | 9329 | isLogicalSlotAccessRestricted  = true; | 
|  | 9330 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9331 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9332 | try { | 
|  | 9333 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); | 
| Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9334 | if (slots == null || slots.length == 0) { | 
|  | 9335 | Rlog.i(LOG_TAG, "slots is null or empty."); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9336 | return null; | 
|  | 9337 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9338 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; | 
|  | 9339 | for (int i = 0; i < slots.length; i++) { | 
|  | 9340 | UiccSlot slot = slots[i]; | 
|  | 9341 | if (slot == null) { | 
|  | 9342 | continue; | 
|  | 9343 | } | 
|  | 9344 |  | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9345 | String cardId; | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9346 | UiccCard card = slot.getUiccCard(); | 
|  | 9347 | if (card != null) { | 
|  | 9348 | cardId = card.getCardId(); | 
| Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9349 | } else { | 
| Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9350 | cardId = slot.getEid(); | 
|  | 9351 | if (TextUtils.isEmpty(cardId)) { | 
| Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9352 | // If cardId is null, use iccId of default port as cardId. | 
|  | 9353 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); | 
| Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9354 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9355 | } | 
|  | 9356 |  | 
| Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9357 | if (cardId != null) { | 
|  | 9358 | // if cardId is an ICCID, strip off trailing Fs before exposing to user | 
|  | 9359 | // if cardId is an EID, it's all digits so this is fine | 
|  | 9360 | cardId = IccUtils.stripTrailingFs(cardId); | 
|  | 9361 | } | 
|  | 9362 |  | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9363 | int cardState = 0; | 
|  | 9364 | switch (slot.getCardState()) { | 
|  | 9365 | case CARDSTATE_ABSENT: | 
|  | 9366 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; | 
|  | 9367 | break; | 
|  | 9368 | case CARDSTATE_PRESENT: | 
|  | 9369 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; | 
|  | 9370 | break; | 
|  | 9371 | case CARDSTATE_ERROR: | 
|  | 9372 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; | 
|  | 9373 | break; | 
|  | 9374 | case CARDSTATE_RESTRICTED: | 
|  | 9375 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; | 
|  | 9376 | break; | 
|  | 9377 | default: | 
|  | 9378 | break; | 
|  | 9379 |  | 
|  | 9380 | } | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9381 | List<UiccPortInfo> portInfos = new ArrayList<>(); | 
|  | 9382 | int[] portIndexes = slot.getPortList(); | 
|  | 9383 | for (int portIdx : portIndexes) { | 
|  | 9384 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, | 
| Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9385 | callingPackage, /* hasReadPermission= */ true)); | 
| Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9386 | portInfos.add(new UiccPortInfo(iccId, portIdx, | 
|  | 9387 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9388 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9389 | infos[i] = new UiccSlotInfo( | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9390 | slot.isEuicc(), | 
|  | 9391 | cardId, | 
|  | 9392 | cardState, | 
| Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9393 | slot.isExtendedApduSupported(), | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9394 | slot.isRemovable(), portInfos); | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9395 | //setting the value after compatibility check | 
|  | 9396 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9397 | } | 
|  | 9398 | return infos; | 
|  | 9399 | } finally { | 
|  | 9400 | Binder.restoreCallingIdentity(identity); | 
| Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9401 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9402 | } | 
|  | 9403 |  | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9404 | /* Returns null if doesn't have read permission or carrier privilege access. */ | 
|  | 9405 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, | 
|  | 9406 | boolean hasReadPermission) { | 
|  | 9407 | String iccId = slot.getIccId(portIndex); | 
|  | 9408 | if (hasReadPermission) { // if has read permission | 
|  | 9409 | return iccId; | 
|  | 9410 | } else { | 
|  | 9411 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { | 
|  | 9412 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); | 
|  | 9413 | // if no read permission, checking carrier privilege access | 
|  | 9414 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { | 
|  | 9415 | return iccId; | 
|  | 9416 | } | 
|  | 9417 | } | 
|  | 9418 | } | 
|  | 9419 | // No read permission or carrier privilege access. | 
|  | 9420 | return UiccPortInfo.ICCID_REDACTED; | 
|  | 9421 | } | 
|  | 9422 |  | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9423 | @Override | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9424 | @Deprecated | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9425 | public boolean switchSlots(int[] physicalSlots) { | 
|  | 9426 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9427 |  | 
|  | 9428 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9429 | try { | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9430 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); | 
|  | 9431 | for (int i = 0; i < physicalSlots.length; i++) { | 
|  | 9432 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. | 
|  | 9433 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, | 
|  | 9434 | physicalSlots[i], i)); | 
|  | 9435 | } | 
|  | 9436 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9437 | } finally { | 
|  | 9438 | Binder.restoreCallingIdentity(identity); | 
|  | 9439 | } | 
| Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9440 | } | 
| Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9441 |  | 
|  | 9442 | @Override | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9443 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 9444 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { | 
|  | 9445 | enforceModifyPermission(); | 
|  | 9446 |  | 
|  | 9447 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9448 | try { | 
| Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9449 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); | 
| sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9450 | } finally { | 
|  | 9451 | Binder.restoreCallingIdentity(identity); | 
|  | 9452 | } | 
|  | 9453 | } | 
|  | 9454 |  | 
|  | 9455 | @Override | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9456 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { | 
| Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9457 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9458 | try { | 
|  | 9459 | return UiccController.getInstance().getCardIdForDefaultEuicc(); | 
|  | 9460 | } finally { | 
|  | 9461 | Binder.restoreCallingIdentity(identity); | 
|  | 9462 | } | 
|  | 9463 | } | 
|  | 9464 |  | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9465 | /** | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9466 | * A test API to reload the UICC profile. | 
|  | 9467 | * | 
|  | 9468 | * <p>Requires that the calling app has permission | 
|  | 9469 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. | 
|  | 9470 | * @hide | 
|  | 9471 | */ | 
|  | 9472 | @Override | 
|  | 9473 | public void refreshUiccProfile(int subId) { | 
|  | 9474 | enforceModifyPermission(); | 
|  | 9475 |  | 
|  | 9476 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9477 | try { | 
|  | 9478 | Phone phone = getPhone(subId); | 
|  | 9479 | if (phone == null) { | 
|  | 9480 | return; | 
|  | 9481 | } | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9482 | UiccPort uiccPort = phone.getUiccPort(); | 
|  | 9483 | if (uiccPort == null) { | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9484 | return; | 
|  | 9485 | } | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9486 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); | 
| goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9487 | if (uiccProfile == null) { | 
|  | 9488 | return; | 
|  | 9489 | } | 
|  | 9490 | uiccProfile.refresh(); | 
|  | 9491 | } finally { | 
|  | 9492 | Binder.restoreCallingIdentity(identity); | 
|  | 9493 | } | 
|  | 9494 | } | 
|  | 9495 |  | 
|  | 9496 | /** | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9497 | * Returns false if the mobile data is disabled by default, otherwise return true. | 
|  | 9498 | */ | 
|  | 9499 | private boolean getDefaultDataEnabled() { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9500 | return TelephonyProperties.mobile_data().orElse(true); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9501 | } | 
|  | 9502 |  | 
|  | 9503 | /** | 
|  | 9504 | * Returns true if the data roaming is enabled by default, i.e the system property | 
|  | 9505 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of | 
|  | 9506 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. | 
|  | 9507 | */ | 
|  | 9508 | private boolean getDefaultDataRoamingEnabled(int subId) { | 
|  | 9509 | final CarrierConfigManager configMgr = (CarrierConfigManager) | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9510 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); | 
| Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9511 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9512 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( | 
|  | 9513 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); | 
|  | 9514 | return isDataRoamingEnabled; | 
|  | 9515 | } | 
|  | 9516 |  | 
|  | 9517 | /** | 
|  | 9518 | * Returns the default network type for the given {@code subId}, if the default network type is | 
|  | 9519 | * not set, return {@link Phone#PREFERRED_NT_MODE}. | 
|  | 9520 | */ | 
|  | 9521 | private int getDefaultNetworkType(int subId) { | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9522 | List<Integer> list = TelephonyProperties.default_network(); | 
| Jack Yu | 285100e | 2022-12-02 22:48:35 -0800 | [diff] [blame] | 9523 | int phoneId = SubscriptionManager.getPhoneId(subId); | 
| Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9524 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { | 
|  | 9525 | return list.get(phoneId); | 
|  | 9526 | } | 
|  | 9527 | return Phone.PREFERRED_NT_MODE; | 
| Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9528 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9529 |  | 
|  | 9530 | @Override | 
|  | 9531 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String | 
| chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9532 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9533 | enforceModifyPermission(); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9534 |  | 
|  | 9535 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9536 | try { | 
|  | 9537 | final Phone phone = getPhone(subId); | 
|  | 9538 | if (phone == null) { | 
|  | 9539 | loge("setCarrierTestOverride fails with invalid subId: " + subId); | 
|  | 9540 | return; | 
|  | 9541 | } | 
| Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9542 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 9543 | if (cpt != null) { | 
|  | 9544 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); | 
|  | 9545 | } | 
|  | 9546 | // 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] | 9547 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, | 
|  | 9548 | carrierPrivilegeRules, apn); | 
| Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9549 | if (carrierPrivilegeRules == null) { | 
|  | 9550 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); | 
|  | 9551 | } else { | 
|  | 9552 | mCarrierPrivilegeTestOverrideSubIds.add(subId); | 
|  | 9553 | } | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9554 | } finally { | 
|  | 9555 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9556 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9557 | } | 
|  | 9558 |  | 
|  | 9559 | @Override | 
| Benedict Wong | 6647762 | 2023-02-03 23:30:57 +0000 | [diff] [blame] | 9560 | public void setCarrierServicePackageOverride( | 
|  | 9561 | int subId, String carrierServicePackage, String callingPackage) { | 
|  | 9562 | TelephonyPermissions.enforceShellOnly( | 
|  | 9563 | Binder.getCallingUid(), "setCarrierServicePackageOverride"); | 
|  | 9564 |  | 
|  | 9565 | // Verify that the callingPackage belongs to the calling UID | 
|  | 9566 | mApp.getSystemService(AppOpsManager.class) | 
|  | 9567 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 9568 |  | 
|  | 9569 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9570 | try { | 
|  | 9571 | final Phone phone = getPhone(subId); | 
|  | 9572 | if (phone == null || phone.getSubId() != subId) { | 
|  | 9573 | loge("setCarrierServicePackageOverride fails with invalid subId: " + subId); | 
|  | 9574 | throw new IllegalArgumentException("No phone for subid"); | 
|  | 9575 | } | 
|  | 9576 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); | 
|  | 9577 | if (cpt == null) { | 
|  | 9578 | loge("setCarrierServicePackageOverride failed with no CPT for phone"); | 
|  | 9579 | throw new IllegalStateException("No CPT for phone"); | 
|  | 9580 | } | 
|  | 9581 | cpt.setTestOverrideCarrierServicePackage(carrierServicePackage); | 
|  | 9582 | } finally { | 
|  | 9583 | Binder.restoreCallingIdentity(identity); | 
|  | 9584 | } | 
|  | 9585 | } | 
|  | 9586 |  | 
|  | 9587 | @Override | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9588 | public int getCarrierIdListVersion(int subId) { | 
| Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9589 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); | 
| Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9590 |  | 
|  | 9591 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9592 | try { | 
|  | 9593 | final Phone phone = getPhone(subId); | 
|  | 9594 | if (phone == null) { | 
|  | 9595 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); | 
|  | 9596 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; | 
|  | 9597 | } | 
|  | 9598 | return phone.getCarrierIdListVersion(); | 
|  | 9599 | } finally { | 
|  | 9600 | Binder.restoreCallingIdentity(identity); | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9601 | } | 
| fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9602 | } | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9603 |  | 
|  | 9604 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9605 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, | 
|  | 9606 | String callingFeatureId) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9608 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 9609 | "getNumberOfModemsWithSimultaneousDataConnections")) { | 
| Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9610 | return -1; | 
|  | 9611 | } | 
|  | 9612 |  | 
|  | 9613 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9614 | try { | 
|  | 9615 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); | 
|  | 9616 | } finally { | 
|  | 9617 | Binder.restoreCallingIdentity(identity); | 
|  | 9618 | } | 
|  | 9619 | } | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9620 |  | 
|  | 9621 | @Override | 
|  | 9622 | public int getCdmaRoamingMode(int subId) { | 
| zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9623 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9624 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9625 | mApp, subId, "getCdmaRoamingMode"); | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9626 |  | 
|  | 9627 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9628 | try { | 
|  | 9629 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); | 
|  | 9630 | } finally { | 
|  | 9631 | Binder.restoreCallingIdentity(identity); | 
|  | 9632 | } | 
|  | 9633 | } | 
|  | 9634 |  | 
|  | 9635 | @Override | 
|  | 9636 | public boolean setCdmaRoamingMode(int subId, int mode) { | 
|  | 9637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9638 | mApp, subId, "setCdmaRoamingMode"); | 
|  | 9639 |  | 
|  | 9640 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9641 | try { | 
|  | 9642 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); | 
|  | 9643 | } finally { | 
|  | 9644 | Binder.restoreCallingIdentity(identity); | 
|  | 9645 | } | 
|  | 9646 | } | 
|  | 9647 |  | 
|  | 9648 | @Override | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9649 | public int getCdmaSubscriptionMode(int subId) { | 
|  | 9650 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9651 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9652 | mApp, subId, "getCdmaSubscriptionMode"); | 
|  | 9653 |  | 
|  | 9654 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9655 | try { | 
|  | 9656 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); | 
|  | 9657 | } finally { | 
|  | 9658 | Binder.restoreCallingIdentity(identity); | 
|  | 9659 | } | 
|  | 9660 | } | 
|  | 9661 |  | 
|  | 9662 | @Override | 
| Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9663 | public boolean setCdmaSubscriptionMode(int subId, int mode) { | 
|  | 9664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 9665 | mApp, subId, "setCdmaSubscriptionMode"); | 
|  | 9666 |  | 
|  | 9667 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9668 | try { | 
|  | 9669 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); | 
|  | 9670 | } finally { | 
|  | 9671 | Binder.restoreCallingIdentity(identity); | 
|  | 9672 | } | 
|  | 9673 | } | 
| Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9674 |  | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9675 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9676 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9677 | String callingPackage, String callingFeatureId) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9679 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, | 
|  | 9680 | "getEmergencyNumberList")) { | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9681 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 9682 | } | 
|  | 9683 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9684 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9685 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); | 
|  | 9686 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9687 | if (phone.getEmergencyNumberTracker() != null | 
|  | 9688 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { | 
|  | 9689 | emergencyNumberListInternal.put( | 
|  | 9690 | phone.getSubId(), | 
|  | 9691 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); | 
|  | 9692 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9693 | } | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9694 | return emergencyNumberListInternal; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9695 | } finally { | 
|  | 9696 | Binder.restoreCallingIdentity(identity); | 
|  | 9697 | } | 
| sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9698 | } | 
|  | 9699 |  | 
|  | 9700 | @Override | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9701 | public boolean isEmergencyNumber(String number, boolean exactMatch) { | 
| Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9702 | final Phone defaultPhone = getDefaultPhone(); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9703 | if (!exactMatch) { | 
|  | 9704 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9705 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9706 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9707 | } | 
|  | 9708 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9709 | try { | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9710 | for (Phone phone: PhoneFactory.getPhones()) { | 
| Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9711 | //Note: we ignore passed in param exactMatch. We can remove it once | 
|  | 9712 | // TelephonyManager#isPotentialEmergencyNumber is removed completely | 
| sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9713 | if (phone.getEmergencyNumberTracker() != null | 
| Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9714 | && phone.getEmergencyNumberTracker() | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 9715 | .isEmergencyNumber(number)) { | 
| Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9716 | return true; | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9717 | } | 
| sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9718 | } | 
|  | 9719 | return false; | 
|  | 9720 | } finally { | 
|  | 9721 | Binder.restoreCallingIdentity(identity); | 
|  | 9722 | } | 
|  | 9723 | } | 
|  | 9724 |  | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9725 | /** | 
| Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9726 | * Start emergency callback mode for GsmCdmaPhone for testing. | 
|  | 9727 | */ | 
|  | 9728 | @Override | 
|  | 9729 | public void startEmergencyCallbackMode() { | 
|  | 9730 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9731 | "startEmergencyCallbackMode"); | 
|  | 9732 | enforceModifyPermission(); | 
|  | 9733 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9734 | try { | 
|  | 9735 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 9736 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); | 
|  | 9737 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) | 
|  | 9738 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { | 
|  | 9739 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; | 
|  | 9740 | gsmCdmaPhone.obtainMessage( | 
|  | 9741 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); | 
|  | 9742 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); | 
|  | 9743 | } | 
|  | 9744 | } | 
|  | 9745 | } finally { | 
|  | 9746 | Binder.restoreCallingIdentity(identity); | 
|  | 9747 | } | 
|  | 9748 | } | 
|  | 9749 |  | 
|  | 9750 | /** | 
| sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9751 | * Update emergency number list for test mode. | 
|  | 9752 | */ | 
|  | 9753 | @Override | 
|  | 9754 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { | 
|  | 9755 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9756 | "updateEmergencyNumberListTestMode"); | 
|  | 9757 |  | 
|  | 9758 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9759 | try { | 
|  | 9760 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9761 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 9762 | if (tracker != null) { | 
|  | 9763 | tracker.executeEmergencyNumberTestModeCommand(action, num); | 
|  | 9764 | } | 
|  | 9765 | } | 
|  | 9766 | } finally { | 
|  | 9767 | Binder.restoreCallingIdentity(identity); | 
|  | 9768 | } | 
|  | 9769 | } | 
|  | 9770 |  | 
|  | 9771 | /** | 
|  | 9772 | * Get the full emergency number list for test mode. | 
|  | 9773 | */ | 
|  | 9774 | @Override | 
|  | 9775 | public List<String> getEmergencyNumberListTestMode() { | 
|  | 9776 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 9777 | "getEmergencyNumberListTestMode"); | 
|  | 9778 |  | 
|  | 9779 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9780 | try { | 
|  | 9781 | Set<String> emergencyNumbers = new HashSet<>(); | 
|  | 9782 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9783 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 9784 | if (tracker != null) { | 
|  | 9785 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { | 
|  | 9786 | emergencyNumbers.add(num.getNumber()); | 
|  | 9787 | } | 
|  | 9788 | } | 
|  | 9789 | } | 
|  | 9790 | return new ArrayList<>(emergencyNumbers); | 
|  | 9791 | } finally { | 
|  | 9792 | Binder.restoreCallingIdentity(identity); | 
|  | 9793 | } | 
|  | 9794 | } | 
|  | 9795 |  | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9796 | @Override | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9797 | public int getEmergencyNumberDbVersion(int subId) { | 
|  | 9798 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); | 
|  | 9799 |  | 
|  | 9800 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9801 | try { | 
|  | 9802 | final Phone phone = getPhone(subId); | 
|  | 9803 | if (phone == null) { | 
|  | 9804 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); | 
|  | 9805 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; | 
|  | 9806 | } | 
|  | 9807 | return phone.getEmergencyNumberDbVersion(); | 
|  | 9808 | } finally { | 
|  | 9809 | Binder.restoreCallingIdentity(identity); | 
|  | 9810 | } | 
|  | 9811 | } | 
|  | 9812 |  | 
|  | 9813 | @Override | 
|  | 9814 | public void notifyOtaEmergencyNumberDbInstalled() { | 
|  | 9815 | enforceModifyPermission(); | 
|  | 9816 |  | 
|  | 9817 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9818 | try { | 
|  | 9819 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9820 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 9821 | if (tracker != null) { | 
|  | 9822 | tracker.updateOtaEmergencyNumberDatabase(); | 
|  | 9823 | } | 
|  | 9824 | } | 
|  | 9825 | } finally { | 
|  | 9826 | Binder.restoreCallingIdentity(identity); | 
|  | 9827 | } | 
|  | 9828 | } | 
|  | 9829 |  | 
|  | 9830 | @Override | 
| Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9831 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9832 | enforceActiveEmergencySessionPermission(); | 
|  | 9833 |  | 
|  | 9834 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9835 | try { | 
|  | 9836 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9837 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 9838 | if (tracker != null) { | 
| Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9839 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); | 
|  | 9840 | } | 
|  | 9841 | } | 
|  | 9842 | } finally { | 
|  | 9843 | Binder.restoreCallingIdentity(identity); | 
|  | 9844 | } | 
|  | 9845 | } | 
|  | 9846 |  | 
|  | 9847 | @Override | 
|  | 9848 | public void resetOtaEmergencyNumberDbFilePath() { | 
|  | 9849 | enforceActiveEmergencySessionPermission(); | 
|  | 9850 |  | 
|  | 9851 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9852 | try { | 
|  | 9853 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 9854 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); | 
|  | 9855 | if (tracker != null) { | 
|  | 9856 | tracker.resetOtaEmergencyNumberDbFilePath(); | 
| Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9857 | } | 
|  | 9858 | } | 
|  | 9859 | } finally { | 
|  | 9860 | Binder.restoreCallingIdentity(identity); | 
|  | 9861 | } | 
|  | 9862 | } | 
|  | 9863 |  | 
|  | 9864 | @Override | 
| chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9865 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { | 
|  | 9866 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); | 
|  | 9867 | Phone phone = getPhone(subId); | 
|  | 9868 | if (phone == null) { | 
|  | 9869 | return null; | 
|  | 9870 | } | 
|  | 9871 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9872 | try { | 
|  | 9873 | UiccProfile profile = UiccController.getInstance() | 
|  | 9874 | .getUiccProfileForPhone(phone.getPhoneId()); | 
|  | 9875 | if (profile != null) { | 
|  | 9876 | return profile.getCertsFromCarrierPrivilegeAccessRules(); | 
|  | 9877 | } | 
|  | 9878 | } finally { | 
|  | 9879 | Binder.restoreCallingIdentity(identity); | 
|  | 9880 | } | 
|  | 9881 | return null; | 
|  | 9882 | } | 
| Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9883 |  | 
|  | 9884 | /** | 
|  | 9885 | * Enable or disable a modem stack. | 
|  | 9886 | */ | 
|  | 9887 | @Override | 
|  | 9888 | public boolean enableModemForSlot(int slotIndex, boolean enable) { | 
|  | 9889 | enforceModifyPermission(); | 
|  | 9890 |  | 
|  | 9891 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9892 | try { | 
|  | 9893 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 9894 | if (phone == null) { | 
|  | 9895 | return false; | 
|  | 9896 | } else { | 
|  | 9897 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); | 
|  | 9898 | } | 
|  | 9899 | } finally { | 
|  | 9900 | Binder.restoreCallingIdentity(identity); | 
|  | 9901 | } | 
|  | 9902 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9903 |  | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9904 | /** | 
|  | 9905 | * Whether a modem stack is enabled or not. | 
|  | 9906 | */ | 
|  | 9907 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9908 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, | 
|  | 9909 | String callingFeatureId) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9910 | Phone phone = PhoneFactory.getPhone(slotIndex); | 
|  | 9911 | if (phone == null) return false; | 
|  | 9912 |  | 
|  | 9913 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9914 | mApp, phone.getSubId(), callingPackage, callingFeatureId, | 
|  | 9915 | "isModemEnabledForSlot")) { | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9916 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 9917 | } | 
|  | 9918 |  | 
|  | 9919 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9920 | try { | 
| Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9921 | try { | 
|  | 9922 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); | 
|  | 9923 | } catch (NoSuchElementException ex) { | 
|  | 9924 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); | 
|  | 9925 | } | 
| Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9926 | } finally { | 
|  | 9927 | Binder.restoreCallingIdentity(identity); | 
|  | 9928 | } | 
|  | 9929 | } | 
|  | 9930 |  | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9931 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9932 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9933 | enforceModifyPermission(); | 
|  | 9934 |  | 
|  | 9935 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9936 | try { | 
|  | 9937 | mTelephonySharedPreferences.edit() | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9938 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9939 | .commit(); | 
|  | 9940 | } finally { | 
|  | 9941 | Binder.restoreCallingIdentity(identity); | 
|  | 9942 | } | 
|  | 9943 | } | 
|  | 9944 |  | 
|  | 9945 | @Override | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9946 | @TelephonyManager.IsMultiSimSupportedResult | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9947 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9948 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9949 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, | 
|  | 9950 | "isMultiSimSupported")) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9951 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9952 | } | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9953 |  | 
|  | 9954 | final long identity = Binder.clearCallingIdentity(); | 
|  | 9955 | try { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9956 | return isMultiSimSupportedInternal(); | 
| Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9957 | } finally { | 
|  | 9958 | Binder.restoreCallingIdentity(identity); | 
|  | 9959 | } | 
|  | 9960 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9961 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9962 | @TelephonyManager.IsMultiSimSupportedResult | 
|  | 9963 | private int isMultiSimSupportedInternal() { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9964 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. | 
|  | 9965 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; | 
|  | 9966 | if (numPhysicalSlots < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9967 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); | 
|  | 9968 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9969 | } | 
|  | 9970 | // Check if the hardware supports multisim functionality. If usage of multisim is not | 
|  | 9971 | // supported by the modem, indicate that it is restricted. | 
|  | 9972 | PhoneCapability staticCapability = | 
|  | 9973 | mPhoneConfigurationManager.getStaticPhoneCapability(); | 
|  | 9974 | if (staticCapability == null) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9975 | loge("isMultiSimSupportedInternal: no static configuration available"); | 
|  | 9976 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9977 | } | 
| SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9978 | if (staticCapability.getLogicalModemList().size() < 2) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9979 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); | 
|  | 9980 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9981 | } | 
|  | 9982 | // Check if support of multiple SIMs is restricted by carrier | 
|  | 9983 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9984 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9985 | } | 
|  | 9986 |  | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9987 | return TelephonyManager.MULTISIM_ALLOWED; | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9988 | } | 
|  | 9989 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9990 | /** | 
|  | 9991 | * Switch configs to enable multi-sim or switch back to single-sim | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9992 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE | 
|  | 9993 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE | 
|  | 9994 | * or carrier privileges | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9995 | * @param numOfSims number of active sims we want to switch to | 
|  | 9996 | */ | 
|  | 9997 | @Override | 
|  | 9998 | public void switchMultiSimConfig(int numOfSims) { | 
| Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9999 | if (numOfSims == 1) { | 
|  | 10000 | enforceModifyPermission(); | 
|  | 10001 | } else { | 
|  | 10002 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 10003 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); | 
|  | 10004 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10005 | final long identity = Binder.clearCallingIdentity(); | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10006 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10007 | try { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10008 | //only proceed if multi-sim is not restricted | 
| Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 10009 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { | 
| Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 10010 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); | 
|  | 10011 | return; | 
|  | 10012 | } | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10013 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); | 
|  | 10014 | } finally { | 
|  | 10015 | Binder.restoreCallingIdentity(identity); | 
|  | 10016 | } | 
|  | 10017 | } | 
|  | 10018 |  | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10019 | @Override | 
|  | 10020 | public boolean isApplicationOnUicc(int subId, int appType) { | 
|  | 10021 | enforceReadPrivilegedPermission("isApplicationOnUicc"); | 
|  | 10022 | Phone phone = getPhone(subId); | 
|  | 10023 | if (phone == null) { | 
|  | 10024 | return false; | 
|  | 10025 | } | 
|  | 10026 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10027 | try { | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10028 | UiccPort uiccPort = phone.getUiccPort(); | 
|  | 10029 | if (uiccPort == null) { | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10030 | return false; | 
|  | 10031 | } | 
| Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 10032 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); | 
| Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 10033 | if (uiccProfile == null) { | 
|  | 10034 | return false; | 
|  | 10035 | } | 
|  | 10036 | if (TelephonyManager.APPTYPE_SIM <= appType | 
|  | 10037 | && appType <= TelephonyManager.APPTYPE_ISIM) { | 
|  | 10038 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); | 
|  | 10039 | } | 
|  | 10040 | return false; | 
|  | 10041 | } finally { | 
|  | 10042 | Binder.restoreCallingIdentity(identity); | 
|  | 10043 | } | 
|  | 10044 | } | 
|  | 10045 |  | 
| Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 10046 | /** | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10047 | * Get whether making changes to modem configurations will trigger reboot. | 
|  | 10048 | * Return value defaults to true. | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10049 | */ | 
|  | 10050 | @Override | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10051 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, | 
|  | 10052 | String callingFeatureId) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10053 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
| Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 10054 | mApp, subId, callingPackage, callingFeatureId, | 
|  | 10055 | "doesSwitchMultiSimConfigTriggerReboot")) { | 
| chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 10056 | return false; | 
|  | 10057 | } | 
| Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 10058 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10059 | try { | 
|  | 10060 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); | 
|  | 10061 | } finally { | 
|  | 10062 | Binder.restoreCallingIdentity(identity); | 
|  | 10063 | } | 
|  | 10064 | } | 
|  | 10065 |  | 
| Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 10066 | private void updateModemStateMetrics() { | 
|  | 10067 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); | 
|  | 10068 | // TODO: check the state for each modem if the api is ready. | 
|  | 10069 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); | 
|  | 10070 | } | 
|  | 10071 |  | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10072 | @Override | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10073 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10074 | enforceReadPrivilegedPermission("getSlotsMapping"); | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10075 | // Verify that the callingPackage belongs to the calling UID | 
|  | 10076 | mApp.getSystemService(AppOpsManager.class) | 
|  | 10077 | .checkPackage(Binder.getCallingUid(), callingPackage); | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10078 | final long identity = Binder.clearCallingIdentity(); | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10079 | List<UiccSlotMapping> slotMap = new ArrayList<>(); | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10080 | try { | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10081 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); | 
|  | 10082 | if (slotInfos != null) { | 
|  | 10083 | for (int i = 0; i < slotInfos.length; i++) { | 
|  | 10084 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { | 
|  | 10085 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { | 
|  | 10086 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, | 
|  | 10087 | portInfo.getLogicalSlotIndex())); | 
|  | 10088 | } | 
|  | 10089 | } | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10090 | } | 
|  | 10091 | } | 
| sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 10092 | return slotMap; | 
| Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 10093 | } finally { | 
|  | 10094 | Binder.restoreCallingIdentity(identity); | 
|  | 10095 | } | 
|  | 10096 | } | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10097 |  | 
|  | 10098 | /** | 
|  | 10099 | * Get the IRadio HAL Version | 
| jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10100 | * @deprecated use getHalVersion instead | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10101 | */ | 
| jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10102 | @Deprecated | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10103 | @Override | 
|  | 10104 | public int getRadioHalVersion() { | 
| jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10105 | return getHalVersion(HAL_SERVICE_RADIO); | 
|  | 10106 | } | 
|  | 10107 |  | 
|  | 10108 | /** | 
|  | 10109 | * Get the HAL Version of a specific service | 
|  | 10110 | */ | 
|  | 10111 | @Override | 
|  | 10112 | public int getHalVersion(int service) { | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10113 | Phone phone = getDefaultPhone(); | 
|  | 10114 | if (phone == null) return -1; | 
| jimsun | f9ec162 | 2022-09-13 21:18:43 +0800 | [diff] [blame] | 10115 | HalVersion hv = phone.getHalVersion(service); | 
| Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 10116 | if (hv.equals(HalVersion.UNKNOWN)) return -1; | 
|  | 10117 | return hv.major * 100 + hv.minor; | 
|  | 10118 | } | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10119 |  | 
|  | 10120 | /** | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10121 | * Get the current calling package name. | 
|  | 10122 | * @return the current calling package name | 
|  | 10123 | */ | 
|  | 10124 | @Override | 
|  | 10125 | public String getCurrentPackageName() { | 
|  | 10126 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; | 
|  | 10127 | } | 
|  | 10128 |  | 
|  | 10129 | /** | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10130 | * Return whether data is enabled for certain APN type. This will tell if framework will accept | 
|  | 10131 | * corresponding network requests on a subId. | 
|  | 10132 | * | 
|  | 10133 | *  Data is enabled if: | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10134 | *  1) user data is turned on, or | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10135 | *  2) APN is un-metered for this subscription, or | 
|  | 10136 | *  3) APN type is whitelisted. E.g. MMS is whitelisted if | 
| Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10137 | *  {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10138 | * | 
|  | 10139 | * @return whether data is allowed for a apn type. | 
|  | 10140 | * | 
|  | 10141 | * @hide | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10142 | */ | 
|  | 10143 | @Override | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10144 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { | 
| Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 10145 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " | 
|  | 10146 | + "isDataEnabledForApn"); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10147 |  | 
|  | 10148 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10149 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10150 | try { | 
|  | 10151 | Phone phone = getPhone(subId); | 
|  | 10152 | if (phone == null) return false; | 
|  | 10153 |  | 
| Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 10154 | boolean isMetered; | 
| Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10155 | boolean isDataEnabled; | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10156 | isMetered = phone.getDataNetworkController().getDataConfigManager() | 
|  | 10157 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), | 
|  | 10158 | phone.getServiceState().getDataRoaming()); | 
|  | 10159 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); | 
| Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 10160 | return !isMetered || isDataEnabled; | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10161 | } finally { | 
|  | 10162 | Binder.restoreCallingIdentity(identity); | 
|  | 10163 | } | 
|  | 10164 | } | 
|  | 10165 |  | 
|  | 10166 | @Override | 
| Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 10167 | public boolean isApnMetered(@ApnType int apnType, int subId) { | 
| Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 10168 | enforceReadPrivilegedPermission("isApnMetered"); | 
|  | 10169 |  | 
|  | 10170 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10171 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10172 | try { | 
|  | 10173 | Phone phone = getPhone(subId); | 
|  | 10174 | if (phone == null) return true; // By default return true. | 
| Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 10175 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( | 
|  | 10176 | DataUtils.apnTypeToNetworkCapability(apnType), | 
|  | 10177 | phone.getServiceState().getDataRoaming()); | 
| Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 10178 | } finally { | 
|  | 10179 | Binder.restoreCallingIdentity(identity); | 
|  | 10180 | } | 
|  | 10181 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10182 |  | 
|  | 10183 | @Override | 
| Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 10184 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, | 
|  | 10185 | int subscriptionId, IBooleanConsumer resultCallback) { | 
|  | 10186 | enforceModifyPermission(); | 
|  | 10187 | long token = Binder.clearCallingIdentity(); | 
|  | 10188 | try { | 
|  | 10189 | Phone phone = getPhone(subscriptionId); | 
|  | 10190 | if (phone == null) { | 
|  | 10191 | try { | 
|  | 10192 | if (resultCallback != null) { | 
|  | 10193 | resultCallback.accept(false); | 
|  | 10194 | } | 
|  | 10195 | } catch (RemoteException e) { | 
|  | 10196 | // ignore | 
|  | 10197 | } | 
|  | 10198 | return; | 
|  | 10199 | } | 
|  | 10200 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = | 
|  | 10201 | Pair.create(specifiers, (x) -> { | 
|  | 10202 | try { | 
|  | 10203 | if (resultCallback != null) { | 
|  | 10204 | resultCallback.accept(x); | 
|  | 10205 | } | 
|  | 10206 | } catch (RemoteException e) { | 
|  | 10207 | // ignore | 
|  | 10208 | } | 
|  | 10209 | }); | 
|  | 10210 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); | 
|  | 10211 | } finally { | 
|  | 10212 | Binder.restoreCallingIdentity(token); | 
|  | 10213 | } | 
|  | 10214 | } | 
|  | 10215 |  | 
|  | 10216 | @Override | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10217 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { | 
|  | 10218 | TelephonyPermissions | 
| Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 10219 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10220 | mApp, subId, "getSystemSelectionChannels"); | 
|  | 10221 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 10222 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10223 | try { | 
| Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 10224 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); | 
|  | 10225 | if (result instanceof IllegalStateException) { | 
|  | 10226 | throw (IllegalStateException) result; | 
|  | 10227 | } | 
|  | 10228 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; | 
| Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 10229 | if (DBG) log("getSystemSelectionChannels: " + specifiers); | 
|  | 10230 | return specifiers; | 
|  | 10231 | } finally { | 
|  | 10232 | Binder.restoreCallingIdentity(identity); | 
|  | 10233 | } | 
|  | 10234 | } | 
|  | 10235 |  | 
|  | 10236 | @Override | 
| Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10237 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { | 
| changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 10238 | enforceReadPrivilegedPermission("isMvnoMatched"); | 
| Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 10239 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); | 
| changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 10240 | } | 
|  | 10241 |  | 
|  | 10242 | @Override | 
| Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10243 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, | 
|  | 10244 | IIntegerConsumer pendingSubIdResult) { | 
| Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 10245 | if (callingPackage == null) { | 
|  | 10246 | callingPackage = getCurrentPackageName(); | 
|  | 10247 | } | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10248 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, | 
|  | 10249 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); | 
| Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 10250 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, | 
|  | 10251 | "Sending message")) { | 
| Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 10252 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); | 
|  | 10253 | } | 
|  | 10254 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); | 
|  | 10255 | Intent intent = new Intent(); | 
|  | 10256 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); | 
|  | 10257 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 10258 | // Bring up choose default SMS subscription dialog right now | 
|  | 10259 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, | 
|  | 10260 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); | 
|  | 10261 | mApp.startActivity(intent); | 
|  | 10262 | } | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10263 |  | 
|  | 10264 | @Override | 
| Ayush Sharma | 787854b | 2022-12-12 14:55:02 +0000 | [diff] [blame] | 10265 | public void showSwitchToManagedProfileDialog() { | 
|  | 10266 | enforceModifyPermission(); | 
|  | 10267 |  | 
|  | 10268 | Intent intent = new Intent(); | 
|  | 10269 | intent.setClass(mApp, ErrorDialogActivity.class); | 
|  | 10270 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | 
|  | 10271 | mApp.startActivity(intent); | 
|  | 10272 | } | 
|  | 10273 |  | 
|  | 10274 | @Override | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10275 | public String getMmsUAProfUrl(int subId) { | 
|  | 10276 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 10277 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10278 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10279 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 10280 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); | 
|  | 10281 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { | 
|  | 10282 | return carrierUAProfUrl; | 
|  | 10283 | } | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10284 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 10285 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10286 | } finally { | 
|  | 10287 | Binder.restoreCallingIdentity(identity); | 
|  | 10288 | } | 
|  | 10289 | } | 
|  | 10290 |  | 
|  | 10291 | @Override | 
|  | 10292 | public String getMmsUserAgent(int subId) { | 
|  | 10293 | //TODO investigate if this API should require proper permission check in R b/133791609 | 
|  | 10294 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10295 | try { | 
| Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 10296 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( | 
|  | 10297 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); | 
|  | 10298 | if (!TextUtils.isEmpty(carrierUserAgent)) { | 
|  | 10299 | return carrierUserAgent; | 
|  | 10300 | } | 
| Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 10301 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) | 
|  | 10302 | .getString(com.android.internal.R.string.config_mms_user_agent); | 
| chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 10303 | } finally { | 
|  | 10304 | Binder.restoreCallingIdentity(identity); | 
|  | 10305 | } | 
|  | 10306 | } | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10307 |  | 
|  | 10308 | @Override | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10309 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { | 
|  | 10310 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10311 |  | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10312 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10313 | try { | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10314 | Phone phone = getPhone(subscriptionId); | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10315 | if (phone == null) return false; | 
|  | 10316 |  | 
| Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10317 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); | 
| Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 10318 | } finally { | 
|  | 10319 | Binder.restoreCallingIdentity(identity); | 
|  | 10320 | } | 
|  | 10321 | } | 
|  | 10322 |  | 
|  | 10323 | @Override | 
| Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 10324 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10325 | boolean enabled) { | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10326 | enforceModifyPermission(); | 
|  | 10327 |  | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10328 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10329 | try { | 
| Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10330 | Phone phone = getPhone(subscriptionId); | 
|  | 10331 | if (phone == null) return; | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10332 |  | 
| Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10333 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); | 
| changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10334 | } finally { | 
|  | 10335 | Binder.restoreCallingIdentity(identity); | 
|  | 10336 | } | 
|  | 10337 | } | 
|  | 10338 |  | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10339 | /** | 
| Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10340 | * Updates whether conference event package handling is enabled. | 
| Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10341 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} | 
|  | 10342 | *                                 otherwise. | 
|  | 10343 | */ | 
|  | 10344 | @Override | 
|  | 10345 | public void setCepEnabled(boolean isCepEnabled) { | 
|  | 10346 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); | 
|  | 10347 |  | 
|  | 10348 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10349 | try { | 
|  | 10350 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); | 
|  | 10351 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 10352 | Phone defaultPhone = phone.getImsPhone(); | 
|  | 10353 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { | 
|  | 10354 | ImsPhone imsPhone = (ImsPhone) defaultPhone; | 
|  | 10355 | ImsPhoneCallTracker imsPhoneCallTracker = | 
|  | 10356 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); | 
|  | 10357 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); | 
|  | 10358 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " | 
|  | 10359 | + imsPhone.getMsisdn()); | 
|  | 10360 | } | 
|  | 10361 | } | 
|  | 10362 | } finally { | 
|  | 10363 | Binder.restoreCallingIdentity(identity); | 
|  | 10364 | } | 
|  | 10365 | } | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10366 |  | 
|  | 10367 | /** | 
|  | 10368 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. | 
|  | 10369 | * | 
|  | 10370 | * @param config       The XML file to be read. ASCII/UTF8 encoded text if not compressed. | 
|  | 10371 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed | 
|  | 10372 | *                     before being read. | 
|  | 10373 | */ | 
|  | 10374 | @Override | 
|  | 10375 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean | 
|  | 10376 | isCompressed) { | 
|  | 10377 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 10378 | mApp, subId, "notifyRcsAutoConfigurationReceived"); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10379 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 10380 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 10381 | } | 
|  | 10382 | if (!isImsAvailableOnDevice()) { | 
| joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10383 | // ProvisioningManager can not handle ServiceSpecificException. | 
|  | 10384 | // Throw the IllegalStateException and annotate ProvisioningManager. | 
|  | 10385 | throw new IllegalStateException("IMS not available on device."); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10386 | } | 
|  | 10387 |  | 
|  | 10388 | final long identity = Binder.clearCallingIdentity(); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10389 | try { | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10390 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); | 
|  | 10391 | } finally { | 
|  | 10392 | Binder.restoreCallingIdentity(identity); | 
| allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10393 | } | 
|  | 10394 | } | 
| zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10395 |  | 
|  | 10396 | @Override | 
|  | 10397 | public boolean isIccLockEnabled(int subId) { | 
|  | 10398 | enforceReadPrivilegedPermission("isIccLockEnabled"); | 
|  | 10399 |  | 
|  | 10400 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10401 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10402 | try { | 
|  | 10403 | Phone phone = getPhone(subId); | 
|  | 10404 | if (phone != null && phone.getIccCard() != null) { | 
|  | 10405 | return phone.getIccCard().getIccLockEnabled(); | 
|  | 10406 | } else { | 
|  | 10407 | return false; | 
|  | 10408 | } | 
|  | 10409 | } finally { | 
|  | 10410 | Binder.restoreCallingIdentity(identity); | 
|  | 10411 | } | 
|  | 10412 | } | 
|  | 10413 |  | 
|  | 10414 | /** | 
|  | 10415 | * Set the ICC pin lock enabled or disabled. | 
|  | 10416 | * | 
|  | 10417 | * @return an integer representing the status of IccLock enabled or disabled in the following | 
|  | 10418 | * three cases: | 
|  | 10419 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock | 
|  | 10420 | *   successfully. | 
|  | 10421 | *   - Positive number and zero for remaining password attempts. | 
|  | 10422 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
|  | 10423 | * | 
|  | 10424 | */ | 
|  | 10425 | @Override | 
|  | 10426 | public int setIccLockEnabled(int subId, boolean enabled, String password) { | 
|  | 10427 | enforceModifyPermission(); | 
|  | 10428 |  | 
|  | 10429 | Phone phone = getPhone(subId); | 
|  | 10430 | if (phone == null) { | 
|  | 10431 | return 0; | 
|  | 10432 | } | 
|  | 10433 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10434 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10435 | try { | 
|  | 10436 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, | 
|  | 10437 | new Pair<Boolean, String>(enabled, password), phone, null); | 
|  | 10438 | return attemptsRemaining; | 
|  | 10439 |  | 
|  | 10440 | } catch (Exception e) { | 
|  | 10441 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); | 
|  | 10442 | } finally { | 
|  | 10443 | Binder.restoreCallingIdentity(identity); | 
|  | 10444 | } | 
|  | 10445 | return 0; | 
|  | 10446 | } | 
|  | 10447 |  | 
|  | 10448 | /** | 
|  | 10449 | * Change the ICC password used in ICC pin lock. | 
|  | 10450 | * | 
|  | 10451 | * @return an integer representing the status of IccLock changed in the following three cases: | 
|  | 10452 | *   - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. | 
|  | 10453 | *   - Positive number and zero for remaining password attempts. | 
|  | 10454 | *   - Negative number for other failure cases (such like enabling/disabling PIN failed). | 
|  | 10455 | * | 
|  | 10456 | */ | 
|  | 10457 | @Override | 
|  | 10458 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { | 
|  | 10459 | enforceModifyPermission(); | 
|  | 10460 |  | 
|  | 10461 | Phone phone = getPhone(subId); | 
|  | 10462 | if (phone == null) { | 
|  | 10463 | return 0; | 
|  | 10464 | } | 
|  | 10465 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10466 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10467 | try { | 
|  | 10468 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, | 
|  | 10469 | new Pair<String, String>(oldPassword, newPassword), phone, null); | 
|  | 10470 | return attemptsRemaining; | 
|  | 10471 |  | 
|  | 10472 | } catch (Exception e) { | 
|  | 10473 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); | 
|  | 10474 | } finally { | 
|  | 10475 | Binder.restoreCallingIdentity(identity); | 
|  | 10476 | } | 
|  | 10477 | return 0; | 
|  | 10478 | } | 
| Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10479 |  | 
|  | 10480 | /** | 
|  | 10481 | * Request for receiving user activity notification | 
|  | 10482 | */ | 
|  | 10483 | @Override | 
|  | 10484 | public void requestUserActivityNotification() { | 
|  | 10485 | if (!mNotifyUserActivity.get() | 
|  | 10486 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { | 
|  | 10487 | mNotifyUserActivity.set(true); | 
|  | 10488 | } | 
|  | 10489 | } | 
|  | 10490 |  | 
|  | 10491 | /** | 
|  | 10492 | * Called when userActivity is signalled in the power manager. | 
|  | 10493 | * This is safe to call from any thread, with any window manager locks held or not. | 
|  | 10494 | */ | 
|  | 10495 | @Override | 
|  | 10496 | public void userActivity() { | 
|  | 10497 | // *************************************** | 
|  | 10498 | // *  Inherited from PhoneWindowManager  * | 
|  | 10499 | // *************************************** | 
|  | 10500 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER | 
|  | 10501 | // WITH ITS LOCKS HELD. | 
|  | 10502 | // | 
|  | 10503 | // This code must be VERY careful about the locks | 
|  | 10504 | // it acquires. | 
|  | 10505 | // In fact, the current code acquires way too many, | 
|  | 10506 | // and probably has lurking deadlocks. | 
|  | 10507 |  | 
|  | 10508 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { | 
|  | 10509 | throw new SecurityException("Only the OS may call notifyUserActivity()"); | 
|  | 10510 | } | 
|  | 10511 |  | 
|  | 10512 | if (mNotifyUserActivity.getAndSet(false)) { | 
|  | 10513 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, | 
|  | 10514 | USER_ACTIVITY_NOTIFICATION_DELAY); | 
|  | 10515 | } | 
|  | 10516 | } | 
| Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10517 |  | 
|  | 10518 | @Override | 
|  | 10519 | public boolean canConnectTo5GInDsdsMode() { | 
|  | 10520 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); | 
|  | 10521 | } | 
| Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10522 |  | 
|  | 10523 | @Override | 
|  | 10524 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, | 
|  | 10525 | String callingFeatureId) { | 
|  | 10526 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( | 
|  | 10527 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { | 
|  | 10528 | throw new SecurityException("Requires READ_PHONE_STATE permission."); | 
|  | 10529 | } | 
|  | 10530 |  | 
|  | 10531 | Phone phone = getPhone(subId); | 
|  | 10532 | if (phone == null) { | 
|  | 10533 | throw new RuntimeException("phone is not available"); | 
|  | 10534 | } | 
|  | 10535 | // Now that all security checks passes, perform the operation as ourselves. | 
|  | 10536 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10537 | try { | 
|  | 10538 | return phone.getEquivalentHomePlmns(); | 
|  | 10539 | } finally { | 
|  | 10540 | Binder.restoreCallingIdentity(identity); | 
|  | 10541 | } | 
|  | 10542 | } | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10543 |  | 
|  | 10544 | @Override | 
|  | 10545 | public boolean isRadioInterfaceCapabilitySupported( | 
| Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10546 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { | 
|  | 10547 | Set<String> radioInterfaceCapabilities = | 
| Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10548 | mRadioInterfaceCapabilities.getCapabilities(); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10549 | if (radioInterfaceCapabilities == null) { | 
|  | 10550 | throw new RuntimeException("radio interface capabilities are not available"); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10551 | } | 
| Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10552 | return radioInterfaceCapabilities.contains(capability); | 
| Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10553 | } | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10554 |  | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10555 | @Override | 
|  | 10556 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, | 
|  | 10557 | UaSecurityProtocolIdentifier securityProtocol, | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10558 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { | 
|  | 10559 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
|  | 10560 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", | 
|  | 10561 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 10562 | Manifest.permission.MODIFY_PHONE_STATE); | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10563 | if (DBG) { | 
|  | 10564 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" | 
|  | 10565 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol | 
|  | 10566 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); | 
|  | 10567 | } | 
|  | 10568 |  | 
|  | 10569 | if (!SubscriptionManager.isValidSubscriptionId(subId) | 
|  | 10570 | || appType < TelephonyManager.APPTYPE_UNKNOWN | 
|  | 10571 | || appType > TelephonyManager.APPTYPE_ISIM | 
|  | 10572 | || nafUrl == null || securityProtocol == null || callback == null) { | 
|  | 10573 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); | 
|  | 10574 | if (callback != null) { | 
|  | 10575 | try { | 
|  | 10576 | callback.onAuthenticationFailure( | 
|  | 10577 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); | 
|  | 10578 | } catch (RemoteException exception) { | 
|  | 10579 | log("Fail to notify onAuthenticationFailure due to " + exception); | 
|  | 10580 | } | 
|  | 10581 | return; | 
|  | 10582 | } | 
|  | 10583 | } | 
|  | 10584 |  | 
|  | 10585 | final long token = Binder.clearCallingIdentity(); | 
|  | 10586 | try { | 
|  | 10587 | getGbaManager(subId).bootstrapAuthenticationRequest( | 
|  | 10588 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10589 | forceBootStrapping, callback)); | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10590 | } finally { | 
|  | 10591 | Binder.restoreCallingIdentity(token); | 
|  | 10592 | } | 
|  | 10593 | } | 
|  | 10594 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10595 | /** | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10596 | * Attempts to set the radio power state for all phones for thermal reason. | 
|  | 10597 | * This does not guarantee that the | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10598 | * requested radio power state will actually be set. See {@link | 
|  | 10599 | * PhoneInternalInterface#setRadioPowerForReason} for more details. | 
|  | 10600 | * | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10601 | * @param enable {@code true} if trying to turn radio on. | 
|  | 10602 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code | 
|  | 10603 | * false}. | 
|  | 10604 | */ | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10605 | private boolean setRadioPowerForThermal(boolean enable) { | 
|  | 10606 | boolean isPhoneAvailable = false; | 
|  | 10607 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { | 
|  | 10608 | Phone phone = PhoneFactory.getPhone(i); | 
|  | 10609 | if (phone != null) { | 
| Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10610 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10611 | isPhoneAvailable = true; | 
|  | 10612 | } | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10613 | } | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10614 |  | 
|  | 10615 | // return true if successfully informed the phone object about the thermal radio power | 
|  | 10616 | // request. | 
|  | 10617 | return isPhoneAvailable; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10618 | } | 
|  | 10619 |  | 
|  | 10620 | private int handleDataThrottlingRequest(int subId, | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10621 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10622 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( | 
|  | 10623 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); | 
|  | 10624 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() | 
|  | 10625 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { | 
|  | 10626 | throw new IllegalArgumentException("modem does not support data throttling"); | 
|  | 10627 | } | 
|  | 10628 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10629 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return | 
|  | 10630 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10631 | if (!setRadioPowerForThermal(true)) { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10632 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 10633 | } | 
|  | 10634 |  | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10635 | setDataEnabledForReason( | 
|  | 10636 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10637 |  | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10638 | if (isDataThrottlingSupported) { | 
|  | 10639 | int thermalMitigationResult = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10640 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10641 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { | 
|  | 10642 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); | 
|  | 10643 | } else if (thermalMitigationResult | 
|  | 10644 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { | 
| Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10645 | log("Modem likely does not support data throttling on secondary carrier. Data " + | 
|  | 10646 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); | 
|  | 10647 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10648 | } | 
|  | 10649 | return thermalMitigationResult; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10650 | } | 
| Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10651 |  | 
|  | 10652 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10653 | } | 
|  | 10654 |  | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10655 | private static List<String> getThermalMitigationAllowlist(Context context) { | 
|  | 10656 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { | 
|  | 10657 | for (String pckg : context.getResources() | 
|  | 10658 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { | 
|  | 10659 | sThermalMitigationAllowlistedPackages.add(pckg); | 
|  | 10660 | } | 
|  | 10661 | } | 
|  | 10662 |  | 
|  | 10663 | return sThermalMitigationAllowlistedPackages; | 
|  | 10664 | } | 
|  | 10665 |  | 
| Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10666 | private boolean isAnyPhoneInEmergencyState() { | 
|  | 10667 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); | 
|  | 10668 | if (tm.isInEmergencyCall()) { | 
|  | 10669 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); | 
|  | 10670 | return true; | 
|  | 10671 | } | 
|  | 10672 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 10673 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { | 
|  | 10674 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10675 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " | 
|  | 10676 | + phone.isInEcm()); | 
| Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10677 | return true; | 
|  | 10678 | } | 
|  | 10679 | } | 
|  | 10680 |  | 
|  | 10681 | return false; | 
|  | 10682 | } | 
|  | 10683 |  | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10684 | /** | 
|  | 10685 | * Used by shell commands to add an authorized package name for thermal mitigation. | 
|  | 10686 | * @param packageName name of package to be allowlisted | 
|  | 10687 | * @param context | 
|  | 10688 | */ | 
|  | 10689 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { | 
|  | 10690 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); | 
|  | 10691 | sThermalMitigationAllowlistedPackages.add(packageName); | 
|  | 10692 | } | 
|  | 10693 |  | 
|  | 10694 | /** | 
|  | 10695 | * Used by shell commands to remove an authorized package name for thermal mitigation. | 
|  | 10696 | * @param packageName name of package to remove from allowlist | 
|  | 10697 | * @param context | 
|  | 10698 | */ | 
|  | 10699 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { | 
|  | 10700 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); | 
|  | 10701 | sThermalMitigationAllowlistedPackages.remove(packageName); | 
|  | 10702 | } | 
|  | 10703 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10704 | /** | 
|  | 10705 | * Thermal mitigation request to control functionalities at modem. | 
|  | 10706 | * | 
|  | 10707 | * @param subId the id of the subscription. | 
|  | 10708 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10709 | * @param callingPackage the package name of the calling package. | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10710 | * | 
|  | 10711 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. | 
|  | 10712 | */ | 
|  | 10713 | @Override | 
|  | 10714 | @ThermalMitigationResult | 
|  | 10715 | public int sendThermalMitigationRequest( | 
|  | 10716 | int subId, | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10717 | ThermalMitigationRequest thermalMitigationRequest, | 
|  | 10718 | String callingPackage) throws IllegalArgumentException { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10719 | enforceModifyPermission(); | 
|  | 10720 |  | 
| Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10721 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 10722 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) | 
|  | 10723 | .contains(callingPackage)) { | 
|  | 10724 | throw new SecurityException("Calling package must be configured in the device config. " | 
|  | 10725 | + "calling package: " + callingPackage); | 
|  | 10726 | } | 
|  | 10727 |  | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10728 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
|  | 10729 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10730 |  | 
|  | 10731 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; | 
|  | 10732 | try { | 
|  | 10733 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); | 
|  | 10734 | switch (thermalMitigationAction) { | 
|  | 10735 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: | 
|  | 10736 | thermalMitigationResult = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10737 | handleDataThrottlingRequest(subId, | 
|  | 10738 | thermalMitigationRequest.getDataThrottlingRequest(), | 
|  | 10739 | callingPackage); | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10740 | break; | 
|  | 10741 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: | 
|  | 10742 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 10743 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " | 
|  | 10744 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); | 
|  | 10745 | } | 
|  | 10746 |  | 
|  | 10747 | // Ensure that radio is on. If not able to power on due to phone being | 
|  | 10748 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10749 | if (!setRadioPowerForThermal(true)) { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10750 | thermalMitigationResult = | 
|  | 10751 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 10752 | break; | 
|  | 10753 | } | 
|  | 10754 |  | 
|  | 10755 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, | 
| Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10756 | false, callingPackage); | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10757 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
|  | 10758 | break; | 
|  | 10759 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: | 
|  | 10760 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { | 
|  | 10761 | throw new IllegalArgumentException("dataThrottlingRequest  must be null for" | 
|  | 10762 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); | 
|  | 10763 | } | 
|  | 10764 |  | 
|  | 10765 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); | 
|  | 10766 | if (registry != null) { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10767 | Phone phone = getPhone(subId); | 
|  | 10768 | if (phone == null) { | 
|  | 10769 | thermalMitigationResult = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10770 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10771 | break; | 
|  | 10772 | } | 
|  | 10773 |  | 
| Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10774 | TelephonyConnectionService service = | 
|  | 10775 | registry.getTelephonyConnectionService(); | 
| Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10776 | if (service != null && service.isEmergencyCallPending()) { | 
| Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10777 | Log.e(LOG_TAG, "An emergency call is pending"); | 
|  | 10778 | thermalMitigationResult = | 
|  | 10779 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; | 
|  | 10780 | break; | 
|  | 10781 | } else if (isAnyPhoneInEmergencyState()) { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10782 | thermalMitigationResult = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10783 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10784 | break; | 
|  | 10785 | } | 
|  | 10786 | } else { | 
|  | 10787 | thermalMitigationResult = | 
|  | 10788 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 10789 | break; | 
|  | 10790 | } | 
|  | 10791 |  | 
|  | 10792 | // Turn radio off. If not able to power off due to phone being unavailable, | 
|  | 10793 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. | 
| Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10794 | if (!setRadioPowerForThermal(false)) { | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10795 | thermalMitigationResult = | 
|  | 10796 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; | 
|  | 10797 | break; | 
|  | 10798 | } | 
|  | 10799 | thermalMitigationResult = | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 10800 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; | 
| Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10801 | break; | 
|  | 10802 | default: | 
|  | 10803 | throw new IllegalArgumentException("the requested thermalMitigationAction does " | 
|  | 10804 | + "not exist. Requested action: " + thermalMitigationAction); | 
|  | 10805 | } | 
|  | 10806 | } catch (IllegalArgumentException e) { | 
|  | 10807 | throw e; | 
|  | 10808 | } catch (Exception e) { | 
|  | 10809 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); | 
|  | 10810 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; | 
|  | 10811 | } finally { | 
|  | 10812 | Binder.restoreCallingIdentity(identity); | 
|  | 10813 | } | 
|  | 10814 |  | 
|  | 10815 | if (DBG) { | 
|  | 10816 | log("thermalMitigationRequest returning with thermalMitigationResult: " | 
|  | 10817 | + thermalMitigationResult); | 
|  | 10818 | } | 
|  | 10819 |  | 
|  | 10820 | return thermalMitigationResult; | 
|  | 10821 | } | 
| Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10822 |  | 
|  | 10823 | /** | 
|  | 10824 | * Set the GbaService Package Name that Telephony will bind to. | 
|  | 10825 | * | 
|  | 10826 | * @param subId The sim that the GbaService is associated with. | 
|  | 10827 | * @param packageName The name of the package to be replaced with. | 
|  | 10828 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 10829 | */ | 
|  | 10830 | @Override | 
|  | 10831 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { | 
|  | 10832 | enforceModifyPermission(); | 
|  | 10833 |  | 
|  | 10834 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10835 | try { | 
|  | 10836 | return getGbaManager(subId).overrideServicePackage(packageName); | 
|  | 10837 | } finally { | 
|  | 10838 | Binder.restoreCallingIdentity(identity); | 
|  | 10839 | } | 
|  | 10840 | } | 
|  | 10841 |  | 
|  | 10842 | /** | 
|  | 10843 | * Return the package name of the currently bound GbaService. | 
|  | 10844 | * | 
|  | 10845 | * @param subId The sim that the GbaService is associated with. | 
|  | 10846 | * @return the package name of the GbaService configuration, null if GBA is not supported. | 
|  | 10847 | */ | 
|  | 10848 | @Override | 
|  | 10849 | public String getBoundGbaService(int subId) { | 
|  | 10850 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); | 
|  | 10851 |  | 
|  | 10852 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10853 | try { | 
|  | 10854 | return getGbaManager(subId).getServicePackage(); | 
|  | 10855 | } finally { | 
|  | 10856 | Binder.restoreCallingIdentity(identity); | 
|  | 10857 | } | 
|  | 10858 | } | 
|  | 10859 |  | 
|  | 10860 | /** | 
|  | 10861 | * Set the release time for telephony to unbind GbaService. | 
|  | 10862 | * | 
|  | 10863 | * @param subId The sim that the GbaService is associated with. | 
|  | 10864 | * @param interval The release time to unbind GbaService by millisecond. | 
|  | 10865 | * @return true if setting the GbaService to bind to succeeded, false if it did not. | 
|  | 10866 | */ | 
|  | 10867 | @Override | 
|  | 10868 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { | 
|  | 10869 | enforceModifyPermission(); | 
|  | 10870 |  | 
|  | 10871 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10872 | try { | 
|  | 10873 | return getGbaManager(subId).overrideReleaseTime(interval); | 
|  | 10874 | } finally { | 
|  | 10875 | Binder.restoreCallingIdentity(identity); | 
|  | 10876 | } | 
|  | 10877 | } | 
|  | 10878 |  | 
|  | 10879 | /** | 
|  | 10880 | * Return the release time for telephony to unbind GbaService. | 
|  | 10881 | * | 
|  | 10882 | * @param subId The sim that the GbaService is associated with. | 
|  | 10883 | * @return The release time to unbind GbaService by millisecond. | 
|  | 10884 | */ | 
|  | 10885 | @Override | 
|  | 10886 | public int getGbaReleaseTime(int subId) { | 
|  | 10887 | enforceReadPrivilegedPermission("getGbaReleaseTime"); | 
|  | 10888 |  | 
|  | 10889 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10890 | try { | 
|  | 10891 | return getGbaManager(subId).getReleaseTime(); | 
|  | 10892 | } finally { | 
|  | 10893 | Binder.restoreCallingIdentity(identity); | 
|  | 10894 | } | 
|  | 10895 | } | 
|  | 10896 |  | 
|  | 10897 | private GbaManager getGbaManager(int subId) { | 
|  | 10898 | GbaManager instance = GbaManager.getInstance(subId); | 
|  | 10899 | if (instance == null) { | 
|  | 10900 | String packageName = mApp.getResources().getString(R.string.config_gba_package); | 
|  | 10901 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); | 
|  | 10902 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); | 
|  | 10903 | } | 
|  | 10904 | return instance; | 
|  | 10905 | } | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10906 |  | 
|  | 10907 | /** | 
|  | 10908 | * indicate whether the device and the carrier can support | 
|  | 10909 | * RCS VoLTE single registration. | 
|  | 10910 | */ | 
|  | 10911 | @Override | 
|  | 10912 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10913 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
|  | 10914 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", | 
|  | 10915 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 10916 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10917 |  | 
|  | 10918 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 10919 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 10920 | } | 
|  | 10921 |  | 
|  | 10922 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10923 | try { | 
|  | 10924 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); | 
|  | 10925 | if (rpm != null) { | 
| Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10926 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); | 
|  | 10927 | if (isCapable != null) { | 
|  | 10928 | return isCapable; | 
|  | 10929 | } | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10930 | } | 
| Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10931 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, | 
|  | 10932 | "service is temporarily unavailable."); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10933 | } finally { | 
|  | 10934 | Binder.restoreCallingIdentity(identity); | 
|  | 10935 | } | 
|  | 10936 | } | 
|  | 10937 |  | 
|  | 10938 | /** | 
|  | 10939 | * Register RCS provisioning callback. | 
|  | 10940 | */ | 
|  | 10941 | @Override | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10942 | public void registerRcsProvisioningCallback(int subId, | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10943 | IRcsConfigCallback callback) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10944 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10945 | Binder.getCallingUid(), "registerRcsProvisioningCallback", | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10946 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 10947 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10948 |  | 
|  | 10949 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 10950 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 10951 | } | 
|  | 10952 | if (!isImsAvailableOnDevice()) { | 
|  | 10953 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 10954 | "IMS not available on device."); | 
|  | 10955 | } | 
|  | 10956 |  | 
|  | 10957 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10958 | try { | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10959 | if (!RcsProvisioningMonitor.getInstance() | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10960 | .registerRcsProvisioningCallback(subId, callback)) { | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10961 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, | 
|  | 10962 | "Active subscription not found."); | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10963 | } | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10964 | } finally { | 
|  | 10965 | Binder.restoreCallingIdentity(identity); | 
|  | 10966 | } | 
|  | 10967 | } | 
|  | 10968 |  | 
|  | 10969 | /** | 
|  | 10970 | * Unregister RCS provisioning callback. | 
|  | 10971 | */ | 
|  | 10972 | @Override | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10973 | public void unregisterRcsProvisioningCallback(int subId, | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10974 | IRcsConfigCallback callback) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10975 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10976 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10977 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, | 
|  | 10978 | permission.READ_PRIVILEGED_PHONE_STATE); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10979 |  | 
|  | 10980 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 10981 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 10982 | } | 
|  | 10983 | if (!isImsAvailableOnDevice()) { | 
| joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 10984 | // operation failed silently | 
|  | 10985 | Rlog.w(LOG_TAG, "IMS not available on device."); | 
|  | 10986 | return; | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10987 | } | 
|  | 10988 |  | 
|  | 10989 | final long identity = Binder.clearCallingIdentity(); | 
|  | 10990 | try { | 
| Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10991 | RcsProvisioningMonitor.getInstance() | 
| Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10992 | .unregisterRcsProvisioningCallback(subId, callback); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10993 | } finally { | 
|  | 10994 | Binder.restoreCallingIdentity(identity); | 
|  | 10995 | } | 
|  | 10996 | } | 
|  | 10997 |  | 
|  | 10998 | /** | 
|  | 10999 | * trigger RCS reconfiguration. | 
|  | 11000 | */ | 
|  | 11001 | public void triggerRcsReconfiguration(int subId) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11002 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), | 
|  | 11003 | "triggerRcsReconfiguration", | 
|  | 11004 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11005 |  | 
|  | 11006 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 11007 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 11008 | } | 
|  | 11009 | if (!isImsAvailableOnDevice()) { | 
| joonhunshin | 46b49a3 | 2022-12-21 05:33:23 +0000 | [diff] [blame] | 11010 | // ProvisioningManager can not handle ServiceSpecificException. | 
|  | 11011 | // Throw the IllegalStateException and annotate ProvisioningManager. | 
|  | 11012 | throw new IllegalStateException("IMS not available on device."); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11013 | } | 
|  | 11014 |  | 
|  | 11015 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11016 | try { | 
|  | 11017 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); | 
|  | 11018 | } finally { | 
|  | 11019 | Binder.restoreCallingIdentity(identity); | 
|  | 11020 | } | 
|  | 11021 | } | 
|  | 11022 |  | 
|  | 11023 | /** | 
|  | 11024 | * Provide the client configuration parameters of the RCS application. | 
|  | 11025 | */ | 
|  | 11026 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { | 
| Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 11027 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), | 
|  | 11028 | "setRcsClientConfiguration", | 
|  | 11029 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11030 |  | 
|  | 11031 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { | 
|  | 11032 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); | 
|  | 11033 | } | 
|  | 11034 | if (!isImsAvailableOnDevice()) { | 
|  | 11035 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 11036 | "IMS not available on device."); | 
|  | 11037 | } | 
|  | 11038 |  | 
|  | 11039 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11040 |  | 
|  | 11041 | try { | 
|  | 11042 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); | 
|  | 11043 | if (configBinder == null) { | 
|  | 11044 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11045 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, | 
|  | 11046 | "could not find the requested subscription"); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11047 | } else { | 
|  | 11048 | configBinder.setRcsClientConfiguration(rcc); | 
|  | 11049 | } | 
| joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 11050 |  | 
|  | 11051 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, | 
|  | 11052 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11053 | } catch (RemoteException e) { | 
|  | 11054 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); | 
| Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 11055 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, | 
|  | 11056 | "service is temporarily unavailable."); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11057 | } finally { | 
|  | 11058 | Binder.restoreCallingIdentity(identity); | 
|  | 11059 | } | 
|  | 11060 | } | 
|  | 11061 |  | 
|  | 11062 | /** | 
| Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 11063 | * Enables or disables the test mode for RCS VoLTE single registration. | 
|  | 11064 | */ | 
|  | 11065 | @Override | 
|  | 11066 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { | 
|  | 11067 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11068 | "setRcsSingleRegistrationTestModeEnabled"); | 
|  | 11069 |  | 
|  | 11070 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); | 
|  | 11071 | } | 
|  | 11072 |  | 
|  | 11073 | /** | 
|  | 11074 | * Gets the test mode for RCS VoLTE single registration. | 
|  | 11075 | */ | 
|  | 11076 | @Override | 
|  | 11077 | public boolean getRcsSingleRegistrationTestModeEnabled() { | 
|  | 11078 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11079 | "getRcsSingleRegistrationTestModeEnabled"); | 
|  | 11080 |  | 
|  | 11081 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); | 
|  | 11082 | } | 
|  | 11083 |  | 
|  | 11084 | /** | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11085 | * Overrides the config of RCS VoLTE single registration enabled for the device. | 
|  | 11086 | */ | 
|  | 11087 | @Override | 
|  | 11088 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { | 
|  | 11089 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11090 | "setDeviceSingleRegistrationEnabledOverride"); | 
|  | 11091 | enforceModifyPermission(); | 
|  | 11092 |  | 
|  | 11093 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 11094 | : Boolean.parseBoolean(enabledStr); | 
|  | 11095 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); | 
| Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 11096 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11097 | } | 
|  | 11098 |  | 
|  | 11099 | /** | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11100 | * Sends a device to device communication message.  Only usable via shell. | 
|  | 11101 | * @param message message to send. | 
|  | 11102 | * @param value message value. | 
|  | 11103 | */ | 
|  | 11104 | @Override | 
|  | 11105 | public void sendDeviceToDeviceMessage(int message, int value) { | 
|  | 11106 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
| Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11107 | "sendDeviceToDeviceMessage"); | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11108 | enforceModifyPermission(); | 
|  | 11109 |  | 
|  | 11110 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11111 | try { | 
|  | 11112 | TelephonyConnectionService service = | 
|  | 11113 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); | 
|  | 11114 | if (service == null) { | 
|  | 11115 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); | 
|  | 11116 | return; | 
|  | 11117 | } | 
|  | 11118 | service.sendTestDeviceToDeviceMessage(message, value); | 
|  | 11119 | } finally { | 
|  | 11120 | Binder.restoreCallingIdentity(identity); | 
|  | 11121 | } | 
|  | 11122 | } | 
|  | 11123 |  | 
| Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 11124 | /** | 
|  | 11125 | * Sets the specified device to device transport active. | 
|  | 11126 | * @param transport The transport to set active. | 
|  | 11127 | */ | 
|  | 11128 | @Override | 
|  | 11129 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { | 
|  | 11130 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11131 | "setActiveDeviceToDeviceTransport"); | 
|  | 11132 | enforceModifyPermission(); | 
|  | 11133 |  | 
|  | 11134 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11135 | try { | 
|  | 11136 | TelephonyConnectionService service = | 
|  | 11137 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); | 
|  | 11138 | if (service == null) { | 
|  | 11139 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); | 
|  | 11140 | return; | 
|  | 11141 | } | 
|  | 11142 | service.setActiveDeviceToDeviceTransport(transport); | 
|  | 11143 | } finally { | 
|  | 11144 | Binder.restoreCallingIdentity(identity); | 
|  | 11145 | } | 
|  | 11146 | } | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11147 |  | 
| Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 11148 | @Override | 
|  | 11149 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { | 
|  | 11150 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11151 | "setDeviceToDeviceForceEnabled"); | 
|  | 11152 |  | 
|  | 11153 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11154 | try { | 
|  | 11155 | Arrays.stream(PhoneFactory.getPhones()).forEach( | 
|  | 11156 | p -> { | 
|  | 11157 | Phone thePhone = p.getImsPhone(); | 
|  | 11158 | if (thePhone != null && thePhone instanceof ImsPhone) { | 
|  | 11159 | ImsPhone imsPhone = (ImsPhone) thePhone; | 
|  | 11160 | CallTracker tracker = imsPhone.getCallTracker(); | 
|  | 11161 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { | 
|  | 11162 | ImsPhoneCallTracker imsPhoneCallTracker = | 
|  | 11163 | (ImsPhoneCallTracker) tracker; | 
|  | 11164 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); | 
|  | 11165 | } | 
|  | 11166 | } | 
|  | 11167 | } | 
|  | 11168 | ); | 
|  | 11169 | } finally { | 
|  | 11170 | Binder.restoreCallingIdentity(identity); | 
|  | 11171 | } | 
|  | 11172 | } | 
|  | 11173 |  | 
| Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 11174 | /** | 
| Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 11175 | * Gets the config of RCS VoLTE single registration enabled for the device. | 
|  | 11176 | */ | 
|  | 11177 | @Override | 
|  | 11178 | public boolean getDeviceSingleRegistrationEnabled() { | 
|  | 11179 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); | 
|  | 11180 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); | 
|  | 11181 | } | 
|  | 11182 |  | 
|  | 11183 | /** | 
|  | 11184 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 11185 | */ | 
|  | 11186 | @Override | 
|  | 11187 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { | 
|  | 11188 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11189 | "setCarrierSingleRegistrationEnabledOverride"); | 
|  | 11190 | enforceModifyPermission(); | 
|  | 11191 |  | 
|  | 11192 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 11193 | : Boolean.parseBoolean(enabledStr); | 
|  | 11194 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( | 
|  | 11195 | subId, enabled); | 
|  | 11196 | } | 
|  | 11197 |  | 
|  | 11198 | /** | 
|  | 11199 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. | 
|  | 11200 | */ | 
|  | 11201 | @Override | 
|  | 11202 | public boolean getCarrierSingleRegistrationEnabled(int subId) { | 
|  | 11203 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); | 
|  | 11204 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); | 
|  | 11205 | } | 
| Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11206 |  | 
|  | 11207 | /** | 
| Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 11208 | * Overrides the ims feature validation result | 
|  | 11209 | */ | 
|  | 11210 | @Override | 
|  | 11211 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { | 
|  | 11212 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11213 | "setImsFeatureValidationOverride"); | 
|  | 11214 |  | 
|  | 11215 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null | 
|  | 11216 | : Boolean.parseBoolean(enabledStr); | 
|  | 11217 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( | 
|  | 11218 | subId, enabled); | 
|  | 11219 | } | 
|  | 11220 |  | 
|  | 11221 | /** | 
|  | 11222 | * Gets the ims feature validation override value | 
|  | 11223 | */ | 
|  | 11224 | @Override | 
|  | 11225 | public boolean getImsFeatureValidationOverride(int subId) { | 
|  | 11226 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11227 | "getImsFeatureValidationOverride"); | 
|  | 11228 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); | 
|  | 11229 | } | 
|  | 11230 |  | 
|  | 11231 | /** | 
| Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 11232 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage | 
|  | 11233 | * their mobile plan. | 
|  | 11234 | */ | 
|  | 11235 | @Override | 
|  | 11236 | public String getMobileProvisioningUrl() { | 
|  | 11237 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); | 
|  | 11238 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11239 | try { | 
|  | 11240 | return getDefaultPhone().getMobileProvisioningUrl(); | 
|  | 11241 | } finally { | 
|  | 11242 | Binder.restoreCallingIdentity(identity); | 
|  | 11243 | } | 
|  | 11244 | } | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11245 |  | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11246 | /** | 
| calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 11247 | * Get the EAB contact from the EAB database. | 
|  | 11248 | */ | 
|  | 11249 | @Override | 
|  | 11250 | public String getContactFromEab(String contact) { | 
|  | 11251 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); | 
|  | 11252 | enforceModifyPermission(); | 
|  | 11253 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11254 | try { | 
|  | 11255 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); | 
|  | 11256 | } finally { | 
|  | 11257 | Binder.restoreCallingIdentity(identity); | 
|  | 11258 | } | 
|  | 11259 | } | 
|  | 11260 |  | 
|  | 11261 | /** | 
| Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 11262 | * Get the EAB capability from the EAB database. | 
|  | 11263 | */ | 
|  | 11264 | @Override | 
|  | 11265 | public String getCapabilityFromEab(String contact) { | 
|  | 11266 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); | 
|  | 11267 | enforceModifyPermission(); | 
|  | 11268 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11269 | try { | 
|  | 11270 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); | 
|  | 11271 | } finally { | 
|  | 11272 | Binder.restoreCallingIdentity(identity); | 
|  | 11273 | } | 
|  | 11274 | } | 
|  | 11275 |  | 
|  | 11276 | /** | 
| James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 11277 | * Remove the EAB contacts from the EAB database. | 
|  | 11278 | */ | 
|  | 11279 | @Override | 
|  | 11280 | public int removeContactFromEab(int subId, String contacts) { | 
|  | 11281 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); | 
|  | 11282 | enforceModifyPermission(); | 
|  | 11283 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11284 | try { | 
|  | 11285 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); | 
|  | 11286 | } finally { | 
|  | 11287 | Binder.restoreCallingIdentity(identity); | 
|  | 11288 | } | 
|  | 11289 | } | 
|  | 11290 |  | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11291 | @Override | 
| James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11292 | public boolean getDeviceUceEnabled() { | 
|  | 11293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); | 
|  | 11294 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11295 | try { | 
|  | 11296 | return mApp.getDeviceUceEnabled(); | 
|  | 11297 | } finally { | 
|  | 11298 | Binder.restoreCallingIdentity(identity); | 
|  | 11299 | } | 
|  | 11300 | } | 
|  | 11301 |  | 
|  | 11302 | @Override | 
|  | 11303 | public void setDeviceUceEnabled(boolean isEnabled) { | 
|  | 11304 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); | 
|  | 11305 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11306 | try { | 
|  | 11307 | mApp.setDeviceUceEnabled(isEnabled); | 
|  | 11308 | } finally { | 
|  | 11309 | Binder.restoreCallingIdentity(identity); | 
|  | 11310 | } | 
|  | 11311 | } | 
|  | 11312 |  | 
| Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11313 | /** | 
|  | 11314 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. | 
|  | 11315 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 11316 | */ | 
|  | 11317 | // Used for SHELL command only right now. | 
|  | 11318 | @Override | 
|  | 11319 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, | 
|  | 11320 | List<String> featureTags) { | 
|  | 11321 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11322 | "addUceRegistrationOverrideShell"); | 
|  | 11323 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11324 | try { | 
|  | 11325 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, | 
|  | 11326 | new ArraySet<>(featureTags)); | 
|  | 11327 | } catch (ImsException e) { | 
|  | 11328 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11329 | } finally { | 
|  | 11330 | Binder.restoreCallingIdentity(identity); | 
|  | 11331 | } | 
|  | 11332 | } | 
|  | 11333 |  | 
|  | 11334 | /** | 
|  | 11335 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. | 
|  | 11336 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 11337 | */ | 
|  | 11338 | // Used for SHELL command only right now. | 
|  | 11339 | @Override | 
|  | 11340 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, | 
|  | 11341 | List<String> featureTags) { | 
|  | 11342 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11343 | "removeUceRegistrationOverrideShell"); | 
|  | 11344 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11345 | try { | 
|  | 11346 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, | 
|  | 11347 | new ArraySet<>(featureTags)); | 
|  | 11348 | } catch (ImsException e) { | 
|  | 11349 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11350 | } finally { | 
|  | 11351 | Binder.restoreCallingIdentity(identity); | 
|  | 11352 | } | 
|  | 11353 | } | 
|  | 11354 |  | 
|  | 11355 | /** | 
|  | 11356 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. | 
|  | 11357 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 11358 | */ | 
|  | 11359 | // Used for SHELL command only right now. | 
|  | 11360 | @Override | 
|  | 11361 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { | 
|  | 11362 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11363 | "clearUceRegistrationOverrideShell"); | 
|  | 11364 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11365 | try { | 
|  | 11366 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); | 
|  | 11367 | } catch (ImsException e) { | 
|  | 11368 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11369 | } finally { | 
|  | 11370 | Binder.restoreCallingIdentity(identity); | 
|  | 11371 | } | 
|  | 11372 | } | 
|  | 11373 |  | 
|  | 11374 | /** | 
|  | 11375 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. | 
|  | 11376 | */ | 
|  | 11377 | // Used for SHELL command only right now. | 
|  | 11378 | @Override | 
|  | 11379 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { | 
|  | 11380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), | 
|  | 11381 | "getLatestRcsContactUceCapabilityShell"); | 
|  | 11382 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11383 | try { | 
|  | 11384 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); | 
|  | 11385 | } catch (ImsException e) { | 
|  | 11386 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11387 | } finally { | 
|  | 11388 | Binder.restoreCallingIdentity(identity); | 
|  | 11389 | } | 
|  | 11390 | } | 
|  | 11391 |  | 
|  | 11392 | /** | 
|  | 11393 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the | 
|  | 11394 | * device does not have an active PUBLISH. | 
|  | 11395 | */ | 
|  | 11396 | // Used for SHELL command only right now. | 
|  | 11397 | @Override | 
|  | 11398 | public String getLastUcePidfXmlShell(int subId) { | 
|  | 11399 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); | 
|  | 11400 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11401 | try { | 
|  | 11402 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); | 
|  | 11403 | } catch (ImsException e) { | 
|  | 11404 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11405 | } finally { | 
|  | 11406 | Binder.restoreCallingIdentity(identity); | 
|  | 11407 | } | 
|  | 11408 | } | 
|  | 11409 |  | 
| James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11410 | /** | 
|  | 11411 | * Remove UCE requests cannot be sent to the network status. | 
|  | 11412 | */ | 
|  | 11413 | // Used for SHELL command only right now. | 
|  | 11414 | @Override | 
|  | 11415 | public boolean removeUceRequestDisallowedStatus(int subId) { | 
|  | 11416 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); | 
|  | 11417 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11418 | try { | 
|  | 11419 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); | 
|  | 11420 | } catch (ImsException e) { | 
|  | 11421 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11422 | } finally { | 
|  | 11423 | Binder.restoreCallingIdentity(identity); | 
|  | 11424 | } | 
|  | 11425 | } | 
|  | 11426 |  | 
| James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11427 | /** | 
|  | 11428 | * Remove UCE requests cannot be sent to the network status. | 
|  | 11429 | */ | 
|  | 11430 | // Used for SHELL command only. | 
|  | 11431 | @Override | 
|  | 11432 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { | 
|  | 11433 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); | 
|  | 11434 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11435 | try { | 
|  | 11436 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); | 
|  | 11437 | } catch (ImsException e) { | 
|  | 11438 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); | 
|  | 11439 | } finally { | 
|  | 11440 | Binder.restoreCallingIdentity(identity); | 
|  | 11441 | } | 
|  | 11442 | } | 
| Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11443 |  | 
| James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11444 | @Override | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11445 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, | 
|  | 11446 | String callingPackage) { | 
|  | 11447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 11448 | mApp, subId, "setSignalStrengthUpdateRequest"); | 
|  | 11449 |  | 
|  | 11450 | final int callingUid = Binder.getCallingUid(); | 
|  | 11451 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 11452 | mApp.getSystemService(AppOpsManager.class) | 
|  | 11453 | .checkPackage(callingUid, callingPackage); | 
|  | 11454 |  | 
| Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11455 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11456 |  | 
|  | 11457 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11458 | try { | 
|  | 11459 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, | 
|  | 11460 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); | 
|  | 11461 |  | 
|  | 11462 | if (result instanceof IllegalStateException) { | 
|  | 11463 | throw (IllegalStateException) result; | 
|  | 11464 | } | 
|  | 11465 | } finally { | 
|  | 11466 | Binder.restoreCallingIdentity(identity); | 
|  | 11467 | } | 
|  | 11468 | } | 
|  | 11469 |  | 
|  | 11470 | @Override | 
|  | 11471 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, | 
|  | 11472 | String callingPackage) { | 
|  | 11473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( | 
|  | 11474 | mApp, subId, "clearSignalStrengthUpdateRequest"); | 
|  | 11475 |  | 
|  | 11476 | final int callingUid = Binder.getCallingUid(); | 
|  | 11477 | // Verify that tha callingPackage belongs to the calling UID | 
|  | 11478 | mApp.getSystemService(AppOpsManager.class) | 
|  | 11479 | .checkPackage(callingUid, callingPackage); | 
|  | 11480 |  | 
|  | 11481 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11482 | try { | 
|  | 11483 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, | 
|  | 11484 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); | 
|  | 11485 |  | 
|  | 11486 | if (result instanceof IllegalStateException) { | 
|  | 11487 | throw (IllegalStateException) result; | 
|  | 11488 | } | 
|  | 11489 | } finally { | 
|  | 11490 | Binder.restoreCallingIdentity(identity); | 
|  | 11491 | } | 
|  | 11492 | } | 
|  | 11493 |  | 
| Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11494 | private static void validateSignalStrengthUpdateRequest(Context context, | 
|  | 11495 | SignalStrengthUpdateRequest request, int callingUid) { | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11496 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { | 
|  | 11497 | // phone/system process do not have further restriction on request | 
|  | 11498 | return; | 
|  | 11499 | } | 
|  | 11500 |  | 
|  | 11501 | // Applications has restrictions on how to use the request: | 
| Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11502 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11503 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { | 
| Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11504 | context.enforceCallingOrSelfPermission( | 
|  | 11505 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, | 
|  | 11506 | "validateSignalStrengthUpdateRequest"); | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11507 | } | 
|  | 11508 |  | 
|  | 11509 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { | 
| Nagendra Prasad Nagarle Basavaraju | fee544c | 2022-12-07 16:34:52 +0000 | [diff] [blame] | 11510 | // Only system caller can set mHysteresisMs/mIsEnabled. | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11511 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED | 
| Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11512 | || info.isEnabled()) { | 
|  | 11513 | throw new IllegalArgumentException( | 
|  | 11514 | "Only system can set hide fields in SignalThresholdInfo"); | 
|  | 11515 | } | 
|  | 11516 |  | 
|  | 11517 | // Thresholds length for each RAN need in range. This has been validated in | 
|  | 11518 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method | 
|  | 11519 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds | 
|  | 11520 | final int[] thresholds = info.getThresholds(); | 
|  | 11521 | Objects.requireNonNull(thresholds); | 
|  | 11522 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() | 
|  | 11523 | || thresholds.length | 
|  | 11524 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { | 
|  | 11525 | throw new IllegalArgumentException( | 
|  | 11526 | "thresholds length is out of range: " + thresholds.length); | 
|  | 11527 | } | 
|  | 11528 | } | 
|  | 11529 | } | 
| SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11530 |  | 
|  | 11531 | /** | 
|  | 11532 | * Gets the current phone capability. | 
|  | 11533 | * | 
|  | 11534 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. | 
|  | 11535 | * @return the PhoneCapability which describes the data connection capability of modem. | 
|  | 11536 | * It's used to evaluate possible phone config change, for example from single | 
|  | 11537 | * SIM device to multi-SIM device. | 
|  | 11538 | */ | 
|  | 11539 | @Override | 
|  | 11540 | public PhoneCapability getPhoneCapability() { | 
|  | 11541 | enforceReadPrivilegedPermission("getPhoneCapability"); | 
|  | 11542 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11543 | try { | 
|  | 11544 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); | 
|  | 11545 | } finally { | 
|  | 11546 | Binder.restoreCallingIdentity(identity); | 
|  | 11547 | } | 
|  | 11548 | } | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11549 |  | 
|  | 11550 | /** | 
|  | 11551 | * Prepare TelephonyManager for an unattended reboot. The reboot is | 
|  | 11552 | * required to be done shortly after the API is invoked. | 
|  | 11553 | */ | 
|  | 11554 | @Override | 
|  | 11555 | @TelephonyManager.PrepareUnattendedRebootResult | 
|  | 11556 | public int prepareForUnattendedReboot() { | 
| Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11557 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11558 | enforceRebootPermission(); | 
|  | 11559 |  | 
|  | 11560 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11561 | try { | 
| Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11562 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); | 
| Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11563 | } finally { | 
|  | 11564 | Binder.restoreCallingIdentity(identity); | 
|  | 11565 | } | 
|  | 11566 | } | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11567 |  | 
|  | 11568 | /** | 
|  | 11569 | * Request to get the current slicing configuration including URSP rules and | 
|  | 11570 | * NSSAIs (configured, allowed and rejected). | 
|  | 11571 | * | 
|  | 11572 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. | 
|  | 11573 | */ | 
|  | 11574 | @Override | 
|  | 11575 | public void getSlicingConfig(ResultReceiver callback) { | 
| Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11576 | TelephonyPermissions | 
|  | 11577 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
|  | 11578 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); | 
| Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11579 |  | 
|  | 11580 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11581 | try { | 
|  | 11582 | Phone phone = getDefaultPhone(); | 
|  | 11583 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); | 
|  | 11584 | } finally { | 
|  | 11585 | Binder.restoreCallingIdentity(identity); | 
|  | 11586 | } | 
|  | 11587 | } | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11588 |  | 
|  | 11589 | /** | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11590 | * Check whether the given premium capability is available for purchase from the carrier. | 
|  | 11591 | * | 
|  | 11592 | * @param capability The premium capability to check. | 
|  | 11593 | * @param subId The subId to check the premium capability for. | 
|  | 11594 | * | 
|  | 11595 | * @return Whether the given premium capability is available to purchase. | 
|  | 11596 | */ | 
|  | 11597 | @Override | 
|  | 11598 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { | 
|  | 11599 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( | 
|  | 11600 | mApp, "isPremiumCapabilityAvailableForPurchase")) { | 
|  | 11601 | log("Premium capability " | 
|  | 11602 | + TelephonyManager.convertPremiumCapabilityToString(capability) | 
|  | 11603 | + " is not available for purchase due to missing permissions."); | 
|  | 11604 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " | 
|  | 11605 | + "permission READ_BASIC_PHONE_STATE."); | 
|  | 11606 | } | 
|  | 11607 |  | 
|  | 11608 | Phone phone = getPhone(subId); | 
| Thomas Nguyen | 7216ed6 | 2022-11-29 16:45:31 -0800 | [diff] [blame] | 11609 | if (phone == null) { | 
|  | 11610 | loge("isPremiumCapabilityAvailableForPurchase: phone is null, subId=" + subId); | 
|  | 11611 | return false; | 
|  | 11612 | } | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11613 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11614 | try { | 
| Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11615 | return SlicePurchaseController.getInstance(phone) | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11616 | .isPremiumCapabilityAvailableForPurchase(capability); | 
|  | 11617 | } finally { | 
|  | 11618 | Binder.restoreCallingIdentity(identity); | 
|  | 11619 | } | 
|  | 11620 | } | 
|  | 11621 |  | 
|  | 11622 | /** | 
|  | 11623 | * Purchase the given premium capability from the carrier. | 
|  | 11624 | * | 
|  | 11625 | * @param capability The premium capability to purchase. | 
|  | 11626 | * @param callback The result of the purchase request. | 
|  | 11627 | * @param subId The subId to purchase the premium capability for. | 
|  | 11628 | */ | 
|  | 11629 | @Override | 
|  | 11630 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { | 
|  | 11631 | log("purchasePremiumCapability: capability=" | 
|  | 11632 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" | 
|  | 11633 | + getCurrentPackageName()); | 
|  | 11634 |  | 
|  | 11635 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( | 
|  | 11636 | mApp, "purchasePremiumCapability")) { | 
|  | 11637 | log("purchasePremiumCapability " | 
|  | 11638 | + TelephonyManager.convertPremiumCapabilityToString(capability) | 
|  | 11639 | + " failed due to missing permissions."); | 
|  | 11640 | throw new SecurityException("purchasePremiumCapability requires permission " | 
|  | 11641 | + "READ_BASIC_PHONE_STATE."); | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11642 | } else if (!TelephonyPermissions.checkInternetPermissionNoThrow( | 
|  | 11643 | mApp, "purchasePremiumCapability")) { | 
|  | 11644 | log("purchasePremiumCapability " | 
|  | 11645 | + TelephonyManager.convertPremiumCapabilityToString(capability) | 
|  | 11646 | + " failed due to missing permissions."); | 
|  | 11647 | throw new SecurityException("purchasePremiumCapability requires permission INTERNET."); | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11648 | } | 
|  | 11649 |  | 
|  | 11650 | Phone phone = getPhone(subId); | 
| Sarah Chin | 1969411 | 2022-12-06 15:41:37 -0800 | [diff] [blame] | 11651 | if (phone == null) { | 
|  | 11652 | try { | 
|  | 11653 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_REQUEST_FAILED; | 
|  | 11654 | callback.accept(result); | 
|  | 11655 | loge("purchasePremiumCapability: phone is null, subId=" + subId); | 
|  | 11656 | } catch (RemoteException e) { | 
|  | 11657 | String logStr = "Purchase premium capability " | 
|  | 11658 | + TelephonyManager.convertPremiumCapabilityToString(capability) | 
|  | 11659 | + " failed due to RemoteException handling null phone: " + e; | 
|  | 11660 | if (DBG) log(logStr); | 
|  | 11661 | AnomalyReporter.reportAnomaly( | 
|  | 11662 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); | 
|  | 11663 | } | 
|  | 11664 | return; | 
|  | 11665 | } | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11666 |  | 
|  | 11667 | String callingProcess; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11668 | try { | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11669 | callingProcess = mApp.getPackageManager().getApplicationInfo( | 
|  | 11670 | getCurrentPackageName(), 0).processName; | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11671 | } catch (PackageManager.NameNotFoundException e) { | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11672 | callingProcess = getCurrentPackageName(); | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11673 | } | 
| Sarah Chin | 532d6bb | 2022-12-28 22:50:43 -0800 | [diff] [blame] | 11674 |  | 
|  | 11675 | boolean isVisible = false; | 
|  | 11676 | ActivityManager am = mApp.getSystemService(ActivityManager.class); | 
|  | 11677 | if (am != null) { | 
|  | 11678 | List<ActivityManager.RunningAppProcessInfo> processes = am.getRunningAppProcesses(); | 
|  | 11679 | if (processes != null) { | 
|  | 11680 | for (ActivityManager.RunningAppProcessInfo process : processes) { | 
|  | 11681 | log("purchasePremiumCapability: process " + process.processName | 
|  | 11682 | + "has importance " + process.importance); | 
|  | 11683 | if (process.processName.equals(callingProcess) && process.importance | 
|  | 11684 | <= ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { | 
|  | 11685 | isVisible = true; | 
|  | 11686 | break; | 
|  | 11687 | } | 
|  | 11688 | } | 
|  | 11689 | } | 
|  | 11690 | } | 
|  | 11691 |  | 
|  | 11692 | if (!isVisible) { | 
|  | 11693 | try { | 
|  | 11694 | int result = TelephonyManager.PURCHASE_PREMIUM_CAPABILITY_RESULT_NOT_FOREGROUND; | 
|  | 11695 | callback.accept(result); | 
|  | 11696 | loge("purchasePremiumCapability: " + callingProcess + " is not in the foreground."); | 
|  | 11697 | } catch (RemoteException e) { | 
|  | 11698 | String logStr = "Purchase premium capability " | 
|  | 11699 | + TelephonyManager.convertPremiumCapabilityToString(capability) | 
|  | 11700 | + " failed due to RemoteException handling background application: " + e; | 
|  | 11701 | if (DBG) log(logStr); | 
|  | 11702 | AnomalyReporter.reportAnomaly( | 
|  | 11703 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); | 
|  | 11704 | } | 
|  | 11705 | return; | 
|  | 11706 | } | 
|  | 11707 |  | 
| Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11708 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, | 
| Sarah Chin | b8218c2 | 2023-01-04 13:35:29 -0800 | [diff] [blame] | 11709 | new PurchasePremiumCapabilityArgument(capability, callback), phone, null); | 
| Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11710 | } | 
|  | 11711 |  | 
|  | 11712 | /** | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11713 | * Register an IMS connection state callback | 
|  | 11714 | */ | 
|  | 11715 | @Override | 
| Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11716 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, | 
|  | 11717 | String callingPackage) { | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11718 | if (feature == ImsFeature.FEATURE_MMTEL) { | 
|  | 11719 | // ImsMmTelManager | 
|  | 11720 | // The following also checks READ_PRIVILEGED_PHONE_STATE. | 
|  | 11721 | TelephonyPermissions | 
|  | 11722 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( | 
|  | 11723 | mApp, subId, "registerImsStateCallback"); | 
|  | 11724 | } else if (feature == ImsFeature.FEATURE_RCS) { | 
|  | 11725 | // ImsRcsManager or SipDelegateManager | 
|  | 11726 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, | 
|  | 11727 | Binder.getCallingUid(), "registerImsStateCallback", | 
|  | 11728 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
|  | 11729 | Manifest.permission.READ_PRECISE_PHONE_STATE, | 
|  | 11730 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, | 
|  | 11731 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); | 
|  | 11732 | } | 
|  | 11733 |  | 
|  | 11734 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { | 
|  | 11735 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 11736 | "IMS not available on device."); | 
|  | 11737 | } | 
|  | 11738 |  | 
|  | 11739 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { | 
|  | 11740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); | 
|  | 11741 | } | 
|  | 11742 |  | 
|  | 11743 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 11744 | if (controller == null) { | 
|  | 11745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, | 
|  | 11746 | "IMS not available on device."); | 
|  | 11747 | } | 
|  | 11748 |  | 
| Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11749 | if (callingPackage == null) { | 
|  | 11750 | callingPackage = getCurrentPackageName(); | 
|  | 11751 | } | 
|  | 11752 |  | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11753 | final long token = Binder.clearCallingIdentity(); | 
|  | 11754 | try { | 
|  | 11755 | int slotId = getSlotIndexOrException(subId); | 
| Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11756 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); | 
| Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11757 | } catch (ImsException e) { | 
|  | 11758 | throw new ServiceSpecificException(e.getCode()); | 
|  | 11759 | } finally { | 
|  | 11760 | Binder.restoreCallingIdentity(token); | 
|  | 11761 | } | 
|  | 11762 | } | 
|  | 11763 |  | 
|  | 11764 | /** | 
|  | 11765 | * Unregister an IMS connection state callback | 
|  | 11766 | */ | 
|  | 11767 | @Override | 
|  | 11768 | public void unregisterImsStateCallback(IImsStateCallback cb) { | 
|  | 11769 | final long token = Binder.clearCallingIdentity(); | 
|  | 11770 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); | 
|  | 11771 | if (controller == null) { | 
|  | 11772 | return; | 
|  | 11773 | } | 
|  | 11774 | try { | 
|  | 11775 | controller.unregisterImsStateCallback(cb); | 
|  | 11776 | } finally { | 
|  | 11777 | Binder.restoreCallingIdentity(token); | 
|  | 11778 | } | 
|  | 11779 | } | 
| Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11780 |  | 
|  | 11781 | /** | 
|  | 11782 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. | 
|  | 11783 | * | 
|  | 11784 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and | 
|  | 11785 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws | 
|  | 11786 | * SecurityException. | 
|  | 11787 | * If there is current registered network this value will be same as the registered cell | 
|  | 11788 | * identity. If the device goes out of service the previous cell identity is cached and | 
|  | 11789 | * will be returned. If the cache age of the Cell identity is more than 24 hours | 
|  | 11790 | * it will be cleared and null will be returned. | 
|  | 11791 | * | 
|  | 11792 | */ | 
|  | 11793 | @Override | 
|  | 11794 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, | 
|  | 11795 | String callingFeatureId) { | 
|  | 11796 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 11797 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = | 
|  | 11798 | LocationAccessPolicy.checkLocationPermission(mApp, | 
|  | 11799 | new LocationAccessPolicy.LocationPermissionQuery.Builder() | 
|  | 11800 | .setCallingPackage(callingPackage) | 
|  | 11801 | .setCallingFeatureId(callingFeatureId) | 
|  | 11802 | .setCallingPid(Binder.getCallingPid()) | 
|  | 11803 | .setCallingUid(Binder.getCallingUid()) | 
|  | 11804 | .setMethod("getLastKnownCellIdentity") | 
|  | 11805 | .setLogAsInfo(true) | 
|  | 11806 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) | 
|  | 11807 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) | 
|  | 11808 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) | 
|  | 11809 | .build()); | 
|  | 11810 |  | 
|  | 11811 | boolean hasFinePermission = | 
|  | 11812 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; | 
|  | 11813 | if (!hasFinePermission | 
|  | 11814 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { | 
|  | 11815 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " | 
| Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11816 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); | 
| Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11817 | } | 
|  | 11818 |  | 
|  | 11819 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11820 | try { | 
| Ling Ma | c28f021 | 2023-03-24 16:07:15 -0700 | [diff] [blame] | 11821 | ServiceStateTracker sst = getPhoneFromSubIdOrDefault(subId).getServiceStateTracker(); | 
| Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11822 | if (sst == null) return null; | 
|  | 11823 | return sst.getLastKnownCellIdentity(); | 
|  | 11824 | } finally { | 
|  | 11825 | Binder.restoreCallingIdentity(identity); | 
|  | 11826 | } | 
|  | 11827 | } | 
| Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11828 |  | 
| jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11829 | /** | 
|  | 11830 | * Sets the modem service class Name that Telephony will bind to. | 
|  | 11831 | * | 
|  | 11832 | * @param serviceName The class name of the modem service. | 
|  | 11833 | * @return true if the operation is succeed, otherwise false. | 
|  | 11834 | */ | 
|  | 11835 | public boolean setModemService(String serviceName) { | 
|  | 11836 | Log.d(LOG_TAG, "setModemService - " + serviceName); | 
|  | 11837 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); | 
|  | 11838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11839 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
|  | 11840 | "setModemService"); | 
| jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11841 | return mPhoneConfigurationManager.setModemService(serviceName); | 
|  | 11842 | } | 
|  | 11843 |  | 
|  | 11844 | /** | 
|  | 11845 | * Return the class name of the currently bounded modem service. | 
|  | 11846 | * | 
|  | 11847 | * @return the class name of the modem service. | 
|  | 11848 | */ | 
|  | 11849 | public String getModemService() { | 
|  | 11850 | String result; | 
|  | 11851 | Log.d(LOG_TAG, "getModemService"); | 
|  | 11852 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); | 
|  | 11853 | TelephonyPermissions | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 11854 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( | 
| jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11855 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, | 
|  | 11856 | "getModemService"); | 
|  | 11857 | result = mPhoneConfigurationManager.getModemService(); | 
|  | 11858 | Log.d(LOG_TAG, "result = " + result); | 
|  | 11859 | return result; | 
|  | 11860 | } | 
| Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11861 |  | 
|  | 11862 | @Override | 
|  | 11863 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { | 
|  | 11864 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. | 
|  | 11865 | mApp.enforceCallingOrSelfPermission( | 
|  | 11866 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); | 
|  | 11867 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 11868 |  | 
|  | 11869 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11870 | try { | 
|  | 11871 | Phone phone = getPhone(subId); | 
|  | 11872 | if (phone == null) return; | 
| Grant Menke | 63ade12 | 2023-01-20 14:31:54 -0800 | [diff] [blame] | 11873 | Log.i(LOG_TAG, "setVoiceServiceStateOverride: subId=" + subId + ", phone=" + phone | 
|  | 11874 | + ", hasService=" + hasService + ", callingPackage=" + callingPackage); | 
| Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11875 | phone.setVoiceServiceStateOverride(hasService); | 
|  | 11876 | } finally { | 
|  | 11877 | Binder.restoreCallingIdentity(identity); | 
|  | 11878 | } | 
|  | 11879 | } | 
| Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11880 |  | 
|  | 11881 | /** | 
|  | 11882 | * set removable eSIM as default eUICC. | 
|  | 11883 | * | 
|  | 11884 | * @hide | 
|  | 11885 | */ | 
|  | 11886 | @Override | 
|  | 11887 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { | 
|  | 11888 | enforceModifyPermission(); | 
|  | 11889 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 11890 |  | 
|  | 11891 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11892 | try { | 
|  | 11893 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); | 
|  | 11894 | }  finally { | 
|  | 11895 | Binder.restoreCallingIdentity(identity); | 
|  | 11896 | } | 
|  | 11897 | } | 
|  | 11898 |  | 
|  | 11899 | /** | 
|  | 11900 | * Returns whether the removable eSIM is default eUICC or not. | 
|  | 11901 | * | 
|  | 11902 | * @hide | 
|  | 11903 | */ | 
|  | 11904 | @Override | 
|  | 11905 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { | 
|  | 11906 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); | 
|  | 11907 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); | 
|  | 11908 |  | 
|  | 11909 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11910 | try { | 
|  | 11911 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); | 
|  | 11912 | }  finally { | 
|  | 11913 | Binder.restoreCallingIdentity(identity); | 
|  | 11914 | } | 
|  | 11915 | } | 
|  | 11916 |  | 
| Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11917 | /** | 
|  | 11918 | * Get the component name of the default app to direct respond-via-message intent for the | 
|  | 11919 | * user associated with this subscription, update the cache if there is no respond-via-message | 
|  | 11920 | * application currently configured for this user. | 
|  | 11921 | * @return component name of the app and class to direct Respond Via Message intent to, or | 
|  | 11922 | * {@code null} if the functionality is not supported. | 
|  | 11923 | * @hide | 
|  | 11924 | */ | 
|  | 11925 | @Override | 
|  | 11926 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, | 
|  | 11927 | boolean updateIfNeeded) { | 
|  | 11928 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); | 
| Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11929 |  | 
| Aishwarya Mallampati | 5e581e1 | 2023-01-17 21:57:06 +0000 | [diff] [blame] | 11930 | Context context = getPhoneFromSubIdOrDefault(subId).getContext(); | 
|  | 11931 |  | 
| Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame] | 11932 | UserHandle userHandle = null; | 
|  | 11933 | final long identity = Binder.clearCallingIdentity(); | 
|  | 11934 | try { | 
|  | 11935 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); | 
|  | 11936 | } finally { | 
|  | 11937 | Binder.restoreCallingIdentity(identity); | 
|  | 11938 | } | 
|  | 11939 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, | 
|  | 11940 | updateIfNeeded, userHandle); | 
|  | 11941 | } | 
| Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11942 |  | 
|  | 11943 | /** | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11944 | * Set whether the device is able to connect with null ciphering or integrity | 
|  | 11945 | * algorithms. This is a global setting and will apply to all active subscriptions | 
|  | 11946 | * and all new subscriptions after this. | 
|  | 11947 | * | 
|  | 11948 | * @param enabled when true, null  cipher and integrity algorithms are allowed. | 
|  | 11949 | * @hide | 
|  | 11950 | */ | 
|  | 11951 | @Override | 
|  | 11952 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) | 
|  | 11953 | public void setNullCipherAndIntegrityEnabled(boolean enabled) { | 
|  | 11954 | enforceModifyPermission(); | 
|  | 11955 | checkForNullCipherAndIntegritySupport(); | 
|  | 11956 |  | 
|  | 11957 | // Persist the state of our preference. Each GsmCdmaPhone instance is responsible | 
|  | 11958 | // for listening to these preference changes and applying them immediately. | 
|  | 11959 | SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); | 
|  | 11960 | editor.putBoolean(Phone.PREF_NULL_CIPHER_AND_INTEGRITY_ENABLED, enabled); | 
|  | 11961 | editor.apply(); | 
|  | 11962 |  | 
|  | 11963 | for (Phone phone: PhoneFactory.getPhones()) { | 
|  | 11964 | phone.handleNullCipherEnabledChange(); | 
|  | 11965 | } | 
|  | 11966 | } | 
|  | 11967 |  | 
|  | 11968 |  | 
|  | 11969 | /** | 
|  | 11970 | * Get whether the device is able to connect with null ciphering or integrity | 
|  | 11971 | * algorithms. Note that this retrieves the phone-global preference and not | 
|  | 11972 | * the state of the radio. | 
|  | 11973 | * | 
|  | 11974 | * @throws SecurityException if {@link permission#MODIFY_PHONE_STATE} is not satisfied | 
|  | 11975 | * @throws UnsupportedOperationException if the device does not support the minimum HAL | 
|  | 11976 | * version for this feature. | 
|  | 11977 | * @hide | 
|  | 11978 | */ | 
|  | 11979 | @Override | 
|  | 11980 | @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) | 
|  | 11981 | public boolean isNullCipherAndIntegrityPreferenceEnabled() { | 
|  | 11982 | enforceReadPermission(); | 
|  | 11983 | checkForNullCipherAndIntegritySupport(); | 
|  | 11984 | return getDefaultPhone().getNullCipherAndIntegrityEnabledPreference(); | 
|  | 11985 | } | 
|  | 11986 |  | 
|  | 11987 | private void checkForNullCipherAndIntegritySupport() { | 
|  | 11988 | if (getHalVersion(HAL_SERVICE_NETWORK) < MIN_NULL_CIPHER_AND_INTEGRITY_VERSION) { | 
|  | 11989 | throw new UnsupportedOperationException( | 
|  | 11990 | "Null cipher and integrity operations require HAL 2.1 or above"); | 
|  | 11991 | } | 
| Gil Cukierman | 92cc7db | 2023-01-06 19:25:53 +0000 | [diff] [blame] | 11992 | if (!getDefaultPhone().isNullCipherAndIntegritySupported()) { | 
|  | 11993 | throw new UnsupportedOperationException( | 
|  | 11994 | "Null cipher and integrity operations unsupported by modem"); | 
|  | 11995 | } | 
| Gil Cukierman | 1c0eb93 | 2022-12-06 22:28:24 +0000 | [diff] [blame] | 11996 | } | 
|  | 11997 |  | 
|  | 11998 | /** | 
| Jack Yu | f5badd9 | 2022-12-08 00:50:53 -0800 | [diff] [blame] | 11999 | * Get the SIM state for the slot index. | 
|  | 12000 | * For Remote-SIMs, this method returns {@link IccCardConstants.State#UNKNOWN} | 
|  | 12001 | * | 
|  | 12002 | * @return SIM state as the ordinal of {@link IccCardConstants.State} | 
|  | 12003 | */ | 
|  | 12004 | @Override | 
|  | 12005 | @SimState | 
|  | 12006 | public int getSimStateForSlotIndex(int slotIndex) { | 
|  | 12007 | IccCardConstants.State simState; | 
|  | 12008 | if (slotIndex < 0) { | 
|  | 12009 | simState = IccCardConstants.State.UNKNOWN; | 
|  | 12010 | } else { | 
|  | 12011 | Phone phone = null; | 
|  | 12012 | try { | 
|  | 12013 | phone = PhoneFactory.getPhone(slotIndex); | 
|  | 12014 | } catch (IllegalStateException e) { | 
|  | 12015 | // ignore | 
|  | 12016 | } | 
|  | 12017 | if (phone == null) { | 
|  | 12018 | simState = IccCardConstants.State.UNKNOWN; | 
|  | 12019 | } else { | 
|  | 12020 | IccCard icc = phone.getIccCard(); | 
|  | 12021 | if (icc == null) { | 
|  | 12022 | simState = IccCardConstants.State.UNKNOWN; | 
|  | 12023 | } else { | 
|  | 12024 | simState = icc.getState(); | 
|  | 12025 | } | 
|  | 12026 | } | 
|  | 12027 | } | 
|  | 12028 | return simState.ordinal(); | 
|  | 12029 | } | 
| Hui Wang | 9b5793a | 2022-12-05 14:38:06 -0600 | [diff] [blame] | 12030 |  | 
|  | 12031 | /** | 
|  | 12032 | * Get current cell broadcast ranges. | 
|  | 12033 | */ | 
|  | 12034 | @Override | 
|  | 12035 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) | 
|  | 12036 | public List<CellBroadcastIdRange> getCellBroadcastIdRanges(int subId) { | 
|  | 12037 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, | 
|  | 12038 | "getCellBroadcastIdRanges"); | 
|  | 12039 | final long identity = Binder.clearCallingIdentity(); | 
|  | 12040 | try { | 
|  | 12041 | return getPhone(subId).getCellBroadcastIdRanges(); | 
|  | 12042 | } finally { | 
|  | 12043 | Binder.restoreCallingIdentity(identity); | 
|  | 12044 | } | 
|  | 12045 | } | 
|  | 12046 |  | 
|  | 12047 | /** | 
|  | 12048 | * Set reception of cell broadcast messages with the list of the given ranges | 
|  | 12049 | * | 
|  | 12050 | * @param ranges the list of {@link CellBroadcastIdRange} to be enabled | 
|  | 12051 | */ | 
|  | 12052 | @Override | 
|  | 12053 | @RequiresPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS) | 
|  | 12054 | public void setCellBroadcastIdRanges(int subId, @NonNull List<CellBroadcastIdRange> ranges, | 
|  | 12055 | @Nullable IIntegerConsumer callback) { | 
|  | 12056 | mApp.enforceCallingPermission(android.Manifest.permission.MODIFY_CELL_BROADCASTS, | 
|  | 12057 | "setCellBroadcastIdRanges"); | 
|  | 12058 | final long identity = Binder.clearCallingIdentity(); | 
|  | 12059 | try { | 
|  | 12060 | Phone phone = getPhoneFromSubId(subId); | 
|  | 12061 | if (DBG) { | 
|  | 12062 | log("setCellBroadcastIdRanges for subId :" + subId + ", phone:" + phone); | 
|  | 12063 | } | 
|  | 12064 | phone.setCellBroadcastIdRanges(ranges, result -> { | 
|  | 12065 | if (callback != null) { | 
|  | 12066 | try { | 
|  | 12067 | callback.accept(result); | 
|  | 12068 | } catch (RemoteException e) { | 
|  | 12069 | Log.w(LOG_TAG, "setCellBroadcastIdRanges: callback not available."); | 
|  | 12070 | } | 
|  | 12071 | } | 
|  | 12072 | }); | 
|  | 12073 | } finally { | 
|  | 12074 | Binder.restoreCallingIdentity(identity); | 
|  | 12075 | } | 
|  | 12076 | } | 
| Hunsuk Choi | 42cc62a | 2022-10-16 06:03:40 +0000 | [diff] [blame] | 12077 |  | 
|  | 12078 | /** | 
|  | 12079 | * Returns whether the device supports the domain selection service. | 
|  | 12080 | * | 
|  | 12081 | * @return {@code true} if the device supports the domain selection service. | 
|  | 12082 | */ | 
|  | 12083 | @Override | 
|  | 12084 | public boolean isDomainSelectionSupported() { | 
|  | 12085 | mApp.enforceCallingOrSelfPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE, | 
|  | 12086 | "isDomainSelectionSupported"); | 
|  | 12087 |  | 
|  | 12088 | final long identity = Binder.clearCallingIdentity(); | 
|  | 12089 | try { | 
|  | 12090 | return DomainSelectionResolver.getInstance().isDomainSelectionSupported(); | 
|  | 12091 | }  finally { | 
|  | 12092 | Binder.restoreCallingIdentity(identity); | 
|  | 12093 | } | 
|  | 12094 | } | 
| arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12095 |  | 
|  | 12096 | /** | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12097 | * Request to enable or disable the satellite modem and demo mode. If the satellite modem is | 
|  | 12098 | * enabled, this may also disable the cellular modem, and if the satellite modem is disabled, | 
|  | 12099 | * this may also re-enable the cellular modem. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12100 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12101 | * @param subId The subId of the subscription to set satellite enabled for. | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12102 | * @param enableSatellite {@code true} to enable the satellite modem and | 
|  | 12103 | *                        {@code false} to disable. | 
|  | 12104 | * @param enableDemoMode {@code true} to enable demo mode and {@code false} to disable. | 
|  | 12105 | * @param callback The callback to get the result of the request. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12106 | * | 
|  | 12107 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12108 | */ | 
|  | 12109 | @Override | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12110 | public void requestSatelliteEnabled(int subId, boolean enableSatellite, boolean enableDemoMode, | 
|  | 12111 | @NonNull IIntegerConsumer callback) { | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12112 | enforceSatelliteCommunicationPermission("requestSatelliteEnabled"); | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12113 | mSatelliteController.requestSatelliteEnabled(subId, enableSatellite, enableDemoMode, | 
|  | 12114 | callback); | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12115 | } | 
|  | 12116 |  | 
|  | 12117 | /** | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12118 | * Request to get whether the satellite modem is enabled. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12119 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12120 | * @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] | 12121 | * @param result The result receiver that returns whether the satellite modem is enabled | 
|  | 12122 | *               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] | 12123 | * | 
|  | 12124 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12125 | */ | 
|  | 12126 | @Override | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12127 | public void requestIsSatelliteEnabled(int subId, @NonNull ResultReceiver result) { | 
|  | 12128 | enforceSatelliteCommunicationPermission("requestIsSatelliteEnabled"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12129 | mSatelliteController.requestIsSatelliteEnabled(subId, result); | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12130 | } | 
|  | 12131 |  | 
|  | 12132 | /** | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12133 | * Request to get whether the satellite service demo mode is enabled. | 
|  | 12134 | * | 
|  | 12135 | * @param subId The subId of the subscription to check whether the satellite demo mode | 
|  | 12136 | *              is enabled for. | 
|  | 12137 | * @param result The result receiver that returns whether the satellite demo mode is enabled | 
|  | 12138 | *               if the request is successful or an error code if the request failed. | 
|  | 12139 | * | 
|  | 12140 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12141 | */ | 
|  | 12142 | @Override | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12143 | public void requestIsDemoModeEnabled(int subId, @NonNull ResultReceiver result) { | 
|  | 12144 | enforceSatelliteCommunicationPermission("requestIsDemoModeEnabled"); | 
|  | 12145 | mSatelliteController.requestIsDemoModeEnabled(subId, result); | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12146 | } | 
|  | 12147 |  | 
|  | 12148 | /** | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12149 | * Request to get whether the satellite service is supported on the device. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12150 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12151 | * @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] | 12152 | * @param result The result receiver that returns whether the satellite service is supported on | 
|  | 12153 | *               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] | 12154 | */ | 
|  | 12155 | @Override | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12156 | public void requestIsSatelliteSupported(int subId, @NonNull ResultReceiver result) { | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12157 | mSatelliteController.requestIsSatelliteSupported(subId, result); | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12158 | } | 
|  | 12159 |  | 
|  | 12160 | /** | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12161 | * Request to get the {@link SatelliteCapabilities} of the satellite service. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12162 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12163 | * @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] | 12164 | * @param result The result receiver that returns the {@link SatelliteCapabilities} | 
|  | 12165 | *               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] | 12166 | * | 
|  | 12167 | * @throws SecurityException if the caller doesn't have required permission. | 
|  | 12168 | */ | 
|  | 12169 | @Override | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12170 | public void requestSatelliteCapabilities(int subId, @NonNull ResultReceiver result) { | 
|  | 12171 | enforceSatelliteCommunicationPermission("requestSatelliteCapabilities"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12172 | mSatelliteController.requestSatelliteCapabilities(subId, result); | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12173 | } | 
|  | 12174 |  | 
|  | 12175 | /** | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12176 | * Start receiving satellite transmission updates. | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12177 | * This can be called by the pointing UI when the user starts pointing to the satellite. | 
|  | 12178 | * Modem should continue to report the pointing input as the device or satellite moves. | 
|  | 12179 | * | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12180 | * @param subId The subId of the subscription to start satellite transmission updates for. | 
|  | 12181 | * @param resultCallback The callback to get the result of the request. | 
|  | 12182 | * @param callback The callback to notify of satellite transmission updates. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12183 | * | 
|  | 12184 | * @throws SecurityException if the caller doesn't have the required permission. | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12185 | */ | 
|  | 12186 | @Override | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12187 | public void startSatelliteTransmissionUpdates(int subId, | 
|  | 12188 | @NonNull IIntegerConsumer resultCallback, | 
|  | 12189 | @NonNull ISatelliteTransmissionUpdateCallback callback) { | 
|  | 12190 | enforceSatelliteCommunicationPermission("startSatelliteTransmissionUpdates"); | 
|  | 12191 | mSatelliteController.startSatelliteTransmissionUpdates(subId, resultCallback, callback); | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12192 | } | 
|  | 12193 |  | 
|  | 12194 | /** | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12195 | * Stop receiving satellite transmission updates. | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12196 | * This can be called by the pointing UI when the user stops pointing to the satellite. | 
|  | 12197 | * | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12198 | * @param subId The subId of the subscription to stop satellite transmission updates for. | 
|  | 12199 | * @param resultCallback The callback to get the result of the request. | 
|  | 12200 | * @param callback The callback that was passed to {@link #startSatelliteTransmissionUpdates( | 
|  | 12201 | *                 int, IIntegerConsumer, ISatelliteTransmissionUpdateCallback)}. | 
| Sarah Chin | 503828c | 2023-02-01 23:54:20 -0800 | [diff] [blame] | 12202 | * | 
|  | 12203 | * @throws SecurityException if the caller doesn't have the required permission. | 
| Sarah Chin | eccfbd1 | 2023-01-20 19:00:35 -0800 | [diff] [blame] | 12204 | */ | 
|  | 12205 | @Override | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12206 | public void stopSatelliteTransmissionUpdates(int subId, | 
|  | 12207 | @NonNull IIntegerConsumer resultCallback, | 
|  | 12208 | @NonNull ISatelliteTransmissionUpdateCallback callback) { | 
|  | 12209 | enforceSatelliteCommunicationPermission("stopSatelliteTransmissionUpdates"); | 
|  | 12210 | mSatelliteController.stopSatelliteTransmissionUpdates(subId, resultCallback, callback); | 
| Aishwarya Mallampati | 60fe113 | 2023-01-24 19:07:21 +0000 | [diff] [blame] | 12211 | } | 
|  | 12212 |  | 
|  | 12213 | /** | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12214 | * Register the subscription with a satellite provider. | 
|  | 12215 | * This is needed to register the subscription if the provider allows dynamic registration. | 
|  | 12216 | * | 
|  | 12217 | * @param subId The subId of the subscription to be provisioned. | 
| Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12218 | * @param token The token to be used as a unique identifier for provisioning with satellite | 
|  | 12219 | *              gateway. | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12220 | * @param regionId The region ID for the device's current location. | 
|  | 12221 | * @param callback The callback to get the result of the request. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12222 | * | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12223 | * @return The signal transport used by the caller to cancel the provision request, | 
|  | 12224 | *         or {@code null} if the request failed. | 
|  | 12225 | * | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12226 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12227 | */ | 
|  | 12228 | @Override | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12229 | @Nullable public ICancellationSignal provisionSatelliteService(int subId, | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12230 | @NonNull String token, @NonNull String regionId, @NonNull IIntegerConsumer callback) { | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12231 | enforceSatelliteCommunicationPermission("provisionSatelliteService"); | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12232 | return mSatelliteController.provisionSatelliteService(subId, token, regionId, callback); | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12233 | } | 
|  | 12234 |  | 
|  | 12235 | /** | 
| Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12236 | * Unregister the device/subscription with the satellite provider. | 
|  | 12237 | * This is needed if the provider allows dynamic registration. Once deprovisioned, | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12238 | * {@link SatelliteProvisionStateCallback#onSatelliteProvisionStateChanged(boolean)} | 
| Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12239 | * should report as deprovisioned. | 
|  | 12240 | * | 
|  | 12241 | * @param subId The subId of the subscription to be deprovisioned. | 
|  | 12242 | * @param token The token of the device/subscription to be deprovisioned. | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12243 | * @param callback The callback to get the result of the request. | 
| Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12244 | * | 
|  | 12245 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12246 | */ | 
|  | 12247 | @Override | 
|  | 12248 | public void deprovisionSatelliteService(int subId, | 
|  | 12249 | @NonNull String token, @NonNull IIntegerConsumer callback) { | 
|  | 12250 | enforceSatelliteCommunicationPermission("deprovisionSatelliteService"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12251 | mSatelliteController.deprovisionSatelliteService(subId, token, callback); | 
| Thomas Nguyen | 4a29b8e | 2023-02-13 09:26:15 -0800 | [diff] [blame] | 12252 | } | 
|  | 12253 |  | 
|  | 12254 | /** | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12255 | * Registers for the satellite provision state changed. | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12256 | * | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12257 | * @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] | 12258 | * @param callback The callback to handle the satellite provision state changed event. | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12259 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12260 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. | 
|  | 12261 | * | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12262 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12263 | */ | 
|  | 12264 | @Override | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12265 | @SatelliteManager.SatelliteError public int registerForSatelliteProvisionStateChanged(int subId, | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12266 | @NonNull ISatelliteProvisionStateCallback callback) { | 
| Thomas Nguyen | e77de6d | 2023-02-10 17:42:43 -0800 | [diff] [blame] | 12267 | enforceSatelliteCommunicationPermission("registerForSatelliteProvisionStateChanged"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12268 | return mSatelliteController.registerForSatelliteProvisionStateChanged(subId, callback); | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12269 | } | 
|  | 12270 |  | 
|  | 12271 | /** | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12272 | * Unregisters for the satellite provision state changed. | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12273 | * If callback was not registered before, the request will be ignored. | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12274 | * | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12275 | * @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] | 12276 | * @param callback The callback that was passed to | 
|  | 12277 | * {@link #registerForSatelliteProvisionStateChanged(int, ISatelliteProvisionStateCallback)}. | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12278 | * | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12279 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12280 | */ | 
|  | 12281 | @Override | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12282 | public void unregisterForSatelliteProvisionStateChanged( | 
|  | 12283 | int subId, @NonNull ISatelliteProvisionStateCallback callback) { | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12284 | enforceSatelliteCommunicationPermission("unregisterForSatelliteProvisionStateChanged"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12285 | mSatelliteController.unregisterForSatelliteProvisionStateChanged(subId, callback); | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12286 | } | 
|  | 12287 |  | 
|  | 12288 | /** | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12289 | * Request to get whether the device is provisioned with a satellite provider. | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12290 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12291 | * @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] | 12292 | * @param result The result receiver that returns whether the device is provisioned with a | 
|  | 12293 | *               satellite provider if the request is successful or an error code if the | 
|  | 12294 | *               request failed. | 
|  | 12295 | * | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12296 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12297 | */ | 
|  | 12298 | @Override | 
| Sarah Chin | 4a9e8b8 | 2023-02-10 21:10:57 -0800 | [diff] [blame] | 12299 | public void requestIsSatelliteProvisioned(int subId, @NonNull ResultReceiver result) { | 
|  | 12300 | enforceSatelliteCommunicationPermission("requestIsSatelliteProvisioned"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12301 | mSatelliteController.requestIsSatelliteProvisioned(subId, result); | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12302 | } | 
|  | 12303 |  | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12304 | /** | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12305 | * Registers for modem state changed from satellite modem. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12306 | * | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12307 | * @param subId The subId of the subscription to register for satellite modem state changed. | 
|  | 12308 | * @param callback The callback to handle the satellite modem state changed event. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12309 | * | 
|  | 12310 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. | 
|  | 12311 | * | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12312 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12313 | */ | 
|  | 12314 | @Override | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12315 | @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId, | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12316 | @NonNull ISatelliteStateCallback callback) { | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12317 | enforceSatelliteCommunicationPermission("registerForSatelliteModemStateChanged"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12318 | return mSatelliteController.registerForSatelliteModemStateChanged(subId, callback); | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12319 | } | 
|  | 12320 |  | 
|  | 12321 | /** | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12322 | * Unregisters for modem state changed from satellite modem. | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12323 | * If callback was not registered before, the request will be ignored. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12324 | * | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12325 | * @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] | 12326 | * @param callback The callback that was passed to | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12327 | *                 {@link #registerForSatelliteModemStateChanged(int, ISatelliteStateCallback)}. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12328 | * | 
|  | 12329 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12330 | */ | 
|  | 12331 | @Override | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12332 | public void unregisterForSatelliteModemStateChanged(int subId, | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12333 | @NonNull ISatelliteStateCallback callback) { | 
| Sarah Chin | 4345798 | 2023-02-15 17:50:38 -0800 | [diff] [blame] | 12334 | enforceSatelliteCommunicationPermission("unregisterForSatelliteModemStateChanged"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12335 | mSatelliteController.unregisterForSatelliteModemStateChanged(subId, callback); | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12336 | } | 
|  | 12337 |  | 
|  | 12338 | /** | 
|  | 12339 | * Register to receive incoming datagrams over satellite. | 
|  | 12340 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12341 | * @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] | 12342 | * @param callback The callback to handle incoming datagrams over satellite. | 
|  | 12343 | * | 
|  | 12344 | * @return The {@link SatelliteManager.SatelliteError} result of the operation. | 
|  | 12345 | * | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12346 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12347 | */ | 
|  | 12348 | @Override | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12349 | @SatelliteManager.SatelliteError public int registerForSatelliteDatagram(int subId, | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12350 | @NonNull ISatelliteDatagramCallback callback) { | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12351 | enforceSatelliteCommunicationPermission("registerForSatelliteDatagram"); | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12352 | return mSatelliteController.registerForSatelliteDatagram(subId, callback); | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12353 | } | 
|  | 12354 |  | 
|  | 12355 | /** | 
|  | 12356 | * Unregister to stop receiving incoming datagrams over satellite. | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12357 | * If callback was not registered before, the request will be ignored. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12358 | * | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12359 | * @param subId The subId of the subscription to unregister for incoming satellite datagrams. | 
|  | 12360 | * @param callback The callback that was passed to | 
| Sarah Chin | abf081b | 2023-03-09 23:00:57 -0800 | [diff] [blame] | 12361 | *                 {@link #registerForSatelliteDatagram(int, ISatelliteDatagramCallback)}. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12362 | * | 
|  | 12363 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12364 | */ | 
|  | 12365 | @Override | 
| Thomas Nguyen | 299d6cd | 2023-02-14 09:57:15 -0800 | [diff] [blame] | 12366 | public void unregisterForSatelliteDatagram(int subId, | 
|  | 12367 | @NonNull ISatelliteDatagramCallback callback) { | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12368 | enforceSatelliteCommunicationPermission("unregisterForSatelliteDatagram"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12369 | mSatelliteController.unregisterForSatelliteDatagram(subId, callback); | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12370 | } | 
|  | 12371 |  | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12372 | /** | 
|  | 12373 | * Poll pending satellite datagrams over satellite. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12374 | * | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12375 | * This method requests modem to check if there are any pending datagrams to be received over | 
|  | 12376 | * satellite. If there are any incoming datagrams, they will be received via | 
| Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12377 | * {@link SatelliteDatagramCallback#onSatelliteDatagramReceived(long, SatelliteDatagram, int, | 
| Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12378 | * ILongConsumer)})} | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12379 | * | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12380 | * @param subId The subId of the subscription used for receiving datagrams. | 
|  | 12381 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12382 | * | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12383 | * @throws SecurityException if the caller doesn't have required permission. | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12384 | */ | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12385 | @Override | 
|  | 12386 | public void pollPendingSatelliteDatagrams(int subId, IIntegerConsumer callback) { | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12387 | enforceSatelliteCommunicationPermission("pollPendingSatelliteDatagrams"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12388 | mSatelliteController.pollPendingSatelliteDatagrams(subId, callback); | 
| Aishwarya Mallampati | 740d9ab | 2023-02-08 23:07:05 +0000 | [diff] [blame] | 12389 | } | 
|  | 12390 |  | 
| Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12391 | /** | 
|  | 12392 | * Send datagram over satellite. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12393 | * | 
| Aishwarya Mallampati | 4d9a094 | 2023-02-16 18:01:53 +0000 | [diff] [blame] | 12394 | * Gateway encodes SOS message or location sharing message into a datagram and passes it as | 
|  | 12395 | * input to this method. Datagram received here will be passed down to modem without any | 
|  | 12396 | * encoding or encryption. | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12397 | * | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12398 | * @param subId The subId of the subscription to send satellite datagrams for. | 
|  | 12399 | * @param datagramType datagram type indicating whether the datagram is of type | 
|  | 12400 | *                     SOS_SMS or LOCATION_SHARING. | 
|  | 12401 | * @param datagram encoded gateway datagram which is encrypted by the caller. | 
|  | 12402 | *                 Datagram will be passed down to modem without any encoding or encryption. | 
| Aishwarya Mallampati | a46437b | 2023-02-21 18:52:58 +0000 | [diff] [blame] | 12403 | * @param needFullScreenPointingUI this is used to indicate pointingUI app to open in | 
|  | 12404 | *                                 full screen mode. | 
| Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12405 | * @param callback The callback to get {@link SatelliteManager.SatelliteError} of the request. | 
| Aishwarya Mallampati | 224317a | 2023-02-13 22:09:30 +0000 | [diff] [blame] | 12406 | * | 
|  | 12407 | * @throws SecurityException if the caller doesn't have required permission. | 
| Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12408 | */ | 
|  | 12409 | @Override | 
| Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12410 | public void sendSatelliteDatagram(int subId, @SatelliteManager.DatagramType int datagramType, | 
|  | 12411 | @NonNull SatelliteDatagram datagram, boolean needFullScreenPointingUI, | 
|  | 12412 | @NonNull IIntegerConsumer callback) { | 
| Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12413 | enforceSatelliteCommunicationPermission("sendSatelliteDatagram"); | 
| Aishwarya Mallampati | 14e0de0 | 2023-03-03 00:34:32 +0000 | [diff] [blame] | 12414 | mSatelliteController.sendSatelliteDatagram(subId, datagramType, datagram, | 
|  | 12415 | needFullScreenPointingUI, callback); | 
| Aishwarya Mallampati | e8ac686 | 2023-02-09 22:13:02 +0000 | [diff] [blame] | 12416 | } | 
|  | 12417 |  | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12418 | /** | 
|  | 12419 | * Request to get whether satellite communication is allowed for the current location. | 
|  | 12420 | * | 
|  | 12421 | * @param subId The subId of the subscription to check whether satellite communication is | 
|  | 12422 | *              allowed for the current location for. | 
|  | 12423 | * @param result The result receiver that returns whether satellite communication is allowed | 
|  | 12424 | *               for the current location if the request is successful or an error code | 
|  | 12425 | *               if the request failed. | 
|  | 12426 | * | 
|  | 12427 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12428 | */ | 
|  | 12429 | @Override | 
|  | 12430 | public void requestIsSatelliteCommunicationAllowedForCurrentLocation(int subId, | 
|  | 12431 | @NonNull ResultReceiver result) { | 
|  | 12432 | enforceSatelliteCommunicationPermission( | 
|  | 12433 | "requestIsSatelliteCommunicationAllowedForCurrentLocation"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12434 | mSatelliteController.requestIsSatelliteCommunicationAllowedForCurrentLocation(subId, | 
|  | 12435 | result); | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12436 | } | 
|  | 12437 |  | 
|  | 12438 | /** | 
| Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12439 | * Request to get the time after which the satellite will be visible | 
| Sarah Chin | df715ec | 2023-02-13 13:46:24 -0800 | [diff] [blame] | 12440 | * | 
| Sarah Chin | 5f57c58 | 2023-02-14 04:16:10 -0800 | [diff] [blame] | 12441 | * @param subId The subId to get the time after which the satellite will be visible for. | 
|  | 12442 | * @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] | 12443 | *               be visible if the request is successful or an error code if the request failed. | 
|  | 12444 | * | 
|  | 12445 | * @throws SecurityException if the caller doesn't have the required permission. | 
|  | 12446 | */ | 
|  | 12447 | @Override | 
|  | 12448 | public void requestTimeForNextSatelliteVisibility(int subId, @NonNull ResultReceiver result) { | 
|  | 12449 | enforceSatelliteCommunicationPermission("requestTimeForNextSatelliteVisibility"); | 
| Aishwarya Mallampati | 481aeee | 2023-02-17 21:32:22 +0000 | [diff] [blame] | 12450 | mSatelliteController.requestTimeForNextSatelliteVisibility(subId, result); | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12451 | } | 
|  | 12452 |  | 
| Thomas Nguyen | 8ee4968 | 2023-02-01 11:46:09 -0800 | [diff] [blame] | 12453 | /** | 
| arunvoddu | d5c6ce0 | 2022-12-11 06:03:12 +0000 | [diff] [blame] | 12454 | * Check whether the caller (or self, if not processing an IPC) can read device identifiers. | 
|  | 12455 | * | 
|  | 12456 | * <p>This method behaves in one of the following ways: | 
|  | 12457 | * <ul> | 
|  | 12458 | *     <li>return true : if the calling package has the appop permission {@link | 
|  | 12459 | *     Manifest.permission#USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER} in the manifest </> | 
|  | 12460 | *     <li>return true : if any one subscription has the READ_PRIVILEGED_PHONE_STATE | 
|  | 12461 | *     permission, the calling package passes a DevicePolicyManager Device Owner / Profile | 
|  | 12462 | *     Owner device identifier access check, or the calling package has carrier privileges</> | 
|  | 12463 | *     <li>throw SecurityException: if the caller does not meet any of the requirements. | 
|  | 12464 | * </ul> | 
|  | 12465 | */ | 
|  | 12466 | private static boolean checkCallingOrSelfReadDeviceIdentifiersForAnySub(Context context, | 
|  | 12467 | String callingPackage, @Nullable String callingFeatureId, String message) { | 
|  | 12468 | for (Phone phone : PhoneFactory.getPhones()) { | 
|  | 12469 | if (TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(context, | 
|  | 12470 | phone.getSubId(), callingPackage, callingFeatureId, message)) { | 
|  | 12471 | return true; | 
|  | 12472 | } | 
|  | 12473 | } | 
|  | 12474 | return false; | 
|  | 12475 | } | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12476 |  | 
|  | 12477 | /** | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12478 | * @return The subscription manager service instance. | 
|  | 12479 | */ | 
|  | 12480 | public SubscriptionManagerService getSubscriptionManagerService() { | 
|  | 12481 | return SubscriptionManagerService.getInstance(); | 
|  | 12482 | } | 
|  | 12483 |  | 
|  | 12484 | /** | 
| arunvoddu | d740101 | 2022-12-15 16:08:12 +0000 | [diff] [blame] | 12485 | * Class binds the consumer[callback] and carrierId. | 
|  | 12486 | */ | 
|  | 12487 | private static class CallerCallbackInfo { | 
|  | 12488 | private final Consumer<Integer> mConsumer; | 
|  | 12489 | private final int mCarrierId; | 
|  | 12490 |  | 
|  | 12491 | public CallerCallbackInfo(Consumer<Integer> consumer, int carrierId) { | 
|  | 12492 | mConsumer = consumer; | 
|  | 12493 | mCarrierId = carrierId; | 
|  | 12494 | } | 
|  | 12495 |  | 
|  | 12496 | public Consumer<Integer> getConsumer() { | 
|  | 12497 | return mConsumer; | 
|  | 12498 | } | 
|  | 12499 |  | 
|  | 12500 | public int getCarrierId() { | 
|  | 12501 | return mCarrierId; | 
|  | 12502 | } | 
|  | 12503 | } | 
| Jack Yu | fa8ed01 | 2023-02-11 15:42:28 -0800 | [diff] [blame] | 12504 | } |