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; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | 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] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 34 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 35 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 36 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 37 | import android.compat.annotation.ChangeId; |
| 38 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 44 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.AsyncResult; |
| 48 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 49 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 52 | import android.os.IBinder; |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 53 | import android.os.LocaleList; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.Looper; |
| 55 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 56 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 57 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 58 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 59 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 60 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 61 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 62 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 63 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 64 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 65 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 66 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 67 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 68 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 69 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 70 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 71 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 72 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 74 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 75 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 76 | import android.telephony.AccessNetworkConstants; |
| 77 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 78 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 79 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 80 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 81 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 82 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 83 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 84 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 85 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 86 | import android.telephony.CellIdentityCdma; |
| 87 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 89 | import android.telephony.CellInfoGsm; |
| 90 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 91 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 92 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 93 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 94 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 95 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 96 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 97 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 98 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 99 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 100 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 101 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 102 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 103 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 104 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 105 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 106 | import android.telephony.SignalStrengthUpdateRequest; |
| 107 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 108 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 109 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 110 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 111 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 112 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 113 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 114 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 115 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 116 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 117 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 118 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 119 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 120 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 121 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 122 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 123 | import android.telephony.gba.GbaAuthRequest; |
| 124 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 125 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 126 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 127 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 128 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 129 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 136 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 137 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 138 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 139 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 141 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 142 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 144 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 145 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 146 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 147 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 148 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 149 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 164 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 180 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.data.DataUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 193 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 194 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccIoResult; |
| 198 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 206 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 208 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 210 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 211 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 212 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 213 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 214 | import com.android.phone.slicestore.SliceStore; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 216 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 218 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 219 | import com.android.services.telephony.TelecomAccountRegistry; |
| 220 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 221 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 222 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 224 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 225 | import java.io.IOException; |
| 226 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 227 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 229 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 230 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 231 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 232 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 233 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 234 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 235 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 236 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 237 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 238 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 239 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 240 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 241 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 242 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 243 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * Implementation of the ITelephony interface. |
| 247 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 248 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 249 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 250 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 251 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 252 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | |
| 254 | // Message codes used with mMainThreadHandler |
| 255 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 256 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 257 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 258 | private static final int CMD_OPEN_CHANNEL = 9; |
| 259 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 260 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 261 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 262 | private static final int CMD_NV_READ_ITEM = 13; |
| 263 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 264 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 265 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 266 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 267 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 268 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 269 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 270 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 271 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 272 | private static final int CMD_SEND_ENVELOPE = 25; |
| 273 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 274 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 275 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 276 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 277 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 278 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 279 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 280 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 281 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 282 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 283 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 284 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 285 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 286 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 287 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 288 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 289 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 290 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 291 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 292 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 293 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 294 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 295 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 296 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 297 | private static final int CMD_SWITCH_SLOTS = 50; |
| 298 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 299 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 300 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 301 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 302 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 303 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 304 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 305 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 306 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 307 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 308 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 309 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 310 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 311 | private static final int CMD_MODEM_REBOOT = 64; |
| 312 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 313 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 314 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 315 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 316 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 318 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 320 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 321 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 322 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 323 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 324 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 325 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 326 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 327 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 328 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 329 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 330 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 331 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 332 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 333 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 334 | private static final int CMD_GET_CALL_WAITING = 87; |
| 335 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 336 | private static final int CMD_SET_CALL_WAITING = 89; |
| 337 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 338 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 339 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 340 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 341 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 342 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 343 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 344 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 345 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 347 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 348 | private static final int CMD_SET_SIM_POWER = 101; |
| 349 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 350 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 351 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 352 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 353 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 354 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 355 | 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] | 356 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 357 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 358 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 359 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 360 | private static final int CMD_ENABLE_VONR = 113; |
| 361 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 362 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 363 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 364 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 365 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 367 | // Parameters of select command. |
| 368 | private static final int SELECT_COMMAND = 0xA4; |
| 369 | private static final int SELECT_P1 = 0x04; |
| 370 | private static final int SELECT_P2 = 0; |
| 371 | private static final int SELECT_P3 = 0x10; |
| 372 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | /** The singleton instance. */ |
| 374 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 375 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 378 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 379 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 380 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 381 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 382 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 383 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 384 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 385 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 386 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 387 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 388 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 389 | /** User Activity */ |
| 390 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 391 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 392 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 393 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 394 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 395 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 396 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 397 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 398 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 399 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 400 | // String to store multi SIM allowed |
| 401 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 402 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 403 | // The AID of ISD-R. |
| 404 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 405 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 406 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 407 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 408 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 409 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 410 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 411 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 412 | 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] | 413 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 414 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 415 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 416 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 417 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 418 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 419 | */ |
| 420 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 421 | "reset_network_erase_modem_config_enabled"; |
| 422 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 423 | 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] | 424 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 425 | /** |
| 426 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 427 | * one ICCID active at the same time. |
| 428 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 429 | * |
| 430 | * @hide |
| 431 | */ |
| 432 | @ChangeId |
| 433 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 434 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 435 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 436 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 437 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 438 | * operation fails. |
| 439 | */ |
| 440 | @ChangeId |
| 441 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 442 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 443 | |
| 444 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 445 | * A request object to use for transmitting data to an ICC. |
| 446 | */ |
| 447 | private static final class IccAPDUArgument { |
| 448 | public int channel, cla, command, p1, p2, p3; |
| 449 | public String data; |
| 450 | |
| 451 | public IccAPDUArgument(int channel, int cla, int command, |
| 452 | int p1, int p2, int p3, String data) { |
| 453 | this.channel = channel; |
| 454 | this.cla = cla; |
| 455 | this.command = command; |
| 456 | this.p1 = p1; |
| 457 | this.p2 = p2; |
| 458 | this.p3 = p3; |
| 459 | this.data = data; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 464 | * A request object to use for transmitting data to an ICC. |
| 465 | */ |
| 466 | private static final class ManualNetworkSelectionArgument { |
| 467 | public OperatorInfo operatorInfo; |
| 468 | public boolean persistSelection; |
| 469 | |
| 470 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 471 | this.operatorInfo = operatorInfo; |
| 472 | this.persistSelection = persistSelection; |
| 473 | } |
| 474 | } |
| 475 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 476 | private static final class PurchasePremiumCapabilityArgument { |
| 477 | public @TelephonyManager.PremiumCapability int capability; |
| 478 | public @NonNull String appName; |
| 479 | public @NonNull IIntegerConsumer callback; |
| 480 | |
| 481 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 482 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 483 | this.capability = capability; |
| 484 | this.appName = appName; |
| 485 | this.callback = callback; |
| 486 | } |
| 487 | } |
| 488 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 489 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 491 | * request after sending. The main thread will notify the request when it is complete. |
| 492 | */ |
| 493 | private static final class MainThreadRequest { |
| 494 | /** The argument to use for the request */ |
| 495 | public Object argument; |
| 496 | /** The result of the request that is run on the main thread */ |
| 497 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 498 | // The subscriber id that this request applies to. Defaults to |
| 499 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 500 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 501 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 502 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 503 | public Phone phone; |
| 504 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 505 | public WorkSource workSource; |
| 506 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 | public MainThreadRequest(Object argument) { |
| 508 | this.argument = argument; |
| 509 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 510 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 511 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 512 | this.argument = argument; |
| 513 | if (phone != null) { |
| 514 | this.phone = phone; |
| 515 | } |
| 516 | this.workSource = workSource; |
| 517 | } |
| 518 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 519 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 520 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 521 | if (subId != null) { |
| 522 | this.subId = subId; |
| 523 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 524 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 526 | } |
| 527 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 528 | private static final class IncomingThirdPartyCallArgs { |
| 529 | public final ComponentName component; |
| 530 | public final String callId; |
| 531 | public final String callerDisplayName; |
| 532 | |
| 533 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 534 | String callerDisplayName) { |
| 535 | this.component = component; |
| 536 | this.callId = callId; |
| 537 | this.callerDisplayName = callerDisplayName; |
| 538 | } |
| 539 | } |
| 540 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 541 | /** |
| 542 | * A handler that processes messages on the main thread in the phone process. Since many |
| 543 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 544 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 545 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 546 | * on, which will be notified when the operation completes and will contain the result of the |
| 547 | * request. |
| 548 | * |
| 549 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 550 | * note that request.result must be set to something non-null for the calling thread to |
| 551 | * unblock. |
| 552 | */ |
| 553 | private final class MainThreadHandler extends Handler { |
| 554 | @Override |
| 555 | public void handleMessage(Message msg) { |
| 556 | MainThreadRequest request; |
| 557 | Message onCompleted; |
| 558 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 559 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 561 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 562 | |
| 563 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | case CMD_HANDLE_USSD_REQUEST: { |
| 565 | request = (MainThreadRequest) msg.obj; |
| 566 | final Phone phone = getPhoneFromRequest(request); |
| 567 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 568 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 570 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 571 | if (!isUssdApiAllowed(request.subId)) { |
| 572 | // Carrier does not support use of this API, return failure. |
| 573 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 574 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 575 | Bundle returnData = new Bundle(); |
| 576 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 577 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 578 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | request.result = true; |
| 580 | notifyRequester(request); |
| 581 | return; |
| 582 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 583 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | try { |
| 585 | request.result = phone != null |
| 586 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 587 | } catch (CallStateException cse) { |
| 588 | request.result = false; |
| 589 | } |
| 590 | // Wake up the requesting thread |
| 591 | notifyRequester(request); |
| 592 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 595 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 596 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 597 | final Phone phone = getPhoneFromRequest(request); |
| 598 | request.result = phone != null ? |
| 599 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 600 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 601 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 603 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 604 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 605 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 606 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 608 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 609 | uiccPort = getUiccPortFromRequest(request); |
| 610 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 611 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 612 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 613 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 614 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 616 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 617 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 618 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 619 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 620 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 621 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
| 627 | if (ar.exception == null && ar.result != null) { |
| 628 | request.result = ar.result; |
| 629 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 630 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | if (ar.result == null) { |
| 632 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 633 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 635 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | } else { |
| 637 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 638 | } |
| 639 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 641 | break; |
| 642 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 644 | request = (MainThreadRequest) msg.obj; |
| 645 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 646 | uiccPort = getUiccPortFromRequest(request); |
| 647 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 649 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 650 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | } else { |
| 652 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 653 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 654 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 655 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 656 | iccArgument.p2, |
| 657 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | } |
| 659 | break; |
| 660 | |
| 661 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 662 | ar = (AsyncResult) msg.obj; |
| 663 | request = (MainThreadRequest) ar.userObj; |
| 664 | if (ar.exception == null && ar.result != null) { |
| 665 | request.result = ar.result; |
| 666 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | if (ar.result == null) { |
| 669 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 670 | } else if (ar.exception instanceof CommandException) { |
| 671 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 672 | ar.exception); |
| 673 | } else { |
| 674 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 675 | } |
| 676 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case CMD_EXCHANGE_SIM_IO: |
| 681 | request = (MainThreadRequest) msg.obj; |
| 682 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 683 | uiccPort = getUiccPortFromRequest(request); |
| 684 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 686 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 687 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | } else { |
| 689 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 690 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 691 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 693 | iccArgument.data, onCompleted); |
| 694 | } |
| 695 | break; |
| 696 | |
| 697 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 698 | ar = (AsyncResult) msg.obj; |
| 699 | request = (MainThreadRequest) ar.userObj; |
| 700 | if (ar.exception == null && ar.result != null) { |
| 701 | request.result = ar.result; |
| 702 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 703 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 704 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 705 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | break; |
| 707 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 708 | case CMD_SEND_ENVELOPE: |
| 709 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 710 | uiccPort = getUiccPortFromRequest(request); |
| 711 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 712 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 713 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 714 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | } else { |
| 716 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 717 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 718 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_SEND_ENVELOPE_DONE: |
| 722 | ar = (AsyncResult) msg.obj; |
| 723 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 724 | if (ar.exception == null && ar.result != null) { |
| 725 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 726 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 727 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 728 | if (ar.result == null) { |
| 729 | loge("sendEnvelopeWithStatus: Empty response"); |
| 730 | } else if (ar.exception instanceof CommandException) { |
| 731 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 732 | ar.exception); |
| 733 | } else { |
| 734 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 735 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 736 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 737 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | case CMD_OPEN_CHANNEL: |
| 741 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 742 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 743 | IccLogicalChannelRequest openChannelRequest = |
| 744 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 745 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 746 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 747 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 748 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 749 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 750 | } else { |
| 751 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 752 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 753 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 754 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_OPEN_CHANNEL_DONE: |
| 758 | ar = (AsyncResult) msg.obj; |
| 759 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 760 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 762 | int[] result = (int[]) ar.result; |
| 763 | int channelId = result[0]; |
| 764 | byte[] selectResponse = null; |
| 765 | if (result.length > 1) { |
| 766 | selectResponse = new byte[result.length - 1]; |
| 767 | for (int i = 1; i < result.length; ++i) { |
| 768 | selectResponse[i - 1] = (byte) result[i]; |
| 769 | } |
| 770 | } |
| 771 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 772 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 773 | |
| 774 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 775 | if (uiccPort == null) { |
| 776 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 777 | } else { |
| 778 | IccLogicalChannelRequest channelRequest = |
| 779 | (IccLogicalChannelRequest) request.argument; |
| 780 | channelRequest.channel = channelId; |
| 781 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 782 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 783 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | if (ar.result == null) { |
| 785 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 787 | if (ar.exception != null) { |
| 788 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 789 | } |
| 790 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 791 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 792 | if (ar.exception instanceof CommandException) { |
| 793 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 794 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 795 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 796 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 797 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 798 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 802 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 803 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 804 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 805 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 806 | break; |
| 807 | |
| 808 | case CMD_CLOSE_CHANNEL: |
| 809 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 810 | uiccPort = getUiccPortFromRequest(request); |
| 811 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 812 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 813 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 815 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 816 | } else { |
| 817 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 818 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 819 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 820 | break; |
| 821 | |
| 822 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 823 | ar = (AsyncResult) msg.obj; |
| 824 | request = (MainThreadRequest) ar.userObj; |
| 825 | if (ar.exception == null) { |
| 826 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 827 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 828 | if (uiccPort == null) { |
| 829 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 830 | } else { |
| 831 | final int channelId = (Integer) request.argument; |
| 832 | uiccPort.onLogicalChannelClosed(channelId); |
| 833 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 834 | } else { |
| 835 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 836 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 837 | if (ar.exception instanceof CommandException) { |
| 838 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 839 | CommandException.Error error = |
| 840 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 841 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 842 | // should only throw exceptions from the binder threads. |
| 843 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 844 | "iccCloseLogicalChannel: invalid argument "); |
| 845 | } |
| 846 | } else { |
| 847 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 848 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 849 | request.result = (exception != null) ? exception : |
| 850 | new IllegalStateException( |
| 851 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 852 | } |
| 853 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 854 | break; |
| 855 | |
| 856 | case CMD_NV_READ_ITEM: |
| 857 | request = (MainThreadRequest) msg.obj; |
| 858 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 859 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 860 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 864 | ar = (AsyncResult) msg.obj; |
| 865 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 866 | if (ar.exception == null && ar.result != null) { |
| 867 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 868 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 869 | request.result = ""; |
| 870 | if (ar.result == null) { |
| 871 | loge("nvReadItem: Empty response"); |
| 872 | } else if (ar.exception instanceof CommandException) { |
| 873 | loge("nvReadItem: CommandException: " + |
| 874 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 875 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 876 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 877 | } |
| 878 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 879 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 880 | break; |
| 881 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 882 | case CMD_NV_WRITE_ITEM: |
| 883 | request = (MainThreadRequest) msg.obj; |
| 884 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 885 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 886 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 887 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_NV_WRITE_ITEM_DONE: |
| 891 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 892 | break; |
| 893 | |
| 894 | case CMD_NV_WRITE_CDMA_PRL: |
| 895 | request = (MainThreadRequest) msg.obj; |
| 896 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 897 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 901 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 902 | break; |
| 903 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 904 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 905 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 906 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 907 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 908 | break; |
| 909 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 910 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 911 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 912 | break; |
| 913 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 914 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 915 | request = (MainThreadRequest) msg.obj; |
| 916 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 917 | request); |
| 918 | Phone phone = getPhoneFromRequest(request); |
| 919 | if (phone != null) { |
| 920 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 921 | } else { |
| 922 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 923 | request.result = false; |
| 924 | notifyRequester(request); |
| 925 | } |
| 926 | break; |
| 927 | } |
| 928 | |
| 929 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 930 | ar = (AsyncResult) msg.obj; |
| 931 | request = (MainThreadRequest) ar.userObj; |
| 932 | if (ar.exception == null && ar.result != null) { |
| 933 | request.result = ar.result; |
| 934 | } else { |
| 935 | // request.result must be set to something non-null |
| 936 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 937 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 938 | request.result = ar.result; |
| 939 | } else { |
| 940 | request.result = false; |
| 941 | } |
| 942 | if (ar.result == null) { |
| 943 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 944 | } else if (ar.exception instanceof CommandException) { |
| 945 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 946 | + ar.exception); |
| 947 | } else { |
| 948 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 949 | } |
| 950 | } |
| 951 | notifyRequester(request); |
| 952 | break; |
| 953 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 954 | case CMD_IS_VONR_ENABLED: { |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 957 | request); |
| 958 | Phone phone = getPhoneFromRequest(request); |
| 959 | if (phone != null) { |
| 960 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 961 | } else { |
| 962 | loge("isVoNrEnabled: No phone object"); |
| 963 | request.result = false; |
| 964 | notifyRequester(request); |
| 965 | } |
| 966 | break; |
| 967 | } |
| 968 | |
| 969 | case EVENT_IS_VONR_ENABLED_DONE: |
| 970 | ar = (AsyncResult) msg.obj; |
| 971 | request = (MainThreadRequest) ar.userObj; |
| 972 | if (ar.exception == null && ar.result != null) { |
| 973 | request.result = ar.result; |
| 974 | } else { |
| 975 | // request.result must be set to something non-null |
| 976 | // for the calling thread to unblock |
| 977 | if (ar.result != null) { |
| 978 | request.result = ar.result; |
| 979 | } else { |
| 980 | request.result = false; |
| 981 | } |
| 982 | if (ar.result == null) { |
| 983 | loge("isVoNrEnabled: Empty response"); |
| 984 | } else if (ar.exception instanceof CommandException) { |
| 985 | loge("isVoNrEnabled: CommandException: " |
| 986 | + ar.exception); |
| 987 | } else { |
| 988 | loge("isVoNrEnabled: Unknown exception"); |
| 989 | } |
| 990 | } |
| 991 | notifyRequester(request); |
| 992 | break; |
| 993 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 994 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 995 | request = (MainThreadRequest) msg.obj; |
| 996 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 997 | Phone phone = getPhoneFromRequest(request); |
| 998 | if (phone != null) { |
| 999 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1000 | request.workSource); |
| 1001 | } else { |
| 1002 | loge("enableNrDualConnectivity: No phone object"); |
| 1003 | request.result = |
| 1004 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1005 | notifyRequester(request); |
| 1006 | } |
| 1007 | break; |
| 1008 | } |
| 1009 | |
| 1010 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1011 | ar = (AsyncResult) msg.obj; |
| 1012 | request = (MainThreadRequest) ar.userObj; |
| 1013 | if (ar.exception == null) { |
| 1014 | request.result = |
| 1015 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1016 | } else { |
| 1017 | request.result = |
| 1018 | TelephonyManager |
| 1019 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1020 | if (ar.exception instanceof CommandException) { |
| 1021 | CommandException.Error error = |
| 1022 | ((CommandException) (ar.exception)).getCommandError(); |
| 1023 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1024 | request.result = |
| 1025 | TelephonyManager |
| 1026 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1027 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1028 | request.result = |
| 1029 | TelephonyManager |
| 1030 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1031 | } |
| 1032 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1033 | + ar.exception); |
| 1034 | } else { |
| 1035 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1036 | } |
| 1037 | } |
| 1038 | notifyRequester(request); |
| 1039 | break; |
| 1040 | } |
| 1041 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1042 | case CMD_ENABLE_VONR: { |
| 1043 | request = (MainThreadRequest) msg.obj; |
| 1044 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1045 | Phone phone = getPhoneFromRequest(request); |
| 1046 | if (phone != null) { |
| 1047 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1048 | request.workSource); |
| 1049 | } else { |
| 1050 | loge("setVoNrEnabled: No phone object"); |
| 1051 | request.result = |
| 1052 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1053 | notifyRequester(request); |
| 1054 | } |
| 1055 | break; |
| 1056 | } |
| 1057 | |
| 1058 | case EVENT_ENABLE_VONR_DONE: { |
| 1059 | ar = (AsyncResult) msg.obj; |
| 1060 | request = (MainThreadRequest) ar.userObj; |
| 1061 | if (ar.exception == null) { |
| 1062 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1063 | } else { |
| 1064 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1065 | if (ar.exception instanceof CommandException) { |
| 1066 | CommandException.Error error = |
| 1067 | ((CommandException) (ar.exception)).getCommandError(); |
| 1068 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1069 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1070 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1071 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1072 | } else { |
| 1073 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1074 | } |
| 1075 | loge("setVoNrEnabled" + ": CommandException: " |
| 1076 | + ar.exception); |
| 1077 | } else { |
| 1078 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1079 | } |
| 1080 | } |
| 1081 | notifyRequester(request); |
| 1082 | break; |
| 1083 | } |
| 1084 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1085 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1086 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1087 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1088 | request); |
| 1089 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1090 | break; |
| 1091 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1092 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1093 | ar = (AsyncResult) msg.obj; |
| 1094 | request = (MainThreadRequest) ar.userObj; |
| 1095 | if (ar.exception == null && ar.result != null) { |
| 1096 | request.result = ar.result; // Integer |
| 1097 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1098 | // request.result must be set to something non-null |
| 1099 | // for the calling thread to unblock |
| 1100 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1101 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1102 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1103 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1104 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1105 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1107 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1108 | } |
| 1109 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1110 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1111 | break; |
| 1112 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1113 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1114 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1115 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1116 | request); |
| 1117 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1118 | (Pair<Integer, Long>) request.argument; |
| 1119 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1120 | reasonWithNetworkTypes.first, |
| 1121 | reasonWithNetworkTypes.second, |
| 1122 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1123 | break; |
| 1124 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1125 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1126 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1129 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1130 | request = (MainThreadRequest)msg.obj; |
| 1131 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1132 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1133 | break; |
| 1134 | |
| 1135 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1136 | ar = (AsyncResult)msg.obj; |
| 1137 | request = (MainThreadRequest)ar.userObj; |
| 1138 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1139 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1140 | break; |
| 1141 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1142 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1143 | request = (MainThreadRequest) msg.obj; |
| 1144 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1145 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1146 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1147 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1148 | break; |
| 1149 | |
| 1150 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1151 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1152 | break; |
| 1153 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1154 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1155 | request = (MainThreadRequest) msg.obj; |
| 1156 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1157 | request); |
| 1158 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1159 | break; |
| 1160 | |
| 1161 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1162 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1163 | break; |
| 1164 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1165 | case CMD_PERFORM_NETWORK_SCAN: |
| 1166 | request = (MainThreadRequest) msg.obj; |
| 1167 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1168 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1169 | break; |
| 1170 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1172 | request = (MainThreadRequest) msg.obj; |
| 1173 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1175 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1176 | request.argument; |
| 1177 | int callForwardingReason = args.first; |
| 1178 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1180 | } |
| 1181 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1182 | ar = (AsyncResult) msg.obj; |
| 1183 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1185 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1186 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1189 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1190 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1191 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1192 | // any service for voice call. |
| 1193 | if ((callForwardInfo.serviceClass |
| 1194 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1195 | callForwardingInfo = new CallForwardingInfo( |
| 1196 | callForwardInfo.status |
| 1197 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1198 | callForwardInfo.reason, |
| 1199 | callForwardInfo.number, |
| 1200 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | break; |
| 1202 | } |
| 1203 | } |
| 1204 | // Didn't find a call forward info for voice call. |
| 1205 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1207 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | } else { |
| 1211 | if (ar.result == null) { |
| 1212 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1213 | } |
| 1214 | if (ar.exception != null) { |
| 1215 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1216 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1217 | int errorCode = TelephonyManager |
| 1218 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | if (ar.exception instanceof CommandException) { |
| 1220 | CommandException.Error error = |
| 1221 | ((CommandException) (ar.exception)).getCommandError(); |
| 1222 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1223 | errorCode = TelephonyManager |
| 1224 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1226 | errorCode = TelephonyManager |
| 1227 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } |
| 1229 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1236 | request = (MainThreadRequest) msg.obj; |
| 1237 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1241 | request.argument).first; |
| 1242 | request.phone.setCallForwardingOption( |
| 1243 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1244 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1246 | callForwardingInfoToSet.getReason(), |
| 1247 | callForwardingInfoToSet.getNumber(), |
| 1248 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1249 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | ar = (AsyncResult) msg.obj; |
| 1254 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | Consumer<Integer> callback = |
| 1256 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1257 | request.argument).second; |
| 1258 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1260 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1261 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1262 | if (ar.exception instanceof CommandException) { |
| 1263 | CommandException.Error error = |
| 1264 | ((CommandException) (ar.exception)).getCommandError(); |
| 1265 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1266 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1267 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1269 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1270 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | callback.accept(errorCode); |
| 1274 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1275 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | request = (MainThreadRequest) msg.obj; |
| 1282 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1283 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1284 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1285 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1286 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1287 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | ar = (AsyncResult) msg.obj; |
| 1289 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1291 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1292 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1293 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | // Service Class is a bit mask per 3gpp 27.007. |
| 1295 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1296 | if (callForwardResults.length > 1 |
| 1297 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1299 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1301 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1303 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | } |
| 1305 | } else { |
| 1306 | if (ar.result == null) { |
| 1307 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1308 | } |
| 1309 | if (ar.exception != null) { |
| 1310 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1311 | } |
| 1312 | if (ar.exception instanceof CommandException) { |
| 1313 | CommandException.Error error = |
| 1314 | ((CommandException) (ar.exception)).getCommandError(); |
| 1315 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1316 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1318 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1319 | callWaitingStatus = |
| 1320 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1324 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1325 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1326 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1327 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1328 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | request = (MainThreadRequest) msg.obj; |
| 1330 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1331 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1332 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1333 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1336 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1337 | ar = (AsyncResult) msg.obj; |
| 1338 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1340 | Consumer<Integer> callback = |
| 1341 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1342 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1343 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1344 | if (ar.exception instanceof CommandException) { |
| 1345 | CommandException.Error error = |
| 1346 | ((CommandException) (ar.exception)).getCommandError(); |
| 1347 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1348 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1349 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1350 | callback.accept( |
| 1351 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1352 | } else { |
| 1353 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1354 | } |
| 1355 | } else { |
| 1356 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1357 | } |
| 1358 | } else { |
| 1359 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1360 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1361 | } |
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 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1364 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1365 | ar = (AsyncResult) msg.obj; |
| 1366 | request = (MainThreadRequest) ar.userObj; |
| 1367 | CellNetworkScanResult cellScanResult; |
| 1368 | if (ar.exception == null && ar.result != null) { |
| 1369 | cellScanResult = new CellNetworkScanResult( |
| 1370 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1371 | (List<OperatorInfo>) ar.result); |
| 1372 | } else { |
| 1373 | if (ar.result == null) { |
| 1374 | loge("getCellNetworkScanResults: Empty response"); |
| 1375 | } |
| 1376 | if (ar.exception != null) { |
| 1377 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1378 | } |
| 1379 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1380 | if (ar.exception instanceof CommandException) { |
| 1381 | CommandException.Error error = |
| 1382 | ((CommandException) (ar.exception)).getCommandError(); |
| 1383 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1384 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1385 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1386 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1387 | } |
| 1388 | } |
| 1389 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1390 | } |
| 1391 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1392 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1393 | break; |
| 1394 | |
| 1395 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1396 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1397 | ManualNetworkSelectionArgument selArg = |
| 1398 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1399 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1400 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1401 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1402 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1403 | break; |
| 1404 | |
| 1405 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1406 | ar = (AsyncResult) msg.obj; |
| 1407 | request = (MainThreadRequest) ar.userObj; |
| 1408 | if (ar.exception == null) { |
| 1409 | request.result = true; |
| 1410 | } else { |
| 1411 | request.result = false; |
| 1412 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1413 | } |
| 1414 | notifyRequester(request); |
| 1415 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1416 | break; |
| 1417 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1418 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1419 | request = (MainThreadRequest) msg.obj; |
| 1420 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1421 | if (defaultPhone != null) { |
| 1422 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1423 | } else { |
| 1424 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1425 | Bundle bundle = new Bundle(); |
| 1426 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1427 | new ModemActivityInfo(0, 0, 0, |
| 1428 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1429 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1430 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1431 | break; |
| 1432 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1433 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1434 | ar = (AsyncResult) msg.obj; |
| 1435 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1436 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1437 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1438 | if (mLastModemActivityInfo == null) { |
| 1439 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1440 | mLastModemActivitySpecificInfo[0] = |
| 1441 | new ActivityStatsTechSpecificInfo( |
| 1442 | 0, |
| 1443 | 0, |
| 1444 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1445 | 0); |
| 1446 | mLastModemActivityInfo = |
| 1447 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1448 | } |
| 1449 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1450 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1451 | // Update the last modem activity info and the result of the request. |
| 1452 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1453 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1454 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1455 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1456 | mLastModemActivityInfo = |
| 1457 | new ModemActivityInfo( |
| 1458 | mLastModemActivityInfo.getTimestampMillis(), |
| 1459 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1460 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1461 | mLastModemActivitySpecificInfo); |
| 1462 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1463 | } else { |
| 1464 | if (ar.result == null) { |
| 1465 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1466 | error = TelephonyManager.ModemActivityInfoException |
| 1467 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1468 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1469 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1470 | error = TelephonyManager.ModemActivityInfoException |
| 1471 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1472 | } else { |
| 1473 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1474 | error = TelephonyManager.ModemActivityInfoException |
| 1475 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1476 | } |
| 1477 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1478 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1479 | if (mLastModemActivityInfo != null) { |
| 1480 | bundle.putParcelable( |
| 1481 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1482 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1483 | } else { |
| 1484 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1485 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1486 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1487 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1488 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1489 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1490 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1491 | case CMD_SET_ALLOWED_CARRIERS: |
| 1492 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1493 | CarrierRestrictionRules argument = |
| 1494 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1495 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1496 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | |
| 1499 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1500 | ar = (AsyncResult) msg.obj; |
| 1501 | request = (MainThreadRequest) ar.userObj; |
| 1502 | if (ar.exception == null && ar.result != null) { |
| 1503 | request.result = ar.result; |
| 1504 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1505 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1506 | if (ar.exception instanceof CommandException) { |
| 1507 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1508 | CommandException.Error error = |
| 1509 | ((CommandException) (ar.exception)).getCommandError(); |
| 1510 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1511 | request.result = |
| 1512 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1513 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1514 | } else { |
| 1515 | loge("setAllowedCarriers: Unknown exception"); |
| 1516 | } |
| 1517 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1518 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1519 | break; |
| 1520 | |
| 1521 | case CMD_GET_ALLOWED_CARRIERS: |
| 1522 | request = (MainThreadRequest) msg.obj; |
| 1523 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1524 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1525 | break; |
| 1526 | |
| 1527 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1528 | ar = (AsyncResult) msg.obj; |
| 1529 | request = (MainThreadRequest) ar.userObj; |
| 1530 | if (ar.exception == null && ar.result != null) { |
| 1531 | request.result = ar.result; |
| 1532 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1533 | request.result = new IllegalStateException( |
| 1534 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1535 | if (ar.result == null) { |
| 1536 | loge("getAllowedCarriers: Empty response"); |
| 1537 | } else if (ar.exception instanceof CommandException) { |
| 1538 | loge("getAllowedCarriers: CommandException: " + |
| 1539 | ar.exception); |
| 1540 | } else { |
| 1541 | loge("getAllowedCarriers: Unknown exception"); |
| 1542 | } |
| 1543 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1544 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1545 | break; |
| 1546 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1547 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1548 | ar = (AsyncResult) msg.obj; |
| 1549 | request = (MainThreadRequest) ar.userObj; |
| 1550 | if (ar.exception == null && ar.result != null) { |
| 1551 | request.result = ar.result; |
| 1552 | } else { |
| 1553 | request.result = new IllegalArgumentException( |
| 1554 | "Failed to retrieve Forbidden Plmns"); |
| 1555 | if (ar.result == null) { |
| 1556 | loge("getForbiddenPlmns: Empty response"); |
| 1557 | } else { |
| 1558 | loge("getForbiddenPlmns: Unknown exception"); |
| 1559 | } |
| 1560 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1561 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1562 | break; |
| 1563 | |
| 1564 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1565 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1566 | uiccPort = getUiccPortFromRequest(request); |
| 1567 | if (uiccPort == null) { |
| 1568 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1569 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1570 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1571 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1572 | break; |
| 1573 | } |
| 1574 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1575 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1576 | if (uiccApp == null) { |
| 1577 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1578 | + appType); |
| 1579 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1580 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1581 | break; |
| 1582 | } else { |
| 1583 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1584 | + " specified type -- " + appType); |
| 1585 | } |
| 1586 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1587 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1588 | onCompleted); |
| 1589 | break; |
| 1590 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1591 | case CMD_SWITCH_SLOTS: |
| 1592 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1593 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1594 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1595 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | |
| 1598 | case EVENT_SWITCH_SLOTS_DONE: |
| 1599 | ar = (AsyncResult) msg.obj; |
| 1600 | request = (MainThreadRequest) ar.userObj; |
| 1601 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1602 | notifyRequester(request); |
| 1603 | break; |
| 1604 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1605 | request = (MainThreadRequest) msg.obj; |
| 1606 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1607 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1608 | break; |
| 1609 | |
| 1610 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | if (ar.exception != null) { |
| 1614 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1615 | } else { |
| 1616 | int mode = ((int[]) ar.result)[0]; |
| 1617 | if (mode == 0) { |
| 1618 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1619 | } else { |
| 1620 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1621 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1622 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1623 | notifyRequester(request); |
| 1624 | break; |
| 1625 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1626 | request = (MainThreadRequest) msg.obj; |
| 1627 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1628 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1629 | break; |
| 1630 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1631 | ar = (AsyncResult) msg.obj; |
| 1632 | request = (MainThreadRequest) ar.userObj; |
| 1633 | if (ar.exception != null) { |
| 1634 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1635 | } else { |
| 1636 | request.result = ((int[]) ar.result)[0]; |
| 1637 | } |
| 1638 | notifyRequester(request); |
| 1639 | break; |
| 1640 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1641 | request = (MainThreadRequest) msg.obj; |
| 1642 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1643 | int mode = (int) request.argument; |
| 1644 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1645 | break; |
| 1646 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1647 | ar = (AsyncResult) msg.obj; |
| 1648 | request = (MainThreadRequest) ar.userObj; |
| 1649 | request.result = ar.exception == null; |
| 1650 | notifyRequester(request); |
| 1651 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1652 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1653 | request = (MainThreadRequest) msg.obj; |
| 1654 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1655 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1656 | break; |
| 1657 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1658 | ar = (AsyncResult) msg.obj; |
| 1659 | request = (MainThreadRequest) ar.userObj; |
| 1660 | if (ar.exception != null) { |
| 1661 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1662 | } else { |
| 1663 | request.result = ((int[]) ar.result)[0]; |
| 1664 | } |
| 1665 | notifyRequester(request); |
| 1666 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1667 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1668 | request = (MainThreadRequest) msg.obj; |
| 1669 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1670 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1671 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1672 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1673 | break; |
| 1674 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1675 | ar = (AsyncResult) msg.obj; |
| 1676 | request = (MainThreadRequest) ar.userObj; |
| 1677 | request.result = ar.exception == null; |
| 1678 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1679 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1680 | case CMD_GET_ALL_CELL_INFO: |
| 1681 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1682 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1683 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1684 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1685 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1686 | ar = (AsyncResult) msg.obj; |
| 1687 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1688 | // If a timeout occurs, the response will be null |
| 1689 | request.result = (ar.exception == null && ar.result != null) |
| 1690 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1691 | synchronized (request) { |
| 1692 | request.notifyAll(); |
| 1693 | } |
| 1694 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1695 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1696 | request = (MainThreadRequest) msg.obj; |
| 1697 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1698 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1699 | break; |
| 1700 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1701 | ar = (AsyncResult) msg.obj; |
| 1702 | request = (MainThreadRequest) ar.userObj; |
| 1703 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1704 | try { |
| 1705 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1706 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1707 | cb.onError( |
| 1708 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1709 | ar.exception.getClass().getName(), |
| 1710 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1711 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1712 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1713 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1714 | } else { |
| 1715 | // use the result as returned |
| 1716 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1717 | } |
| 1718 | } catch (RemoteException re) { |
| 1719 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1720 | } |
| 1721 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1722 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1723 | request = (MainThreadRequest) msg.obj; |
| 1724 | WorkSource ws = (WorkSource) request.argument; |
| 1725 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1726 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1727 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1728 | } |
| 1729 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1730 | ar = (AsyncResult) msg.obj; |
| 1731 | request = (MainThreadRequest) ar.userObj; |
| 1732 | if (ar.exception == null) { |
| 1733 | request.result = ar.result; |
| 1734 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1735 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1736 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1737 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | synchronized (request) { |
| 1741 | request.notifyAll(); |
| 1742 | } |
| 1743 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1744 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1745 | case CMD_MODEM_REBOOT: |
| 1746 | request = (MainThreadRequest) msg.obj; |
| 1747 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1748 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1749 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1750 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1751 | handleNullReturnEvent(msg, "rebootModem"); |
| 1752 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1753 | case CMD_REQUEST_ENABLE_MODEM: |
| 1754 | request = (MainThreadRequest) msg.obj; |
| 1755 | boolean enable = (boolean) request.argument; |
| 1756 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1757 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1758 | PhoneConfigurationManager.getInstance() |
| 1759 | .enablePhone(request.phone, enable, onCompleted); |
| 1760 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1761 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1762 | ar = (AsyncResult) msg.obj; |
| 1763 | request = (MainThreadRequest) ar.userObj; |
| 1764 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1765 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1766 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1767 | if ((boolean) request.result) { |
| 1768 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1769 | updateModemStateMetrics(); |
| 1770 | } else { |
| 1771 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1772 | + ar.exception); |
| 1773 | } |
| 1774 | notifyRequester(request); |
| 1775 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1776 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1777 | case CMD_GET_MODEM_STATUS: |
| 1778 | request = (MainThreadRequest) msg.obj; |
| 1779 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1780 | PhoneConfigurationManager.getInstance() |
| 1781 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1782 | break; |
| 1783 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1784 | ar = (AsyncResult) msg.obj; |
| 1785 | request = (MainThreadRequest) ar.userObj; |
| 1786 | int id = request.phone.getPhoneId(); |
| 1787 | if (ar.exception == null && ar.result != null) { |
| 1788 | request.result = ar.result; |
| 1789 | //update the cache as modem status has changed |
| 1790 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1791 | (boolean) request.result); |
| 1792 | } else { |
| 1793 | // Return true if modem status cannot be retrieved. For most cases, |
| 1794 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1795 | // and disable modem are not supported. Modem is always on. |
| 1796 | // TODO: this should be fixed in R to support a third |
| 1797 | // status UNKNOWN b/131631629 |
| 1798 | request.result = true; |
| 1799 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1800 | + ar.exception); |
| 1801 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1802 | notifyRequester(request); |
| 1803 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1804 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1805 | request = (MainThreadRequest) msg.obj; |
| 1806 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1807 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1808 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1809 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1810 | break; |
| 1811 | } |
| 1812 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1813 | ar = (AsyncResult) msg.obj; |
| 1814 | request = (MainThreadRequest) ar.userObj; |
| 1815 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1816 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1817 | args.second.accept(ar.exception == null); |
| 1818 | notifyRequester(request); |
| 1819 | break; |
| 1820 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1821 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1822 | request = (MainThreadRequest) msg.obj; |
| 1823 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1824 | Phone phone = getPhoneFromRequest(request); |
| 1825 | if (phone != null) { |
| 1826 | phone.getSystemSelectionChannels(onCompleted); |
| 1827 | } else { |
| 1828 | loge("getSystemSelectionChannels: No phone object"); |
| 1829 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1830 | notifyRequester(request); |
| 1831 | } |
| 1832 | break; |
| 1833 | } |
| 1834 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1835 | ar = (AsyncResult) msg.obj; |
| 1836 | request = (MainThreadRequest) ar.userObj; |
| 1837 | if (ar.exception == null && ar.result != null) { |
| 1838 | request.result = ar.result; |
| 1839 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1840 | request.result = new IllegalStateException( |
| 1841 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1842 | if (ar.result == null) { |
| 1843 | loge("getSystemSelectionChannels: Empty response"); |
| 1844 | } else { |
| 1845 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1846 | } |
| 1847 | } |
| 1848 | notifyRequester(request); |
| 1849 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1850 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1851 | ar = (AsyncResult) msg.obj; |
| 1852 | request = (MainThreadRequest) ar.userObj; |
| 1853 | if (ar.exception == null && ar.result != null) { |
| 1854 | request.result = ar.result; |
| 1855 | } else { |
| 1856 | request.result = -1; |
| 1857 | loge("Failed to set Forbidden Plmns"); |
| 1858 | if (ar.result == null) { |
| 1859 | loge("setForbidenPlmns: Empty response"); |
| 1860 | } else if (ar.exception != null) { |
| 1861 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1862 | request.result = -1; |
| 1863 | } else { |
| 1864 | loge("setForbiddenPlmns: Unknown exception"); |
| 1865 | } |
| 1866 | } |
| 1867 | notifyRequester(request); |
| 1868 | break; |
| 1869 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1870 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1871 | uiccPort = getUiccPortFromRequest(request); |
| 1872 | if (uiccPort == null) { |
| 1873 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1874 | request.result = -1; |
| 1875 | notifyRequester(request); |
| 1876 | break; |
| 1877 | } |
| 1878 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1879 | (Pair<Integer, List<String>>) request.argument; |
| 1880 | appType = setFplmnsArgs.first; |
| 1881 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1882 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1883 | if (uiccApp == null) { |
| 1884 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1885 | request.result = -1; |
| 1886 | loge("Failed to get UICC App"); |
| 1887 | notifyRequester(request); |
| 1888 | } else { |
| 1889 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1890 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1891 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1892 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1893 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1894 | case CMD_ERASE_MODEM_CONFIG: |
| 1895 | request = (MainThreadRequest) msg.obj; |
| 1896 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1897 | defaultPhone.eraseModemConfig(onCompleted); |
| 1898 | break; |
| 1899 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1900 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1901 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1902 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1903 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1904 | request = (MainThreadRequest) msg.obj; |
| 1905 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1906 | notifyRequester(request); |
| 1907 | break; |
| 1908 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1909 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1910 | request = (MainThreadRequest) msg.obj; |
| 1911 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1912 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1913 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1914 | changed.first, changed.second, onCompleted); |
| 1915 | break; |
| 1916 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1917 | ar = (AsyncResult) msg.obj; |
| 1918 | request = (MainThreadRequest) ar.userObj; |
| 1919 | if (ar.exception == null) { |
| 1920 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1921 | // If the operation is successful, update the PIN storage |
| 1922 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1923 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1924 | UiccController.getInstance().getPinStorage() |
| 1925 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1926 | } else { |
| 1927 | request.result = msg.arg1; |
| 1928 | } |
| 1929 | notifyRequester(request); |
| 1930 | break; |
| 1931 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1932 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1933 | request = (MainThreadRequest) msg.obj; |
| 1934 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1935 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1936 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1937 | enabled.first, enabled.second, onCompleted); |
| 1938 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1939 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1940 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1941 | ar = (AsyncResult) msg.obj; |
| 1942 | request = (MainThreadRequest) ar.userObj; |
| 1943 | if (ar.exception == null) { |
| 1944 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1945 | // If the operation is successful, update the PIN storage |
| 1946 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1947 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1948 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1949 | UiccController.getInstance().getPinStorage() |
| 1950 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1951 | } else { |
| 1952 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1953 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1954 | } else { |
| 1955 | request.result = msg.arg1; |
| 1956 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1957 | |
| 1958 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1959 | notifyRequester(request); |
| 1960 | break; |
| 1961 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1962 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1963 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1964 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1965 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1966 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1967 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1968 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1969 | |
| 1970 | case CMD_SET_DATA_THROTTLING: { |
| 1971 | request = (MainThreadRequest) msg.obj; |
| 1972 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1973 | DataThrottlingRequest dataThrottlingRequest = |
| 1974 | (DataThrottlingRequest) request.argument; |
| 1975 | Phone phone = getPhoneFromRequest(request); |
| 1976 | if (phone != null) { |
| 1977 | phone.setDataThrottling(onCompleted, |
| 1978 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1979 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1980 | } else { |
| 1981 | loge("setDataThrottling: No phone object"); |
| 1982 | request.result = |
| 1983 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1984 | notifyRequester(request); |
| 1985 | } |
| 1986 | |
| 1987 | break; |
| 1988 | } |
| 1989 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1990 | ar = (AsyncResult) msg.obj; |
| 1991 | request = (MainThreadRequest) ar.userObj; |
| 1992 | |
| 1993 | if (ar.exception == null) { |
| 1994 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1995 | } else if (ar.exception instanceof CommandException) { |
| 1996 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1997 | CommandException.Error error = |
| 1998 | ((CommandException) (ar.exception)).getCommandError(); |
| 1999 | |
| 2000 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2001 | request.result = TelephonyManager |
| 2002 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2003 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2004 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2005 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2006 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2007 | } else { |
| 2008 | request.result = |
| 2009 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2010 | } |
| 2011 | } else { |
| 2012 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2013 | } |
| 2014 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2015 | notifyRequester(request); |
| 2016 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2017 | |
| 2018 | case CMD_SET_SIM_POWER: { |
| 2019 | request = (MainThreadRequest) msg.obj; |
| 2020 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2021 | request = (MainThreadRequest) msg.obj; |
| 2022 | int stateToSet = |
| 2023 | ((Pair<Integer, IIntegerConsumer>) |
| 2024 | request.argument).first; |
| 2025 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2026 | break; |
| 2027 | } |
| 2028 | case EVENT_SET_SIM_POWER_DONE: { |
| 2029 | ar = (AsyncResult) msg.obj; |
| 2030 | request = (MainThreadRequest) ar.userObj; |
| 2031 | IIntegerConsumer callback = |
| 2032 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2033 | if (ar.exception != null) { |
| 2034 | loge("setSimPower exception: " + ar.exception); |
| 2035 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2036 | .RESULT_ERROR_UNKNOWN; |
| 2037 | if (ar.exception instanceof CommandException) { |
| 2038 | CommandException.Error error = |
| 2039 | ((CommandException) (ar.exception)).getCommandError(); |
| 2040 | if (error == CommandException.Error.SIM_ERR) { |
| 2041 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2042 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2043 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2044 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2045 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2046 | } else { |
| 2047 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2048 | } |
| 2049 | } |
| 2050 | try { |
| 2051 | callback.accept(errorCode); |
| 2052 | } catch (RemoteException e) { |
| 2053 | // Ignore if the remote process is no longer available to call back. |
| 2054 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2055 | } |
| 2056 | } else { |
| 2057 | try { |
| 2058 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2059 | } catch (RemoteException e) { |
| 2060 | // Ignore if the remote process is no longer available to call back. |
| 2061 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2062 | } |
| 2063 | } |
| 2064 | break; |
| 2065 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2066 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2067 | request = (MainThreadRequest) msg.obj; |
| 2068 | |
| 2069 | final Phone phone = getPhoneFromRequest(request); |
| 2070 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2071 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2072 | notifyRequester(request); |
| 2073 | break; |
| 2074 | } |
| 2075 | |
| 2076 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2077 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2078 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2079 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2080 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2081 | request.subId, pair.first /*callingUid*/, |
| 2082 | pair.second /*request*/, onCompleted); |
| 2083 | break; |
| 2084 | } |
| 2085 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2086 | ar = (AsyncResult) msg.obj; |
| 2087 | request = (MainThreadRequest) ar.userObj; |
| 2088 | // request.result will be the exception of ar if present, true otherwise. |
| 2089 | // Be cautious not to leave result null which will wait() forever |
| 2090 | request.result = ar.exception != null ? ar.exception : true; |
| 2091 | notifyRequester(request); |
| 2092 | break; |
| 2093 | } |
| 2094 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2095 | request = (MainThreadRequest) msg.obj; |
| 2096 | |
| 2097 | Phone phone = getPhoneFromRequest(request); |
| 2098 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2099 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2100 | notifyRequester(request); |
| 2101 | break; |
| 2102 | } |
| 2103 | |
| 2104 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2105 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2106 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2107 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2108 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2109 | request.subId, pair.first /*callingUid*/, |
| 2110 | pair.second /*request*/, onCompleted); |
| 2111 | break; |
| 2112 | } |
| 2113 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2114 | ar = (AsyncResult) msg.obj; |
| 2115 | request = (MainThreadRequest) ar.userObj; |
| 2116 | request.result = ar.exception != null ? ar.exception : true; |
| 2117 | notifyRequester(request); |
| 2118 | break; |
| 2119 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2120 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2121 | case CMD_GET_SLICING_CONFIG: { |
| 2122 | request = (MainThreadRequest) msg.obj; |
| 2123 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2124 | request.phone.getSlicingConfig(onCompleted); |
| 2125 | break; |
| 2126 | } |
| 2127 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2128 | ar = (AsyncResult) msg.obj; |
| 2129 | request = (MainThreadRequest) ar.userObj; |
| 2130 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2131 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2132 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2133 | Bundle bundle = new Bundle(); |
| 2134 | int resultCode = 0; |
| 2135 | if (ar.exception != null) { |
| 2136 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2137 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2138 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2139 | } else if (ar.result == null) { |
| 2140 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2141 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2142 | } else { |
| 2143 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2144 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2145 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2149 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2150 | } |
| 2151 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2152 | result.send(resultCode, bundle); |
| 2153 | notifyRequester(request); |
| 2154 | break; |
| 2155 | } |
| 2156 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2157 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2158 | request = (MainThreadRequest) msg.obj; |
| 2159 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2160 | PurchasePremiumCapabilityArgument arg = |
| 2161 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2162 | SliceStore.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2163 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2164 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2165 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2166 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2167 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2168 | ar = (AsyncResult) msg.obj; |
| 2169 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2170 | PurchasePremiumCapabilityArgument arg = |
| 2171 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2172 | try { |
| 2173 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2174 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2175 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2176 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2177 | + ", result= " |
| 2178 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2179 | } catch (RemoteException e) { |
| 2180 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2181 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2182 | + " failed: " + e; |
| 2183 | if (DBG) log(logStr); |
| 2184 | AnomalyReporter.reportAnomaly( |
| 2185 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2186 | } |
| 2187 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2188 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2189 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2190 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2191 | request = (MainThreadRequest) msg.obj; |
| 2192 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2193 | UiccController.getInstance().getPinStorage() |
| 2194 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2195 | notifyRequester(request); |
| 2196 | break; |
| 2197 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | default: |
| 2199 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2200 | break; |
| 2201 | } |
| 2202 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2203 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2204 | private void notifyRequester(MainThreadRequest request) { |
| 2205 | synchronized (request) { |
| 2206 | request.notifyAll(); |
| 2207 | } |
| 2208 | } |
| 2209 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2210 | private void handleNullReturnEvent(Message msg, String command) { |
| 2211 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2212 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2213 | if (ar.exception == null) { |
| 2214 | request.result = true; |
| 2215 | } else { |
| 2216 | request.result = false; |
| 2217 | if (ar.exception instanceof CommandException) { |
| 2218 | loge(command + ": CommandException: " + ar.exception); |
| 2219 | } else { |
| 2220 | loge(command + ": Unknown exception"); |
| 2221 | } |
| 2222 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2223 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2224 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | /** |
| 2228 | * Posts the specified command to be executed on the main thread, |
| 2229 | * waits for the request to complete, and returns the result. |
| 2230 | * @see #sendRequestAsync |
| 2231 | */ |
| 2232 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2233 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2234 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | /** |
| 2238 | * Posts the specified command to be executed on the main thread, |
| 2239 | * waits for the request to complete, and returns the result. |
| 2240 | * @see #sendRequestAsync |
| 2241 | */ |
| 2242 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2243 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2244 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | /** |
| 2248 | * Posts the specified command to be executed on the main thread, |
| 2249 | * waits for the request to complete, and returns the result. |
| 2250 | * @see #sendRequestAsync |
| 2251 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2252 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2253 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2254 | } |
| 2255 | |
| 2256 | /** |
| 2257 | * Posts the specified command to be executed on the main thread, |
| 2258 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2259 | * if not timeout or null otherwise. |
| 2260 | * @see #sendRequestAsync |
| 2261 | */ |
| 2262 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2263 | long timeoutInMs) { |
| 2264 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | /** |
| 2268 | * Posts the specified command to be executed on the main thread, |
| 2269 | * waits for the request to complete, and returns the result. |
| 2270 | * @see #sendRequestAsync |
| 2271 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2272 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2273 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Posts the specified command to be executed on the main thread, |
| 2278 | * waits for the request to complete, and returns the result. |
| 2279 | * @see #sendRequestAsync |
| 2280 | */ |
| 2281 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2282 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2283 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2287 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2288 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2289 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2290 | * @see #sendRequestAsync |
| 2291 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2292 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2293 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2295 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2296 | } |
| 2297 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2298 | MainThreadRequest request = null; |
| 2299 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2300 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2301 | } else if (phone != null) { |
| 2302 | request = new MainThreadRequest(argument, phone, workSource); |
| 2303 | } else { |
| 2304 | request = new MainThreadRequest(argument, subId, workSource); |
| 2305 | } |
| 2306 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2308 | msg.sendToTarget(); |
| 2309 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2310 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2311 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2312 | if (timeoutInMs >= 0) { |
| 2313 | // Wait for at least timeoutInMs before returning null request result |
| 2314 | long now = SystemClock.elapsedRealtime(); |
| 2315 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2316 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2317 | try { |
| 2318 | request.wait(deadline - now); |
| 2319 | } catch (InterruptedException e) { |
| 2320 | // Do nothing, go back and check if request is completed or timeout |
| 2321 | } finally { |
| 2322 | now = SystemClock.elapsedRealtime(); |
| 2323 | } |
| 2324 | } |
| 2325 | } else { |
| 2326 | // Wait for the request to complete |
| 2327 | while (request.result == null) { |
| 2328 | try { |
| 2329 | request.wait(); |
| 2330 | } catch (InterruptedException e) { |
| 2331 | // Do nothing, go back and wait until the request is complete |
| 2332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } |
| 2335 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2336 | if (request.result == null) { |
| 2337 | Log.wtf(LOG_TAG, |
| 2338 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | return request.result; |
| 2341 | } |
| 2342 | |
| 2343 | /** |
| 2344 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2345 | * Posts the specified command to be executed on the main thread, and |
| 2346 | * returns immediately. |
| 2347 | * @see #sendRequest |
| 2348 | */ |
| 2349 | private void sendRequestAsync(int command) { |
| 2350 | mMainThreadHandler.sendEmptyMessage(command); |
| 2351 | } |
| 2352 | |
| 2353 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2354 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2355 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2356 | */ |
| 2357 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2358 | sendRequestAsync(command, argument, null, null); |
| 2359 | } |
| 2360 | |
| 2361 | /** |
| 2362 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2363 | * @see {@link #sendRequest(int,Object)} |
| 2364 | */ |
| 2365 | private void sendRequestAsync( |
| 2366 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2367 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2368 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2369 | msg.sendToTarget(); |
| 2370 | } |
| 2371 | |
| 2372 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2374 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2375 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2376 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | synchronized (PhoneInterfaceManager.class) { |
| 2378 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2379 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | } else { |
| 2381 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2382 | } |
| 2383 | return sInstance; |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2388 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2391 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2392 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2394 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2396 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2397 | mTelephonySharedPreferences = |
| 2398 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2399 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2400 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2401 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2402 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2403 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2404 | publish(); |
| 2405 | } |
| 2406 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2407 | private Phone getDefaultPhone() { |
| 2408 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2409 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2410 | } |
| 2411 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | private void publish() { |
| 2413 | if (DBG) log("publish: " + this); |
| 2414 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2415 | TelephonyFrameworkInitializer |
| 2416 | .getTelephonyServiceManager() |
| 2417 | .getTelephonyServiceRegisterer() |
| 2418 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2421 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2422 | if (request.phone != null) { |
| 2423 | return request.phone; |
| 2424 | } else { |
| 2425 | return getPhoneFromSubId(request.subId); |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | private Phone getPhoneFromSubId(int subId) { |
| 2430 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2431 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2432 | } |
| 2433 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2434 | @Nullable |
| 2435 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2436 | Phone phone = getPhoneFromRequest(request); |
| 2437 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2438 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2439 | } |
| 2440 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2441 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2442 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2443 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2446 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2447 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2448 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2449 | } |
| 2450 | |
| 2451 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2452 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2453 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2456 | private boolean isImsAvailableOnDevice() { |
| 2457 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2458 | if (pm == null) { |
| 2459 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2460 | // so do not throw error and allow. |
| 2461 | return true; |
| 2462 | } |
| 2463 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2464 | } |
| 2465 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2467 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2470 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2471 | if (DBG) log("dial: " + number); |
| 2472 | // No permission check needed here: This is just a wrapper around the |
| 2473 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2474 | // the UI before it does anything. |
| 2475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2476 | final long identity = Binder.clearCallingIdentity(); |
| 2477 | try { |
| 2478 | String url = createTelUrl(number); |
| 2479 | if (url == null) { |
| 2480 | return; |
| 2481 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2482 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2483 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2484 | PhoneConstants.State state = mCM.getState(subId); |
| 2485 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2486 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2487 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2488 | mApp.startActivity(intent); |
| 2489 | } |
| 2490 | } finally { |
| 2491 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | } |
| 2493 | } |
| 2494 | |
| 2495 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2496 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2499 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2500 | if (DBG) log("call: " + number); |
| 2501 | |
| 2502 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2503 | // need to do a permission check since we're calling startActivity() |
| 2504 | // from the context of the phone app. |
| 2505 | enforceCallPermission(); |
| 2506 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2507 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2508 | != AppOpsManager.MODE_ALLOWED) { |
| 2509 | return; |
| 2510 | } |
| 2511 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | String url = createTelUrl(number); |
| 2515 | if (url == null) { |
| 2516 | return; |
| 2517 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | boolean isValid = false; |
| 2520 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2521 | if (slist != null) { |
| 2522 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2523 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2524 | isValid = true; |
| 2525 | break; |
| 2526 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2527 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | if (!isValid) { |
| 2530 | return; |
| 2531 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2532 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2534 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2535 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2536 | mApp.startActivity(intent); |
| 2537 | } finally { |
| 2538 | Binder.restoreCallingIdentity(identity); |
| 2539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2542 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2543 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2544 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2545 | } |
| 2546 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2547 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2548 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2549 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2550 | } |
| 2551 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2552 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2554 | |
| 2555 | final long identity = Binder.clearCallingIdentity(); |
| 2556 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2557 | Phone phone = getPhone(subId); |
| 2558 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2559 | checkSimPin.start(); |
| 2560 | return checkSimPin.unlockSim(null, pin); |
| 2561 | } finally { |
| 2562 | Binder.restoreCallingIdentity(identity); |
| 2563 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2566 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2568 | |
| 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2571 | Phone phone = getPhone(subId); |
| 2572 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | checkSimPuk.start(); |
| 2574 | return checkSimPuk.unlockSim(puk, pin); |
| 2575 | } finally { |
| 2576 | Binder.restoreCallingIdentity(identity); |
| 2577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2581 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2582 | * a synchronous one. |
| 2583 | */ |
| 2584 | private static class UnlockSim extends Thread { |
| 2585 | |
| 2586 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2587 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | |
| 2589 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2590 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2591 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | |
| 2593 | // For replies from SimCard interface |
| 2594 | private Handler mHandler; |
| 2595 | |
| 2596 | // For async handler to identify request type |
| 2597 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2598 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2599 | UnlockSim(int phoneId, IccCard simCard) { |
| 2600 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | mSimCard = simCard; |
| 2602 | } |
| 2603 | |
| 2604 | @Override |
| 2605 | public void run() { |
| 2606 | Looper.prepare(); |
| 2607 | synchronized (UnlockSim.this) { |
| 2608 | mHandler = new Handler() { |
| 2609 | @Override |
| 2610 | public void handleMessage(Message msg) { |
| 2611 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2612 | switch (msg.what) { |
| 2613 | case SUPPLY_PIN_COMPLETE: |
| 2614 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2615 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2616 | mRetryCount = msg.arg1; |
| 2617 | if (ar.exception != null) { |
| 2618 | if (ar.exception instanceof CommandException && |
| 2619 | ((CommandException)(ar.exception)).getCommandError() |
| 2620 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2621 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2622 | } //When UiccCardApp dispose,handle message and return exception |
| 2623 | else if (ar.exception instanceof CommandException && |
| 2624 | ((CommandException) (ar.exception)).getCommandError() |
| 2625 | == CommandException.Error.ABORTED) { |
| 2626 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2627 | } else { |
| 2628 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2629 | } |
| 2630 | } else { |
| 2631 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2632 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | mDone = true; |
| 2634 | UnlockSim.this.notifyAll(); |
| 2635 | } |
| 2636 | break; |
| 2637 | } |
| 2638 | } |
| 2639 | }; |
| 2640 | UnlockSim.this.notifyAll(); |
| 2641 | } |
| 2642 | Looper.loop(); |
| 2643 | } |
| 2644 | |
| 2645 | /* |
| 2646 | * Use PIN or PUK to unlock SIM card |
| 2647 | * |
| 2648 | * If PUK is null, unlock SIM card with PIN |
| 2649 | * |
| 2650 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2651 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2652 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2653 | |
| 2654 | while (mHandler == null) { |
| 2655 | try { |
| 2656 | wait(); |
| 2657 | } catch (InterruptedException e) { |
| 2658 | Thread.currentThread().interrupt(); |
| 2659 | } |
| 2660 | } |
| 2661 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2662 | |
| 2663 | if (puk == null) { |
| 2664 | mSimCard.supplyPin(pin, callback); |
| 2665 | } else { |
| 2666 | mSimCard.supplyPuk(puk, pin, callback); |
| 2667 | } |
| 2668 | |
| 2669 | while (!mDone) { |
| 2670 | try { |
| 2671 | Log.d(LOG_TAG, "wait for done"); |
| 2672 | wait(); |
| 2673 | } catch (InterruptedException e) { |
| 2674 | // Restore the interrupted status |
| 2675 | Thread.currentThread().interrupt(); |
| 2676 | } |
| 2677 | } |
| 2678 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2679 | int[] resultArray = new int[2]; |
| 2680 | resultArray[0] = mResult; |
| 2681 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2682 | |
| 2683 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2684 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2687 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2691 | /** |
| 2692 | * This method has been removed due to privacy and stability concerns. |
| 2693 | */ |
| 2694 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2695 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2696 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2697 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2700 | @Override |
| 2701 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2702 | mApp.getSystemService(AppOpsManager.class) |
| 2703 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2704 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2705 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2706 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2707 | // Callers targeting S have no business invoking this method. |
| 2708 | return; |
| 2709 | } |
| 2710 | |
| 2711 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2712 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2713 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2714 | .setCallingPackage(callingPackage) |
| 2715 | .setCallingFeatureId(null) |
| 2716 | .setCallingPid(Binder.getCallingPid()) |
| 2717 | .setCallingUid(Binder.getCallingUid()) |
| 2718 | .setMethod("updateServiceLocation") |
| 2719 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2720 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2721 | .build()); |
| 2722 | // Apps that lack location permission have no business calling this method; |
| 2723 | // however, because no permission was declared in the public API, denials must |
| 2724 | // all be "soft". |
| 2725 | switch (locationResult) { |
| 2726 | case DENIED_HARD: /* fall through */ |
| 2727 | case DENIED_SOFT: |
| 2728 | return; |
| 2729 | } |
| 2730 | |
| 2731 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2732 | final long identity = Binder.clearCallingIdentity(); |
| 2733 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2734 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2736 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | } |
| 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2740 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2743 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2744 | @Override |
| 2745 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2746 | return isRadioOnWithFeature(callingPackage, null); |
| 2747 | } |
| 2748 | |
| 2749 | |
| 2750 | @Override |
| 2751 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2752 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2753 | callingFeatureId); |
| 2754 | } |
| 2755 | |
| 2756 | @Deprecated |
| 2757 | @Override |
| 2758 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2759 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2763 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2764 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2765 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2766 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2767 | return false; |
| 2768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | |
| 2770 | final long identity = Binder.clearCallingIdentity(); |
| 2771 | try { |
| 2772 | return isRadioOnForSubscriber(subId); |
| 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
| 2775 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | final long identity = Binder.clearCallingIdentity(); |
| 2780 | try { |
| 2781 | final Phone phone = getPhone(subId); |
| 2782 | if (phone != null) { |
| 2783 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2784 | } else { |
| 2785 | return false; |
| 2786 | } |
| 2787 | } finally { |
| 2788 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2789 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2793 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2795 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2796 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | |
| 2799 | final long identity = Binder.clearCallingIdentity(); |
| 2800 | try { |
| 2801 | final Phone phone = getPhone(subId); |
| 2802 | if (phone != null) { |
| 2803 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2804 | } |
| 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2807 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2811 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2814 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2815 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2816 | |
| 2817 | final long identity = Binder.clearCallingIdentity(); |
| 2818 | try { |
| 2819 | final Phone phone = getPhone(subId); |
| 2820 | if (phone == null) { |
| 2821 | return false; |
| 2822 | } |
| 2823 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2824 | toggleRadioOnOffForSubscriber(subId); |
| 2825 | } |
| 2826 | return true; |
| 2827 | } finally { |
| 2828 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2829 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2830 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2831 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2832 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2833 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2834 | /* |
| 2835 | * If any of the Radios are available, it will need to be |
| 2836 | * shutdown. So return true if any Radio is available. |
| 2837 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | final long identity = Binder.clearCallingIdentity(); |
| 2839 | try { |
| 2840 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2841 | Phone phone = PhoneFactory.getPhone(i); |
| 2842 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2843 | } |
| 2844 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2845 | return false; |
| 2846 | } finally { |
| 2847 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2848 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2852 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2853 | enforceModifyPermission(); |
| 2854 | |
| 2855 | final long identity = Binder.clearCallingIdentity(); |
| 2856 | try { |
| 2857 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2858 | logv("Shutting down Phone " + i); |
| 2859 | shutdownRadioUsingPhoneId(i); |
| 2860 | } |
| 2861 | } finally { |
| 2862 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2867 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2868 | if (phone != null && phone.isRadioAvailable()) { |
| 2869 | phone.shutdownRadio(); |
| 2870 | } |
| 2871 | } |
| 2872 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2874 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2875 | |
| 2876 | final long identity = Binder.clearCallingIdentity(); |
| 2877 | try { |
| 2878 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2879 | if (defaultPhone != null) { |
| 2880 | defaultPhone.setRadioPower(turnOn); |
| 2881 | return true; |
| 2882 | } else { |
| 2883 | loge("There's no default phone."); |
| 2884 | return false; |
| 2885 | } |
| 2886 | } finally { |
| 2887 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2888 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2891 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2892 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | |
| 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
| 2896 | final Phone phone = getPhone(subId); |
| 2897 | if (phone != null) { |
| 2898 | phone.setRadioPower(turnOn); |
| 2899 | return true; |
| 2900 | } else { |
| 2901 | return false; |
| 2902 | } |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2908 | /** |
| 2909 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2910 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2911 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2912 | * powering it off, and these radio off votes will be cleared. |
| 2913 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2914 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2915 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2916 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2917 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2918 | * check its vote. |
| 2919 | * |
| 2920 | * @param subId The subscription ID. |
| 2921 | * @param reason The reason for powering off radio. |
| 2922 | * @return true on success and false on failure. |
| 2923 | */ |
| 2924 | public boolean requestRadioPowerOffForReason(int subId, |
| 2925 | @TelephonyManager.RadioPowerReason int reason) { |
| 2926 | enforceModifyPermission(); |
| 2927 | |
| 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | final Phone phone = getPhone(subId); |
| 2931 | if (phone != null) { |
| 2932 | phone.setRadioPowerForReason(false, reason); |
| 2933 | return true; |
| 2934 | } else { |
| 2935 | return false; |
| 2936 | } |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
| 2939 | } |
| 2940 | } |
| 2941 | |
| 2942 | /** |
| 2943 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2944 | * {@link requestRadioPowerOffForReason}. |
| 2945 | * |
| 2946 | * @param subId The subscription ID. |
| 2947 | * @param reason The reason for powering off radio. |
| 2948 | * @return true on success and false on failure. |
| 2949 | */ |
| 2950 | public boolean clearRadioPowerOffForReason(int subId, |
| 2951 | @TelephonyManager.RadioPowerReason int reason) { |
| 2952 | enforceModifyPermission(); |
| 2953 | |
| 2954 | final long identity = Binder.clearCallingIdentity(); |
| 2955 | try { |
| 2956 | final Phone phone = getPhone(subId); |
| 2957 | if (phone != null) { |
| 2958 | phone.setRadioPowerForReason(true, reason); |
| 2959 | return true; |
| 2960 | } else { |
| 2961 | return false; |
| 2962 | } |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | /** |
| 2969 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2970 | * |
| 2971 | * @param subId The subscription ID. |
| 2972 | * @param callingPackage The package making the call. |
| 2973 | * @param callingFeatureId The feature in the package. |
| 2974 | * @return List of reasons for powering off radio. |
| 2975 | */ |
| 2976 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 2977 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 2978 | |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | List result = new ArrayList(); |
| 2981 | try { |
| 2982 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 2983 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 2984 | return result; |
| 2985 | } |
| 2986 | |
| 2987 | final Phone phone = getPhone(subId); |
| 2988 | if (phone != null) { |
| 2989 | result.addAll(phone.getRadioPowerOffReasons()); |
| 2990 | } |
| 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
| 2994 | return result; |
| 2995 | } |
| 2996 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2997 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2998 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2999 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3000 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | |
| 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 3005 | final Phone phone = getPhone(subId); |
| 3006 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3007 | phone.getDataSettingsManager().setDataEnabled( |
| 3008 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | return true; |
| 3010 | } else { |
| 3011 | return false; |
| 3012 | } |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3018 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3019 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3020 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | |
| 3023 | final long identity = Binder.clearCallingIdentity(); |
| 3024 | try { |
| 3025 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 3026 | final Phone phone = getPhone(subId); |
| 3027 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3028 | phone.getDataSettingsManager().setDataEnabled( |
| 3029 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | return true; |
| 3031 | } else { |
| 3032 | return false; |
| 3033 | } |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3036 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3039 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3040 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | final long identity = Binder.clearCallingIdentity(); |
| 3042 | try { |
| 3043 | final Phone phone = getPhone(subId); |
| 3044 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3045 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3046 | } else { |
| 3047 | return false; |
| 3048 | } |
| 3049 | } finally { |
| 3050 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3051 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3052 | } |
| 3053 | |
| 3054 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3055 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3056 | } |
| 3057 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3058 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3059 | enforceCallPermission(); |
| 3060 | |
| 3061 | final long identity = Binder.clearCallingIdentity(); |
| 3062 | try { |
| 3063 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3064 | return; |
| 3065 | } |
| 3066 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3067 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
| 3070 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3071 | }; |
| 3072 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3073 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3074 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3075 | |
| 3076 | final long identity = Binder.clearCallingIdentity(); |
| 3077 | try { |
| 3078 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3079 | return false; |
| 3080 | } |
| 3081 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3082 | } finally { |
| 3083 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3087 | /** |
| 3088 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3089 | * tag on getCallState Binder call. |
| 3090 | */ |
| 3091 | @Deprecated |
| 3092 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3093 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3094 | if (CompatChanges.isChangeEnabled( |
| 3095 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3096 | Binder.getCallingUid())) { |
| 3097 | // Do not allow this API to be called on API version 31+, it should only be |
| 3098 | // called on old apps using this Binder call directly. |
| 3099 | throw new SecurityException("This method can only be used for applications " |
| 3100 | + "targeting API version 30 or less."); |
| 3101 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3104 | Phone phone = getPhone(getDefaultSubscription()); |
| 3105 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3106 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3107 | } finally { |
| 3108 | Binder.restoreCallingIdentity(identity); |
| 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | @Override |
| 3113 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3114 | if (CompatChanges.isChangeEnabled( |
| 3115 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3116 | Binder.getCallingUid())) { |
| 3117 | // Check READ_PHONE_STATE for API version 31+ |
| 3118 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3119 | featureId, "getCallStateForSubscription")) { |
| 3120 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3121 | + "targeting API level 31+."); |
| 3122 | } |
| 3123 | } |
| 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3127 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3128 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3129 | } finally { |
| 3130 | Binder.restoreCallingIdentity(identity); |
| 3131 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3134 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3135 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3136 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3137 | } |
| 3138 | |
| 3139 | @Override |
| 3140 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3141 | final long identity = Binder.clearCallingIdentity(); |
| 3142 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3143 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3144 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3145 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3146 | } else { |
| 3147 | return PhoneConstantConversions.convertDataState( |
| 3148 | PhoneConstants.DataState.DISCONNECTED); |
| 3149 | } |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3152 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3156 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3157 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3158 | } |
| 3159 | |
| 3160 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3161 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3162 | final long identity = Binder.clearCallingIdentity(); |
| 3163 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3164 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3165 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3166 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3167 | } else { |
| 3168 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3169 | } |
| 3170 | } finally { |
| 3171 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3172 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3173 | } |
| 3174 | |
| 3175 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3176 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3177 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3178 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3179 | |
| 3180 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3181 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3182 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3183 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3184 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3185 | .setCallingPid(Binder.getCallingPid()) |
| 3186 | .setCallingUid(Binder.getCallingUid()) |
| 3187 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3188 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3189 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3190 | .build()); |
| 3191 | switch (locationResult) { |
| 3192 | case DENIED_HARD: |
| 3193 | throw new SecurityException("Not allowed to access cell location"); |
| 3194 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3195 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3196 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3197 | } |
| 3198 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3199 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
| 3202 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3203 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3204 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | } finally { |
| 3206 | Binder.restoreCallingIdentity(identity); |
| 3207 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3208 | } |
| 3209 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3210 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3211 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3212 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3213 | // registered cell info, so return a NULL country instead. |
| 3214 | final long identity = Binder.clearCallingIdentity(); |
| 3215 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3216 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3217 | // Get default phone in this case. |
| 3218 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3219 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3220 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3222 | if (phone == null) return ""; |
| 3223 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3224 | if (sst == null) return ""; |
| 3225 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3226 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3227 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3228 | } finally { |
| 3229 | Binder.restoreCallingIdentity(identity); |
| 3230 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3233 | /** |
| 3234 | * This method was removed due to potential issues caused by performing partial |
| 3235 | * updates of service state, and lack of a credible use case. |
| 3236 | * |
| 3237 | * This has the ability to break the telephony implementation by disabling notification of |
| 3238 | * changes in device connectivity. DO NOT USE THIS! |
| 3239 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3240 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3241 | public void enableLocationUpdates() { |
| 3242 | mApp.enforceCallingOrSelfPermission( |
| 3243 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3246 | /** |
| 3247 | * This method was removed due to potential issues caused by performing partial |
| 3248 | * updates of service state, and lack of a credible use case. |
| 3249 | * |
| 3250 | * This has the ability to break the telephony implementation by disabling notification of |
| 3251 | * changes in device connectivity. DO NOT USE THIS! |
| 3252 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3253 | @Override |
| 3254 | public void disableLocationUpdates() { |
| 3255 | mApp.enforceCallingOrSelfPermission( |
| 3256 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | @Override |
| 3260 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3261 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3262 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3263 | try { |
| 3264 | mApp.getSystemService(AppOpsManager.class) |
| 3265 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3266 | } catch (SecurityException e) { |
| 3267 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3268 | throw e; |
| 3269 | } |
| 3270 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3271 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3272 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3273 | throw new SecurityException( |
| 3274 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3275 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3276 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3277 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3278 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3279 | return null; |
| 3280 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3281 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3282 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3283 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3284 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3285 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3286 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3287 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3288 | for (CellInfo ci : info) { |
| 3289 | if (ci instanceof CellInfoGsm) { |
| 3290 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3291 | } else if (ci instanceof CellInfoWcdma) { |
| 3292 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3293 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3294 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3295 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3298 | private List<CellInfo> getCachedCellInfo() { |
| 3299 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3300 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3301 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3302 | if (info != null) cellInfos.addAll(info); |
| 3303 | } |
| 3304 | return cellInfos; |
| 3305 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3306 | |
| 3307 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3308 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3309 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3310 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3311 | |
| 3312 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3313 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3314 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3315 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3316 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3317 | .setCallingPid(Binder.getCallingPid()) |
| 3318 | .setCallingUid(Binder.getCallingUid()) |
| 3319 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3320 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3321 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3322 | .build()); |
| 3323 | switch (locationResult) { |
| 3324 | case DENIED_HARD: |
| 3325 | throw new SecurityException("Not allowed to access cell info"); |
| 3326 | case DENIED_SOFT: |
| 3327 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3328 | } |
| 3329 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3330 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3331 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3332 | return getCachedCellInfo(); |
| 3333 | } |
| 3334 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3335 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3336 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3340 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3341 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3342 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | if (info != null) cellInfos.addAll(info); |
| 3344 | } |
| 3345 | return cellInfos; |
| 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3351 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3352 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3353 | String callingFeatureId) { |
| 3354 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3355 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3359 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3360 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3361 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3362 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3365 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3366 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3367 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3368 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3369 | |
| 3370 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3371 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3372 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3373 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3374 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3375 | .setCallingPid(Binder.getCallingPid()) |
| 3376 | .setCallingUid(Binder.getCallingUid()) |
| 3377 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3378 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3379 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3380 | .build()); |
| 3381 | switch (locationResult) { |
| 3382 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3383 | if (TelephonyPermissions |
| 3384 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3385 | // Safetynet logging for b/154934934 |
| 3386 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3387 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3388 | throw new SecurityException("Not allowed to access cell info"); |
| 3389 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3390 | if (TelephonyPermissions |
| 3391 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3392 | // Safetynet logging for b/154934934 |
| 3393 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3394 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3395 | try { |
| 3396 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3397 | } catch (RemoteException re) { |
| 3398 | // Drop without consequences |
| 3399 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3400 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3403 | |
| 3404 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3405 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3406 | |
| 3407 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3408 | } |
| 3409 | |
| 3410 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3411 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3412 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3413 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3414 | |
| 3415 | final long identity = Binder.clearCallingIdentity(); |
| 3416 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3417 | Phone phone = getPhone(subId); |
| 3418 | if (phone == null) { |
| 3419 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3420 | } else { |
| 3421 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3422 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3426 | } |
| 3427 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3428 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3429 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3430 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3431 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3432 | return null; |
| 3433 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3434 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3435 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3436 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3437 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3438 | return null; |
| 3439 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3440 | |
| 3441 | final long identity = Binder.clearCallingIdentity(); |
| 3442 | try { |
| 3443 | return phone.getImei(); |
| 3444 | } finally { |
| 3445 | Binder.restoreCallingIdentity(identity); |
| 3446 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3450 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3451 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3452 | String tac = null; |
| 3453 | if (phone != null) { |
| 3454 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3455 | try { |
| 3456 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3457 | } catch (IndexOutOfBoundsException e) { |
| 3458 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3459 | return null; |
| 3460 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3461 | } |
| 3462 | return tac; |
| 3463 | } |
| 3464 | |
| 3465 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3466 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3467 | try { |
| 3468 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3469 | } catch (SecurityException se) { |
| 3470 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3471 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3472 | + Binder.getCallingUid()); |
| 3473 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3474 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3475 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3476 | return null; |
| 3477 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3478 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3479 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3480 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3481 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3482 | return null; |
| 3483 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3484 | |
| 3485 | final long identity = Binder.clearCallingIdentity(); |
| 3486 | try { |
| 3487 | return phone.getMeid(); |
| 3488 | } finally { |
| 3489 | Binder.restoreCallingIdentity(identity); |
| 3490 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
| 3493 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3494 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3495 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3496 | String manufacturerCode = null; |
| 3497 | if (phone != null) { |
| 3498 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3499 | try { |
| 3500 | manufacturerCode = |
| 3501 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3502 | } catch (IndexOutOfBoundsException e) { |
| 3503 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3504 | return null; |
| 3505 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3506 | } |
| 3507 | return manufacturerCode; |
| 3508 | } |
| 3509 | |
| 3510 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3511 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3512 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3513 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3514 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3515 | return null; |
| 3516 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3517 | int subId = phone.getSubId(); |
| 3518 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3519 | mApp, subId, callingPackage, callingFeatureId, |
| 3520 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3521 | return null; |
| 3522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3523 | |
| 3524 | final long identity = Binder.clearCallingIdentity(); |
| 3525 | try { |
| 3526 | return phone.getDeviceSvn(); |
| 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3532 | @Override |
| 3533 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | final long identity = Binder.clearCallingIdentity(); |
| 3535 | try { |
| 3536 | final Phone phone = getPhone(subId); |
| 3537 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(identity); |
| 3540 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | @Override |
| 3544 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | final Phone phone = getPhone(subId); |
| 3548 | return phone == null ? null : phone.getCarrierName(); |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
| 3551 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3552 | } |
| 3553 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3554 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3555 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3556 | final long identity = Binder.clearCallingIdentity(); |
| 3557 | try { |
| 3558 | final Phone phone = getPhone(subId); |
| 3559 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3560 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3567 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3568 | final long identity = Binder.clearCallingIdentity(); |
| 3569 | try { |
| 3570 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3571 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
| 3575 | } |
| 3576 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3577 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3578 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3579 | if (!isSubscriptionMccMnc) { |
| 3580 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3581 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3582 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3583 | if (phone == null) { |
| 3584 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3585 | } |
| 3586 | final long identity = Binder.clearCallingIdentity(); |
| 3587 | try { |
| 3588 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3589 | } finally { |
| 3590 | Binder.restoreCallingIdentity(identity); |
| 3591 | } |
| 3592 | } |
| 3593 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3594 | // |
| 3595 | // Internal helper methods. |
| 3596 | // |
| 3597 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3598 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3599 | * Make sure the caller is the calling package itself |
| 3600 | * |
| 3601 | * @throws SecurityException if the caller is not the calling package |
| 3602 | */ |
| 3603 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3604 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3605 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3606 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3607 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3608 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3609 | } catch (PackageManager.NameNotFoundException e) { |
| 3610 | // packageUid is -1 |
| 3611 | } |
| 3612 | if (packageUid != callingUid) { |
| 3613 | throw new SecurityException(message + ": Package " + callingPackage |
| 3614 | + " does not belong to " + callingUid); |
| 3615 | } |
| 3616 | } |
| 3617 | |
| 3618 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3619 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3620 | * |
| 3621 | * @throws SecurityException if the caller does not have the required permission |
| 3622 | */ |
| 3623 | private void enforceModifyPermission() { |
| 3624 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3625 | } |
| 3626 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3627 | private void enforceActiveEmergencySessionPermission() { |
| 3628 | mApp.enforceCallingOrSelfPermission( |
| 3629 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3630 | } |
| 3631 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3632 | /** |
| 3633 | * Make sure the caller has the CALL_PHONE permission. |
| 3634 | * |
| 3635 | * @throws SecurityException if the caller does not have the required permission |
| 3636 | */ |
| 3637 | private void enforceCallPermission() { |
| 3638 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3639 | } |
| 3640 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3641 | private void enforceSettingsPermission() { |
| 3642 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3645 | private void enforceRebootPermission() { |
| 3646 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3647 | } |
| 3648 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3649 | private String createTelUrl(String number) { |
| 3650 | if (TextUtils.isEmpty(number)) { |
| 3651 | return null; |
| 3652 | } |
| 3653 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3654 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3657 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3658 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3659 | } |
| 3660 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3661 | private static void logv(String msg) { |
| 3662 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3663 | } |
| 3664 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3665 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3666 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3667 | } |
| 3668 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3669 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3670 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3671 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3674 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3675 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
| 3678 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3679 | if (phone == null) { |
| 3680 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3681 | } else { |
| 3682 | return phone.getPhoneType(); |
| 3683 | } |
| 3684 | } finally { |
| 3685 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | /** |
| 3690 | * Returns the CDMA ERI icon index to display |
| 3691 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3692 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3693 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3694 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3695 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3698 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3699 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3700 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3702 | mApp, subId, callingPackage, callingFeatureId, |
| 3703 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3704 | return -1; |
| 3705 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3706 | |
| 3707 | final long identity = Binder.clearCallingIdentity(); |
| 3708 | try { |
| 3709 | final Phone phone = getPhone(subId); |
| 3710 | if (phone != null) { |
| 3711 | return phone.getCdmaEriIconIndex(); |
| 3712 | } else { |
| 3713 | return -1; |
| 3714 | } |
| 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | /** |
| 3721 | * Returns the CDMA ERI icon mode, |
| 3722 | * 0 - ON |
| 3723 | * 1 - FLASHING |
| 3724 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3725 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3726 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3727 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3728 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3731 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3732 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3733 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3734 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3735 | mApp, subId, callingPackage, callingFeatureId, |
| 3736 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3737 | return -1; |
| 3738 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3739 | |
| 3740 | final long identity = Binder.clearCallingIdentity(); |
| 3741 | try { |
| 3742 | final Phone phone = getPhone(subId); |
| 3743 | if (phone != null) { |
| 3744 | return phone.getCdmaEriIconMode(); |
| 3745 | } else { |
| 3746 | return -1; |
| 3747 | } |
| 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3750 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
| 3753 | /** |
| 3754 | * Returns the CDMA ERI text, |
| 3755 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3756 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3757 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3758 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3759 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3763 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3764 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3765 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3766 | mApp, subId, callingPackage, callingFeatureId, |
| 3767 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3768 | return null; |
| 3769 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3770 | |
| 3771 | final long identity = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | final Phone phone = getPhone(subId); |
| 3774 | if (phone != null) { |
| 3775 | return phone.getCdmaEriText(); |
| 3776 | } else { |
| 3777 | return null; |
| 3778 | } |
| 3779 | } finally { |
| 3780 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3781 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3785 | * Returns the CDMA MDN. |
| 3786 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3787 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3788 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3790 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | |
| 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3795 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | return phone.getLine1Number(); |
| 3797 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3798 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3799 | return null; |
| 3800 | } |
| 3801 | } finally { |
| 3802 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Returns the CDMA MIN. |
| 3808 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3809 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3810 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3812 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | |
| 3814 | final long identity = Binder.clearCallingIdentity(); |
| 3815 | try { |
| 3816 | final Phone phone = getPhone(subId); |
| 3817 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3818 | return phone.getCdmaMin(); |
| 3819 | } else { |
| 3820 | return null; |
| 3821 | } |
| 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3824 | } |
| 3825 | } |
| 3826 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3827 | @Override |
| 3828 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3829 | INumberVerificationCallback callback, String callingPackage) { |
| 3830 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3831 | != PERMISSION_GRANTED) { |
| 3832 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3833 | } |
| 3834 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3835 | |
| 3836 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3837 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3838 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3839 | + "calling package: " + callingPackage |
| 3840 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | if (range == null) { |
| 3844 | throw new NullPointerException("Range must be non-null"); |
| 3845 | } |
| 3846 | |
| 3847 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3848 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3849 | |
| 3850 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3851 | } |
| 3852 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3853 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3854 | * Returns true if CDMA provisioning needs to run. |
| 3855 | */ |
| 3856 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3859 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3860 | } finally { |
| 3861 | Binder.restoreCallingIdentity(identity); |
| 3862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3866 | * Sets the voice mail number of a given subId. |
| 3867 | */ |
| 3868 | @Override |
| 3869 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3870 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3871 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3872 | |
| 3873 | final long identity = Binder.clearCallingIdentity(); |
| 3874 | try { |
| 3875 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3876 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3877 | return success; |
| 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
| 3880 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3881 | } |
| 3882 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3883 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3884 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3885 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3886 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3887 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3888 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3889 | throw new SecurityException("caller must be system dialer"); |
| 3890 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | |
| 3892 | final long identity = Binder.clearCallingIdentity(); |
| 3893 | try { |
| 3894 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3895 | if (phoneAccountHandle == null) { |
| 3896 | return null; |
| 3897 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3898 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3899 | } finally { |
| 3900 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3901 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3905 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3906 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3907 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3908 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3909 | mApp, subId, callingPackage, callingFeatureId, |
| 3910 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3911 | return null; |
| 3912 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3913 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3914 | final long identity = Binder.clearCallingIdentity(); |
| 3915 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3916 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3917 | } finally { |
| 3918 | Binder.restoreCallingIdentity(identity); |
| 3919 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3923 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3924 | VisualVoicemailSmsFilterSettings settings) { |
| 3925 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3926 | |
| 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3930 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(identity); |
| 3933 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3937 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3938 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | |
| 3940 | final long identity = Binder.clearCallingIdentity(); |
| 3941 | try { |
| 3942 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3943 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3944 | } finally { |
| 3945 | Binder.restoreCallingIdentity(identity); |
| 3946 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3950 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3951 | String callingPackage, int subId) { |
| 3952 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | |
| 3954 | final long identity = Binder.clearCallingIdentity(); |
| 3955 | try { |
| 3956 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3957 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
| 3960 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3964 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3965 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3966 | |
| 3967 | final long identity = Binder.clearCallingIdentity(); |
| 3968 | try { |
| 3969 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3970 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3971 | } finally { |
| 3972 | Binder.restoreCallingIdentity(identity); |
| 3973 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3977 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3978 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3979 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3980 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3981 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3982 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3983 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3984 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3985 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3986 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3987 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3988 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3989 | * Sets the voice activation state of a given subId. |
| 3990 | */ |
| 3991 | @Override |
| 3992 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3994 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3995 | |
| 3996 | final long identity = Binder.clearCallingIdentity(); |
| 3997 | try { |
| 3998 | final Phone phone = getPhone(subId); |
| 3999 | if (phone != null) { |
| 4000 | phone.setVoiceActivationState(activationState); |
| 4001 | } else { |
| 4002 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4003 | } |
| 4004 | } finally { |
| 4005 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4006 | } |
| 4007 | } |
| 4008 | |
| 4009 | /** |
| 4010 | * Sets the data activation state of a given subId. |
| 4011 | */ |
| 4012 | @Override |
| 4013 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4015 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4016 | |
| 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
| 4019 | final Phone phone = getPhone(subId); |
| 4020 | if (phone != null) { |
| 4021 | phone.setDataActivationState(activationState); |
| 4022 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4023 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4024 | } |
| 4025 | } finally { |
| 4026 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4027 | } |
| 4028 | } |
| 4029 | |
| 4030 | /** |
| 4031 | * Returns the voice activation state of a given subId. |
| 4032 | */ |
| 4033 | @Override |
| 4034 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4035 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4036 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4037 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4038 | final long identity = Binder.clearCallingIdentity(); |
| 4039 | try { |
| 4040 | if (phone != null) { |
| 4041 | return phone.getVoiceActivationState(); |
| 4042 | } else { |
| 4043 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4044 | } |
| 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | /** |
| 4051 | * Returns the data activation state of a given subId. |
| 4052 | */ |
| 4053 | @Override |
| 4054 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4056 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4057 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4058 | final long identity = Binder.clearCallingIdentity(); |
| 4059 | try { |
| 4060 | if (phone != null) { |
| 4061 | return phone.getDataActivationState(); |
| 4062 | } else { |
| 4063 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4064 | } |
| 4065 | } finally { |
| 4066 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4067 | } |
| 4068 | } |
| 4069 | |
| 4070 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4071 | * Returns the unread count of voicemails for a subId |
| 4072 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4073 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4074 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4075 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4076 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4077 | mApp, subId, callingPackage, callingFeatureId, |
| 4078 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4079 | return 0; |
| 4080 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4081 | final long identity = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | final Phone phone = getPhone(subId); |
| 4084 | if (phone != null) { |
| 4085 | return phone.getVoiceMessageCount(); |
| 4086 | } else { |
| 4087 | return 0; |
| 4088 | } |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4091 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
| 4094 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4095 | * returns true, if the device is in a state where both voice and data |
| 4096 | * are supported simultaneously. This can change based on location or network condition. |
| 4097 | */ |
| 4098 | @Override |
| 4099 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | final Phone phone = getPhone(subId); |
| 4103 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4110 | * Send the dialer code if called from the current default dialer or the caller has |
| 4111 | * carrier privilege. |
| 4112 | * @param inputCode The dialer code to send |
| 4113 | */ |
| 4114 | @Override |
| 4115 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4116 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4117 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4118 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4119 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4120 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4121 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4122 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4123 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4124 | |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4127 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4128 | } finally { |
| 4129 | Binder.restoreCallingIdentity(identity); |
| 4130 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4131 | } |
| 4132 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4133 | @Override |
| 4134 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4135 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4136 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4137 | mApp, subId, "getNetworkSelectionMode"); |
| 4138 | final long identity = Binder.clearCallingIdentity(); |
| 4139 | try { |
| 4140 | if (!isActiveSubscription(subId)) { |
| 4141 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4142 | } |
| 4143 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4144 | } finally { |
| 4145 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4146 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4147 | } |
| 4148 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4150 | public boolean isInEmergencySmsMode() { |
| 4151 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4152 | final long identity = Binder.clearCallingIdentity(); |
| 4153 | try { |
| 4154 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4155 | if (phone.isInEmergencySmsMode()) { |
| 4156 | return true; |
| 4157 | } |
| 4158 | } |
| 4159 | } finally { |
| 4160 | Binder.restoreCallingIdentity(identity); |
| 4161 | } |
| 4162 | return false; |
| 4163 | } |
| 4164 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4165 | /** |
| 4166 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4167 | * @param subId The subscription to use to check the configuration. |
| 4168 | * @param c The callback that will be used to send the result. |
| 4169 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4170 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4171 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4172 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4173 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4174 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4175 | |
| 4176 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4177 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4178 | "IMS not available on device."); |
| 4179 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | final long token = Binder.clearCallingIdentity(); |
| 4181 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4182 | int slotId = getSlotIndexOrException(subId); |
| 4183 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4184 | |
| 4185 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4186 | if (controller != null) { |
| 4187 | ImsManager imsManager = controller.getImsManager(subId); |
| 4188 | if (imsManager != null) { |
| 4189 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4190 | } else { |
| 4191 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4192 | } |
| 4193 | } else { |
| 4194 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4195 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4196 | } catch (ImsException e) { |
| 4197 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4198 | } finally { |
| 4199 | Binder.restoreCallingIdentity(token); |
| 4200 | } |
| 4201 | } |
| 4202 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4203 | /** |
| 4204 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4205 | * @param subId The subscription to use to check the configuration. |
| 4206 | * @param c The callback that will be used to send the result. |
| 4207 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4209 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4210 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4211 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4212 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4213 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4214 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4215 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4216 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4217 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4218 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4219 | if (controller != null) { |
| 4220 | ImsManager imsManager = controller.getImsManager(subId); |
| 4221 | if (imsManager != null) { |
| 4222 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4223 | } else { |
| 4224 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4225 | + "is inactive, ignoring unregister."); |
| 4226 | // If the ImsManager is not valid, just return, since the callback |
| 4227 | // will already have been removed internally. |
| 4228 | } |
| 4229 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4230 | } finally { |
| 4231 | Binder.restoreCallingIdentity(token); |
| 4232 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4235 | /** |
| 4236 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4237 | */ |
| 4238 | @Override |
| 4239 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4240 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4241 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4242 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4243 | "IMS not available on device."); |
| 4244 | } |
| 4245 | final long token = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | Phone phone = getPhone(subId); |
| 4248 | if (phone == null) { |
| 4249 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4250 | + subId + "'"); |
| 4251 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4252 | } |
| 4253 | phone.getImsRegistrationState(regState -> { |
| 4254 | try { |
| 4255 | consumer.accept((regState == null) |
| 4256 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4257 | } catch (RemoteException e) { |
| 4258 | // Ignore if the remote process is no longer available to call back. |
| 4259 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4260 | } |
| 4261 | }); |
| 4262 | } finally { |
| 4263 | Binder.restoreCallingIdentity(token); |
| 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | /** |
| 4268 | * Get the transport type for the IMS service registration state. |
| 4269 | */ |
| 4270 | @Override |
| 4271 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4272 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4273 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4274 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4275 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4276 | "IMS not available on device."); |
| 4277 | } |
| 4278 | final long token = Binder.clearCallingIdentity(); |
| 4279 | try { |
| 4280 | Phone phone = getPhone(subId); |
| 4281 | if (phone == null) { |
| 4282 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4283 | + subId + "'"); |
| 4284 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4285 | } |
| 4286 | phone.getImsRegistrationTech(regTech -> { |
| 4287 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4288 | int regTechConverted = (regTech == null) |
| 4289 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4290 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4291 | regTechConverted); |
| 4292 | try { |
| 4293 | consumer.accept(regTechConverted); |
| 4294 | } catch (RemoteException e) { |
| 4295 | // Ignore if the remote process is no longer available to call back. |
| 4296 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4297 | } |
| 4298 | }); |
| 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(token); |
| 4301 | } |
| 4302 | } |
| 4303 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4304 | /** |
| 4305 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4306 | * @param subId The subscription to use to check the configuration. |
| 4307 | * @param c The callback that will be used to send the result. |
| 4308 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4309 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4310 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4311 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4312 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4313 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4314 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4316 | "IMS not available on device."); |
| 4317 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4318 | final long token = Binder.clearCallingIdentity(); |
| 4319 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4320 | int slotId = getSlotIndexOrException(subId); |
| 4321 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4322 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4323 | } catch (ImsException e) { |
| 4324 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(token); |
| 4327 | } |
| 4328 | } |
| 4329 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4330 | /** |
| 4331 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4332 | * @param subId The subscription to use to check the configuration. |
| 4333 | * @param c The callback that will be used to send the result. |
| 4334 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4335 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4336 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4337 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4338 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4339 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4340 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4341 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4342 | |
| 4343 | final long token = Binder.clearCallingIdentity(); |
| 4344 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4345 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4346 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4347 | } catch (ImsException e) { |
| 4348 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4349 | + "is inactive, ignoring unregister."); |
| 4350 | // If the subscription is no longer active, just return, since the callback |
| 4351 | // will already have been removed internally. |
| 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(token); |
| 4354 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4358 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4359 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | final long token = Binder.clearCallingIdentity(); |
| 4361 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4362 | int slotId = getSlotIndexOrException(subId); |
| 4363 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4364 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4365 | } catch (com.android.ims.ImsException e) { |
| 4366 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4367 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4368 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4369 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4370 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(token); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4377 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4378 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4379 | final long token = Binder.clearCallingIdentity(); |
| 4380 | try { |
| 4381 | Phone phone = getPhone(subId); |
| 4382 | if (phone == null) return false; |
| 4383 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4384 | } catch (com.android.ims.ImsException e) { |
| 4385 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4386 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4387 | } finally { |
| 4388 | Binder.restoreCallingIdentity(token); |
| 4389 | } |
| 4390 | } |
| 4391 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4392 | /** |
| 4393 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4394 | * subscription. |
| 4395 | * @param subId The subscription to use to check the configuration. |
| 4396 | * @param callback The callback that will be used to send the result. |
| 4397 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4398 | * @param transportType The transport type of the MmTelFeature capability. |
| 4399 | */ |
| 4400 | @Override |
| 4401 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4402 | int transportType) { |
| 4403 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4404 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4405 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4406 | "IMS not available on device."); |
| 4407 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4408 | final long token = Binder.clearCallingIdentity(); |
| 4409 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4410 | int slotId = getSlotIndex(subId); |
| 4411 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4412 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4413 | + subId + "'"); |
| 4414 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4415 | } |
| 4416 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4417 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4418 | transportType, aBoolean -> { |
| 4419 | try { |
| 4420 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4421 | } catch (RemoteException e) { |
| 4422 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4423 | + "running. Ignore"); |
| 4424 | } |
| 4425 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4426 | } catch (ImsException e) { |
| 4427 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4428 | } finally { |
| 4429 | Binder.restoreCallingIdentity(token); |
| 4430 | } |
| 4431 | } |
| 4432 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4433 | /** |
| 4434 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4435 | * @param subId The subscription to use to check the configuration. |
| 4436 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4437 | @Override |
| 4438 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4439 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4440 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4441 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | final long token = Binder.clearCallingIdentity(); |
| 4443 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4444 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4445 | // 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] | 4446 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4447 | } catch (ImsException e) { |
| 4448 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(token); |
| 4451 | } |
| 4452 | } |
| 4453 | |
| 4454 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4455 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4457 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4458 | final long identity = Binder.clearCallingIdentity(); |
| 4459 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4460 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4461 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4462 | // 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] | 4463 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4464 | } catch (ImsException e) { |
| 4465 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
| 4469 | } |
| 4470 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4471 | /** |
| 4472 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4473 | * @param subId The subscription to use to check the configuration. |
| 4474 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4475 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4476 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4477 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4478 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4479 | final long identity = Binder.clearCallingIdentity(); |
| 4480 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4481 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4482 | // 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] | 4483 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4484 | } catch (ImsException e) { |
| 4485 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(identity); |
| 4488 | } |
| 4489 | } |
| 4490 | |
| 4491 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4492 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4494 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4495 | final long identity = Binder.clearCallingIdentity(); |
| 4496 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4497 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4498 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4499 | // 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] | 4500 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4501 | } catch (ImsException e) { |
| 4502 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
| 4505 | } |
| 4506 | } |
| 4507 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4508 | /** |
| 4509 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4510 | * @param subId The subscription to use to check the configuration. |
| 4511 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4512 | @Override |
| 4513 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4514 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4515 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4516 | final long identity = Binder.clearCallingIdentity(); |
| 4517 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4518 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4519 | // 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] | 4520 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4521 | } catch (ImsException e) { |
| 4522 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4523 | } finally { |
| 4524 | Binder.restoreCallingIdentity(identity); |
| 4525 | } |
| 4526 | } |
| 4527 | |
| 4528 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4529 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4530 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4531 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4534 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4535 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4536 | // 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] | 4537 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4538 | } catch (ImsException e) { |
| 4539 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4540 | } finally { |
| 4541 | Binder.restoreCallingIdentity(identity); |
| 4542 | } |
| 4543 | } |
| 4544 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4545 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4546 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4547 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4548 | * @param subId The subscription to use to check the configuration. |
| 4549 | */ |
| 4550 | @Override |
| 4551 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4552 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4553 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4554 | final long identity = Binder.clearCallingIdentity(); |
| 4555 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4556 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4557 | // 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] | 4558 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4559 | } catch (ImsException e) { |
| 4560 | throw new ServiceSpecificException(e.getCode()); |
| 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
| 4563 | } |
| 4564 | } |
| 4565 | |
| 4566 | /** |
| 4567 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4568 | * Requires MODIFY_PHONE_STATE permission. |
| 4569 | * @param subId The subscription to use to check the configuration. |
| 4570 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4571 | * false otherwise |
| 4572 | */ |
| 4573 | @Override |
| 4574 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4576 | "setCrossSimCallingEnabled"); |
| 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4579 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4580 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4581 | // 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] | 4582 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4583 | } catch (ImsException e) { |
| 4584 | throw new ServiceSpecificException(e.getCode()); |
| 4585 | } finally { |
| 4586 | Binder.restoreCallingIdentity(identity); |
| 4587 | } |
| 4588 | } |
| 4589 | |
| 4590 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4591 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4592 | * @param subId The subscription to use to check the configuration. |
| 4593 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4594 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4595 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4597 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4598 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | final long identity = Binder.clearCallingIdentity(); |
| 4600 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4601 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4602 | // 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] | 4603 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4604 | } catch (ImsException e) { |
| 4605 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4606 | } finally { |
| 4607 | Binder.restoreCallingIdentity(identity); |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4612 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4614 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4617 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4618 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4619 | // 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] | 4620 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
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(identity); |
| 4625 | } |
| 4626 | } |
| 4627 | |
| 4628 | @Override |
| 4629 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4631 | "setVoWiFiNonPersistent"); |
| 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 will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4636 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4637 | } catch (ImsException e) { |
| 4638 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
| 4641 | } |
| 4642 | } |
| 4643 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4644 | /** |
| 4645 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4646 | * @param subId The subscription to use to check the configuration. |
| 4647 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4648 | @Override |
| 4649 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4650 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4651 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4652 | final long identity = Binder.clearCallingIdentity(); |
| 4653 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4654 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4655 | // 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] | 4656 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4657 | } catch (ImsException e) { |
| 4658 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | @Override |
| 4665 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4666 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4667 | "setVoWiFiModeSetting"); |
| 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4670 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4671 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4672 | // 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] | 4673 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4674 | } catch (ImsException e) { |
| 4675 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4676 | } finally { |
| 4677 | Binder.restoreCallingIdentity(identity); |
| 4678 | } |
| 4679 | } |
| 4680 | |
| 4681 | @Override |
| 4682 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4683 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4684 | final long identity = Binder.clearCallingIdentity(); |
| 4685 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4686 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4687 | // 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] | 4688 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4689 | } catch (ImsException e) { |
| 4690 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | @Override |
| 4697 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4699 | "setVoWiFiRoamingModeSetting"); |
| 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4702 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4703 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4704 | // 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] | 4705 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4706 | } catch (ImsException e) { |
| 4707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
| 4710 | } |
| 4711 | } |
| 4712 | |
| 4713 | @Override |
| 4714 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4716 | "setRttCapabilityEnabled"); |
| 4717 | final long identity = Binder.clearCallingIdentity(); |
| 4718 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4719 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4720 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4721 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4722 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4723 | } catch (ImsException e) { |
| 4724 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4725 | } finally { |
| 4726 | Binder.restoreCallingIdentity(identity); |
| 4727 | } |
| 4728 | } |
| 4729 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4730 | /** |
| 4731 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4732 | * @param subId The subscription to use to check the configuration. |
| 4733 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4734 | @Override |
| 4735 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4736 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4737 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4740 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4741 | // 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] | 4742 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4743 | } catch (ImsException e) { |
| 4744 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
| 4747 | } |
| 4748 | } |
| 4749 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4750 | @Override |
| 4751 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4752 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4753 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4754 | final long identity = Binder.clearCallingIdentity(); |
| 4755 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4756 | if (!isImsAvailableOnDevice()) { |
| 4757 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4758 | "IMS not available on device."); |
| 4759 | } |
| 4760 | int slotId = getSlotIndexOrException(subId); |
| 4761 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4762 | ImsManager.getInstance(mApp, slotId) |
| 4763 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4764 | } catch (ImsException e) { |
| 4765 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4766 | } finally { |
| 4767 | Binder.restoreCallingIdentity(identity); |
| 4768 | } |
| 4769 | } |
| 4770 | |
| 4771 | @Override |
| 4772 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4773 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4774 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4775 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4776 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4777 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4778 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4779 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4780 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4781 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4782 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4783 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4784 | + "is inactive, ignoring unregister."); |
| 4785 | // If the subscription is no longer active, just return, since the callback will already |
| 4786 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4787 | } finally { |
| 4788 | Binder.restoreCallingIdentity(identity); |
| 4789 | } |
| 4790 | } |
| 4791 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4792 | @Override |
| 4793 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4794 | IFeatureProvisioningCallback callback) { |
| 4795 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4796 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4797 | |
| 4798 | final long identity = Binder.clearCallingIdentity(); |
| 4799 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4800 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4801 | } |
| 4802 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4803 | try { |
| 4804 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4805 | if (controller == null) { |
| 4806 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4807 | "Device does not support IMS"); |
| 4808 | } |
| 4809 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4810 | } finally { |
| 4811 | Binder.restoreCallingIdentity(identity); |
| 4812 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | @Override |
| 4816 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4817 | IFeatureProvisioningCallback callback) { |
| 4818 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4819 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4820 | |
| 4821 | final long identity = Binder.clearCallingIdentity(); |
| 4822 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4823 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4824 | } |
| 4825 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4826 | try { |
| 4827 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4828 | if (controller == null) { |
| 4829 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4830 | return; |
| 4831 | } |
| 4832 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4833 | } finally { |
| 4834 | Binder.restoreCallingIdentity(identity); |
| 4835 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4836 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4837 | |
| 4838 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4840 | message); |
| 4841 | } |
| 4842 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4843 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4844 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4845 | boolean isProvisioned) { |
| 4846 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4847 | |
| 4848 | final long identity = Binder.clearCallingIdentity(); |
| 4849 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4850 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4851 | if (controller == null) { |
| 4852 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4853 | return; |
| 4854 | } |
| 4855 | controller.setRcsProvisioningStatusForCapability( |
| 4856 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4857 | } finally { |
| 4858 | Binder.restoreCallingIdentity(identity); |
| 4859 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | |
| 4863 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4864 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4865 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4866 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4867 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4868 | final long identity = Binder.clearCallingIdentity(); |
| 4869 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4870 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4871 | if (controller == null) { |
| 4872 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4873 | |
| 4874 | // device does not support IMS, this method will return true always. |
| 4875 | return true; |
| 4876 | } |
| 4877 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4878 | } finally { |
| 4879 | Binder.restoreCallingIdentity(identity); |
| 4880 | } |
| 4881 | } |
| 4882 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4883 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4884 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4885 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4886 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4887 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4890 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4891 | if (controller == null) { |
| 4892 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4893 | return; |
| 4894 | } |
| 4895 | controller.setImsProvisioningStatusForCapability( |
| 4896 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
| 4899 | } |
| 4900 | } |
| 4901 | |
| 4902 | @Override |
| 4903 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4904 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4905 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4906 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4907 | final long identity = Binder.clearCallingIdentity(); |
| 4908 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4909 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4910 | if (controller == null) { |
| 4911 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4912 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4913 | // device does not support IMS, this method will return true always. |
| 4914 | return true; |
| 4915 | } |
| 4916 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4917 | } finally { |
| 4918 | Binder.restoreCallingIdentity(identity); |
| 4919 | } |
| 4920 | } |
| 4921 | |
| 4922 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4923 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4924 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4925 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4926 | |
| 4927 | final long identity = Binder.clearCallingIdentity(); |
| 4928 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4929 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4930 | if (controller == null) { |
| 4931 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4932 | |
| 4933 | // device does not support IMS, this method will return false |
| 4934 | return false; |
| 4935 | } |
| 4936 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4939 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4940 | } |
| 4941 | |
| 4942 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4943 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4944 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4945 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4946 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4947 | final long identity = Binder.clearCallingIdentity(); |
| 4948 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4949 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4950 | if (controller == null) { |
| 4951 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4952 | |
| 4953 | // device does not support IMS, this method will return false |
| 4954 | return false; |
| 4955 | } |
| 4956 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4957 | } finally { |
| 4958 | Binder.restoreCallingIdentity(identity); |
| 4959 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4960 | } |
| 4961 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4962 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4963 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4964 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4965 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4966 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4967 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4968 | mApp, subId, "getImsProvisioningInt"); |
| 4969 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4970 | final long identity = Binder.clearCallingIdentity(); |
| 4971 | try { |
| 4972 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4973 | int slotId = getSlotIndex(subId); |
| 4974 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4975 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4976 | + subId + "' for key:" + key); |
| 4977 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4978 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4979 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4980 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4981 | if (controller == null) { |
| 4982 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4983 | |
| 4984 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4985 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4986 | } |
| 4987 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4988 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4989 | return retVal; |
| 4990 | } |
| 4991 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4992 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4993 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4994 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4995 | + subId + "' for key:" + key); |
| 4996 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4997 | } finally { |
| 4998 | Binder.restoreCallingIdentity(identity); |
| 4999 | } |
| 5000 | } |
| 5001 | |
| 5002 | @Override |
| 5003 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5004 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5005 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5006 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5007 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5008 | mApp, subId, "getImsProvisioningString"); |
| 5009 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5010 | final long identity = Binder.clearCallingIdentity(); |
| 5011 | try { |
| 5012 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5013 | int slotId = getSlotIndex(subId); |
| 5014 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5015 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5016 | + subId + "' for key:" + key); |
| 5017 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5018 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5019 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5020 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5021 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5022 | + subId + "' for key:" + key); |
| 5023 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
| 5027 | } |
| 5028 | |
| 5029 | @Override |
| 5030 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5031 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5032 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5033 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5034 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5035 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5036 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5037 | final long identity = Binder.clearCallingIdentity(); |
| 5038 | try { |
| 5039 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5040 | int slotId = getSlotIndex(subId); |
| 5041 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5042 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5043 | + subId + "' for key:" + key); |
| 5044 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5045 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5046 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5047 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5048 | if (controller == null) { |
| 5049 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5050 | |
| 5051 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5052 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5053 | } |
| 5054 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5055 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5056 | return retVal; |
| 5057 | } |
| 5058 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5059 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5060 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5061 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5062 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5063 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
| 5067 | } |
| 5068 | |
| 5069 | @Override |
| 5070 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5071 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5072 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5073 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5075 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5076 | final long identity = Binder.clearCallingIdentity(); |
| 5077 | try { |
| 5078 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5079 | int slotId = getSlotIndex(subId); |
| 5080 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5081 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5082 | + subId + "' for key:" + key); |
| 5083 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5084 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5085 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5086 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5087 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5088 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5089 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
| 5093 | } |
| 5094 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5095 | /** |
| 5096 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5097 | * for the given slot ID or no ImsResolver instance has been created. |
| 5098 | * @param slotId The slot ID that the IMS service is created for. |
| 5099 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5100 | */ |
| 5101 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5102 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5103 | ImsFeature.FEATURE_MMTEL)) { |
| 5104 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5105 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5106 | } |
| 5107 | } |
| 5108 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5109 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5110 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5111 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5112 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5113 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5114 | } |
| 5115 | return slotId; |
| 5116 | } |
| 5117 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5118 | private int getSlotIndex(int subId) { |
| 5119 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5120 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5121 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5122 | } |
| 5123 | return slotId; |
| 5124 | } |
| 5125 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5126 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5127 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5128 | */ |
| 5129 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5130 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5131 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5132 | try { |
| 5133 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5134 | } catch (SecurityException se) { |
| 5135 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5136 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5137 | + Binder.getCallingUid()); |
| 5138 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5139 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5140 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5141 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5142 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5143 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5144 | mApp, subId, callingPackage, callingFeatureId, |
| 5145 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5146 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5147 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | final long identity = Binder.clearCallingIdentity(); |
| 5150 | try { |
| 5151 | final Phone phone = getPhone(subId); |
| 5152 | if (phone != null) { |
| 5153 | return phone.getServiceState().getDataNetworkType(); |
| 5154 | } else { |
| 5155 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5156 | } |
| 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | /** |
| 5163 | * Returns the data network type |
| 5164 | */ |
| 5165 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5166 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5167 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5168 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | /** |
| 5172 | * Returns the data network type for a subId |
| 5173 | */ |
| 5174 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5175 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5176 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5177 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5178 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5179 | mApp, functionName)) { |
| 5180 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5181 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5182 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5183 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
| 5188 | final Phone phone = getPhone(subId); |
| 5189 | if (phone != null) { |
| 5190 | return phone.getServiceState().getDataNetworkType(); |
| 5191 | } else { |
| 5192 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5193 | } |
| 5194 | } finally { |
| 5195 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5200 | * Returns the Voice network type for a subId |
| 5201 | */ |
| 5202 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5203 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5204 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5205 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5206 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5207 | mApp, functionName)) { |
| 5208 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5209 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5210 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5211 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5214 | final long identity = Binder.clearCallingIdentity(); |
| 5215 | try { |
| 5216 | final Phone phone = getPhone(subId); |
| 5217 | if (phone != null) { |
| 5218 | return phone.getServiceState().getVoiceNetworkType(); |
| 5219 | } else { |
| 5220 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5221 | } |
| 5222 | } finally { |
| 5223 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5224 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | /** |
| 5228 | * @return true if a ICC card is present |
| 5229 | */ |
| 5230 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5231 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5232 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5233 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5237 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5238 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5239 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5240 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
| 5243 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5244 | if (phone != null) { |
| 5245 | return phone.getIccCard().hasIccCard(); |
| 5246 | } else { |
| 5247 | return false; |
| 5248 | } |
| 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5251 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | /** |
| 5255 | * Return if the current radio is LTE on CDMA. This |
| 5256 | * is a tri-state return value as for a period of time |
| 5257 | * the mode may be unknown. |
| 5258 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5259 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5260 | * @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] | 5261 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5262 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5263 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5264 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5265 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5266 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5269 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5270 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5271 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5272 | try { |
| 5273 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5274 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5275 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5276 | } |
| 5277 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | final long identity = Binder.clearCallingIdentity(); |
| 5279 | try { |
| 5280 | final Phone phone = getPhone(subId); |
| 5281 | if (phone == null) { |
| 5282 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5283 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5284 | return TelephonyProperties.lte_on_cdma_device() |
| 5285 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | } |
| 5287 | } finally { |
| 5288 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5289 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5292 | /** |
| 5293 | * {@hide} |
| 5294 | * Returns Default subId, 0 in the case of single standby. |
| 5295 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5296 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5297 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5298 | } |
| 5299 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5300 | private int getSlotForDefaultSubscription() { |
| 5301 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5302 | } |
| 5303 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5304 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5305 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5306 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5307 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5308 | private boolean isActiveSubscription(int subId) { |
| 5309 | return mSubscriptionController.isActiveSubId(subId); |
| 5310 | } |
| 5311 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5312 | /** |
| 5313 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5314 | */ |
| 5315 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5316 | final long identity = Binder.clearCallingIdentity(); |
| 5317 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5318 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5320 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5321 | } finally { |
| 5322 | Binder.restoreCallingIdentity(identity); |
| 5323 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | /** |
| 5327 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5328 | */ |
| 5329 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | final long identity = Binder.clearCallingIdentity(); |
| 5331 | try { |
| 5332 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5333 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5335 | } finally { |
| 5336 | Binder.restoreCallingIdentity(identity); |
| 5337 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5338 | } |
| 5339 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5340 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5341 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5342 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5343 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5344 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5345 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5346 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5347 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5348 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5349 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5350 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5351 | } |
| 5352 | return PhoneFactory.getPhone(phoneId); |
| 5353 | } |
| 5354 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5355 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5356 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5357 | @NonNull IccLogicalChannelRequest request) { |
| 5358 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5359 | /*message=*/ "iccOpenLogicalChannel"); |
| 5360 | |
| 5361 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5362 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5363 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5364 | |
| 5365 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5366 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5367 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5368 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5369 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5370 | Phone phone; |
| 5371 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5373 | mApp, request.subId, message); |
| 5374 | phone = getPhoneFromSubId(request.subId); |
| 5375 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5376 | enforceModifyPermission(); |
| 5377 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5378 | } else { |
| 5379 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5380 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5381 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5385 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5386 | final long identity = Binder.clearCallingIdentity(); |
| 5387 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5388 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5389 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5390 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5391 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5392 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5393 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | loge("The calling package is not allowed to access ISD-R."); |
| 5395 | throw new SecurityException( |
| 5396 | "The calling package is not allowed to access ISD-R."); |
| 5397 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5398 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5399 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5401 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5402 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | return response; |
| 5404 | } finally { |
| 5405 | Binder.restoreCallingIdentity(identity); |
| 5406 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5410 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5411 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5412 | /*message=*/"iccCloseLogicalChannel"); |
| 5413 | |
| 5414 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5415 | |
| 5416 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5417 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5418 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5419 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5420 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5421 | // before this feature is enabled, this API should only return false if |
| 5422 | // the operation fails instead of throwing runtime exception for |
| 5423 | // backward-compatibility. |
| 5424 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5425 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | final long identity = Binder.clearCallingIdentity(); |
| 5427 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5428 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5429 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5431 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5432 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5433 | Boolean success = false; |
| 5434 | if (result instanceof RuntimeException) { |
| 5435 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5436 | if (shouldThrowExceptionOnFailure) { |
| 5437 | throw (RuntimeException) result; |
| 5438 | } else { |
| 5439 | return false; |
| 5440 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5441 | } else if (result instanceof Boolean) { |
| 5442 | success = (Boolean) result; |
| 5443 | } else { |
| 5444 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5445 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5446 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5447 | return success; |
| 5448 | } finally { |
| 5449 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5450 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5451 | } |
| 5452 | |
| 5453 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5454 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5455 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5456 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5457 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5458 | if (DBG) { |
| 5459 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5460 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5461 | + p3 + " data=" + data); |
| 5462 | } |
| 5463 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5464 | command, p1, p2, p3, data); |
| 5465 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5466 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5467 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5468 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5469 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5470 | enforceModifyPermission(); |
| 5471 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5472 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5473 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5474 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5475 | } |
| 5476 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5477 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5478 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5482 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | final long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5485 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5486 | return ""; |
| 5487 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5490 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5491 | null /* workSource */); |
| 5492 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5493 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | // Append the returned status code to the end of the response payload. |
| 5495 | String s = Integer.toHexString( |
| 5496 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5497 | if (response.payload != null) { |
| 5498 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5499 | } |
| 5500 | return s; |
| 5501 | } finally { |
| 5502 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5503 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5504 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5505 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5506 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5507 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5508 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5509 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5510 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5511 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5512 | if (DBG) { |
| 5513 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5514 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5515 | } |
| 5516 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5517 | cla, command, p1, p2, p3, data); |
| 5518 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5519 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5520 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5521 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5522 | 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] | 5523 | enforceModifyPermission(); |
| 5524 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5525 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5526 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5527 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5528 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5532 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5533 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5534 | } |
| 5535 | |
| 5536 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5537 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5538 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | final long identity = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5542 | && TextUtils.equals(ISDR_AID, data)) { |
| 5543 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5544 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5545 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | if (bestComponent == null |
| 5547 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5548 | loge("The calling package is not allowed to select ISD-R."); |
| 5549 | throw new SecurityException( |
| 5550 | "The calling package is not allowed to select ISD-R."); |
| 5551 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5552 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5553 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5554 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5555 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5556 | null /* workSource */); |
| 5557 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5558 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5559 | // Append the returned status code to the end of the response payload. |
| 5560 | String s = Integer.toHexString( |
| 5561 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5562 | if (response.payload != null) { |
| 5563 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5564 | } |
| 5565 | return s; |
| 5566 | } finally { |
| 5567 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5568 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5572 | 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] | 5573 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5575 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | final long identity = Binder.clearCallingIdentity(); |
| 5578 | try { |
| 5579 | if (DBG) { |
| 5580 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5581 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5582 | } |
| 5583 | |
| 5584 | IccIoResult response = |
| 5585 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5586 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5587 | subId); |
| 5588 | |
| 5589 | if (DBG) { |
| 5590 | log("Exchange SIM_IO [R]" + response); |
| 5591 | } |
| 5592 | |
| 5593 | byte[] result = null; |
| 5594 | int length = 2; |
| 5595 | if (response.payload != null) { |
| 5596 | length = 2 + response.payload.length; |
| 5597 | result = new byte[length]; |
| 5598 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5599 | } else { |
| 5600 | result = new byte[length]; |
| 5601 | } |
| 5602 | |
| 5603 | result[length - 1] = (byte) response.sw2; |
| 5604 | result[length - 2] = (byte) response.sw1; |
| 5605 | return result; |
| 5606 | } finally { |
| 5607 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5608 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5609 | } |
| 5610 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5611 | /** |
| 5612 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5613 | * on a particular subscription |
| 5614 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5615 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5616 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5617 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5618 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5619 | return null; |
| 5620 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | |
| 5622 | final long identity = Binder.clearCallingIdentity(); |
| 5623 | try { |
| 5624 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5625 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5626 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5627 | return null; |
| 5628 | } |
| 5629 | Object response = sendRequest( |
| 5630 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5631 | if (response instanceof String[]) { |
| 5632 | return (String[]) response; |
| 5633 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5634 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5635 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5636 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | } finally { |
| 5638 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5639 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5640 | } |
| 5641 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5642 | /** |
| 5643 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5644 | * subscription. |
| 5645 | * |
| 5646 | * @param subId the id of the subscription. |
| 5647 | * @param appType the uicc app type, must be USIM or SIM. |
| 5648 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5649 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5650 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5651 | * @return number of fplmns that is successfully written to the SIM. |
| 5652 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5653 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5654 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5656 | mApp, subId, "setForbiddenPlmns"); |
| 5657 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5658 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5659 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5660 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5661 | } |
| 5662 | if (fplmns == null) { |
| 5663 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5664 | } |
| 5665 | for (String fplmn : fplmns) { |
| 5666 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5667 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5668 | } |
| 5669 | } |
| 5670 | final long identity = Binder.clearCallingIdentity(); |
| 5671 | try { |
| 5672 | Object response = sendRequest( |
| 5673 | CMD_SET_FORBIDDEN_PLMNS, |
| 5674 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5675 | subId); |
| 5676 | return (int) response; |
| 5677 | } finally { |
| 5678 | Binder.restoreCallingIdentity(identity); |
| 5679 | } |
| 5680 | } |
| 5681 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5682 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5683 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5685 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5686 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5687 | final long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5690 | if (response.payload == null) { |
| 5691 | return ""; |
| 5692 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | // Append the returned status code to the end of the response payload. |
| 5695 | String s = Integer.toHexString( |
| 5696 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5697 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5698 | return s; |
| 5699 | } finally { |
| 5700 | Binder.restoreCallingIdentity(identity); |
| 5701 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5702 | } |
| 5703 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5704 | /** |
| 5705 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5706 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5707 | * |
| 5708 | * @param itemID the ID of the item to read |
| 5709 | * @return the NV item as a String, or null on error. |
| 5710 | */ |
| 5711 | @Override |
| 5712 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5713 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5715 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | |
| 5717 | final long identity = Binder.clearCallingIdentity(); |
| 5718 | try { |
| 5719 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5720 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5721 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5722 | return value; |
| 5723 | } finally { |
| 5724 | Binder.restoreCallingIdentity(identity); |
| 5725 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5726 | } |
| 5727 | |
| 5728 | /** |
| 5729 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5730 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5731 | * |
| 5732 | * @param itemID the ID of the item to read |
| 5733 | * @param itemValue the value to write, as a String |
| 5734 | * @return true on success; false on any failure |
| 5735 | */ |
| 5736 | @Override |
| 5737 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5738 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5739 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5740 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5741 | |
| 5742 | final long identity = Binder.clearCallingIdentity(); |
| 5743 | try { |
| 5744 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5745 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5746 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5748 | return success; |
| 5749 | } finally { |
| 5750 | Binder.restoreCallingIdentity(identity); |
| 5751 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5752 | } |
| 5753 | |
| 5754 | /** |
| 5755 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5756 | * Used for device configuration by some CDMA operators. |
| 5757 | * |
| 5758 | * @param preferredRoamingList byte array containing the new PRL |
| 5759 | * @return true on success; false on any failure |
| 5760 | */ |
| 5761 | @Override |
| 5762 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5763 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5764 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | |
| 5766 | final long identity = Binder.clearCallingIdentity(); |
| 5767 | try { |
| 5768 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5769 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5770 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5771 | return success; |
| 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5775 | } |
| 5776 | |
| 5777 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5778 | * 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] | 5779 | * Used for device configuration by some CDMA operators. |
| 5780 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5781 | * @param slotIndex - device slot. |
| 5782 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5783 | * @return true on success; false on any failure |
| 5784 | */ |
| 5785 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5786 | public boolean resetModemConfig(int slotIndex) { |
| 5787 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5788 | if (phone != null) { |
| 5789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5790 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5791 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5792 | final long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
| 5794 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5795 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5796 | return success; |
| 5797 | } finally { |
| 5798 | Binder.restoreCallingIdentity(identity); |
| 5799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5801 | return false; |
| 5802 | } |
| 5803 | |
| 5804 | /** |
| 5805 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5806 | * |
| 5807 | * @param slotIndex - device slot. |
| 5808 | * |
| 5809 | * @return true on success; false on any failure |
| 5810 | */ |
| 5811 | @Override |
| 5812 | public boolean rebootModem(int slotIndex) { |
| 5813 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5814 | if (phone != null) { |
| 5815 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5816 | mApp, phone.getSubId(), "rebootModem"); |
| 5817 | |
| 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5821 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5822 | return success; |
| 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
| 5825 | } |
| 5826 | } |
| 5827 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5828 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5829 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5830 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5831 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5832 | * {@link #disableIms(int)}. |
| 5833 | * @param slotIndex device slot. |
| 5834 | */ |
| 5835 | public void resetIms(int slotIndex) { |
| 5836 | enforceModifyPermission(); |
| 5837 | |
| 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
| 5840 | if (mImsResolver == null) { |
| 5841 | // may happen if the does not support IMS. |
| 5842 | return; |
| 5843 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5844 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
| 5847 | } |
| 5848 | } |
| 5849 | |
| 5850 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5851 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5852 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5853 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5854 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5855 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5856 | |
| 5857 | final long identity = Binder.clearCallingIdentity(); |
| 5858 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5859 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5860 | // may happen if the device does not support IMS. |
| 5861 | return; |
| 5862 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5863 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
| 5866 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5870 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5871 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5872 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5873 | public void disableIms(int slotId) { |
| 5874 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5875 | |
| 5876 | final long identity = Binder.clearCallingIdentity(); |
| 5877 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5878 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5879 | // may happen if the device does not support IMS. |
| 5880 | return; |
| 5881 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5882 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5883 | } finally { |
| 5884 | Binder.restoreCallingIdentity(identity); |
| 5885 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5889 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5890 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5891 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5892 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5893 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5894 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5895 | |
| 5896 | final long identity = Binder.clearCallingIdentity(); |
| 5897 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5898 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5899 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5900 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5901 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5902 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
| 5905 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5906 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5907 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5908 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5909 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5910 | @Override |
| 5911 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5912 | enforceModifyPermission(); |
| 5913 | |
| 5914 | final long identity = Binder.clearCallingIdentity(); |
| 5915 | try { |
| 5916 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5917 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5918 | } finally { |
| 5919 | Binder.restoreCallingIdentity(identity); |
| 5920 | } |
| 5921 | } |
| 5922 | |
| 5923 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5924 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5925 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5926 | */ |
| 5927 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5928 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | |
| 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5932 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5933 | // may happen if the device does not support IMS. |
| 5934 | return null; |
| 5935 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5936 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
| 5939 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5940 | } |
| 5941 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5942 | /** |
| 5943 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5944 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5945 | */ |
| 5946 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5947 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5948 | |
| 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5951 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5952 | // may happen if the device does not support IMS. |
| 5953 | return null; |
| 5954 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5955 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5956 | } finally { |
| 5957 | Binder.restoreCallingIdentity(identity); |
| 5958 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5959 | } |
| 5960 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5961 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5962 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5963 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5964 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5965 | * @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] | 5966 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5967 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5968 | * @param packageName The name of the package that the current configuration will be replaced |
| 5969 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5970 | * @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] | 5971 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5972 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5973 | int[] featureTypes, String packageName) { |
| 5974 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5975 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5977 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5978 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5979 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | final long identity = Binder.clearCallingIdentity(); |
| 5981 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5982 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5983 | // may happen if the device does not support IMS. |
| 5984 | return false; |
| 5985 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5986 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5987 | for (int featureType : featureTypes) { |
| 5988 | featureConfig.put(featureType, packageName); |
| 5989 | } |
| 5990 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5991 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | } finally { |
| 5993 | Binder.restoreCallingIdentity(identity); |
| 5994 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5998 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5999 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6000 | * |
| 6001 | * This should only be used for testing. |
| 6002 | * |
| 6003 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6004 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6005 | */ |
| 6006 | @Override |
| 6007 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 6008 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 6009 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6010 | "clearCarrierImsServiceOverride"); |
| 6011 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 6012 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6013 | "clearCarrierImsServiceOverride"); |
| 6014 | |
| 6015 | final long identity = Binder.clearCallingIdentity(); |
| 6016 | try { |
| 6017 | if (mImsResolver == null) { |
| 6018 | // may happen if the device does not support IMS. |
| 6019 | return false; |
| 6020 | } |
| 6021 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6028 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6029 | * |
| 6030 | * @param slotId The slot that the ImsService is associated with. |
| 6031 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6032 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6033 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6034 | * @return the package name of the ImsService configuration. |
| 6035 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6036 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6037 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6038 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6039 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6040 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6041 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6042 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6043 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | final long identity = Binder.clearCallingIdentity(); |
| 6045 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6046 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6047 | // may happen if the device does not support IMS. |
| 6048 | return ""; |
| 6049 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6050 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6051 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6052 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
| 6055 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6058 | /** |
| 6059 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6060 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6061 | * @param callback A callback with an integer containing the |
| 6062 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6063 | */ |
| 6064 | @Override |
| 6065 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6066 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6067 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6068 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6069 | "IMS not available on device."); |
| 6070 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6071 | final long token = Binder.clearCallingIdentity(); |
| 6072 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6073 | int slotId = getSlotIndex(subId); |
| 6074 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6075 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6076 | + subId + "'"); |
| 6077 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6078 | } |
| 6079 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6080 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6081 | try { |
| 6082 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6083 | } catch (RemoteException e) { |
| 6084 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6085 | + "Ignore"); |
| 6086 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6087 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6088 | } catch (ImsException e) { |
| 6089 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6090 | } finally { |
| 6091 | Binder.restoreCallingIdentity(token); |
| 6092 | } |
| 6093 | } |
| 6094 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6095 | /** |
| 6096 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6097 | */ |
| 6098 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6099 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6100 | |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6103 | // NOTE: Before S, this method only set the default phone. |
| 6104 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6105 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6106 | phone.setImsRegistrationState(registered); |
| 6107 | } |
| 6108 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6109 | } finally { |
| 6110 | Binder.restoreCallingIdentity(identity); |
| 6111 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6112 | } |
| 6113 | |
| 6114 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6115 | * Set the network selection mode to automatic. |
| 6116 | * |
| 6117 | */ |
| 6118 | @Override |
| 6119 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6120 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6121 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6122 | |
| 6123 | final long identity = Binder.clearCallingIdentity(); |
| 6124 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6125 | if (!isActiveSubscription(subId)) { |
| 6126 | return; |
| 6127 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6129 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6130 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6131 | } finally { |
| 6132 | Binder.restoreCallingIdentity(identity); |
| 6133 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6134 | } |
| 6135 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6136 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6137 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6138 | * |
| 6139 | * @param subId the id of the subscription. |
| 6140 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6141 | * the operator to attach to. |
| 6142 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6143 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6144 | * normal network selection next time. |
| 6145 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6146 | */ |
| 6147 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6148 | public boolean setNetworkSelectionModeManual( |
| 6149 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6150 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6151 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6152 | |
| 6153 | if (!isActiveSubscription(subId)) { |
| 6154 | return false; |
| 6155 | } |
| 6156 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6159 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6161 | if (DBG) { |
| 6162 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6163 | + " operator: " + operatorInfo); |
| 6164 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6166 | } finally { |
| 6167 | Binder.restoreCallingIdentity(identity); |
| 6168 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6169 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6170 | /** |
| 6171 | * Get the manual network selection |
| 6172 | * |
| 6173 | * @param subId the id of the subscription. |
| 6174 | * |
| 6175 | * @return the previously saved user selected PLMN |
| 6176 | */ |
| 6177 | @Override |
| 6178 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6179 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6180 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6181 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6182 | |
| 6183 | final long identity = Binder.clearCallingIdentity(); |
| 6184 | try { |
| 6185 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6186 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | final Phone phone = getPhone(subId); |
| 6190 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6191 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6192 | } |
| 6193 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6194 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6195 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
| 6198 | } |
| 6199 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6200 | |
| 6201 | /** |
| 6202 | * Scans for available networks. |
| 6203 | */ |
| 6204 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6205 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6206 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6208 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6209 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6210 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6211 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6212 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6213 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6214 | .setCallingPid(Binder.getCallingPid()) |
| 6215 | .setCallingUid(Binder.getCallingUid()) |
| 6216 | .setMethod("getCellNetworkScanResults") |
| 6217 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6218 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6219 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6220 | .build()); |
| 6221 | switch (locationResult) { |
| 6222 | case DENIED_HARD: |
| 6223 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6224 | case DENIED_SOFT: |
| 6225 | return null; |
| 6226 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6227 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6228 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6229 | try { |
| 6230 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6231 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6232 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | } finally { |
| 6234 | Binder.restoreCallingIdentity(identity); |
| 6235 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6239 | * Get the call forwarding info, given the call forwarding reason. |
| 6240 | */ |
| 6241 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6242 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6243 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6244 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6245 | long identity = Binder.clearCallingIdentity(); |
| 6246 | try { |
| 6247 | if (DBG) { |
| 6248 | log("getCallForwarding: subId " + subId |
| 6249 | + " callForwardingReason" + callForwardingReason); |
| 6250 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6251 | |
| 6252 | Phone phone = getPhone(subId); |
| 6253 | if (phone == null) { |
| 6254 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6255 | callback.onError( |
| 6256 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6257 | } catch (RemoteException e) { |
| 6258 | // ignore |
| 6259 | } |
| 6260 | return; |
| 6261 | } |
| 6262 | |
| 6263 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6264 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6265 | @Override |
| 6266 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6267 | try { |
| 6268 | callback.onCallForwardingInfoAvailable(info); |
| 6269 | } catch (RemoteException e) { |
| 6270 | // ignore |
| 6271 | } |
| 6272 | } |
| 6273 | |
| 6274 | @Override |
| 6275 | public void onError(int error) { |
| 6276 | try { |
| 6277 | callback.onError(error); |
| 6278 | } catch (RemoteException e) { |
| 6279 | // ignore |
| 6280 | } |
| 6281 | } |
| 6282 | }); |
| 6283 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
| 6286 | } |
| 6287 | } |
| 6288 | |
| 6289 | /** |
| 6290 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6291 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6292 | */ |
| 6293 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6294 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6295 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6296 | enforceModifyPermission(); |
| 6297 | long identity = Binder.clearCallingIdentity(); |
| 6298 | try { |
| 6299 | if (DBG) { |
| 6300 | log("setCallForwarding: subId " + subId |
| 6301 | + " callForwardingInfo" + callForwardingInfo); |
| 6302 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6303 | |
| 6304 | Phone phone = getPhone(subId); |
| 6305 | if (phone == null) { |
| 6306 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6307 | callback.accept( |
| 6308 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6309 | } catch (RemoteException e) { |
| 6310 | // ignore |
| 6311 | } |
| 6312 | return; |
| 6313 | } |
| 6314 | |
| 6315 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6316 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6317 | |
| 6318 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6319 | } finally { |
| 6320 | Binder.restoreCallingIdentity(identity); |
| 6321 | } |
| 6322 | } |
| 6323 | |
| 6324 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6325 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6326 | */ |
| 6327 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6328 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6329 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6330 | long identity = Binder.clearCallingIdentity(); |
| 6331 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6332 | Phone phone = getPhone(subId); |
| 6333 | if (phone == null) { |
| 6334 | try { |
| 6335 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6336 | } catch (RemoteException e) { |
| 6337 | // ignore |
| 6338 | } |
| 6339 | return; |
| 6340 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6341 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6342 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6343 | boolean requireUssd = c.getBoolean( |
| 6344 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6345 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6346 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6347 | if (requireUssd) { |
| 6348 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6349 | getSubscriptionCarrierId(subId)); |
| 6350 | String newUssdCommand = ""; |
| 6351 | try { |
| 6352 | newUssdCommand = carrierXmlParser.getFeature( |
| 6353 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6354 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6355 | } catch (NullPointerException e) { |
| 6356 | loge("Failed to generate USSD number" + e); |
| 6357 | } |
| 6358 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6359 | mMainThreadHandler, callback, carrierXmlParser, |
| 6360 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6361 | final String ussdCommand = newUssdCommand; |
| 6362 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6363 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6364 | }); |
| 6365 | } else { |
| 6366 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6367 | callback::accept); |
| 6368 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6369 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
| 6373 | } |
| 6374 | |
| 6375 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6376 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6377 | */ |
| 6378 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6379 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6380 | enforceModifyPermission(); |
| 6381 | long identity = Binder.clearCallingIdentity(); |
| 6382 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6383 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6384 | |
| 6385 | Phone phone = getPhone(subId); |
| 6386 | if (phone == null) { |
| 6387 | try { |
| 6388 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6389 | } catch (RemoteException e) { |
| 6390 | // ignore |
| 6391 | } |
| 6392 | return; |
| 6393 | } |
| 6394 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6395 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6396 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6397 | boolean requireUssd = c.getBoolean( |
| 6398 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6399 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6400 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6401 | if (requireUssd) { |
| 6402 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6403 | getSubscriptionCarrierId(subId)); |
| 6404 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6405 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6406 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6407 | String newUssdCommand = ""; |
| 6408 | try { |
| 6409 | newUssdCommand = carrierXmlParser.getFeature( |
| 6410 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6411 | .makeCommand(ssAction, null); |
| 6412 | } catch (NullPointerException e) { |
| 6413 | loge("Failed to generate USSD number" + e); |
| 6414 | } |
| 6415 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6416 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6417 | final String ussdCommand = newUssdCommand; |
| 6418 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6419 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6420 | }); |
| 6421 | } else { |
| 6422 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6423 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6424 | |
| 6425 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6426 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6433 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6434 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6435 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6436 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6437 | * location related information which will be sent if the caller already possess |
| 6438 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6439 | * @param request contains the radio access networks with bands/channels to scan |
| 6440 | * @param messenger callback messenger for scan results or errors |
| 6441 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6442 | * @return the id of the requested scan which can be used to stop the scan. |
| 6443 | */ |
| 6444 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6445 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6446 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6447 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6449 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6450 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6451 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6452 | if (!renounceFineLocationAccess) { |
| 6453 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6454 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6455 | .setCallingPackage(callingPackage) |
| 6456 | .setCallingFeatureId(callingFeatureId) |
| 6457 | .setCallingPid(Binder.getCallingPid()) |
| 6458 | .setCallingUid(Binder.getCallingUid()) |
| 6459 | .setMethod("requestNetworkScan") |
| 6460 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6461 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6462 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6463 | .build()); |
| 6464 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6465 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6466 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6467 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6468 | if (e != null) { |
| 6469 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6470 | throw e; |
| 6471 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6472 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6473 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6474 | } |
| 6475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6477 | int callingUid = Binder.getCallingUid(); |
| 6478 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6479 | final long identity = Binder.clearCallingIdentity(); |
| 6480 | try { |
| 6481 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6482 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6483 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6484 | } finally { |
| 6485 | Binder.restoreCallingIdentity(identity); |
| 6486 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6487 | } |
| 6488 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6489 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6490 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame^] | 6491 | boolean hasCarrierPriv; |
| 6492 | final long identity = Binder.clearCallingIdentity(); |
| 6493 | try { |
| 6494 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6495 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6499 | boolean hasNetworkScanPermission = |
| 6500 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6501 | == PERMISSION_GRANTED; |
| 6502 | |
| 6503 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6504 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6505 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6506 | } |
| 6507 | |
| 6508 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6509 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6510 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6511 | return new SecurityException("Specific channels must not be" |
| 6512 | + " scanned without location access."); |
| 6513 | } |
| 6514 | } |
| 6515 | } |
| 6516 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6517 | return null; |
| 6518 | } |
| 6519 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6520 | /** |
| 6521 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6522 | * |
| 6523 | * @param subId id of the subscription |
| 6524 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6525 | */ |
| 6526 | @Override |
| 6527 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6529 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6531 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6532 | final long identity = Binder.clearCallingIdentity(); |
| 6533 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6534 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
| 6537 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6541 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6542 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6543 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6544 | */ |
| 6545 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6546 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6547 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6548 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6549 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | |
| 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6553 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6554 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6555 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6556 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6557 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | } finally { |
| 6559 | Binder.restoreCallingIdentity(identity); |
| 6560 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6564 | * Get the allowed network types for certain reason. |
| 6565 | * |
| 6566 | * @param subId the id of the subscription. |
| 6567 | * @param reason the reason the allowed network type change is taking place |
| 6568 | * @return the allowed network types. |
| 6569 | */ |
| 6570 | @Override |
| 6571 | public long getAllowedNetworkTypesForReason(int subId, |
| 6572 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6573 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6574 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6575 | final long identity = Binder.clearCallingIdentity(); |
| 6576 | try { |
| 6577 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6578 | } finally { |
| 6579 | Binder.restoreCallingIdentity(identity); |
| 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6584 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6585 | * @param subId subscription id of the sim card |
| 6586 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6587 | * This can be passed following states |
| 6588 | * <ol> |
| 6589 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6590 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6591 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6592 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6593 | * </ol> |
| 6594 | * @return operation result. |
| 6595 | */ |
| 6596 | @Override |
| 6597 | public int setNrDualConnectivityState(int subId, |
| 6598 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6599 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6600 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6601 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6602 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6603 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6604 | } |
| 6605 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6606 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6607 | final long identity = Binder.clearCallingIdentity(); |
| 6608 | try { |
| 6609 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6610 | nrDualConnectivityState, subId, |
| 6611 | workSource); |
| 6612 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6613 | return result; |
| 6614 | } finally { |
| 6615 | Binder.restoreCallingIdentity(identity); |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | /** |
| 6620 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6621 | * @return true if dual connectivity is enabled else false |
| 6622 | */ |
| 6623 | @Override |
| 6624 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6625 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6626 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6627 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6628 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6629 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6630 | return false; |
| 6631 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6632 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6633 | final long identity = Binder.clearCallingIdentity(); |
| 6634 | try { |
| 6635 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6636 | null, subId, workSource); |
| 6637 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6638 | return isEnabled; |
| 6639 | } finally { |
| 6640 | Binder.restoreCallingIdentity(identity); |
| 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6645 | * Set the allowed network types of the device and |
| 6646 | * provide the reason triggering the allowed network change. |
| 6647 | * |
| 6648 | * @param subId the id of the subscription. |
| 6649 | * @param reason the reason the allowed network type change is taking place |
| 6650 | * @param allowedNetworkTypes the allowed network types. |
| 6651 | * @return true on success; false on any failure. |
| 6652 | */ |
| 6653 | @Override |
| 6654 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6655 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6656 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6658 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6659 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6660 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6661 | return false; |
| 6662 | } |
| 6663 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6664 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6665 | return false; |
| 6666 | } |
| 6667 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6668 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6669 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6670 | |
| 6671 | |
| 6672 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6673 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6674 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6675 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6676 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6677 | final long identity = Binder.clearCallingIdentity(); |
| 6678 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6679 | Boolean success = (Boolean) sendRequest( |
| 6680 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6681 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6682 | |
| 6683 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6684 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(identity); |
| 6687 | } |
| 6688 | } |
| 6689 | |
| 6690 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6691 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6692 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6693 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6694 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6695 | * @hide |
| 6696 | */ |
| 6697 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6698 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6699 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6700 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6701 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6702 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6703 | if (phone != null) { |
| 6704 | return phone.hasMatchedTetherApnSetting(); |
| 6705 | } else { |
| 6706 | return false; |
| 6707 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6710 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6711 | } |
| 6712 | |
| 6713 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6714 | * Get the user enabled state of Mobile Data. |
| 6715 | * |
| 6716 | * TODO: remove and use isUserDataEnabled. |
| 6717 | * This can't be removed now because some vendor codes |
| 6718 | * calls through ITelephony directly while they should |
| 6719 | * use TelephonyManager. |
| 6720 | * |
| 6721 | * @return true on enabled |
| 6722 | */ |
| 6723 | @Override |
| 6724 | public boolean getDataEnabled(int subId) { |
| 6725 | return isUserDataEnabled(subId); |
| 6726 | } |
| 6727 | |
| 6728 | /** |
| 6729 | * Get whether mobile data is enabled per user setting. |
| 6730 | * |
| 6731 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6732 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6733 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6734 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6735 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6736 | * |
| 6737 | * @return {@code true} if data is enabled else {@code false} |
| 6738 | */ |
| 6739 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6740 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6741 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6742 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6743 | try { |
| 6744 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6745 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6746 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6747 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6748 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6749 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6751 | mApp, subId, functionName); |
| 6752 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6753 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6754 | |
| 6755 | final long identity = Binder.clearCallingIdentity(); |
| 6756 | try { |
| 6757 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6758 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6759 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6760 | if (phone != null) { |
| 6761 | boolean retVal = phone.isUserDataEnabled(); |
| 6762 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6763 | return retVal; |
| 6764 | } else { |
| 6765 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6766 | return false; |
| 6767 | } |
| 6768 | } finally { |
| 6769 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6770 | } |
| 6771 | } |
| 6772 | |
| 6773 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6774 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6775 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6776 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6777 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6778 | * @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] | 6779 | */ |
| 6780 | @Override |
| 6781 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6782 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6783 | try { |
| 6784 | try { |
| 6785 | mApp.enforceCallingOrSelfPermission( |
| 6786 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6787 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6788 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6789 | try { |
| 6790 | mApp.enforceCallingOrSelfPermission( |
| 6791 | android.Manifest.permission.READ_PHONE_STATE, |
| 6792 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6793 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6794 | mApp.enforceCallingOrSelfPermission( |
| 6795 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6796 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6797 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6798 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6799 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6801 | |
| 6802 | final long identity = Binder.clearCallingIdentity(); |
| 6803 | try { |
| 6804 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6805 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6806 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6807 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6808 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6809 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6810 | return retVal; |
| 6811 | } else { |
| 6812 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6813 | return false; |
| 6814 | } |
| 6815 | } finally { |
| 6816 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6817 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6818 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6819 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6820 | /** |
| 6821 | * Check if data is enabled for a specific reason |
| 6822 | * @param subId Subscription index |
| 6823 | * @param reason the reason the data enable change is taking place |
| 6824 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6825 | */ |
| 6826 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6827 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6828 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6829 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6830 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6831 | try { |
| 6832 | mApp.enforceCallingOrSelfPermission( |
| 6833 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6834 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6835 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6836 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6837 | functionName); |
| 6838 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6839 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6840 | try { |
| 6841 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6842 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6843 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6844 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6845 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6846 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6847 | } |
| 6848 | |
| 6849 | |
| 6850 | final long identity = Binder.clearCallingIdentity(); |
| 6851 | try { |
| 6852 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6853 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6854 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6855 | + " reason=" + reason); |
| 6856 | } |
| 6857 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6858 | if (phone != null) { |
| 6859 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6860 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6861 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6862 | return retVal; |
| 6863 | } else { |
| 6864 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6865 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6866 | + subId + " retVal=false"); |
| 6867 | } |
| 6868 | return false; |
| 6869 | } |
| 6870 | } finally { |
| 6871 | Binder.restoreCallingIdentity(identity); |
| 6872 | } |
| 6873 | } |
| 6874 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6875 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6876 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6877 | // No permission needed; this only lets the caller inspect their own status. |
| 6878 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6879 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6880 | |
| 6881 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6882 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6883 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6884 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6885 | } |
| 6886 | |
| 6887 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6888 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6889 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6890 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6891 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6892 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6893 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6894 | if (cpt == null) { |
| 6895 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6896 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6897 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6898 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6902 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6903 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6904 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6905 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6906 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6907 | Phone phone = getPhone(subId); |
| 6908 | if (phone == null) { |
| 6909 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6910 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6911 | } |
| 6912 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6913 | if (cpt == null) { |
| 6914 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6915 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6916 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6917 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | @Override |
| 6921 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6922 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6923 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6924 | } |
| 6925 | |
| 6926 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6927 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6928 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6929 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6930 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6931 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6932 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6933 | if (phone == null) { |
| 6934 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6935 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6936 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6937 | if (cpt == null) { |
| 6938 | continue; |
| 6939 | } |
| 6940 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6941 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6942 | break; |
| 6943 | } |
| 6944 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6945 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6946 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6947 | |
| 6948 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6949 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6950 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6951 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6952 | if (phone == null) { |
| 6953 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6954 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6955 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6956 | if (cpt == null) { |
| 6957 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6958 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6959 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6960 | } |
| 6961 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6962 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6963 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6964 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6965 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6966 | if (phone == null) { |
| 6967 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6968 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6969 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6970 | if (cpt == null) { |
| 6971 | return Collections.emptyList(); |
| 6972 | } |
| 6973 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6974 | } |
| 6975 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6976 | @Override |
| 6977 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6978 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6979 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6980 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6981 | try { |
| 6982 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6983 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6984 | } |
| 6985 | } finally { |
| 6986 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6987 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6988 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6989 | } |
| 6990 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6991 | @Override |
| 6992 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6993 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6994 | |
| 6995 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6996 | if (phone == null) { |
| 6997 | return null; |
| 6998 | } |
| 6999 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7000 | if (cpt == null) { |
| 7001 | return null; |
| 7002 | } |
| 7003 | return cpt.getCarrierServicePackageName(); |
| 7004 | } |
| 7005 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7006 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7007 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7008 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7009 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7010 | return null; |
| 7011 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7012 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7013 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7014 | return null; |
| 7015 | } |
| 7016 | return iccId; |
| 7017 | } |
| 7018 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7019 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7020 | public void setCallComposerStatus(int subId, int status) { |
| 7021 | enforceModifyPermission(); |
| 7022 | |
| 7023 | final long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
| 7025 | Phone phone = getPhone(subId); |
| 7026 | if (phone != null) { |
| 7027 | Phone defaultPhone = phone.getImsPhone(); |
| 7028 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7029 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7030 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7031 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7032 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7033 | } |
| 7034 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7035 | } catch (ImsException e) { |
| 7036 | throw new ServiceSpecificException(e.getCode()); |
| 7037 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7038 | Binder.restoreCallingIdentity(identity); |
| 7039 | } |
| 7040 | } |
| 7041 | |
| 7042 | @Override |
| 7043 | public int getCallComposerStatus(int subId) { |
| 7044 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7045 | |
| 7046 | final long identity = Binder.clearCallingIdentity(); |
| 7047 | try { |
| 7048 | Phone phone = getPhone(subId); |
| 7049 | if (phone != null) { |
| 7050 | Phone defaultPhone = phone.getImsPhone(); |
| 7051 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7052 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7053 | return imsPhone.getCallComposerStatus(); |
| 7054 | } |
| 7055 | } |
| 7056 | } finally { |
| 7057 | Binder.restoreCallingIdentity(identity); |
| 7058 | } |
| 7059 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7060 | } |
| 7061 | |
| 7062 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7063 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7064 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7065 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7066 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | final String iccId = getIccId(subId); |
| 7071 | final Phone phone = getPhone(subId); |
| 7072 | if (phone == null) { |
| 7073 | return false; |
| 7074 | } |
| 7075 | final String subscriberId = phone.getSubscriberId(); |
| 7076 | |
| 7077 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7078 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | + subscriberId + " to " + number); |
| 7080 | } |
| 7081 | |
| 7082 | if (TextUtils.isEmpty(iccId)) { |
| 7083 | return false; |
| 7084 | } |
| 7085 | |
| 7086 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7087 | |
| 7088 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7089 | if (alphaTag == null) { |
| 7090 | editor.remove(alphaTagPrefKey); |
| 7091 | } else { |
| 7092 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7093 | } |
| 7094 | |
| 7095 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7096 | // track all merged IMSIs based on line number |
| 7097 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7098 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7099 | if (number == null) { |
| 7100 | editor.remove(numberPrefKey); |
| 7101 | editor.remove(subscriberPrefKey); |
| 7102 | } else { |
| 7103 | editor.putString(numberPrefKey, number); |
| 7104 | editor.putString(subscriberPrefKey, subscriberId); |
| 7105 | } |
| 7106 | |
| 7107 | editor.commit(); |
| 7108 | return true; |
| 7109 | } finally { |
| 7110 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7111 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7115 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7116 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7117 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7118 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7119 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7120 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7121 | return null; |
| 7122 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7123 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | final long identity = Binder.clearCallingIdentity(); |
| 7125 | try { |
| 7126 | String iccId = getIccId(subId); |
| 7127 | if (iccId != null) { |
| 7128 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7129 | if (DBG_MERGE) { |
| 7130 | log("getLine1NumberForDisplay returning " |
| 7131 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7132 | } |
| 7133 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7134 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7135 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7136 | return null; |
| 7137 | } finally { |
| 7138 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7139 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7143 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7144 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7146 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7147 | return null; |
| 7148 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7149 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | final long identity = Binder.clearCallingIdentity(); |
| 7151 | try { |
| 7152 | String iccId = getIccId(subId); |
| 7153 | if (iccId != null) { |
| 7154 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7155 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7156 | } |
| 7157 | return null; |
| 7158 | } finally { |
| 7159 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7160 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7161 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7162 | |
| 7163 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7164 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7165 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7166 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7167 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7168 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7169 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7170 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7171 | return null; |
| 7172 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7173 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7174 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7175 | // the process, where TelephonyManager was instantiated. |
| 7176 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7177 | final long identity = Binder.clearCallingIdentity(); |
| 7178 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7179 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7181 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7182 | |
| 7183 | // Figure out what subscribers are currently active |
| 7184 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7185 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7186 | // Only consider subs which match the current subId |
| 7187 | // This logic can be simplified. See b/131189269 for progress. |
| 7188 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7189 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7190 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7191 | |
| 7192 | // First pass, find a number override for an active subscriber |
| 7193 | String mergeNumber = null; |
| 7194 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7195 | for (String key : prefs.keySet()) { |
| 7196 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7197 | final String subscriberId = (String) prefs.get(key); |
| 7198 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7199 | final String iccId = key.substring( |
| 7200 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7201 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7202 | mergeNumber = (String) prefs.get(numberKey); |
| 7203 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7204 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7205 | + " for active subscriber " + subscriberId); |
| 7206 | } |
| 7207 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7208 | break; |
| 7209 | } |
| 7210 | } |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | // Shortcut when no active merged subscribers |
| 7215 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7216 | return null; |
| 7217 | } |
| 7218 | |
| 7219 | // Second pass, find all subscribers under that line override |
| 7220 | final ArraySet<String> result = new ArraySet<>(); |
| 7221 | for (String key : prefs.keySet()) { |
| 7222 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7223 | final String number = (String) prefs.get(key); |
| 7224 | if (mergeNumber.equals(number)) { |
| 7225 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7226 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7227 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7228 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7229 | result.add(subscriberId); |
| 7230 | } |
| 7231 | } |
| 7232 | } |
| 7233 | } |
| 7234 | |
| 7235 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7236 | Arrays.sort(resultArray); |
| 7237 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7238 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7239 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7240 | } |
| 7241 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7244 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7245 | } |
| 7246 | |
| 7247 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7248 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7249 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7250 | |
| 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7254 | TelephonyManager.class); |
| 7255 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7256 | if (subscriberId == null) { |
| 7257 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7258 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7259 | + subId); |
| 7260 | } |
| 7261 | return null; |
| 7262 | } |
| 7263 | |
| 7264 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7265 | .getSubscriptionInfo(subId); |
| 7266 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7267 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7268 | if (groupUuid == null) { |
| 7269 | return new String[]{subscriberId}; |
| 7270 | } |
| 7271 | |
| 7272 | // Get all subscriberIds from the group. |
| 7273 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7274 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7275 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7276 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7277 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7278 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7279 | if (subscriberId != null) { |
| 7280 | mergedSubscriberIds.add(subscriberId); |
| 7281 | } |
| 7282 | } |
| 7283 | |
| 7284 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7285 | } finally { |
| 7286 | Binder.restoreCallingIdentity(identity); |
| 7287 | |
| 7288 | } |
| 7289 | } |
| 7290 | |
| 7291 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7292 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7293 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7294 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7295 | |
| 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
| 7298 | final Phone phone = getPhone(subId); |
| 7299 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7300 | } finally { |
| 7301 | Binder.restoreCallingIdentity(identity); |
| 7302 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7303 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7304 | |
| 7305 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7306 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7307 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7308 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7309 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7310 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7311 | |
| 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
| 7314 | final Phone phone = getPhone(subId); |
| 7315 | if (phone == null) { |
| 7316 | return false; |
| 7317 | } |
| 7318 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7319 | cdmaNonRoamingList); |
| 7320 | } finally { |
| 7321 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7322 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7323 | } |
| 7324 | |
| 7325 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7326 | @Deprecated |
| 7327 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7328 | enforceModifyPermission(); |
| 7329 | |
| 7330 | int returnValue = 0; |
| 7331 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7332 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7333 | if(result.exception == null) { |
| 7334 | if (result.result != null) { |
| 7335 | byte[] responseData = (byte[])(result.result); |
| 7336 | if(responseData.length > oemResp.length) { |
| 7337 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7338 | responseData.length + "bytes. Buffer Size is " + |
| 7339 | oemResp.length + "bytes."); |
| 7340 | } |
| 7341 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7342 | returnValue = responseData.length; |
| 7343 | } |
| 7344 | } else { |
| 7345 | CommandException ex = (CommandException) result.exception; |
| 7346 | returnValue = ex.getCommandError().ordinal(); |
| 7347 | if(returnValue > 0) returnValue *= -1; |
| 7348 | } |
| 7349 | } catch (RuntimeException e) { |
| 7350 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7351 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7352 | if(returnValue > 0) returnValue *= -1; |
| 7353 | } |
| 7354 | |
| 7355 | return returnValue; |
| 7356 | } |
| 7357 | |
| 7358 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7359 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7360 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7361 | try { |
| 7362 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7363 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7364 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7365 | } catch (SecurityException e) { |
| 7366 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7367 | throw e; |
| 7368 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7369 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7370 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7371 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7372 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | final long identity = Binder.clearCallingIdentity(); |
| 7374 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7375 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7376 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7377 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7378 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7379 | } finally { |
| 7380 | Binder.restoreCallingIdentity(identity); |
| 7381 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7382 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7383 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7384 | |
| 7385 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7386 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7387 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7388 | try { |
| 7389 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7390 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7391 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7392 | } |
| 7393 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7394 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7395 | } |
| 7396 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7397 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7398 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7399 | throw new SecurityException("App must be the dialer role holder to" |
| 7400 | + " upload a call composer pic"); |
| 7401 | } |
| 7402 | |
| 7403 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7404 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7405 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7406 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7407 | boolean readUntilEnd = false; |
| 7408 | int totalBytesRead = 0; |
| 7409 | byte[] buffer = new byte[16 * 1024]; |
| 7410 | while (true) { |
| 7411 | int numRead; |
| 7412 | try { |
| 7413 | numRead = input.read(buffer); |
| 7414 | } catch (IOException e) { |
| 7415 | try { |
| 7416 | fd.checkError(); |
| 7417 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7418 | null); |
| 7419 | } catch (IOException e1) { |
| 7420 | // This means that the other side closed explicitly with an error. If this |
| 7421 | // happens, log and ignore. |
| 7422 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7423 | } |
| 7424 | break; |
| 7425 | } |
| 7426 | if (numRead == -1) { |
| 7427 | readUntilEnd = true; |
| 7428 | break; |
| 7429 | } |
| 7430 | totalBytesRead += numRead; |
| 7431 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7432 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7433 | try { |
| 7434 | input.close(); |
| 7435 | } catch (IOException e) { |
| 7436 | // ignore |
| 7437 | } |
| 7438 | break; |
| 7439 | } |
| 7440 | output.write(buffer, 0, numRead); |
| 7441 | } |
| 7442 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7443 | // close is above, where the picture size is too big. |
| 7444 | |
| 7445 | try { |
| 7446 | fd.checkError(); |
| 7447 | } catch (IOException e) { |
| 7448 | loge("Remote end for call composer closed with an error: " + e); |
| 7449 | return; |
| 7450 | } |
| 7451 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7452 | if (!readUntilEnd) { |
| 7453 | loge("Did not finish reading entire image; aborting"); |
| 7454 | return; |
| 7455 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7456 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7457 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7458 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7459 | new CallComposerPictureTransfer.Factory() {}, |
| 7460 | imageData, |
| 7461 | (result) -> { |
| 7462 | if (result.first != null) { |
| 7463 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7464 | Bundle outputResult = new Bundle(); |
| 7465 | outputResult.putParcelable( |
| 7466 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7467 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7468 | outputResult); |
| 7469 | } else { |
| 7470 | callback.send(result.second, null); |
| 7471 | } |
| 7472 | } |
| 7473 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7474 | }); |
| 7475 | } |
| 7476 | |
| 7477 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7478 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7479 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7480 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7481 | |
| 7482 | final long identity = Binder.clearCallingIdentity(); |
| 7483 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7484 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7485 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | } finally { |
| 7487 | Binder.restoreCallingIdentity(identity); |
| 7488 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7489 | } |
| 7490 | |
| 7491 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7492 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7493 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7494 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7495 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7496 | return false; |
| 7497 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7498 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 | final long identity = Binder.clearCallingIdentity(); |
| 7500 | try { |
| 7501 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7502 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7503 | // In the long run, we may instead need to check if there exists a connection service |
| 7504 | // which can support video calling. |
| 7505 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7506 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7507 | return imsManager.isVtEnabledByPlatform() |
| 7508 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7509 | && imsManager.isVtEnabledByUser(); |
| 7510 | } finally { |
| 7511 | Binder.restoreCallingIdentity(identity); |
| 7512 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7513 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7514 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7516 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7517 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7518 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7519 | mApp, subId, callingPackage, callingFeatureId, |
| 7520 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | return false; |
| 7522 | } |
| 7523 | |
| 7524 | final long identity = Binder.clearCallingIdentity(); |
| 7525 | try { |
| 7526 | CarrierConfigManager configManager = |
| 7527 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7528 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7529 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7530 | } finally { |
| 7531 | Binder.restoreCallingIdentity(identity); |
| 7532 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7533 | } |
| 7534 | |
| 7535 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7536 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7538 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | return false; |
| 7540 | } |
| 7541 | |
| 7542 | final long identity = Binder.clearCallingIdentity(); |
| 7543 | try { |
| 7544 | CarrierConfigManager configManager = |
| 7545 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7546 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7548 | } finally { |
| 7549 | Binder.restoreCallingIdentity(identity); |
| 7550 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7551 | } |
| 7552 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7553 | @Override |
| 7554 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7555 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7556 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7557 | } |
| 7558 | |
| 7559 | @Override |
| 7560 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | final long identity = Binder.clearCallingIdentity(); |
| 7562 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7563 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
| 7566 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7567 | } |
| 7568 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7569 | /** |
| 7570 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7571 | * support for the feature and device firmware support. |
| 7572 | * |
| 7573 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7574 | */ |
| 7575 | @Override |
| 7576 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7578 | final Phone phone = getPhone(subscriptionId); |
| 7579 | if (phone == null) { |
| 7580 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7581 | return false; |
| 7582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7584 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7586 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7587 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7588 | return isCarrierSupported && isDeviceSupported; |
| 7589 | } finally { |
| 7590 | Binder.restoreCallingIdentity(identity); |
| 7591 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7592 | } |
| 7593 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7594 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7595 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7596 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7597 | * 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] | 7598 | */ |
| 7599 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7602 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7603 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7604 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7605 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7606 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7607 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
| 7610 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7611 | } |
| 7612 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7613 | @Deprecated |
| 7614 | @Override |
| 7615 | public String getDeviceId(String callingPackage) { |
| 7616 | return getDeviceIdWithFeature(callingPackage, null); |
| 7617 | } |
| 7618 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7619 | /** |
| 7620 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7621 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7622 | * |
| 7623 | * <p>Requires Permission: |
| 7624 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7625 | */ |
| 7626 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7627 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7628 | try { |
| 7629 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7630 | } catch (SecurityException se) { |
| 7631 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7632 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7633 | + Binder.getCallingUid()); |
| 7634 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7635 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7636 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7637 | return null; |
| 7638 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7639 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7640 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7641 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7642 | return null; |
| 7643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7644 | |
| 7645 | final long identity = Binder.clearCallingIdentity(); |
| 7646 | try { |
| 7647 | return phone.getDeviceId(); |
| 7648 | } finally { |
| 7649 | Binder.restoreCallingIdentity(identity); |
| 7650 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7651 | } |
| 7652 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7653 | /** |
| 7654 | * {@hide} |
| 7655 | * Returns the IMS Registration Status on a particular subid |
| 7656 | * |
| 7657 | * @param subId |
| 7658 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7659 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7660 | Phone phone = getPhone(subId); |
| 7661 | if (phone != null) { |
| 7662 | return phone.isImsRegistered(); |
| 7663 | } else { |
| 7664 | return false; |
| 7665 | } |
| 7666 | } |
| 7667 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7668 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7669 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7670 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7671 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7672 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7673 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7674 | } |
| 7675 | final long identity = Binder.clearCallingIdentity(); |
| 7676 | try { |
| 7677 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7678 | } finally { |
| 7679 | Binder.restoreCallingIdentity(identity); |
| 7680 | } |
| 7681 | } |
| 7682 | |
| 7683 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7684 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7685 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7686 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7687 | mApp, |
| 7688 | subscriptionId, |
| 7689 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7690 | final long identity = Binder.clearCallingIdentity(); |
| 7691 | try { |
| 7692 | Phone phone = getPhone(subscriptionId); |
| 7693 | if (phone == null) { |
| 7694 | return null; |
| 7695 | } |
| 7696 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7697 | } finally { |
| 7698 | Binder.restoreCallingIdentity(identity); |
| 7699 | } |
| 7700 | } |
| 7701 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7702 | /** |
| 7703 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7704 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7705 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7706 | final long identity = Binder.clearCallingIdentity(); |
| 7707 | try { |
| 7708 | Phone phone = getPhone(subId); |
| 7709 | if (phone != null) { |
| 7710 | return phone.isWifiCallingEnabled(); |
| 7711 | } else { |
| 7712 | return false; |
| 7713 | } |
| 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7716 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7717 | } |
| 7718 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7719 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7720 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7721 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7722 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | Phone phone = getPhone(subId); |
| 7726 | if (phone != null) { |
| 7727 | return phone.isVideoEnabled(); |
| 7728 | } else { |
| 7729 | return false; |
| 7730 | } |
| 7731 | } finally { |
| 7732 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7733 | } |
| 7734 | } |
| 7735 | |
| 7736 | /** |
| 7737 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7738 | * defined in {@link ImsRegistrationImplBase}. |
| 7739 | */ |
| 7740 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7741 | final long identity = Binder.clearCallingIdentity(); |
| 7742 | try { |
| 7743 | Phone phone = getPhone(subId); |
| 7744 | if (phone != null) { |
| 7745 | return phone.getImsRegistrationTech(); |
| 7746 | } else { |
| 7747 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7748 | } |
| 7749 | } finally { |
| 7750 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7751 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7752 | } |
| 7753 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7754 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7755 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7756 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7757 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7758 | return; |
| 7759 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7760 | Phone defaultPhone = getDefaultPhone(); |
| 7761 | if (defaultPhone != null) { |
| 7762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7763 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7764 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7765 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7766 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7767 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7768 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7769 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7770 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7771 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7772 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7773 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7774 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7775 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7776 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7777 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7778 | // There has been issues when Sms raw table somehow stores orphan |
| 7779 | // fragments. They lead to garbled message when new fragments come |
| 7780 | // in and combined with those stale ones. In case this happens again, |
| 7781 | // user can reset all network settings which will clean up this table. |
| 7782 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7783 | // Clean up IMS settings as well here. |
| 7784 | int slotId = getSlotIndex(subId); |
| 7785 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7786 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7787 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7788 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7789 | if (defaultPhone == null) { |
| 7790 | return; |
| 7791 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7792 | // Erase modem config if erase modem on network setting is enabled. |
| 7793 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7794 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7795 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7796 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7797 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7798 | |
| 7799 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7800 | } finally { |
| 7801 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7802 | } |
| 7803 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7804 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7805 | @VisibleForTesting |
| 7806 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7807 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7808 | return; |
| 7809 | } |
| 7810 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7811 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7812 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7813 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7814 | "user=" + defaultNetworkType); |
| 7815 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7816 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7817 | defaultNetworkType, null); |
| 7818 | } |
| 7819 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7820 | private void cleanUpSmsRawTable(Context context) { |
| 7821 | ContentResolver resolver = context.getContentResolver(); |
| 7822 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7823 | resolver.delete(uri, null, null); |
| 7824 | } |
| 7825 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7826 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7827 | public String getSimLocaleForSubscriber(int subId) { |
| 7828 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7829 | final Phone phone = getPhone(subId); |
| 7830 | if (phone == null) { |
| 7831 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7832 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7834 | final long identity = Binder.clearCallingIdentity(); |
| 7835 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7836 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7837 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7838 | if (info == null) { |
| 7839 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7840 | return null; |
| 7841 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7842 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7843 | // preferences (EF-PL and EF-LI)... |
| 7844 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7845 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7846 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7847 | if (localeFromDefaultSim != null) { |
| 7848 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7849 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7850 | + localeFromDefaultSim); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7851 | return matchLocaleFromSupportedLocaleList(localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7852 | } else { |
| 7853 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7854 | } |
| 7855 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7856 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7857 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7858 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7859 | // the SIM and carrier preferences does not include a country we add the country |
| 7860 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7861 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7862 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7863 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7864 | return matchLocaleFromSupportedLocaleList(mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | } |
| 7866 | |
| 7867 | if (DBG) log("No locale found - returning null"); |
| 7868 | return null; |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
| 7871 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7872 | } |
| 7873 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7874 | @VisibleForTesting |
| 7875 | String matchLocaleFromSupportedLocaleList(@NonNull Locale inputLocale) { |
| 7876 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
| 7877 | getDefaultPhone().getContext()); |
| 7878 | for (String localeTag : supportedLocale) { |
| 7879 | if (LocaleList.matchesLanguageAndScript( |
| 7880 | inputLocale, Locale.forLanguageTag(localeTag)) |
| 7881 | && inputLocale.getCountry().equals( |
| 7882 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7883 | return localeTag; |
| 7884 | } |
| 7885 | } |
| 7886 | return inputLocale.toLanguageTag(); |
| 7887 | } |
| 7888 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7889 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7890 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7891 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7892 | } |
| 7893 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7894 | /** |
| 7895 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7896 | */ |
| 7897 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7898 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7899 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7900 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7901 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7902 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7903 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7904 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7905 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7906 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7907 | * representing the state of the modem. |
| 7908 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7909 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7910 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7911 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7912 | */ |
| 7913 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7914 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7915 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7916 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7917 | |
| 7918 | final long identity = Binder.clearCallingIdentity(); |
| 7919 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7920 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7921 | } finally { |
| 7922 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7923 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7924 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7925 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7926 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7927 | // less than total activity duration. |
| 7928 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7929 | if (info == null) { |
| 7930 | return false; |
| 7931 | } |
| 7932 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7933 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7934 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7935 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7936 | return (info.isValid() |
| 7937 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7938 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7939 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7940 | && (totalTxTimeMs <= activityDurationMs)); |
| 7941 | } |
| 7942 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7943 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7944 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7945 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7946 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7947 | |
| 7948 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7949 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7950 | } |
| 7951 | |
| 7952 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7953 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7954 | rat, |
| 7955 | freq, |
| 7956 | info.getReceiveTimeMillis(rat, freq) |
| 7957 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7958 | } |
| 7959 | |
| 7960 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7961 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7962 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7963 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7964 | |
| 7965 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7966 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7967 | } |
| 7968 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7969 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7970 | rat, |
| 7971 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7972 | } |
| 7973 | |
| 7974 | /** |
| 7975 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7976 | * @param info recent ModemActivityInfo |
| 7977 | */ |
| 7978 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7979 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7980 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7981 | boolean matched; |
| 7982 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7983 | matched = false; |
| 7984 | int rat = info.getSpecificInfoRat(i); |
| 7985 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7986 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7987 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7988 | //if it already exists |
| 7989 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7990 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7991 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7992 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7993 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7994 | updateLastModemActivityInfo(info, rat, freq); |
| 7995 | matched = true; |
| 7996 | } |
| 7997 | } else { |
| 7998 | updateLastModemActivityInfo(info, rat); |
| 7999 | matched = true; |
| 8000 | } |
| 8001 | } |
| 8002 | } |
| 8003 | |
| 8004 | if (!matched) { |
| 8005 | mDeltaSpecificInfo = |
| 8006 | new ActivityStatsTechSpecificInfo( |
| 8007 | rat, |
| 8008 | freq, |
| 8009 | info.getTransmitTimeMillis(rat, freq), |
| 8010 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 8011 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 8012 | } |
| 8013 | } |
| 8014 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8015 | mLastModemActivitySpecificInfo = |
| 8016 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8017 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8018 | |
| 8019 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8020 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8021 | info.getSleepTimeMillis() |
| 8022 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8023 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8024 | info.getIdleTimeMillis() |
| 8025 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 8026 | } |
| 8027 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8028 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8029 | * Returns the service state information on specified subscription. |
| 8030 | */ |
| 8031 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8032 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8033 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8034 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8036 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8037 | return null; |
| 8038 | } |
| 8039 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8040 | boolean hasFinePermission = false; |
| 8041 | boolean hasCoarsePermission = false; |
| 8042 | if (!renounceFineLocationAccess) { |
| 8043 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8044 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8045 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8046 | .setCallingPackage(callingPackage) |
| 8047 | .setCallingFeatureId(callingFeatureId) |
| 8048 | .setCallingPid(Binder.getCallingPid()) |
| 8049 | .setCallingUid(Binder.getCallingUid()) |
| 8050 | .setMethod("getServiceStateForSubscriber") |
| 8051 | .setLogAsInfo(true) |
| 8052 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8053 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8054 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8055 | .build()); |
| 8056 | hasFinePermission = |
| 8057 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8058 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8059 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8060 | if (!renounceCoarseLocationAccess) { |
| 8061 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8062 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8063 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8064 | .setCallingPackage(callingPackage) |
| 8065 | .setCallingFeatureId(callingFeatureId) |
| 8066 | .setCallingPid(Binder.getCallingPid()) |
| 8067 | .setCallingUid(Binder.getCallingUid()) |
| 8068 | .setMethod("getServiceStateForSubscriber") |
| 8069 | .setLogAsInfo(true) |
| 8070 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8071 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8072 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8073 | .build()); |
| 8074 | hasCoarsePermission = |
| 8075 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8076 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8077 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8078 | final Phone phone = getPhone(subId); |
| 8079 | if (phone == null) { |
| 8080 | return null; |
| 8081 | } |
| 8082 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8083 | final long identity = Binder.clearCallingIdentity(); |
| 8084 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8085 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8086 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8088 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8089 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8090 | Rlog.d(LOG_TAG, |
| 8091 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8092 | return null; |
| 8093 | } |
| 8094 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8095 | ServiceState ss = phone.getServiceState(); |
| 8096 | |
| 8097 | // Scrub out the location info in ServiceState depending on what level of access |
| 8098 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8099 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8100 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8101 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8105 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8106 | |
| 8107 | /** |
| 8108 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8109 | * |
| 8110 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8111 | * voicemail ringtone. |
| 8112 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8113 | * PhoneAccount. |
| 8114 | */ |
| 8115 | @Override |
| 8116 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8117 | final long identity = Binder.clearCallingIdentity(); |
| 8118 | try { |
| 8119 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8120 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8121 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8122 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8123 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8124 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
| 8127 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8131 | * Sets the per-account voicemail ringtone. |
| 8132 | * |
| 8133 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8134 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8135 | * |
| 8136 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8137 | * voicemail ringtone. |
| 8138 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8139 | * PhoneAccount. |
| 8140 | */ |
| 8141 | @Override |
| 8142 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8143 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8144 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8145 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8146 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8147 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8148 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8149 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8150 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8151 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | |
| 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
| 8155 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8156 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8157 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8158 | } |
| 8159 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8160 | } finally { |
| 8161 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8162 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8163 | } |
| 8164 | |
| 8165 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8166 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8167 | * |
| 8168 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8169 | * voicemail vibration setting. |
| 8170 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8171 | */ |
| 8172 | @Override |
| 8173 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8174 | final long identity = Binder.clearCallingIdentity(); |
| 8175 | try { |
| 8176 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8177 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8178 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8179 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8181 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8182 | } finally { |
| 8183 | Binder.restoreCallingIdentity(identity); |
| 8184 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8185 | } |
| 8186 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8187 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8188 | * Sets the per-account voicemail vibration. |
| 8189 | * |
| 8190 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8191 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8192 | * |
| 8193 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8194 | * voicemail vibration setting. |
| 8195 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8196 | * specific PhoneAccount. |
| 8197 | */ |
| 8198 | @Override |
| 8199 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8200 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8201 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8202 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8203 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8204 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8205 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8206 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8207 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8208 | } |
| 8209 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8213 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8214 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8215 | } |
| 8216 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8217 | } finally { |
| 8218 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8219 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8220 | } |
| 8221 | |
| 8222 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8223 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8224 | * |
| 8225 | * @throws SecurityException if the caller does not have the required permission |
| 8226 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8227 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8228 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8229 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8230 | } |
| 8231 | |
| 8232 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8233 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8234 | * permission. |
| 8235 | * |
| 8236 | * @throws SecurityException if the caller does not have the required permission |
| 8237 | */ |
| 8238 | private void enforceSendSmsPermission() { |
| 8239 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8240 | } |
| 8241 | |
| 8242 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8243 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8244 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8245 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8246 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8247 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8248 | final long identity = Binder.clearCallingIdentity(); |
| 8249 | try { |
| 8250 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8251 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8252 | if (componentName == null) { |
| 8253 | throw new SecurityException( |
| 8254 | "Caller not current active visual voicemail package[null]"); |
| 8255 | } |
| 8256 | String vvmPackage = componentName.getPackageName(); |
| 8257 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8258 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8259 | } |
| 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8262 | } |
| 8263 | } |
| 8264 | |
| 8265 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8266 | * Return the application ID for the app type. |
| 8267 | * |
| 8268 | * @param subId the subscription ID that this request applies to. |
| 8269 | * @param appType the uicc app type. |
| 8270 | * @return Application ID for specificied app type, or null if no uicc. |
| 8271 | */ |
| 8272 | @Override |
| 8273 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8274 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8275 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | |
| 8277 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8278 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8279 | if (phone == null) { |
| 8280 | return null; |
| 8281 | } |
| 8282 | String aid = null; |
| 8283 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8284 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | .getApplicationByType(appType).getAid(); |
| 8286 | } catch (Exception e) { |
| 8287 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8288 | } |
| 8289 | return aid; |
| 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8292 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8293 | } |
| 8294 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8295 | /** |
| 8296 | * Return the Electronic Serial Number. |
| 8297 | * |
| 8298 | * @param subId the subscription ID that this request applies to. |
| 8299 | * @return ESN or null if error. |
| 8300 | */ |
| 8301 | @Override |
| 8302 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8303 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8304 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8305 | |
| 8306 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8307 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8308 | if (phone == null) { |
| 8309 | return null; |
| 8310 | } |
| 8311 | String esn = null; |
| 8312 | try { |
| 8313 | esn = phone.getEsn(); |
| 8314 | } catch (Exception e) { |
| 8315 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8316 | } |
| 8317 | return esn; |
| 8318 | } finally { |
| 8319 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8320 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8321 | } |
| 8322 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8323 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8324 | * Return the Preferred Roaming List Version. |
| 8325 | * |
| 8326 | * @param subId the subscription ID that this request applies to. |
| 8327 | * @return PRLVersion or null if error. |
| 8328 | */ |
| 8329 | @Override |
| 8330 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8331 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8332 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8333 | |
| 8334 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8335 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8336 | if (phone == null) { |
| 8337 | return null; |
| 8338 | } |
| 8339 | String cdmaPrlVersion = null; |
| 8340 | try { |
| 8341 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8342 | } catch (Exception e) { |
| 8343 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8344 | } |
| 8345 | return cdmaPrlVersion; |
| 8346 | } finally { |
| 8347 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8348 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8352 | * Get snapshot of Telephony histograms |
| 8353 | * @return List of Telephony histograms |
| 8354 | * @hide |
| 8355 | */ |
| 8356 | @Override |
| 8357 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8359 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8360 | |
| 8361 | final long identity = Binder.clearCallingIdentity(); |
| 8362 | try { |
| 8363 | return RIL.getTelephonyRILTimingHistograms(); |
| 8364 | } finally { |
| 8365 | Binder.restoreCallingIdentity(identity); |
| 8366 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8367 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8368 | |
| 8369 | /** |
| 8370 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8371 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8372 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8373 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8374 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8375 | * @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] | 8376 | */ |
| 8377 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8378 | @TelephonyManager.SetCarrierRestrictionResult |
| 8379 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8380 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8381 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8382 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8383 | if (carrierRestrictionRules == null) { |
| 8384 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8385 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8386 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | final long identity = Binder.clearCallingIdentity(); |
| 8388 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8389 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8390 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8391 | } finally { |
| 8392 | Binder.restoreCallingIdentity(identity); |
| 8393 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8394 | } |
| 8395 | |
| 8396 | /** |
| 8397 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8398 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8399 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8400 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8401 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8402 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8403 | */ |
| 8404 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8405 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8406 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8407 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8411 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8412 | if (response instanceof CarrierRestrictionRules) { |
| 8413 | return (CarrierRestrictionRules) response; |
| 8414 | } |
| 8415 | // Response is an Exception of some kind, |
| 8416 | // which is signalled to the user as a NULL retval |
| 8417 | return null; |
| 8418 | } catch (Exception e) { |
| 8419 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8420 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8421 | } finally { |
| 8422 | Binder.restoreCallingIdentity(identity); |
| 8423 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8424 | } |
| 8425 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8426 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8427 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8428 | * @param subId the subscription ID that this action applies to. |
| 8429 | * @param enabled control enable or disable radio. |
| 8430 | * {@hide} |
| 8431 | */ |
| 8432 | @Override |
| 8433 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8434 | enforceModifyPermission(); |
| 8435 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8436 | |
| 8437 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8438 | if (phone == null) { |
| 8439 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8440 | return; |
| 8441 | } |
| 8442 | try { |
| 8443 | phone.carrierActionSetRadioEnabled(enabled); |
| 8444 | } catch (Exception e) { |
| 8445 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8446 | } finally { |
| 8447 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8448 | } |
| 8449 | } |
| 8450 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8451 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8452 | * Enable or disable Voice over NR (VoNR) |
| 8453 | * @param subId the subscription ID that this action applies to. |
| 8454 | * @param enabled enable or disable VoNR. |
| 8455 | * @return operation result. |
| 8456 | */ |
| 8457 | @Override |
| 8458 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8459 | enforceModifyPermission(); |
| 8460 | final Phone phone = getPhone(subId); |
| 8461 | |
| 8462 | final long identity = Binder.clearCallingIdentity(); |
| 8463 | if (phone == null) { |
| 8464 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8465 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8466 | } |
| 8467 | |
| 8468 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8469 | try { |
| 8470 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8471 | workSource); |
| 8472 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8473 | |
| 8474 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8475 | if (DBG) { |
| 8476 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8477 | } |
| 8478 | SubscriptionManager.setSubscriptionProperty( |
| 8479 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8480 | (enabled ? "1" : "0")); |
| 8481 | } |
| 8482 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8483 | return result; |
| 8484 | } finally { |
| 8485 | Binder.restoreCallingIdentity(identity); |
| 8486 | } |
| 8487 | } |
| 8488 | |
| 8489 | /** |
| 8490 | * Is voice over NR enabled |
| 8491 | * @return true if VoNR is enabled else false |
| 8492 | */ |
| 8493 | @Override |
| 8494 | public boolean isVoNrEnabled(int subId) { |
| 8495 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8496 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8497 | final long identity = Binder.clearCallingIdentity(); |
| 8498 | try { |
| 8499 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8500 | null, subId, workSource); |
| 8501 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8502 | return isEnabled; |
| 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
| 8505 | } |
| 8506 | } |
| 8507 | |
| 8508 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8509 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8510 | * network status based on which carrier apps could apply actions accordingly, |
| 8511 | * enable/disable default url handler for example. |
| 8512 | * |
| 8513 | * @param subId the subscription ID that this action applies to. |
| 8514 | * @param report control start/stop reporting the default network status. |
| 8515 | * {@hide} |
| 8516 | */ |
| 8517 | @Override |
| 8518 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8519 | enforceModifyPermission(); |
| 8520 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8521 | |
| 8522 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8523 | if (phone == null) { |
| 8524 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8525 | return; |
| 8526 | } |
| 8527 | try { |
| 8528 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8529 | } catch (Exception e) { |
| 8530 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8531 | } finally { |
| 8532 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8533 | } |
| 8534 | } |
| 8535 | |
| 8536 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8537 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8538 | * @param subId the subscription ID that this action applies to. |
| 8539 | * {@hide} |
| 8540 | */ |
| 8541 | @Override |
| 8542 | public void carrierActionResetAll(int subId) { |
| 8543 | enforceModifyPermission(); |
| 8544 | final Phone phone = getPhone(subId); |
| 8545 | if (phone == null) { |
| 8546 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8547 | return; |
| 8548 | } |
| 8549 | try { |
| 8550 | phone.carrierActionResetAll(); |
| 8551 | } catch (Exception e) { |
| 8552 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8553 | } |
| 8554 | } |
| 8555 | |
| 8556 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8557 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8558 | * bug report is being generated. |
| 8559 | */ |
| 8560 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8561 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8562 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8563 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8564 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8565 | + Binder.getCallingPid() |
| 8566 | + ", uid=" + Binder.getCallingUid() |
| 8567 | + "without permission " |
| 8568 | + android.Manifest.permission.DUMP); |
| 8569 | return; |
| 8570 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8571 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8572 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8573 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8574 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8575 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8576 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8577 | @NonNull String[] args) { |
| 8578 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8579 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8580 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8581 | } |
| 8582 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8583 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8584 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8585 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8586 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8587 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8588 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8589 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8590 | */ |
| 8591 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8592 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8593 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8594 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8595 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8596 | try { |
| 8597 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8598 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8599 | } catch (SecurityException se) { |
| 8600 | enforceModifyPermission(); |
| 8601 | } |
| 8602 | } else { |
| 8603 | enforceModifyPermission(); |
| 8604 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8605 | |
| 8606 | final long identity = Binder.clearCallingIdentity(); |
| 8607 | try { |
| 8608 | Phone phone = getPhone(subId); |
| 8609 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8610 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8611 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8612 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8613 | phone.getDataSettingsManager().setDataEnabled( |
| 8614 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8616 | } |
| 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8619 | } |
| 8620 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8621 | |
| 8622 | /** |
| 8623 | * Get Client request stats |
| 8624 | * @return List of Client Request Stats |
| 8625 | * @hide |
| 8626 | */ |
| 8627 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8628 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8629 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8631 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8632 | return null; |
| 8633 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8634 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8636 | final long identity = Binder.clearCallingIdentity(); |
| 8637 | try { |
| 8638 | if (phone != null) { |
| 8639 | return phone.getClientRequestStats(); |
| 8640 | } |
| 8641 | |
| 8642 | return null; |
| 8643 | } finally { |
| 8644 | Binder.restoreCallingIdentity(identity); |
| 8645 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8646 | } |
| 8647 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8648 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8649 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8650 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8651 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8652 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8653 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8654 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8655 | // commands that plumb through the RIL as root, like so: |
| 8656 | // $ adb root |
| 8657 | // $ adb shell cmd phone ... |
| 8658 | packageName = "root"; |
| 8659 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8660 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8661 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8662 | |
| 8663 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8664 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8665 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8666 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8667 | * @param state State of SIM (power down, power up, pass through) |
| 8668 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8669 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8670 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8671 | * |
| 8672 | **/ |
| 8673 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8674 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8675 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8676 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8677 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8678 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8679 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8680 | final long identity = Binder.clearCallingIdentity(); |
| 8681 | try { |
| 8682 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8683 | phone.setSimPowerState(state, null, workSource); |
| 8684 | } |
| 8685 | } finally { |
| 8686 | Binder.restoreCallingIdentity(identity); |
| 8687 | } |
| 8688 | } |
| 8689 | |
| 8690 | /** |
| 8691 | * Set SIM card power state. |
| 8692 | * |
| 8693 | * @param slotIndex SIM slot id. |
| 8694 | * @param state State of SIM (power down, power up, pass through) |
| 8695 | * @param callback callback to trigger after success or failure |
| 8696 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8697 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8698 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8699 | * |
| 8700 | **/ |
| 8701 | @Override |
| 8702 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8703 | IIntegerConsumer callback) { |
| 8704 | enforceModifyPermission(); |
| 8705 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8706 | |
| 8707 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8708 | |
| 8709 | final long identity = Binder.clearCallingIdentity(); |
| 8710 | try { |
| 8711 | if (phone != null) { |
| 8712 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8713 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8714 | } |
| 8715 | } finally { |
| 8716 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8717 | } |
| 8718 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8719 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8720 | private boolean isUssdApiAllowed(int subId) { |
| 8721 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8722 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8723 | if (configManager == null) { |
| 8724 | return false; |
| 8725 | } |
| 8726 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8727 | if (pb == null) { |
| 8728 | return false; |
| 8729 | } |
| 8730 | return pb.getBoolean( |
| 8731 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8732 | } |
| 8733 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8734 | /** |
| 8735 | * Check if phone is in emergency callback mode |
| 8736 | * @return true if phone is in emergency callback mode |
| 8737 | * @param subId sub id |
| 8738 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8739 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8740 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8741 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8742 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8743 | |
| 8744 | final long identity = Binder.clearCallingIdentity(); |
| 8745 | try { |
| 8746 | if (phone != null) { |
| 8747 | return phone.isInEcm(); |
| 8748 | } else { |
| 8749 | return false; |
| 8750 | } |
| 8751 | } finally { |
| 8752 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8753 | } |
| 8754 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8755 | |
| 8756 | /** |
| 8757 | * Get the current signal strength information for the given subscription. |
| 8758 | * Because this information is not updated when the device is in a low power state |
| 8759 | * it should not be relied-upon to be current. |
| 8760 | * @param subId Subscription index |
| 8761 | * @return the most recent cached signal strength info from the modem |
| 8762 | */ |
| 8763 | @Override |
| 8764 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | try { |
| 8767 | Phone p = getPhone(subId); |
| 8768 | if (p == null) { |
| 8769 | return null; |
| 8770 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8771 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8772 | return p.getSignalStrength(); |
| 8773 | } finally { |
| 8774 | Binder.restoreCallingIdentity(identity); |
| 8775 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8776 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8777 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8778 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8779 | * Get the current modem radio state for the given slot. |
| 8780 | * @param slotIndex slot index. |
| 8781 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8782 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8783 | * @return the current radio power state from the modem |
| 8784 | */ |
| 8785 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8786 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8787 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8788 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8789 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8790 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8791 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8792 | } |
| 8793 | |
| 8794 | final long identity = Binder.clearCallingIdentity(); |
| 8795 | try { |
| 8796 | return phone.getRadioPowerState(); |
| 8797 | } finally { |
| 8798 | Binder.restoreCallingIdentity(identity); |
| 8799 | } |
| 8800 | } |
| 8801 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8802 | } |
| 8803 | |
| 8804 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8805 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8806 | * |
| 8807 | * <p>Requires one of the following permissions: |
| 8808 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8809 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8810 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8811 | * privileges. |
| 8812 | * |
| 8813 | * @param subId subscription id |
| 8814 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8815 | * {@code false}. |
| 8816 | */ |
| 8817 | @Override |
| 8818 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8819 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8820 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8821 | try { |
| 8822 | mApp.enforceCallingOrSelfPermission( |
| 8823 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8824 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8825 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8826 | mApp.enforceCallingOrSelfPermission( |
| 8827 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8828 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8829 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8830 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8831 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8832 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8833 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8834 | boolean isEnabled = false; |
| 8835 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8836 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8837 | Phone phone = getPhone(subId); |
| 8838 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8839 | } finally { |
| 8840 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8841 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8842 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8843 | } |
| 8844 | |
| 8845 | |
| 8846 | /** |
| 8847 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8848 | * |
| 8849 | * <p> Requires permission: |
| 8850 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8851 | * privileges. |
| 8852 | * |
| 8853 | * @param subId subscription id |
| 8854 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8855 | */ |
| 8856 | @Override |
| 8857 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8859 | mApp, subId, "setDataRoamingEnabled"); |
| 8860 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8861 | final long identity = Binder.clearCallingIdentity(); |
| 8862 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8863 | Phone phone = getPhone(subId); |
| 8864 | if (phone != null) { |
| 8865 | phone.setDataRoamingEnabled(isEnabled); |
| 8866 | } |
| 8867 | } finally { |
| 8868 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8869 | } |
| 8870 | } |
| 8871 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8872 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8873 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8874 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8875 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8876 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8877 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8878 | boolean isAllowed = true; |
| 8879 | final long identity = Binder.clearCallingIdentity(); |
| 8880 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8881 | Phone phone = getPhone(subId); |
| 8882 | if (phone != null) { |
| 8883 | isAllowed = phone.isCspPlmnEnabled(); |
| 8884 | } |
| 8885 | } finally { |
| 8886 | Binder.restoreCallingIdentity(identity); |
| 8887 | } |
| 8888 | return isAllowed; |
| 8889 | } |
| 8890 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8891 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8892 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8893 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8894 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8895 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8896 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8897 | if (phone == null) { |
| 8898 | return false; |
| 8899 | } |
| 8900 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8901 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8902 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8903 | } |
| 8904 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8905 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8906 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8907 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8908 | mApp.getSystemService(AppOpsManager.class) |
| 8909 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8910 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8911 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8912 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8913 | try { |
| 8914 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8915 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8916 | } catch (SecurityException e) { |
| 8917 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8918 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8919 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8920 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8921 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8922 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8923 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8924 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8925 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8926 | Binder.getCallingUid())) { |
| 8927 | isIccIdAccessRestricted = true; |
| 8928 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8929 | final long identity = Binder.clearCallingIdentity(); |
| 8930 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8931 | UiccController uiccController = UiccController.getInstance(); |
| 8932 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8933 | if (hasReadPermission) { |
| 8934 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8935 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8936 | |
| 8937 | // Remove private info if the caller doesn't have access |
| 8938 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8939 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8940 | //setting the value after compatibility check |
| 8941 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8942 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8943 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8944 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8945 | if (card == null) { |
| 8946 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8947 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8948 | continue; |
| 8949 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8950 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8951 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8952 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8953 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8954 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8955 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8956 | for (UiccPortInfo portInfo : portInfos) { |
| 8957 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8958 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8959 | if (port == null) { |
| 8960 | // assume no access if port is null |
| 8961 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8962 | continue; |
| 8963 | } |
| 8964 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8965 | uiccPortInfos.add(portInfo); |
| 8966 | } else { |
| 8967 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8968 | } |
| 8969 | } |
| 8970 | filteredInfos.add(new UiccCardInfo( |
| 8971 | cardInfo.isEuicc(), |
| 8972 | cardInfo.getCardId(), |
| 8973 | null, |
| 8974 | cardInfo.getPhysicalSlotIndex(), |
| 8975 | cardInfo.isRemovable(), |
| 8976 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8977 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8978 | } |
| 8979 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8980 | } finally { |
| 8981 | Binder.restoreCallingIdentity(identity); |
| 8982 | } |
| 8983 | } |
| 8984 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8985 | /** |
| 8986 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8987 | * generally private and require carrier privileges to view. |
| 8988 | * |
| 8989 | * @hide |
| 8990 | */ |
| 8991 | @NonNull |
| 8992 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8993 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8994 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8995 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8996 | } |
| 8997 | return new UiccCardInfo( |
| 8998 | cardInfo.isEuicc(), |
| 8999 | cardInfo.getCardId(), |
| 9000 | null, |
| 9001 | cardInfo.getPhysicalSlotIndex(), |
| 9002 | cardInfo.isRemovable(), |
| 9003 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9004 | portinfo |
| 9005 | ); |
| 9006 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9007 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9008 | /** |
| 9009 | * @hide |
| 9010 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9011 | * These values are generally private and require carrier privileges to view. |
| 9012 | */ |
| 9013 | @NonNull |
| 9014 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9015 | return new UiccPortInfo( |
| 9016 | UiccPortInfo.ICCID_REDACTED, |
| 9017 | portInfo.getPortIndex(), |
| 9018 | portInfo.getLogicalSlotIndex(), |
| 9019 | portInfo.isActive() |
| 9020 | ); |
| 9021 | } |
| 9022 | @Override |
| 9023 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9024 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9025 | mApp.getSystemService(AppOpsManager.class) |
| 9026 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9027 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9028 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9029 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9030 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9031 | // we are reading iccId which is PII data. |
| 9032 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9033 | |
| 9034 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9035 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9036 | Binder.getCallingUid())) { |
| 9037 | isLogicalSlotAccessRestricted = true; |
| 9038 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9039 | final long identity = Binder.clearCallingIdentity(); |
| 9040 | try { |
| 9041 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9042 | if (slots == null || slots.length == 0) { |
| 9043 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9044 | return null; |
| 9045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9046 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9047 | for (int i = 0; i < slots.length; i++) { |
| 9048 | UiccSlot slot = slots[i]; |
| 9049 | if (slot == null) { |
| 9050 | continue; |
| 9051 | } |
| 9052 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9053 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9054 | UiccCard card = slot.getUiccCard(); |
| 9055 | if (card != null) { |
| 9056 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9057 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9058 | cardId = slot.getEid(); |
| 9059 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9060 | // If cardId is null, use iccId of default port as cardId. |
| 9061 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9062 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9063 | } |
| 9064 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9065 | if (cardId != null) { |
| 9066 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9067 | // if cardId is an EID, it's all digits so this is fine |
| 9068 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9069 | } |
| 9070 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9071 | int cardState = 0; |
| 9072 | switch (slot.getCardState()) { |
| 9073 | case CARDSTATE_ABSENT: |
| 9074 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9075 | break; |
| 9076 | case CARDSTATE_PRESENT: |
| 9077 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9078 | break; |
| 9079 | case CARDSTATE_ERROR: |
| 9080 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9081 | break; |
| 9082 | case CARDSTATE_RESTRICTED: |
| 9083 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9084 | break; |
| 9085 | default: |
| 9086 | break; |
| 9087 | |
| 9088 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9089 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9090 | int[] portIndexes = slot.getPortList(); |
| 9091 | for (int portIdx : portIndexes) { |
| 9092 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9093 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9094 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9095 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9096 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9097 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9098 | slot.isEuicc(), |
| 9099 | cardId, |
| 9100 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9101 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9102 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9103 | //setting the value after compatibility check |
| 9104 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9105 | } |
| 9106 | return infos; |
| 9107 | } finally { |
| 9108 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9109 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9110 | } |
| 9111 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9112 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9113 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9114 | boolean hasReadPermission) { |
| 9115 | String iccId = slot.getIccId(portIndex); |
| 9116 | if (hasReadPermission) { // if has read permission |
| 9117 | return iccId; |
| 9118 | } else { |
| 9119 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9120 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9121 | // if no read permission, checking carrier privilege access |
| 9122 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9123 | return iccId; |
| 9124 | } |
| 9125 | } |
| 9126 | } |
| 9127 | // No read permission or carrier privilege access. |
| 9128 | return UiccPortInfo.ICCID_REDACTED; |
| 9129 | } |
| 9130 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9131 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9132 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9133 | public boolean switchSlots(int[] physicalSlots) { |
| 9134 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9135 | |
| 9136 | final long identity = Binder.clearCallingIdentity(); |
| 9137 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9138 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9139 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9140 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9141 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9142 | physicalSlots[i], i)); |
| 9143 | } |
| 9144 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9145 | } finally { |
| 9146 | Binder.restoreCallingIdentity(identity); |
| 9147 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9148 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9149 | |
| 9150 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9151 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9152 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9153 | enforceModifyPermission(); |
| 9154 | |
| 9155 | final long identity = Binder.clearCallingIdentity(); |
| 9156 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9157 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9158 | } finally { |
| 9159 | Binder.restoreCallingIdentity(identity); |
| 9160 | } |
| 9161 | } |
| 9162 | |
| 9163 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9164 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9165 | final long identity = Binder.clearCallingIdentity(); |
| 9166 | try { |
| 9167 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9168 | } finally { |
| 9169 | Binder.restoreCallingIdentity(identity); |
| 9170 | } |
| 9171 | } |
| 9172 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9173 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9174 | * A test API to reload the UICC profile. |
| 9175 | * |
| 9176 | * <p>Requires that the calling app has permission |
| 9177 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9178 | * @hide |
| 9179 | */ |
| 9180 | @Override |
| 9181 | public void refreshUiccProfile(int subId) { |
| 9182 | enforceModifyPermission(); |
| 9183 | |
| 9184 | final long identity = Binder.clearCallingIdentity(); |
| 9185 | try { |
| 9186 | Phone phone = getPhone(subId); |
| 9187 | if (phone == null) { |
| 9188 | return; |
| 9189 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9190 | UiccPort uiccPort = phone.getUiccPort(); |
| 9191 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9192 | return; |
| 9193 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9194 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9195 | if (uiccProfile == null) { |
| 9196 | return; |
| 9197 | } |
| 9198 | uiccProfile.refresh(); |
| 9199 | } finally { |
| 9200 | Binder.restoreCallingIdentity(identity); |
| 9201 | } |
| 9202 | } |
| 9203 | |
| 9204 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9205 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9206 | */ |
| 9207 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9208 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9209 | } |
| 9210 | |
| 9211 | /** |
| 9212 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9213 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9214 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9215 | */ |
| 9216 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9217 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9218 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9219 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9220 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9221 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9222 | return isDataRoamingEnabled; |
| 9223 | } |
| 9224 | |
| 9225 | /** |
| 9226 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9227 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9228 | */ |
| 9229 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9230 | List<Integer> list = TelephonyProperties.default_network(); |
| 9231 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9232 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9233 | return list.get(phoneId); |
| 9234 | } |
| 9235 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9236 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9237 | |
| 9238 | @Override |
| 9239 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9240 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9241 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9242 | |
| 9243 | final long identity = Binder.clearCallingIdentity(); |
| 9244 | try { |
| 9245 | final Phone phone = getPhone(subId); |
| 9246 | if (phone == null) { |
| 9247 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9248 | return; |
| 9249 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9250 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9251 | if (cpt != null) { |
| 9252 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9253 | } |
| 9254 | // 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] | 9255 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9256 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9257 | if (carrierPrivilegeRules == null) { |
| 9258 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9259 | } else { |
| 9260 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9261 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9262 | } finally { |
| 9263 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9264 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9265 | } |
| 9266 | |
| 9267 | @Override |
| 9268 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9269 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9270 | |
| 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
| 9273 | final Phone phone = getPhone(subId); |
| 9274 | if (phone == null) { |
| 9275 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9276 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9277 | } |
| 9278 | return phone.getCarrierIdListVersion(); |
| 9279 | } finally { |
| 9280 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9281 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9282 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9283 | |
| 9284 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9285 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9286 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9287 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9288 | mApp, subId, callingPackage, callingFeatureId, |
| 9289 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9290 | return -1; |
| 9291 | } |
| 9292 | |
| 9293 | final long identity = Binder.clearCallingIdentity(); |
| 9294 | try { |
| 9295 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9296 | } finally { |
| 9297 | Binder.restoreCallingIdentity(identity); |
| 9298 | } |
| 9299 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9300 | |
| 9301 | @Override |
| 9302 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9303 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9304 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9305 | mApp, subId, "getCdmaRoamingMode"); |
| 9306 | |
| 9307 | final long identity = Binder.clearCallingIdentity(); |
| 9308 | try { |
| 9309 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9310 | } finally { |
| 9311 | Binder.restoreCallingIdentity(identity); |
| 9312 | } |
| 9313 | } |
| 9314 | |
| 9315 | @Override |
| 9316 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9318 | mApp, subId, "setCdmaRoamingMode"); |
| 9319 | |
| 9320 | final long identity = Binder.clearCallingIdentity(); |
| 9321 | try { |
| 9322 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9323 | } finally { |
| 9324 | Binder.restoreCallingIdentity(identity); |
| 9325 | } |
| 9326 | } |
| 9327 | |
| 9328 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9329 | public int getCdmaSubscriptionMode(int subId) { |
| 9330 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9331 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9332 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9333 | |
| 9334 | final long identity = Binder.clearCallingIdentity(); |
| 9335 | try { |
| 9336 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9337 | } finally { |
| 9338 | Binder.restoreCallingIdentity(identity); |
| 9339 | } |
| 9340 | } |
| 9341 | |
| 9342 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9343 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9345 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9346 | |
| 9347 | final long identity = Binder.clearCallingIdentity(); |
| 9348 | try { |
| 9349 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9350 | } finally { |
| 9351 | Binder.restoreCallingIdentity(identity); |
| 9352 | } |
| 9353 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9354 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9355 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9356 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9357 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9358 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9359 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9360 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9361 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9362 | } |
| 9363 | final long identity = Binder.clearCallingIdentity(); |
| 9364 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9365 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9366 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9367 | if (phone.getEmergencyNumberTracker() != null |
| 9368 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9369 | emergencyNumberListInternal.put( |
| 9370 | phone.getSubId(), |
| 9371 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9372 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9373 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9374 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9375 | } finally { |
| 9376 | Binder.restoreCallingIdentity(identity); |
| 9377 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9378 | } |
| 9379 | |
| 9380 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9381 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9382 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9383 | if (!exactMatch) { |
| 9384 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9385 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9386 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9387 | } |
| 9388 | final long identity = Binder.clearCallingIdentity(); |
| 9389 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9390 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9391 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9392 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9393 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9394 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9395 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9396 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9397 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9398 | } |
| 9399 | return false; |
| 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
| 9402 | } |
| 9403 | } |
| 9404 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9405 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9406 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9407 | */ |
| 9408 | @Override |
| 9409 | public void startEmergencyCallbackMode() { |
| 9410 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9411 | "startEmergencyCallbackMode"); |
| 9412 | enforceModifyPermission(); |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
| 9415 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9416 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9417 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9418 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9419 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9420 | gsmCdmaPhone.obtainMessage( |
| 9421 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9422 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9423 | } |
| 9424 | } |
| 9425 | } finally { |
| 9426 | Binder.restoreCallingIdentity(identity); |
| 9427 | } |
| 9428 | } |
| 9429 | |
| 9430 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9431 | * Update emergency number list for test mode. |
| 9432 | */ |
| 9433 | @Override |
| 9434 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9435 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9436 | "updateEmergencyNumberListTestMode"); |
| 9437 | |
| 9438 | final long identity = Binder.clearCallingIdentity(); |
| 9439 | try { |
| 9440 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9441 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9442 | if (tracker != null) { |
| 9443 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9444 | } |
| 9445 | } |
| 9446 | } finally { |
| 9447 | Binder.restoreCallingIdentity(identity); |
| 9448 | } |
| 9449 | } |
| 9450 | |
| 9451 | /** |
| 9452 | * Get the full emergency number list for test mode. |
| 9453 | */ |
| 9454 | @Override |
| 9455 | public List<String> getEmergencyNumberListTestMode() { |
| 9456 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9457 | "getEmergencyNumberListTestMode"); |
| 9458 | |
| 9459 | final long identity = Binder.clearCallingIdentity(); |
| 9460 | try { |
| 9461 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9462 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9463 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9464 | if (tracker != null) { |
| 9465 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9466 | emergencyNumbers.add(num.getNumber()); |
| 9467 | } |
| 9468 | } |
| 9469 | } |
| 9470 | return new ArrayList<>(emergencyNumbers); |
| 9471 | } finally { |
| 9472 | Binder.restoreCallingIdentity(identity); |
| 9473 | } |
| 9474 | } |
| 9475 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9476 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9477 | public int getEmergencyNumberDbVersion(int subId) { |
| 9478 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9479 | |
| 9480 | final long identity = Binder.clearCallingIdentity(); |
| 9481 | try { |
| 9482 | final Phone phone = getPhone(subId); |
| 9483 | if (phone == null) { |
| 9484 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9485 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9486 | } |
| 9487 | return phone.getEmergencyNumberDbVersion(); |
| 9488 | } finally { |
| 9489 | Binder.restoreCallingIdentity(identity); |
| 9490 | } |
| 9491 | } |
| 9492 | |
| 9493 | @Override |
| 9494 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9495 | enforceModifyPermission(); |
| 9496 | |
| 9497 | final long identity = Binder.clearCallingIdentity(); |
| 9498 | try { |
| 9499 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9500 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9501 | if (tracker != null) { |
| 9502 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9503 | } |
| 9504 | } |
| 9505 | } finally { |
| 9506 | Binder.restoreCallingIdentity(identity); |
| 9507 | } |
| 9508 | } |
| 9509 | |
| 9510 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9511 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9512 | enforceActiveEmergencySessionPermission(); |
| 9513 | |
| 9514 | final long identity = Binder.clearCallingIdentity(); |
| 9515 | try { |
| 9516 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9517 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9518 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9519 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9520 | } |
| 9521 | } |
| 9522 | } finally { |
| 9523 | Binder.restoreCallingIdentity(identity); |
| 9524 | } |
| 9525 | } |
| 9526 | |
| 9527 | @Override |
| 9528 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9529 | enforceActiveEmergencySessionPermission(); |
| 9530 | |
| 9531 | final long identity = Binder.clearCallingIdentity(); |
| 9532 | try { |
| 9533 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9534 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9535 | if (tracker != null) { |
| 9536 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9537 | } |
| 9538 | } |
| 9539 | } finally { |
| 9540 | Binder.restoreCallingIdentity(identity); |
| 9541 | } |
| 9542 | } |
| 9543 | |
| 9544 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9545 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9546 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9547 | Phone phone = getPhone(subId); |
| 9548 | if (phone == null) { |
| 9549 | return null; |
| 9550 | } |
| 9551 | final long identity = Binder.clearCallingIdentity(); |
| 9552 | try { |
| 9553 | UiccProfile profile = UiccController.getInstance() |
| 9554 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9555 | if (profile != null) { |
| 9556 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9557 | } |
| 9558 | } finally { |
| 9559 | Binder.restoreCallingIdentity(identity); |
| 9560 | } |
| 9561 | return null; |
| 9562 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9563 | |
| 9564 | /** |
| 9565 | * Enable or disable a modem stack. |
| 9566 | */ |
| 9567 | @Override |
| 9568 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9569 | enforceModifyPermission(); |
| 9570 | |
| 9571 | final long identity = Binder.clearCallingIdentity(); |
| 9572 | try { |
| 9573 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9574 | if (phone == null) { |
| 9575 | return false; |
| 9576 | } else { |
| 9577 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9578 | } |
| 9579 | } finally { |
| 9580 | Binder.restoreCallingIdentity(identity); |
| 9581 | } |
| 9582 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9583 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9584 | /** |
| 9585 | * Whether a modem stack is enabled or not. |
| 9586 | */ |
| 9587 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9588 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9589 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9590 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9591 | if (phone == null) return false; |
| 9592 | |
| 9593 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9594 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9595 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9596 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9597 | } |
| 9598 | |
| 9599 | final long identity = Binder.clearCallingIdentity(); |
| 9600 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9601 | try { |
| 9602 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9603 | } catch (NoSuchElementException ex) { |
| 9604 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9605 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9606 | } finally { |
| 9607 | Binder.restoreCallingIdentity(identity); |
| 9608 | } |
| 9609 | } |
| 9610 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9611 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9612 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9613 | enforceModifyPermission(); |
| 9614 | |
| 9615 | final long identity = Binder.clearCallingIdentity(); |
| 9616 | try { |
| 9617 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9618 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9619 | .commit(); |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
| 9625 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9626 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9627 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9628 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9629 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9630 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9631 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9632 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9633 | |
| 9634 | final long identity = Binder.clearCallingIdentity(); |
| 9635 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9636 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9637 | } finally { |
| 9638 | Binder.restoreCallingIdentity(identity); |
| 9639 | } |
| 9640 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9641 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9642 | @TelephonyManager.IsMultiSimSupportedResult |
| 9643 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9644 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9645 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9646 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9647 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9648 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9649 | } |
| 9650 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9651 | // supported by the modem, indicate that it is restricted. |
| 9652 | PhoneCapability staticCapability = |
| 9653 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9654 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9655 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9656 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9657 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9658 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9659 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9660 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9661 | } |
| 9662 | // Check if support of multiple SIMs is restricted by carrier |
| 9663 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9664 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9665 | } |
| 9666 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9667 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9668 | } |
| 9669 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9670 | /** |
| 9671 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9672 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9673 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9674 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9675 | * @param numOfSims number of active sims we want to switch to |
| 9676 | */ |
| 9677 | @Override |
| 9678 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9679 | if (numOfSims == 1) { |
| 9680 | enforceModifyPermission(); |
| 9681 | } else { |
| 9682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9683 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9684 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9685 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9686 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9687 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9688 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9689 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9690 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9691 | return; |
| 9692 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9693 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9694 | } finally { |
| 9695 | Binder.restoreCallingIdentity(identity); |
| 9696 | } |
| 9697 | } |
| 9698 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9699 | @Override |
| 9700 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9701 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9702 | Phone phone = getPhone(subId); |
| 9703 | if (phone == null) { |
| 9704 | return false; |
| 9705 | } |
| 9706 | final long identity = Binder.clearCallingIdentity(); |
| 9707 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9708 | UiccPort uiccPort = phone.getUiccPort(); |
| 9709 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9710 | return false; |
| 9711 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9712 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9713 | if (uiccProfile == null) { |
| 9714 | return false; |
| 9715 | } |
| 9716 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9717 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9718 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9719 | } |
| 9720 | return false; |
| 9721 | } finally { |
| 9722 | Binder.restoreCallingIdentity(identity); |
| 9723 | } |
| 9724 | } |
| 9725 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9726 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9727 | * Get whether making changes to modem configurations will trigger reboot. |
| 9728 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9729 | */ |
| 9730 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9731 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9732 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9733 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9734 | mApp, subId, callingPackage, callingFeatureId, |
| 9735 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9736 | return false; |
| 9737 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9738 | final long identity = Binder.clearCallingIdentity(); |
| 9739 | try { |
| 9740 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9741 | } finally { |
| 9742 | Binder.restoreCallingIdentity(identity); |
| 9743 | } |
| 9744 | } |
| 9745 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9746 | private void updateModemStateMetrics() { |
| 9747 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9748 | // TODO: check the state for each modem if the api is ready. |
| 9749 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9750 | } |
| 9751 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9752 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9753 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9754 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9755 | // Verify that the callingPackage belongs to the calling UID |
| 9756 | mApp.getSystemService(AppOpsManager.class) |
| 9757 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9758 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9759 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9760 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9761 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9762 | if (slotInfos != null) { |
| 9763 | for (int i = 0; i < slotInfos.length; i++) { |
| 9764 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9765 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9766 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9767 | portInfo.getLogicalSlotIndex())); |
| 9768 | } |
| 9769 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9770 | } |
| 9771 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9772 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9773 | } finally { |
| 9774 | Binder.restoreCallingIdentity(identity); |
| 9775 | } |
| 9776 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9777 | |
| 9778 | /** |
| 9779 | * Get the IRadio HAL Version |
| 9780 | */ |
| 9781 | @Override |
| 9782 | public int getRadioHalVersion() { |
| 9783 | Phone phone = getDefaultPhone(); |
| 9784 | if (phone == null) return -1; |
| 9785 | HalVersion hv = phone.getHalVersion(); |
| 9786 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9787 | return hv.major * 100 + hv.minor; |
| 9788 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9789 | |
| 9790 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9791 | * Get the current calling package name. |
| 9792 | * @return the current calling package name |
| 9793 | */ |
| 9794 | @Override |
| 9795 | public String getCurrentPackageName() { |
| 9796 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9797 | } |
| 9798 | |
| 9799 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9800 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9801 | * corresponding network requests on a subId. |
| 9802 | * |
| 9803 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9804 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9805 | * 2) APN is un-metered for this subscription, or |
| 9806 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9807 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9808 | * |
| 9809 | * @return whether data is allowed for a apn type. |
| 9810 | * |
| 9811 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9812 | */ |
| 9813 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9814 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9815 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9816 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9817 | |
| 9818 | // Now that all security checks passes, perform the operation as ourselves. |
| 9819 | final long identity = Binder.clearCallingIdentity(); |
| 9820 | try { |
| 9821 | Phone phone = getPhone(subId); |
| 9822 | if (phone == null) return false; |
| 9823 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9824 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9825 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9826 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9827 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9828 | phone.getServiceState().getDataRoaming()); |
| 9829 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9830 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9831 | } finally { |
| 9832 | Binder.restoreCallingIdentity(identity); |
| 9833 | } |
| 9834 | } |
| 9835 | |
| 9836 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9837 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9838 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9839 | |
| 9840 | // Now that all security checks passes, perform the operation as ourselves. |
| 9841 | final long identity = Binder.clearCallingIdentity(); |
| 9842 | try { |
| 9843 | Phone phone = getPhone(subId); |
| 9844 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9845 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9846 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9847 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9848 | } finally { |
| 9849 | Binder.restoreCallingIdentity(identity); |
| 9850 | } |
| 9851 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9852 | |
| 9853 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9854 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9855 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9856 | enforceModifyPermission(); |
| 9857 | long token = Binder.clearCallingIdentity(); |
| 9858 | try { |
| 9859 | Phone phone = getPhone(subscriptionId); |
| 9860 | if (phone == null) { |
| 9861 | try { |
| 9862 | if (resultCallback != null) { |
| 9863 | resultCallback.accept(false); |
| 9864 | } |
| 9865 | } catch (RemoteException e) { |
| 9866 | // ignore |
| 9867 | } |
| 9868 | return; |
| 9869 | } |
| 9870 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9871 | Pair.create(specifiers, (x) -> { |
| 9872 | try { |
| 9873 | if (resultCallback != null) { |
| 9874 | resultCallback.accept(x); |
| 9875 | } |
| 9876 | } catch (RemoteException e) { |
| 9877 | // ignore |
| 9878 | } |
| 9879 | }); |
| 9880 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9881 | } finally { |
| 9882 | Binder.restoreCallingIdentity(token); |
| 9883 | } |
| 9884 | } |
| 9885 | |
| 9886 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9887 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9888 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9889 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9890 | mApp, subId, "getSystemSelectionChannels"); |
| 9891 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9892 | final long identity = Binder.clearCallingIdentity(); |
| 9893 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9894 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9895 | if (result instanceof IllegalStateException) { |
| 9896 | throw (IllegalStateException) result; |
| 9897 | } |
| 9898 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9899 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9900 | return specifiers; |
| 9901 | } finally { |
| 9902 | Binder.restoreCallingIdentity(identity); |
| 9903 | } |
| 9904 | } |
| 9905 | |
| 9906 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9907 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9908 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9909 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9910 | } |
| 9911 | |
| 9912 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9913 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9914 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9915 | if (callingPackage == null) { |
| 9916 | callingPackage = getCurrentPackageName(); |
| 9917 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9918 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9919 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9920 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9921 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9922 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9923 | } |
| 9924 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9925 | Intent intent = new Intent(); |
| 9926 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9927 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9928 | // Bring up choose default SMS subscription dialog right now |
| 9929 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9930 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9931 | mApp.startActivity(intent); |
| 9932 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9933 | |
| 9934 | @Override |
| 9935 | public String getMmsUAProfUrl(int subId) { |
| 9936 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9937 | final long identity = Binder.clearCallingIdentity(); |
| 9938 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9939 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9940 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9941 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9942 | return carrierUAProfUrl; |
| 9943 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9944 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9945 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9946 | } finally { |
| 9947 | Binder.restoreCallingIdentity(identity); |
| 9948 | } |
| 9949 | } |
| 9950 | |
| 9951 | @Override |
| 9952 | public String getMmsUserAgent(int subId) { |
| 9953 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9954 | final long identity = Binder.clearCallingIdentity(); |
| 9955 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9956 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9957 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9958 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9959 | return carrierUserAgent; |
| 9960 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9961 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9962 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9963 | } finally { |
| 9964 | Binder.restoreCallingIdentity(identity); |
| 9965 | } |
| 9966 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9967 | |
| 9968 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9969 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9970 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9971 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9972 | final long identity = Binder.clearCallingIdentity(); |
| 9973 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9974 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9975 | if (phone == null) return false; |
| 9976 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 9977 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9978 | } finally { |
| 9979 | Binder.restoreCallingIdentity(identity); |
| 9980 | } |
| 9981 | } |
| 9982 | |
| 9983 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9984 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9985 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9986 | enforceModifyPermission(); |
| 9987 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9988 | final long identity = Binder.clearCallingIdentity(); |
| 9989 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9990 | Phone phone = getPhone(subscriptionId); |
| 9991 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9992 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 9993 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9994 | } finally { |
| 9995 | Binder.restoreCallingIdentity(identity); |
| 9996 | } |
| 9997 | } |
| 9998 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9999 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10000 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10001 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10002 | * otherwise. |
| 10003 | */ |
| 10004 | @Override |
| 10005 | public void setCepEnabled(boolean isCepEnabled) { |
| 10006 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10007 | |
| 10008 | final long identity = Binder.clearCallingIdentity(); |
| 10009 | try { |
| 10010 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10011 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10012 | Phone defaultPhone = phone.getImsPhone(); |
| 10013 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10014 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10015 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10016 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10017 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10018 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10019 | + imsPhone.getMsisdn()); |
| 10020 | } |
| 10021 | } |
| 10022 | } finally { |
| 10023 | Binder.restoreCallingIdentity(identity); |
| 10024 | } |
| 10025 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10026 | |
| 10027 | /** |
| 10028 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10029 | * |
| 10030 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10031 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10032 | * before being read. |
| 10033 | */ |
| 10034 | @Override |
| 10035 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10036 | isCompressed) { |
| 10037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10038 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10039 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10040 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10041 | } |
| 10042 | if (!isImsAvailableOnDevice()) { |
| 10043 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10044 | "IMS not available on device."); |
| 10045 | } |
| 10046 | |
| 10047 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10048 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10049 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10050 | } finally { |
| 10051 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10052 | } |
| 10053 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10054 | |
| 10055 | @Override |
| 10056 | public boolean isIccLockEnabled(int subId) { |
| 10057 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10058 | |
| 10059 | // Now that all security checks passes, perform the operation as ourselves. |
| 10060 | final long identity = Binder.clearCallingIdentity(); |
| 10061 | try { |
| 10062 | Phone phone = getPhone(subId); |
| 10063 | if (phone != null && phone.getIccCard() != null) { |
| 10064 | return phone.getIccCard().getIccLockEnabled(); |
| 10065 | } else { |
| 10066 | return false; |
| 10067 | } |
| 10068 | } finally { |
| 10069 | Binder.restoreCallingIdentity(identity); |
| 10070 | } |
| 10071 | } |
| 10072 | |
| 10073 | /** |
| 10074 | * Set the ICC pin lock enabled or disabled. |
| 10075 | * |
| 10076 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10077 | * three cases: |
| 10078 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10079 | * successfully. |
| 10080 | * - Positive number and zero for remaining password attempts. |
| 10081 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10082 | * |
| 10083 | */ |
| 10084 | @Override |
| 10085 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10086 | enforceModifyPermission(); |
| 10087 | |
| 10088 | Phone phone = getPhone(subId); |
| 10089 | if (phone == null) { |
| 10090 | return 0; |
| 10091 | } |
| 10092 | // Now that all security checks passes, perform the operation as ourselves. |
| 10093 | final long identity = Binder.clearCallingIdentity(); |
| 10094 | try { |
| 10095 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10096 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10097 | return attemptsRemaining; |
| 10098 | |
| 10099 | } catch (Exception e) { |
| 10100 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10101 | } finally { |
| 10102 | Binder.restoreCallingIdentity(identity); |
| 10103 | } |
| 10104 | return 0; |
| 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * Change the ICC password used in ICC pin lock. |
| 10109 | * |
| 10110 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10111 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10112 | * - Positive number and zero for remaining password attempts. |
| 10113 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10114 | * |
| 10115 | */ |
| 10116 | @Override |
| 10117 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10118 | enforceModifyPermission(); |
| 10119 | |
| 10120 | Phone phone = getPhone(subId); |
| 10121 | if (phone == null) { |
| 10122 | return 0; |
| 10123 | } |
| 10124 | // Now that all security checks passes, perform the operation as ourselves. |
| 10125 | final long identity = Binder.clearCallingIdentity(); |
| 10126 | try { |
| 10127 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10128 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10129 | return attemptsRemaining; |
| 10130 | |
| 10131 | } catch (Exception e) { |
| 10132 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10133 | } finally { |
| 10134 | Binder.restoreCallingIdentity(identity); |
| 10135 | } |
| 10136 | return 0; |
| 10137 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10138 | |
| 10139 | /** |
| 10140 | * Request for receiving user activity notification |
| 10141 | */ |
| 10142 | @Override |
| 10143 | public void requestUserActivityNotification() { |
| 10144 | if (!mNotifyUserActivity.get() |
| 10145 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10146 | mNotifyUserActivity.set(true); |
| 10147 | } |
| 10148 | } |
| 10149 | |
| 10150 | /** |
| 10151 | * Called when userActivity is signalled in the power manager. |
| 10152 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10153 | */ |
| 10154 | @Override |
| 10155 | public void userActivity() { |
| 10156 | // *************************************** |
| 10157 | // * Inherited from PhoneWindowManager * |
| 10158 | // *************************************** |
| 10159 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10160 | // WITH ITS LOCKS HELD. |
| 10161 | // |
| 10162 | // This code must be VERY careful about the locks |
| 10163 | // it acquires. |
| 10164 | // In fact, the current code acquires way too many, |
| 10165 | // and probably has lurking deadlocks. |
| 10166 | |
| 10167 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10168 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10169 | } |
| 10170 | |
| 10171 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10172 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10173 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10174 | } |
| 10175 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10176 | |
| 10177 | @Override |
| 10178 | public boolean canConnectTo5GInDsdsMode() { |
| 10179 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10180 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10181 | |
| 10182 | @Override |
| 10183 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10184 | String callingFeatureId) { |
| 10185 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10186 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10187 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10188 | } |
| 10189 | |
| 10190 | Phone phone = getPhone(subId); |
| 10191 | if (phone == null) { |
| 10192 | throw new RuntimeException("phone is not available"); |
| 10193 | } |
| 10194 | // Now that all security checks passes, perform the operation as ourselves. |
| 10195 | final long identity = Binder.clearCallingIdentity(); |
| 10196 | try { |
| 10197 | return phone.getEquivalentHomePlmns(); |
| 10198 | } finally { |
| 10199 | Binder.restoreCallingIdentity(identity); |
| 10200 | } |
| 10201 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10202 | |
| 10203 | @Override |
| 10204 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10205 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10206 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10207 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10208 | if (radioInterfaceCapabilities == null) { |
| 10209 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10210 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10211 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10212 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10213 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10214 | @Override |
| 10215 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10216 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10217 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10218 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10219 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10220 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10221 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10222 | if (DBG) { |
| 10223 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10224 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10225 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10226 | } |
| 10227 | |
| 10228 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10229 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10230 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10231 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10232 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10233 | if (callback != null) { |
| 10234 | try { |
| 10235 | callback.onAuthenticationFailure( |
| 10236 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10237 | } catch (RemoteException exception) { |
| 10238 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10239 | } |
| 10240 | return; |
| 10241 | } |
| 10242 | } |
| 10243 | |
| 10244 | final long token = Binder.clearCallingIdentity(); |
| 10245 | try { |
| 10246 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10247 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10248 | forceBootStrapping, callback)); |
| 10249 | } finally { |
| 10250 | Binder.restoreCallingIdentity(token); |
| 10251 | } |
| 10252 | } |
| 10253 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10254 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10255 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10256 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10257 | * requested radio power state will actually be set. See {@link |
| 10258 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10259 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10260 | * @param enable {@code true} if trying to turn radio on. |
| 10261 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10262 | * false}. |
| 10263 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10264 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10265 | boolean isPhoneAvailable = false; |
| 10266 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10267 | Phone phone = PhoneFactory.getPhone(i); |
| 10268 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10269 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10270 | isPhoneAvailable = true; |
| 10271 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10272 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10273 | |
| 10274 | // return true if successfully informed the phone object about the thermal radio power |
| 10275 | // request. |
| 10276 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10277 | } |
| 10278 | |
| 10279 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10280 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10281 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10282 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10283 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10284 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10285 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10286 | } |
| 10287 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10288 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10289 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10290 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10291 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10292 | } |
| 10293 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10294 | setDataEnabledForReason( |
| 10295 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10296 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10297 | if (isDataThrottlingSupported) { |
| 10298 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10299 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10300 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10301 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10302 | } else if (thermalMitigationResult |
| 10303 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10304 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10305 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10306 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10307 | } |
| 10308 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10309 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10310 | |
| 10311 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10312 | } |
| 10313 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10314 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10315 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10316 | for (String pckg : context.getResources() |
| 10317 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10318 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10319 | } |
| 10320 | } |
| 10321 | |
| 10322 | return sThermalMitigationAllowlistedPackages; |
| 10323 | } |
| 10324 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10325 | private boolean isAnyPhoneInEmergencyState() { |
| 10326 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10327 | if (tm.isInEmergencyCall()) { |
| 10328 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10329 | return true; |
| 10330 | } |
| 10331 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10332 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10333 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10334 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10335 | + phone.isInEcm()); |
| 10336 | return true; |
| 10337 | } |
| 10338 | } |
| 10339 | |
| 10340 | return false; |
| 10341 | } |
| 10342 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10343 | /** |
| 10344 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10345 | * @param packageName name of package to be allowlisted |
| 10346 | * @param context |
| 10347 | */ |
| 10348 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10349 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10350 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10351 | } |
| 10352 | |
| 10353 | /** |
| 10354 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10355 | * @param packageName name of package to remove from allowlist |
| 10356 | * @param context |
| 10357 | */ |
| 10358 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10359 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10360 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10361 | } |
| 10362 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10363 | /** |
| 10364 | * Thermal mitigation request to control functionalities at modem. |
| 10365 | * |
| 10366 | * @param subId the id of the subscription. |
| 10367 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10368 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10369 | * |
| 10370 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10371 | */ |
| 10372 | @Override |
| 10373 | @ThermalMitigationResult |
| 10374 | public int sendThermalMitigationRequest( |
| 10375 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10376 | ThermalMitigationRequest thermalMitigationRequest, |
| 10377 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10378 | enforceModifyPermission(); |
| 10379 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10380 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10381 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10382 | .contains(callingPackage)) { |
| 10383 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10384 | + "calling package: " + callingPackage); |
| 10385 | } |
| 10386 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10387 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10388 | final long identity = Binder.clearCallingIdentity(); |
| 10389 | |
| 10390 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10391 | try { |
| 10392 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10393 | switch (thermalMitigationAction) { |
| 10394 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10395 | thermalMitigationResult = |
| 10396 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10397 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10398 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10399 | break; |
| 10400 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10401 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10402 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10403 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10404 | } |
| 10405 | |
| 10406 | // Ensure that radio is on. If not able to power on due to phone being |
| 10407 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10408 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10409 | thermalMitigationResult = |
| 10410 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10411 | break; |
| 10412 | } |
| 10413 | |
| 10414 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10415 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10416 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10417 | break; |
| 10418 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10419 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10420 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10421 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10422 | } |
| 10423 | |
| 10424 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10425 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10426 | Phone phone = getPhone(subId); |
| 10427 | if (phone == null) { |
| 10428 | thermalMitigationResult = |
| 10429 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10430 | break; |
| 10431 | } |
| 10432 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10433 | TelephonyConnectionService service = |
| 10434 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10435 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10436 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10437 | thermalMitigationResult = |
| 10438 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10439 | break; |
| 10440 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10441 | thermalMitigationResult = |
| 10442 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10443 | break; |
| 10444 | } |
| 10445 | } else { |
| 10446 | thermalMitigationResult = |
| 10447 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10448 | break; |
| 10449 | } |
| 10450 | |
| 10451 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10452 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10453 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10454 | thermalMitigationResult = |
| 10455 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10456 | break; |
| 10457 | } |
| 10458 | thermalMitigationResult = |
| 10459 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10460 | break; |
| 10461 | default: |
| 10462 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10463 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10464 | } |
| 10465 | } catch (IllegalArgumentException e) { |
| 10466 | throw e; |
| 10467 | } catch (Exception e) { |
| 10468 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10469 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10470 | } finally { |
| 10471 | Binder.restoreCallingIdentity(identity); |
| 10472 | } |
| 10473 | |
| 10474 | if (DBG) { |
| 10475 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10476 | + thermalMitigationResult); |
| 10477 | } |
| 10478 | |
| 10479 | return thermalMitigationResult; |
| 10480 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10481 | |
| 10482 | /** |
| 10483 | * Set the GbaService Package Name that Telephony will bind to. |
| 10484 | * |
| 10485 | * @param subId The sim that the GbaService is associated with. |
| 10486 | * @param packageName The name of the package to be replaced with. |
| 10487 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10488 | */ |
| 10489 | @Override |
| 10490 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10491 | enforceModifyPermission(); |
| 10492 | |
| 10493 | final long identity = Binder.clearCallingIdentity(); |
| 10494 | try { |
| 10495 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10496 | } finally { |
| 10497 | Binder.restoreCallingIdentity(identity); |
| 10498 | } |
| 10499 | } |
| 10500 | |
| 10501 | /** |
| 10502 | * Return the package name of the currently bound GbaService. |
| 10503 | * |
| 10504 | * @param subId The sim that the GbaService is associated with. |
| 10505 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10506 | */ |
| 10507 | @Override |
| 10508 | public String getBoundGbaService(int subId) { |
| 10509 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10510 | |
| 10511 | final long identity = Binder.clearCallingIdentity(); |
| 10512 | try { |
| 10513 | return getGbaManager(subId).getServicePackage(); |
| 10514 | } finally { |
| 10515 | Binder.restoreCallingIdentity(identity); |
| 10516 | } |
| 10517 | } |
| 10518 | |
| 10519 | /** |
| 10520 | * Set the release time for telephony to unbind GbaService. |
| 10521 | * |
| 10522 | * @param subId The sim that the GbaService is associated with. |
| 10523 | * @param interval The release time to unbind GbaService by millisecond. |
| 10524 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10525 | */ |
| 10526 | @Override |
| 10527 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10528 | enforceModifyPermission(); |
| 10529 | |
| 10530 | final long identity = Binder.clearCallingIdentity(); |
| 10531 | try { |
| 10532 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10533 | } finally { |
| 10534 | Binder.restoreCallingIdentity(identity); |
| 10535 | } |
| 10536 | } |
| 10537 | |
| 10538 | /** |
| 10539 | * Return the release time for telephony to unbind GbaService. |
| 10540 | * |
| 10541 | * @param subId The sim that the GbaService is associated with. |
| 10542 | * @return The release time to unbind GbaService by millisecond. |
| 10543 | */ |
| 10544 | @Override |
| 10545 | public int getGbaReleaseTime(int subId) { |
| 10546 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10547 | |
| 10548 | final long identity = Binder.clearCallingIdentity(); |
| 10549 | try { |
| 10550 | return getGbaManager(subId).getReleaseTime(); |
| 10551 | } finally { |
| 10552 | Binder.restoreCallingIdentity(identity); |
| 10553 | } |
| 10554 | } |
| 10555 | |
| 10556 | private GbaManager getGbaManager(int subId) { |
| 10557 | GbaManager instance = GbaManager.getInstance(subId); |
| 10558 | if (instance == null) { |
| 10559 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10560 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10561 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10562 | } |
| 10563 | return instance; |
| 10564 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10565 | |
| 10566 | /** |
| 10567 | * indicate whether the device and the carrier can support |
| 10568 | * RCS VoLTE single registration. |
| 10569 | */ |
| 10570 | @Override |
| 10571 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10572 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10573 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10574 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10575 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10576 | |
| 10577 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10578 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10579 | } |
| 10580 | |
| 10581 | final long identity = Binder.clearCallingIdentity(); |
| 10582 | try { |
| 10583 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10584 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10585 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10586 | if (isCapable != null) { |
| 10587 | return isCapable; |
| 10588 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10589 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10590 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10591 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10592 | } finally { |
| 10593 | Binder.restoreCallingIdentity(identity); |
| 10594 | } |
| 10595 | } |
| 10596 | |
| 10597 | /** |
| 10598 | * Register RCS provisioning callback. |
| 10599 | */ |
| 10600 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10601 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10602 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10603 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10604 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10605 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10606 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10607 | |
| 10608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10609 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10610 | } |
| 10611 | if (!isImsAvailableOnDevice()) { |
| 10612 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10613 | "IMS not available on device."); |
| 10614 | } |
| 10615 | |
| 10616 | final long identity = Binder.clearCallingIdentity(); |
| 10617 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10618 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10619 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10620 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10621 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10622 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10623 | } finally { |
| 10624 | Binder.restoreCallingIdentity(identity); |
| 10625 | } |
| 10626 | } |
| 10627 | |
| 10628 | /** |
| 10629 | * Unregister RCS provisioning callback. |
| 10630 | */ |
| 10631 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10632 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10633 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10634 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10635 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10636 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10637 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10638 | |
| 10639 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10640 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10641 | } |
| 10642 | if (!isImsAvailableOnDevice()) { |
| 10643 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10644 | "IMS not available on device."); |
| 10645 | } |
| 10646 | |
| 10647 | final long identity = Binder.clearCallingIdentity(); |
| 10648 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10649 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10650 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10651 | } finally { |
| 10652 | Binder.restoreCallingIdentity(identity); |
| 10653 | } |
| 10654 | } |
| 10655 | |
| 10656 | /** |
| 10657 | * trigger RCS reconfiguration. |
| 10658 | */ |
| 10659 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10660 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10661 | "triggerRcsReconfiguration", |
| 10662 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10663 | |
| 10664 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10665 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10666 | } |
| 10667 | if (!isImsAvailableOnDevice()) { |
| 10668 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10669 | "IMS not available on device."); |
| 10670 | } |
| 10671 | |
| 10672 | final long identity = Binder.clearCallingIdentity(); |
| 10673 | try { |
| 10674 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
| 10680 | /** |
| 10681 | * Provide the client configuration parameters of the RCS application. |
| 10682 | */ |
| 10683 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10684 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10685 | "setRcsClientConfiguration", |
| 10686 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10687 | |
| 10688 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10689 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10690 | } |
| 10691 | if (!isImsAvailableOnDevice()) { |
| 10692 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10693 | "IMS not available on device."); |
| 10694 | } |
| 10695 | |
| 10696 | final long identity = Binder.clearCallingIdentity(); |
| 10697 | |
| 10698 | try { |
| 10699 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10700 | if (configBinder == null) { |
| 10701 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10702 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10703 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10704 | } else { |
| 10705 | configBinder.setRcsClientConfiguration(rcc); |
| 10706 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10707 | |
| 10708 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10709 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10710 | } catch (RemoteException e) { |
| 10711 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10712 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10713 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10714 | } finally { |
| 10715 | Binder.restoreCallingIdentity(identity); |
| 10716 | } |
| 10717 | } |
| 10718 | |
| 10719 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10720 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10721 | */ |
| 10722 | @Override |
| 10723 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10724 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10725 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10726 | |
| 10727 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10728 | } |
| 10729 | |
| 10730 | /** |
| 10731 | * Gets the test mode for RCS VoLTE single registration. |
| 10732 | */ |
| 10733 | @Override |
| 10734 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10735 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10736 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10737 | |
| 10738 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10739 | } |
| 10740 | |
| 10741 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10742 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10743 | */ |
| 10744 | @Override |
| 10745 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10746 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10747 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10748 | enforceModifyPermission(); |
| 10749 | |
| 10750 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10751 | : Boolean.parseBoolean(enabledStr); |
| 10752 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10753 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10754 | } |
| 10755 | |
| 10756 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10757 | * Sends a device to device communication message. Only usable via shell. |
| 10758 | * @param message message to send. |
| 10759 | * @param value message value. |
| 10760 | */ |
| 10761 | @Override |
| 10762 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10763 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10764 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10765 | enforceModifyPermission(); |
| 10766 | |
| 10767 | final long identity = Binder.clearCallingIdentity(); |
| 10768 | try { |
| 10769 | TelephonyConnectionService service = |
| 10770 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10771 | if (service == null) { |
| 10772 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10773 | return; |
| 10774 | } |
| 10775 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10776 | } finally { |
| 10777 | Binder.restoreCallingIdentity(identity); |
| 10778 | } |
| 10779 | } |
| 10780 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10781 | /** |
| 10782 | * Sets the specified device to device transport active. |
| 10783 | * @param transport The transport to set active. |
| 10784 | */ |
| 10785 | @Override |
| 10786 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10787 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10788 | "setActiveDeviceToDeviceTransport"); |
| 10789 | enforceModifyPermission(); |
| 10790 | |
| 10791 | final long identity = Binder.clearCallingIdentity(); |
| 10792 | try { |
| 10793 | TelephonyConnectionService service = |
| 10794 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10795 | if (service == null) { |
| 10796 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10797 | return; |
| 10798 | } |
| 10799 | service.setActiveDeviceToDeviceTransport(transport); |
| 10800 | } finally { |
| 10801 | Binder.restoreCallingIdentity(identity); |
| 10802 | } |
| 10803 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10804 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10805 | @Override |
| 10806 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10807 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10808 | "setDeviceToDeviceForceEnabled"); |
| 10809 | |
| 10810 | final long identity = Binder.clearCallingIdentity(); |
| 10811 | try { |
| 10812 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10813 | p -> { |
| 10814 | Phone thePhone = p.getImsPhone(); |
| 10815 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10816 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10817 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10818 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10819 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10820 | (ImsPhoneCallTracker) tracker; |
| 10821 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10822 | } |
| 10823 | } |
| 10824 | } |
| 10825 | ); |
| 10826 | } finally { |
| 10827 | Binder.restoreCallingIdentity(identity); |
| 10828 | } |
| 10829 | } |
| 10830 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10831 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10832 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10833 | */ |
| 10834 | @Override |
| 10835 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10836 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10837 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10838 | } |
| 10839 | |
| 10840 | /** |
| 10841 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10842 | */ |
| 10843 | @Override |
| 10844 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10845 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10846 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10847 | enforceModifyPermission(); |
| 10848 | |
| 10849 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10850 | : Boolean.parseBoolean(enabledStr); |
| 10851 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10852 | subId, enabled); |
| 10853 | } |
| 10854 | |
| 10855 | /** |
| 10856 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10857 | */ |
| 10858 | @Override |
| 10859 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10860 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10861 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10862 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10863 | |
| 10864 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10865 | * Overrides the ims feature validation result |
| 10866 | */ |
| 10867 | @Override |
| 10868 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10869 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10870 | "setImsFeatureValidationOverride"); |
| 10871 | |
| 10872 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10873 | : Boolean.parseBoolean(enabledStr); |
| 10874 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10875 | subId, enabled); |
| 10876 | } |
| 10877 | |
| 10878 | /** |
| 10879 | * Gets the ims feature validation override value |
| 10880 | */ |
| 10881 | @Override |
| 10882 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10883 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10884 | "getImsFeatureValidationOverride"); |
| 10885 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10886 | } |
| 10887 | |
| 10888 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10889 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10890 | * their mobile plan. |
| 10891 | */ |
| 10892 | @Override |
| 10893 | public String getMobileProvisioningUrl() { |
| 10894 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10895 | final long identity = Binder.clearCallingIdentity(); |
| 10896 | try { |
| 10897 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10898 | } finally { |
| 10899 | Binder.restoreCallingIdentity(identity); |
| 10900 | } |
| 10901 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10902 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10903 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10904 | * Get the EAB contact from the EAB database. |
| 10905 | */ |
| 10906 | @Override |
| 10907 | public String getContactFromEab(String contact) { |
| 10908 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10909 | enforceModifyPermission(); |
| 10910 | final long identity = Binder.clearCallingIdentity(); |
| 10911 | try { |
| 10912 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10913 | } finally { |
| 10914 | Binder.restoreCallingIdentity(identity); |
| 10915 | } |
| 10916 | } |
| 10917 | |
| 10918 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10919 | * Get the EAB capability from the EAB database. |
| 10920 | */ |
| 10921 | @Override |
| 10922 | public String getCapabilityFromEab(String contact) { |
| 10923 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10924 | enforceModifyPermission(); |
| 10925 | final long identity = Binder.clearCallingIdentity(); |
| 10926 | try { |
| 10927 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10928 | } finally { |
| 10929 | Binder.restoreCallingIdentity(identity); |
| 10930 | } |
| 10931 | } |
| 10932 | |
| 10933 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10934 | * Remove the EAB contacts from the EAB database. |
| 10935 | */ |
| 10936 | @Override |
| 10937 | public int removeContactFromEab(int subId, String contacts) { |
| 10938 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10939 | enforceModifyPermission(); |
| 10940 | final long identity = Binder.clearCallingIdentity(); |
| 10941 | try { |
| 10942 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
| 10947 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10948 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10949 | public boolean getDeviceUceEnabled() { |
| 10950 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10951 | final long identity = Binder.clearCallingIdentity(); |
| 10952 | try { |
| 10953 | return mApp.getDeviceUceEnabled(); |
| 10954 | } finally { |
| 10955 | Binder.restoreCallingIdentity(identity); |
| 10956 | } |
| 10957 | } |
| 10958 | |
| 10959 | @Override |
| 10960 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10961 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10962 | final long identity = Binder.clearCallingIdentity(); |
| 10963 | try { |
| 10964 | mApp.setDeviceUceEnabled(isEnabled); |
| 10965 | } finally { |
| 10966 | Binder.restoreCallingIdentity(identity); |
| 10967 | } |
| 10968 | } |
| 10969 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10970 | /** |
| 10971 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10972 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10973 | */ |
| 10974 | // Used for SHELL command only right now. |
| 10975 | @Override |
| 10976 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10977 | List<String> featureTags) { |
| 10978 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10979 | "addUceRegistrationOverrideShell"); |
| 10980 | final long identity = Binder.clearCallingIdentity(); |
| 10981 | try { |
| 10982 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10983 | new ArraySet<>(featureTags)); |
| 10984 | } catch (ImsException e) { |
| 10985 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10986 | } finally { |
| 10987 | Binder.restoreCallingIdentity(identity); |
| 10988 | } |
| 10989 | } |
| 10990 | |
| 10991 | /** |
| 10992 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10993 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10994 | */ |
| 10995 | // Used for SHELL command only right now. |
| 10996 | @Override |
| 10997 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10998 | List<String> featureTags) { |
| 10999 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11000 | "removeUceRegistrationOverrideShell"); |
| 11001 | final long identity = Binder.clearCallingIdentity(); |
| 11002 | try { |
| 11003 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11004 | new ArraySet<>(featureTags)); |
| 11005 | } catch (ImsException e) { |
| 11006 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11007 | } finally { |
| 11008 | Binder.restoreCallingIdentity(identity); |
| 11009 | } |
| 11010 | } |
| 11011 | |
| 11012 | /** |
| 11013 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11014 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11015 | */ |
| 11016 | // Used for SHELL command only right now. |
| 11017 | @Override |
| 11018 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11019 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11020 | "clearUceRegistrationOverrideShell"); |
| 11021 | final long identity = Binder.clearCallingIdentity(); |
| 11022 | try { |
| 11023 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11024 | } catch (ImsException e) { |
| 11025 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11026 | } finally { |
| 11027 | Binder.restoreCallingIdentity(identity); |
| 11028 | } |
| 11029 | } |
| 11030 | |
| 11031 | /** |
| 11032 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11033 | */ |
| 11034 | // Used for SHELL command only right now. |
| 11035 | @Override |
| 11036 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11038 | "getLatestRcsContactUceCapabilityShell"); |
| 11039 | final long identity = Binder.clearCallingIdentity(); |
| 11040 | try { |
| 11041 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11042 | } catch (ImsException e) { |
| 11043 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11044 | } finally { |
| 11045 | Binder.restoreCallingIdentity(identity); |
| 11046 | } |
| 11047 | } |
| 11048 | |
| 11049 | /** |
| 11050 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11051 | * device does not have an active PUBLISH. |
| 11052 | */ |
| 11053 | // Used for SHELL command only right now. |
| 11054 | @Override |
| 11055 | public String getLastUcePidfXmlShell(int subId) { |
| 11056 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11057 | final long identity = Binder.clearCallingIdentity(); |
| 11058 | try { |
| 11059 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11060 | } catch (ImsException e) { |
| 11061 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
| 11066 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11067 | /** |
| 11068 | * Remove UCE requests cannot be sent to the network status. |
| 11069 | */ |
| 11070 | // Used for SHELL command only right now. |
| 11071 | @Override |
| 11072 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11073 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11074 | final long identity = Binder.clearCallingIdentity(); |
| 11075 | try { |
| 11076 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11077 | } catch (ImsException e) { |
| 11078 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11079 | } finally { |
| 11080 | Binder.restoreCallingIdentity(identity); |
| 11081 | } |
| 11082 | } |
| 11083 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11084 | /** |
| 11085 | * Remove UCE requests cannot be sent to the network status. |
| 11086 | */ |
| 11087 | // Used for SHELL command only. |
| 11088 | @Override |
| 11089 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11090 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11091 | final long identity = Binder.clearCallingIdentity(); |
| 11092 | try { |
| 11093 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11094 | } catch (ImsException e) { |
| 11095 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11096 | } finally { |
| 11097 | Binder.restoreCallingIdentity(identity); |
| 11098 | } |
| 11099 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11100 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11101 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11102 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11103 | String callingPackage) { |
| 11104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11105 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11106 | |
| 11107 | final int callingUid = Binder.getCallingUid(); |
| 11108 | // Verify that tha callingPackage belongs to the calling UID |
| 11109 | mApp.getSystemService(AppOpsManager.class) |
| 11110 | .checkPackage(callingUid, callingPackage); |
| 11111 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11112 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11113 | |
| 11114 | final long identity = Binder.clearCallingIdentity(); |
| 11115 | try { |
| 11116 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11117 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11118 | |
| 11119 | if (result instanceof IllegalStateException) { |
| 11120 | throw (IllegalStateException) result; |
| 11121 | } |
| 11122 | } finally { |
| 11123 | Binder.restoreCallingIdentity(identity); |
| 11124 | } |
| 11125 | } |
| 11126 | |
| 11127 | @Override |
| 11128 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11129 | String callingPackage) { |
| 11130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11131 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11132 | |
| 11133 | final int callingUid = Binder.getCallingUid(); |
| 11134 | // Verify that tha callingPackage belongs to the calling UID |
| 11135 | mApp.getSystemService(AppOpsManager.class) |
| 11136 | .checkPackage(callingUid, callingPackage); |
| 11137 | |
| 11138 | final long identity = Binder.clearCallingIdentity(); |
| 11139 | try { |
| 11140 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11141 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11142 | |
| 11143 | if (result instanceof IllegalStateException) { |
| 11144 | throw (IllegalStateException) result; |
| 11145 | } |
| 11146 | } finally { |
| 11147 | Binder.restoreCallingIdentity(identity); |
| 11148 | } |
| 11149 | } |
| 11150 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11151 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11152 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11153 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11154 | // phone/system process do not have further restriction on request |
| 11155 | return; |
| 11156 | } |
| 11157 | |
| 11158 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11159 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11160 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11161 | context.enforceCallingOrSelfPermission( |
| 11162 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11163 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11164 | } |
| 11165 | |
| 11166 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11167 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11168 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11169 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11170 | || info.isEnabled()) { |
| 11171 | throw new IllegalArgumentException( |
| 11172 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11173 | } |
| 11174 | |
| 11175 | // Thresholds length for each RAN need in range. This has been validated in |
| 11176 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11177 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11178 | final int[] thresholds = info.getThresholds(); |
| 11179 | Objects.requireNonNull(thresholds); |
| 11180 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11181 | || thresholds.length |
| 11182 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11183 | throw new IllegalArgumentException( |
| 11184 | "thresholds length is out of range: " + thresholds.length); |
| 11185 | } |
| 11186 | } |
| 11187 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11188 | |
| 11189 | /** |
| 11190 | * Gets the current phone capability. |
| 11191 | * |
| 11192 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11193 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11194 | * It's used to evaluate possible phone config change, for example from single |
| 11195 | * SIM device to multi-SIM device. |
| 11196 | */ |
| 11197 | @Override |
| 11198 | public PhoneCapability getPhoneCapability() { |
| 11199 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11200 | final long identity = Binder.clearCallingIdentity(); |
| 11201 | try { |
| 11202 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11203 | } finally { |
| 11204 | Binder.restoreCallingIdentity(identity); |
| 11205 | } |
| 11206 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11207 | |
| 11208 | /** |
| 11209 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11210 | * required to be done shortly after the API is invoked. |
| 11211 | */ |
| 11212 | @Override |
| 11213 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11214 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11215 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11216 | enforceRebootPermission(); |
| 11217 | |
| 11218 | final long identity = Binder.clearCallingIdentity(); |
| 11219 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11220 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11221 | } finally { |
| 11222 | Binder.restoreCallingIdentity(identity); |
| 11223 | } |
| 11224 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11225 | |
| 11226 | /** |
| 11227 | * Request to get the current slicing configuration including URSP rules and |
| 11228 | * NSSAIs (configured, allowed and rejected). |
| 11229 | * |
| 11230 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11231 | */ |
| 11232 | @Override |
| 11233 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11234 | TelephonyPermissions |
| 11235 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11236 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11237 | |
| 11238 | final long identity = Binder.clearCallingIdentity(); |
| 11239 | try { |
| 11240 | Phone phone = getDefaultPhone(); |
| 11241 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11242 | } finally { |
| 11243 | Binder.restoreCallingIdentity(identity); |
| 11244 | } |
| 11245 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11246 | |
| 11247 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11248 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11249 | * |
| 11250 | * @param capability The premium capability to check. |
| 11251 | * @param subId The subId to check the premium capability for. |
| 11252 | * |
| 11253 | * @return Whether the given premium capability is available to purchase. |
| 11254 | */ |
| 11255 | @Override |
| 11256 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11257 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11258 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11259 | log("Premium capability " |
| 11260 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11261 | + " is not available for purchase due to missing permissions."); |
| 11262 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11263 | + "permission READ_BASIC_PHONE_STATE."); |
| 11264 | } |
| 11265 | |
| 11266 | Phone phone = getPhone(subId); |
| 11267 | final long identity = Binder.clearCallingIdentity(); |
| 11268 | try { |
| 11269 | return SliceStore.getInstance(phone) |
| 11270 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11271 | } finally { |
| 11272 | Binder.restoreCallingIdentity(identity); |
| 11273 | } |
| 11274 | } |
| 11275 | |
| 11276 | /** |
| 11277 | * Purchase the given premium capability from the carrier. |
| 11278 | * |
| 11279 | * @param capability The premium capability to purchase. |
| 11280 | * @param callback The result of the purchase request. |
| 11281 | * @param subId The subId to purchase the premium capability for. |
| 11282 | */ |
| 11283 | @Override |
| 11284 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11285 | log("purchasePremiumCapability: capability=" |
| 11286 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11287 | + getCurrentPackageName()); |
| 11288 | |
| 11289 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11290 | mApp, "purchasePremiumCapability")) { |
| 11291 | log("purchasePremiumCapability " |
| 11292 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11293 | + " failed due to missing permissions."); |
| 11294 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11295 | + "READ_BASIC_PHONE_STATE."); |
| 11296 | } |
| 11297 | |
| 11298 | Phone phone = getPhone(subId); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11299 | String appName; |
| 11300 | try { |
| 11301 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11302 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11303 | } catch (PackageManager.NameNotFoundException e) { |
| 11304 | appName = "An application"; |
| 11305 | } |
| 11306 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11307 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11308 | } |
| 11309 | |
| 11310 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11311 | * Register an IMS connection state callback |
| 11312 | */ |
| 11313 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11314 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11315 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11316 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11317 | // ImsMmTelManager |
| 11318 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11319 | TelephonyPermissions |
| 11320 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11321 | mApp, subId, "registerImsStateCallback"); |
| 11322 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11323 | // ImsRcsManager or SipDelegateManager |
| 11324 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11325 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11326 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11327 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11328 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11329 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11330 | } |
| 11331 | |
| 11332 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11333 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11334 | "IMS not available on device."); |
| 11335 | } |
| 11336 | |
| 11337 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11338 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11339 | } |
| 11340 | |
| 11341 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11342 | if (controller == null) { |
| 11343 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11344 | "IMS not available on device."); |
| 11345 | } |
| 11346 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11347 | if (callingPackage == null) { |
| 11348 | callingPackage = getCurrentPackageName(); |
| 11349 | } |
| 11350 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11351 | final long token = Binder.clearCallingIdentity(); |
| 11352 | try { |
| 11353 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11354 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11355 | } catch (ImsException e) { |
| 11356 | throw new ServiceSpecificException(e.getCode()); |
| 11357 | } finally { |
| 11358 | Binder.restoreCallingIdentity(token); |
| 11359 | } |
| 11360 | } |
| 11361 | |
| 11362 | /** |
| 11363 | * Unregister an IMS connection state callback |
| 11364 | */ |
| 11365 | @Override |
| 11366 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11367 | final long token = Binder.clearCallingIdentity(); |
| 11368 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11369 | if (controller == null) { |
| 11370 | return; |
| 11371 | } |
| 11372 | try { |
| 11373 | controller.unregisterImsStateCallback(cb); |
| 11374 | } finally { |
| 11375 | Binder.restoreCallingIdentity(token); |
| 11376 | } |
| 11377 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11378 | |
| 11379 | /** |
| 11380 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11381 | * |
| 11382 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11383 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11384 | * SecurityException. |
| 11385 | * If there is current registered network this value will be same as the registered cell |
| 11386 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11387 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11388 | * it will be cleared and null will be returned. |
| 11389 | * |
| 11390 | */ |
| 11391 | @Override |
| 11392 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11393 | String callingFeatureId) { |
| 11394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11395 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11396 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11397 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11398 | .setCallingPackage(callingPackage) |
| 11399 | .setCallingFeatureId(callingFeatureId) |
| 11400 | .setCallingPid(Binder.getCallingPid()) |
| 11401 | .setCallingUid(Binder.getCallingUid()) |
| 11402 | .setMethod("getLastKnownCellIdentity") |
| 11403 | .setLogAsInfo(true) |
| 11404 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11405 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11406 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11407 | .build()); |
| 11408 | |
| 11409 | boolean hasFinePermission = |
| 11410 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11411 | if (!hasFinePermission |
| 11412 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11413 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11414 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11415 | } |
| 11416 | |
| 11417 | final long identity = Binder.clearCallingIdentity(); |
| 11418 | try { |
| 11419 | Phone phone = getPhone(subId); |
| 11420 | if (phone == null) return null; |
| 11421 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11422 | if (sst == null) return null; |
| 11423 | return sst.getLastKnownCellIdentity(); |
| 11424 | } finally { |
| 11425 | Binder.restoreCallingIdentity(identity); |
| 11426 | } |
| 11427 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11428 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11429 | /** |
| 11430 | * Sets the modem service class Name that Telephony will bind to. |
| 11431 | * |
| 11432 | * @param serviceName The class name of the modem service. |
| 11433 | * @return true if the operation is succeed, otherwise false. |
| 11434 | */ |
| 11435 | public boolean setModemService(String serviceName) { |
| 11436 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11437 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11439 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11440 | "setModemService"); |
| 11441 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11442 | } |
| 11443 | |
| 11444 | /** |
| 11445 | * Return the class name of the currently bounded modem service. |
| 11446 | * |
| 11447 | * @return the class name of the modem service. |
| 11448 | */ |
| 11449 | public String getModemService() { |
| 11450 | String result; |
| 11451 | Log.d(LOG_TAG, "getModemService"); |
| 11452 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11453 | TelephonyPermissions |
| 11454 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11455 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11456 | "getModemService"); |
| 11457 | result = mPhoneConfigurationManager.getModemService(); |
| 11458 | Log.d(LOG_TAG, "result = " + result); |
| 11459 | return result; |
| 11460 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11461 | |
| 11462 | @Override |
| 11463 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11464 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11465 | mApp.enforceCallingOrSelfPermission( |
| 11466 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11467 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11468 | |
| 11469 | final long identity = Binder.clearCallingIdentity(); |
| 11470 | try { |
| 11471 | Phone phone = getPhone(subId); |
| 11472 | if (phone == null) return; |
| 11473 | phone.setVoiceServiceStateOverride(hasService); |
| 11474 | } finally { |
| 11475 | Binder.restoreCallingIdentity(identity); |
| 11476 | } |
| 11477 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11478 | |
| 11479 | /** |
| 11480 | * set removable eSIM as default eUICC. |
| 11481 | * |
| 11482 | * @hide |
| 11483 | */ |
| 11484 | @Override |
| 11485 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11486 | enforceModifyPermission(); |
| 11487 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11488 | |
| 11489 | final long identity = Binder.clearCallingIdentity(); |
| 11490 | try { |
| 11491 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11492 | } finally { |
| 11493 | Binder.restoreCallingIdentity(identity); |
| 11494 | } |
| 11495 | } |
| 11496 | |
| 11497 | /** |
| 11498 | * Returns whether the removable eSIM is default eUICC or not. |
| 11499 | * |
| 11500 | * @hide |
| 11501 | */ |
| 11502 | @Override |
| 11503 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11504 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11505 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11506 | |
| 11507 | final long identity = Binder.clearCallingIdentity(); |
| 11508 | try { |
| 11509 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11510 | } finally { |
| 11511 | Binder.restoreCallingIdentity(identity); |
| 11512 | } |
| 11513 | } |
| 11514 | |
| 11515 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11516 | } |