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; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame^] | 183 | import com.android.internal.telephony.SmsApplication; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 187 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.data.DataUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 194 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.IccIoResult; |
| 199 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 207 | import com.android.internal.telephony.util.LocaleUtils; |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame^] | 208 | import com.android.internal.telephony.util.TelephonyUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 210 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 211 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 212 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 213 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 214 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 215 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 216 | import com.android.phone.slice.SlicePurchaseController; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 218 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 219 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 220 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 221 | import com.android.services.telephony.TelecomAccountRegistry; |
| 222 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 223 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 224 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 225 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 226 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 227 | import java.io.IOException; |
| 228 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 229 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 230 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 231 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 232 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 233 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 234 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 235 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 236 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 237 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 238 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 239 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 240 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 241 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 242 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 243 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 244 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 245 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 246 | |
| 247 | /** |
| 248 | * Implementation of the ITelephony interface. |
| 249 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 250 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 252 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 253 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 254 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 255 | |
| 256 | // Message codes used with mMainThreadHandler |
| 257 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 258 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 259 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 260 | private static final int CMD_OPEN_CHANNEL = 9; |
| 261 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 262 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 263 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 264 | private static final int CMD_NV_READ_ITEM = 13; |
| 265 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 266 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 267 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 268 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 269 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 270 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 271 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 272 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 273 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 274 | private static final int CMD_SEND_ENVELOPE = 25; |
| 275 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 276 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 277 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 278 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 279 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 280 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 281 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 282 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 283 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 284 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 285 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 286 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 287 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 288 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 289 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 290 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 291 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 292 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 293 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 294 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 295 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 296 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 297 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 298 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 299 | private static final int CMD_SWITCH_SLOTS = 50; |
| 300 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 301 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 302 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 303 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 304 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 305 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 306 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 307 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 308 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 310 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 311 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 312 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 313 | private static final int CMD_MODEM_REBOOT = 64; |
| 314 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 315 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 316 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 317 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 318 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 319 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 320 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 321 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 322 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 323 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 324 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 325 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 326 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 327 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 328 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 329 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 330 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 331 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 332 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 333 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 334 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 335 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 336 | private static final int CMD_GET_CALL_WAITING = 87; |
| 337 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 338 | private static final int CMD_SET_CALL_WAITING = 89; |
| 339 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 340 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 341 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 342 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 343 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 344 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 345 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 346 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 347 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 348 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 349 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 350 | private static final int CMD_SET_SIM_POWER = 101; |
| 351 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 352 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 353 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 354 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 355 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 356 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 357 | 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] | 358 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 359 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 360 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 361 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 362 | private static final int CMD_ENABLE_VONR = 113; |
| 363 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 364 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 365 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 366 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 367 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 369 | // Parameters of select command. |
| 370 | private static final int SELECT_COMMAND = 0xA4; |
| 371 | private static final int SELECT_P1 = 0x04; |
| 372 | private static final int SELECT_P2 = 0; |
| 373 | private static final int SELECT_P3 = 0x10; |
| 374 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | /** The singleton instance. */ |
| 376 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 377 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 378 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 380 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 381 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 382 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 383 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 384 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 385 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 386 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 387 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 388 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 389 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 390 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 392 | /** User Activity */ |
| 393 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 394 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 395 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 396 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 397 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 398 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 399 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 400 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 401 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 402 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 403 | // String to store multi SIM allowed |
| 404 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 405 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 406 | // The AID of ISD-R. |
| 407 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 408 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 409 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 410 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 411 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 412 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 413 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 414 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 415 | 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] | 416 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 417 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 418 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 419 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 420 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 421 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 422 | */ |
| 423 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 424 | "reset_network_erase_modem_config_enabled"; |
| 425 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 426 | 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] | 427 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 428 | /** |
| 429 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 430 | * one ICCID active at the same time. |
| 431 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 432 | * |
| 433 | * @hide |
| 434 | */ |
| 435 | @ChangeId |
| 436 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 437 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 438 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 439 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 440 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 441 | * operation fails. |
| 442 | */ |
| 443 | @ChangeId |
| 444 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 445 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 446 | |
| 447 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 448 | * A request object to use for transmitting data to an ICC. |
| 449 | */ |
| 450 | private static final class IccAPDUArgument { |
| 451 | public int channel, cla, command, p1, p2, p3; |
| 452 | public String data; |
| 453 | |
| 454 | public IccAPDUArgument(int channel, int cla, int command, |
| 455 | int p1, int p2, int p3, String data) { |
| 456 | this.channel = channel; |
| 457 | this.cla = cla; |
| 458 | this.command = command; |
| 459 | this.p1 = p1; |
| 460 | this.p2 = p2; |
| 461 | this.p3 = p3; |
| 462 | this.data = data; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 467 | * A request object to use for transmitting data to an ICC. |
| 468 | */ |
| 469 | private static final class ManualNetworkSelectionArgument { |
| 470 | public OperatorInfo operatorInfo; |
| 471 | public boolean persistSelection; |
| 472 | |
| 473 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 474 | this.operatorInfo = operatorInfo; |
| 475 | this.persistSelection = persistSelection; |
| 476 | } |
| 477 | } |
| 478 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 479 | private static final class PurchasePremiumCapabilityArgument { |
| 480 | public @TelephonyManager.PremiumCapability int capability; |
| 481 | public @NonNull String appName; |
| 482 | public @NonNull IIntegerConsumer callback; |
| 483 | |
| 484 | PurchasePremiumCapabilityArgument(@TelephonyManager.PremiumCapability int capability, |
| 485 | @NonNull String appName, @NonNull IIntegerConsumer callback) { |
| 486 | this.capability = capability; |
| 487 | this.appName = appName; |
| 488 | this.callback = callback; |
| 489 | } |
| 490 | } |
| 491 | |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 492 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 494 | * request after sending. The main thread will notify the request when it is complete. |
| 495 | */ |
| 496 | private static final class MainThreadRequest { |
| 497 | /** The argument to use for the request */ |
| 498 | public Object argument; |
| 499 | /** The result of the request that is run on the main thread */ |
| 500 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 501 | // The subscriber id that this request applies to. Defaults to |
| 502 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 503 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 505 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 506 | public Phone phone; |
| 507 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 508 | public WorkSource workSource; |
| 509 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 510 | public MainThreadRequest(Object argument) { |
| 511 | this.argument = argument; |
| 512 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 513 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 514 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 515 | this.argument = argument; |
| 516 | if (phone != null) { |
| 517 | this.phone = phone; |
| 518 | } |
| 519 | this.workSource = workSource; |
| 520 | } |
| 521 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 522 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 523 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 524 | if (subId != null) { |
| 525 | this.subId = subId; |
| 526 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 527 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 531 | private static final class IncomingThirdPartyCallArgs { |
| 532 | public final ComponentName component; |
| 533 | public final String callId; |
| 534 | public final String callerDisplayName; |
| 535 | |
| 536 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 537 | String callerDisplayName) { |
| 538 | this.component = component; |
| 539 | this.callId = callId; |
| 540 | this.callerDisplayName = callerDisplayName; |
| 541 | } |
| 542 | } |
| 543 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | /** |
| 545 | * A handler that processes messages on the main thread in the phone process. Since many |
| 546 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 547 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 548 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 549 | * on, which will be notified when the operation completes and will contain the result of the |
| 550 | * request. |
| 551 | * |
| 552 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 553 | * note that request.result must be set to something non-null for the calling thread to |
| 554 | * unblock. |
| 555 | */ |
| 556 | private final class MainThreadHandler extends Handler { |
| 557 | @Override |
| 558 | public void handleMessage(Message msg) { |
| 559 | MainThreadRequest request; |
| 560 | Message onCompleted; |
| 561 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 562 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 564 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 565 | |
| 566 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 567 | case CMD_HANDLE_USSD_REQUEST: { |
| 568 | request = (MainThreadRequest) msg.obj; |
| 569 | final Phone phone = getPhoneFromRequest(request); |
| 570 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 571 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 573 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 574 | if (!isUssdApiAllowed(request.subId)) { |
| 575 | // Carrier does not support use of this API, return failure. |
| 576 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 577 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 578 | Bundle returnData = new Bundle(); |
| 579 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 580 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 581 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | request.result = true; |
| 583 | notifyRequester(request); |
| 584 | return; |
| 585 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 586 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | try { |
| 588 | request.result = phone != null |
| 589 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 590 | } catch (CallStateException cse) { |
| 591 | request.result = false; |
| 592 | } |
| 593 | // Wake up the requesting thread |
| 594 | notifyRequester(request); |
| 595 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 598 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 599 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 600 | final Phone phone = getPhoneFromRequest(request); |
| 601 | request.result = phone != null ? |
| 602 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 603 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 604 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 606 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 608 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 612 | uiccPort = getUiccPortFromRequest(request); |
| 613 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 614 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 615 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 617 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 618 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 619 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 620 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 621 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 622 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 623 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 624 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 625 | break; |
| 626 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | ar = (AsyncResult) msg.obj; |
| 629 | request = (MainThreadRequest) ar.userObj; |
| 630 | if (ar.exception == null && ar.result != null) { |
| 631 | request.result = ar.result; |
| 632 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | if (ar.result == null) { |
| 635 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 636 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 637 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 638 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | } else { |
| 640 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 641 | } |
| 642 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 643 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | break; |
| 645 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 647 | request = (MainThreadRequest) msg.obj; |
| 648 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 649 | uiccPort = getUiccPortFromRequest(request); |
| 650 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 652 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 653 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | } else { |
| 655 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 656 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 657 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 658 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 659 | iccArgument.p2, |
| 660 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | } |
| 662 | break; |
| 663 | |
| 664 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 665 | ar = (AsyncResult) msg.obj; |
| 666 | request = (MainThreadRequest) ar.userObj; |
| 667 | if (ar.exception == null && ar.result != null) { |
| 668 | request.result = ar.result; |
| 669 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 670 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | if (ar.result == null) { |
| 672 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 673 | } else if (ar.exception instanceof CommandException) { |
| 674 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 675 | ar.exception); |
| 676 | } else { |
| 677 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 678 | } |
| 679 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 680 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case CMD_EXCHANGE_SIM_IO: |
| 684 | request = (MainThreadRequest) msg.obj; |
| 685 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 686 | uiccPort = getUiccPortFromRequest(request); |
| 687 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 689 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 690 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | } else { |
| 692 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 693 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 694 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 695 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 696 | iccArgument.data, onCompleted); |
| 697 | } |
| 698 | break; |
| 699 | |
| 700 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
| 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; |
| 705 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 706 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 708 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 709 | break; |
| 710 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 711 | case CMD_SEND_ENVELOPE: |
| 712 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 713 | uiccPort = getUiccPortFromRequest(request); |
| 714 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 716 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 718 | } else { |
| 719 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 720 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 721 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case EVENT_SEND_ENVELOPE_DONE: |
| 725 | ar = (AsyncResult) msg.obj; |
| 726 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 727 | if (ar.exception == null && ar.result != null) { |
| 728 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 729 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 731 | if (ar.result == null) { |
| 732 | loge("sendEnvelopeWithStatus: Empty response"); |
| 733 | } else if (ar.exception instanceof CommandException) { |
| 734 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 735 | ar.exception); |
| 736 | } else { |
| 737 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 738 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 739 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 741 | break; |
| 742 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | case CMD_OPEN_CHANNEL: |
| 744 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 745 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 746 | IccLogicalChannelRequest openChannelRequest = |
| 747 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 748 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 749 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 750 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 753 | } else { |
| 754 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 755 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 756 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 757 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case EVENT_OPEN_CHANNEL_DONE: |
| 761 | ar = (AsyncResult) msg.obj; |
| 762 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 763 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 765 | int[] result = (int[]) ar.result; |
| 766 | int channelId = result[0]; |
| 767 | byte[] selectResponse = null; |
| 768 | if (result.length > 1) { |
| 769 | selectResponse = new byte[result.length - 1]; |
| 770 | for (int i = 1; i < result.length; ++i) { |
| 771 | selectResponse[i - 1] = (byte) result[i]; |
| 772 | } |
| 773 | } |
| 774 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 775 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 776 | |
| 777 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 778 | if (uiccPort == null) { |
| 779 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 780 | } else { |
| 781 | IccLogicalChannelRequest channelRequest = |
| 782 | (IccLogicalChannelRequest) request.argument; |
| 783 | channelRequest.channel = channelId; |
| 784 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 785 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 787 | if (ar.result == null) { |
| 788 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 789 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 790 | if (ar.exception != null) { |
| 791 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 792 | } |
| 793 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 794 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 795 | if (ar.exception instanceof CommandException) { |
| 796 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 797 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 798 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 799 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 800 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 801 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 805 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 806 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 807 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 808 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 809 | break; |
| 810 | |
| 811 | case CMD_CLOSE_CHANNEL: |
| 812 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 813 | uiccPort = getUiccPortFromRequest(request); |
| 814 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 815 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 816 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 817 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 818 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 819 | } else { |
| 820 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 821 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 822 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 826 | ar = (AsyncResult) msg.obj; |
| 827 | request = (MainThreadRequest) ar.userObj; |
| 828 | if (ar.exception == null) { |
| 829 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 830 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 831 | if (uiccPort == null) { |
| 832 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 833 | } else { |
| 834 | final int channelId = (Integer) request.argument; |
| 835 | uiccPort.onLogicalChannelClosed(channelId); |
| 836 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 837 | } else { |
| 838 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 839 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 840 | if (ar.exception instanceof CommandException) { |
| 841 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 842 | CommandException.Error error = |
| 843 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 844 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 845 | // should only throw exceptions from the binder threads. |
| 846 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 847 | "iccCloseLogicalChannel: invalid argument "); |
| 848 | } |
| 849 | } else { |
| 850 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 851 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 852 | request.result = (exception != null) ? exception : |
| 853 | new IllegalStateException( |
| 854 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 855 | } |
| 856 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 857 | break; |
| 858 | |
| 859 | case CMD_NV_READ_ITEM: |
| 860 | request = (MainThreadRequest) msg.obj; |
| 861 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 862 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 863 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 867 | ar = (AsyncResult) msg.obj; |
| 868 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 869 | if (ar.exception == null && ar.result != null) { |
| 870 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 871 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 872 | request.result = ""; |
| 873 | if (ar.result == null) { |
| 874 | loge("nvReadItem: Empty response"); |
| 875 | } else if (ar.exception instanceof CommandException) { |
| 876 | loge("nvReadItem: CommandException: " + |
| 877 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 878 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 879 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 880 | } |
| 881 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 882 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 883 | break; |
| 884 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | case CMD_NV_WRITE_ITEM: |
| 886 | request = (MainThreadRequest) msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 888 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 889 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 890 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case EVENT_NV_WRITE_ITEM_DONE: |
| 894 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 895 | break; |
| 896 | |
| 897 | case CMD_NV_WRITE_CDMA_PRL: |
| 898 | request = (MainThreadRequest) msg.obj; |
| 899 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 900 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 904 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 905 | break; |
| 906 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 907 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 908 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 909 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 910 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 913 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 914 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 915 | break; |
| 916 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 917 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 918 | request = (MainThreadRequest) msg.obj; |
| 919 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 920 | request); |
| 921 | Phone phone = getPhoneFromRequest(request); |
| 922 | if (phone != null) { |
| 923 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 924 | } else { |
| 925 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 926 | request.result = false; |
| 927 | notifyRequester(request); |
| 928 | } |
| 929 | break; |
| 930 | } |
| 931 | |
| 932 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 933 | ar = (AsyncResult) msg.obj; |
| 934 | request = (MainThreadRequest) ar.userObj; |
| 935 | if (ar.exception == null && ar.result != null) { |
| 936 | request.result = ar.result; |
| 937 | } else { |
| 938 | // request.result must be set to something non-null |
| 939 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 940 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 941 | request.result = ar.result; |
| 942 | } else { |
| 943 | request.result = false; |
| 944 | } |
| 945 | if (ar.result == null) { |
| 946 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 947 | } else if (ar.exception instanceof CommandException) { |
| 948 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 949 | + ar.exception); |
| 950 | } else { |
| 951 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 952 | } |
| 953 | } |
| 954 | notifyRequester(request); |
| 955 | break; |
| 956 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 957 | case CMD_IS_VONR_ENABLED: { |
| 958 | request = (MainThreadRequest) msg.obj; |
| 959 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 960 | request); |
| 961 | Phone phone = getPhoneFromRequest(request); |
| 962 | if (phone != null) { |
| 963 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 964 | } else { |
| 965 | loge("isVoNrEnabled: No phone object"); |
| 966 | request.result = false; |
| 967 | notifyRequester(request); |
| 968 | } |
| 969 | break; |
| 970 | } |
| 971 | |
| 972 | case EVENT_IS_VONR_ENABLED_DONE: |
| 973 | ar = (AsyncResult) msg.obj; |
| 974 | request = (MainThreadRequest) ar.userObj; |
| 975 | if (ar.exception == null && ar.result != null) { |
| 976 | request.result = ar.result; |
| 977 | } else { |
| 978 | // request.result must be set to something non-null |
| 979 | // for the calling thread to unblock |
| 980 | if (ar.result != null) { |
| 981 | request.result = ar.result; |
| 982 | } else { |
| 983 | request.result = false; |
| 984 | } |
| 985 | if (ar.result == null) { |
| 986 | loge("isVoNrEnabled: Empty response"); |
| 987 | } else if (ar.exception instanceof CommandException) { |
| 988 | loge("isVoNrEnabled: CommandException: " |
| 989 | + ar.exception); |
| 990 | } else { |
| 991 | loge("isVoNrEnabled: Unknown exception"); |
| 992 | } |
| 993 | } |
| 994 | notifyRequester(request); |
| 995 | break; |
| 996 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 997 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 998 | request = (MainThreadRequest) msg.obj; |
| 999 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 1000 | Phone phone = getPhoneFromRequest(request); |
| 1001 | if (phone != null) { |
| 1002 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 1003 | request.workSource); |
| 1004 | } else { |
| 1005 | loge("enableNrDualConnectivity: No phone object"); |
| 1006 | request.result = |
| 1007 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 1008 | notifyRequester(request); |
| 1009 | } |
| 1010 | break; |
| 1011 | } |
| 1012 | |
| 1013 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 1014 | ar = (AsyncResult) msg.obj; |
| 1015 | request = (MainThreadRequest) ar.userObj; |
| 1016 | if (ar.exception == null) { |
| 1017 | request.result = |
| 1018 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1019 | } else { |
| 1020 | request.result = |
| 1021 | TelephonyManager |
| 1022 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1023 | if (ar.exception instanceof CommandException) { |
| 1024 | CommandException.Error error = |
| 1025 | ((CommandException) (ar.exception)).getCommandError(); |
| 1026 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1027 | request.result = |
| 1028 | TelephonyManager |
| 1029 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1030 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1031 | request.result = |
| 1032 | TelephonyManager |
| 1033 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1034 | } |
| 1035 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1036 | + ar.exception); |
| 1037 | } else { |
| 1038 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1039 | } |
| 1040 | } |
| 1041 | notifyRequester(request); |
| 1042 | break; |
| 1043 | } |
| 1044 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1045 | case CMD_ENABLE_VONR: { |
| 1046 | request = (MainThreadRequest) msg.obj; |
| 1047 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1048 | Phone phone = getPhoneFromRequest(request); |
| 1049 | if (phone != null) { |
| 1050 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1051 | request.workSource); |
| 1052 | } else { |
| 1053 | loge("setVoNrEnabled: No phone object"); |
| 1054 | request.result = |
| 1055 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1056 | notifyRequester(request); |
| 1057 | } |
| 1058 | break; |
| 1059 | } |
| 1060 | |
| 1061 | case EVENT_ENABLE_VONR_DONE: { |
| 1062 | ar = (AsyncResult) msg.obj; |
| 1063 | request = (MainThreadRequest) ar.userObj; |
| 1064 | if (ar.exception == null) { |
| 1065 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1066 | } else { |
| 1067 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1068 | if (ar.exception instanceof CommandException) { |
| 1069 | CommandException.Error error = |
| 1070 | ((CommandException) (ar.exception)).getCommandError(); |
| 1071 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1072 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1073 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1074 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1075 | } else { |
| 1076 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1077 | } |
| 1078 | loge("setVoNrEnabled" + ": CommandException: " |
| 1079 | + ar.exception); |
| 1080 | } else { |
| 1081 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1082 | } |
| 1083 | } |
| 1084 | notifyRequester(request); |
| 1085 | break; |
| 1086 | } |
| 1087 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1088 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1089 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1090 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1091 | request); |
| 1092 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1093 | break; |
| 1094 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1095 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1096 | ar = (AsyncResult) msg.obj; |
| 1097 | request = (MainThreadRequest) ar.userObj; |
| 1098 | if (ar.exception == null && ar.result != null) { |
| 1099 | request.result = ar.result; // Integer |
| 1100 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1101 | // request.result must be set to something non-null |
| 1102 | // for the calling thread to unblock |
| 1103 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1104 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1105 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1107 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1108 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1109 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1110 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1111 | } |
| 1112 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1113 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1114 | break; |
| 1115 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1116 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1117 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1118 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1119 | request); |
| 1120 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1121 | (Pair<Integer, Long>) request.argument; |
| 1122 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1123 | reasonWithNetworkTypes.first, |
| 1124 | reasonWithNetworkTypes.second, |
| 1125 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1126 | break; |
| 1127 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1128 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1129 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1130 | break; |
| 1131 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1132 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1133 | request = (MainThreadRequest)msg.obj; |
| 1134 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1135 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1136 | break; |
| 1137 | |
| 1138 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1139 | ar = (AsyncResult)msg.obj; |
| 1140 | request = (MainThreadRequest)ar.userObj; |
| 1141 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1142 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1145 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1146 | request = (MainThreadRequest) msg.obj; |
| 1147 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1148 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1149 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1150 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1154 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1155 | break; |
| 1156 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1157 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1160 | request); |
| 1161 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1162 | break; |
| 1163 | |
| 1164 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1165 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1166 | break; |
| 1167 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1168 | case CMD_PERFORM_NETWORK_SCAN: |
| 1169 | request = (MainThreadRequest) msg.obj; |
| 1170 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1171 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1172 | break; |
| 1173 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1175 | request = (MainThreadRequest) msg.obj; |
| 1176 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1177 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1178 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1179 | request.argument; |
| 1180 | int callForwardingReason = args.first; |
| 1181 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1182 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1183 | } |
| 1184 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1185 | ar = (AsyncResult) msg.obj; |
| 1186 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1188 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1189 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1191 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1193 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1194 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1195 | // any service for voice call. |
| 1196 | if ((callForwardInfo.serviceClass |
| 1197 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1198 | callForwardingInfo = new CallForwardingInfo( |
| 1199 | callForwardInfo.status |
| 1200 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1201 | callForwardInfo.reason, |
| 1202 | callForwardInfo.number, |
| 1203 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | break; |
| 1205 | } |
| 1206 | } |
| 1207 | // Didn't find a call forward info for voice call. |
| 1208 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1210 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | } else { |
| 1214 | if (ar.result == null) { |
| 1215 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1216 | } |
| 1217 | if (ar.exception != null) { |
| 1218 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1219 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1220 | int errorCode = TelephonyManager |
| 1221 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | if (ar.exception instanceof CommandException) { |
| 1223 | CommandException.Error error = |
| 1224 | ((CommandException) (ar.exception)).getCommandError(); |
| 1225 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1226 | errorCode = TelephonyManager |
| 1227 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1228 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1229 | errorCode = TelephonyManager |
| 1230 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | } |
| 1232 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1234 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1235 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1238 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | request = (MainThreadRequest) msg.obj; |
| 1240 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1242 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1243 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1244 | request.argument).first; |
| 1245 | request.phone.setCallForwardingOption( |
| 1246 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1247 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | callForwardingInfoToSet.getReason(), |
| 1250 | callForwardingInfoToSet.getNumber(), |
| 1251 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1252 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1255 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | ar = (AsyncResult) msg.obj; |
| 1257 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | Consumer<Integer> callback = |
| 1259 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1260 | request.argument).second; |
| 1261 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1263 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1264 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | if (ar.exception instanceof CommandException) { |
| 1266 | CommandException.Error error = |
| 1267 | ((CommandException) (ar.exception)).getCommandError(); |
| 1268 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1269 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1270 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1272 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1273 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | callback.accept(errorCode); |
| 1277 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1278 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1279 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1281 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1283 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | request = (MainThreadRequest) msg.obj; |
| 1285 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1286 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1287 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1288 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1289 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1290 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | ar = (AsyncResult) msg.obj; |
| 1292 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1293 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1294 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1296 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | // Service Class is a bit mask per 3gpp 27.007. |
| 1298 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1299 | if (callForwardResults.length > 1 |
| 1300 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1302 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1303 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1304 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1306 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | } |
| 1308 | } else { |
| 1309 | if (ar.result == null) { |
| 1310 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1311 | } |
| 1312 | if (ar.exception != null) { |
| 1313 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1314 | } |
| 1315 | if (ar.exception instanceof CommandException) { |
| 1316 | CommandException.Error error = |
| 1317 | ((CommandException) (ar.exception)).getCommandError(); |
| 1318 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1319 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1320 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1321 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1322 | callWaitingStatus = |
| 1323 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1327 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1329 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1330 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1331 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1332 | request = (MainThreadRequest) msg.obj; |
| 1333 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1334 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1335 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1338 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1339 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | ar = (AsyncResult) msg.obj; |
| 1341 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1343 | Consumer<Integer> callback = |
| 1344 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1345 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1346 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1347 | if (ar.exception instanceof CommandException) { |
| 1348 | CommandException.Error error = |
| 1349 | ((CommandException) (ar.exception)).getCommandError(); |
| 1350 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1351 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1352 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1353 | callback.accept( |
| 1354 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1355 | } else { |
| 1356 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1357 | } |
| 1358 | } else { |
| 1359 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1360 | } |
| 1361 | } else { |
| 1362 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1363 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1364 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1365 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1366 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1367 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1368 | ar = (AsyncResult) msg.obj; |
| 1369 | request = (MainThreadRequest) ar.userObj; |
| 1370 | CellNetworkScanResult cellScanResult; |
| 1371 | if (ar.exception == null && ar.result != null) { |
| 1372 | cellScanResult = new CellNetworkScanResult( |
| 1373 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1374 | (List<OperatorInfo>) ar.result); |
| 1375 | } else { |
| 1376 | if (ar.result == null) { |
| 1377 | loge("getCellNetworkScanResults: Empty response"); |
| 1378 | } |
| 1379 | if (ar.exception != null) { |
| 1380 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1381 | } |
| 1382 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1383 | if (ar.exception instanceof CommandException) { |
| 1384 | CommandException.Error error = |
| 1385 | ((CommandException) (ar.exception)).getCommandError(); |
| 1386 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1387 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1388 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1389 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1390 | } |
| 1391 | } |
| 1392 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1393 | } |
| 1394 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1395 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | |
| 1398 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1399 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1400 | ManualNetworkSelectionArgument selArg = |
| 1401 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1402 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1403 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1404 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1405 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1406 | break; |
| 1407 | |
| 1408 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1409 | ar = (AsyncResult) msg.obj; |
| 1410 | request = (MainThreadRequest) ar.userObj; |
| 1411 | if (ar.exception == null) { |
| 1412 | request.result = true; |
| 1413 | } else { |
| 1414 | request.result = false; |
| 1415 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1416 | } |
| 1417 | notifyRequester(request); |
| 1418 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1419 | break; |
| 1420 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1421 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1424 | if (defaultPhone != null) { |
| 1425 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1426 | } else { |
| 1427 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1428 | Bundle bundle = new Bundle(); |
| 1429 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1430 | new ModemActivityInfo(0, 0, 0, |
| 1431 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1432 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1433 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1436 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1437 | ar = (AsyncResult) msg.obj; |
| 1438 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1439 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1440 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1441 | if (mLastModemActivityInfo == null) { |
| 1442 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1443 | mLastModemActivitySpecificInfo[0] = |
| 1444 | new ActivityStatsTechSpecificInfo( |
| 1445 | 0, |
| 1446 | 0, |
| 1447 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1448 | 0); |
| 1449 | mLastModemActivityInfo = |
| 1450 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1451 | } |
| 1452 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1453 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1454 | // Update the last modem activity info and the result of the request. |
| 1455 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1456 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1457 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1459 | mLastModemActivityInfo = |
| 1460 | new ModemActivityInfo( |
| 1461 | mLastModemActivityInfo.getTimestampMillis(), |
| 1462 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1463 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1464 | mLastModemActivitySpecificInfo); |
| 1465 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | } else { |
| 1467 | if (ar.result == null) { |
| 1468 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1469 | error = TelephonyManager.ModemActivityInfoException |
| 1470 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1471 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1472 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1473 | error = TelephonyManager.ModemActivityInfoException |
| 1474 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1475 | } else { |
| 1476 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1477 | error = TelephonyManager.ModemActivityInfoException |
| 1478 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1481 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1482 | if (mLastModemActivityInfo != null) { |
| 1483 | bundle.putParcelable( |
| 1484 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1485 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1486 | } else { |
| 1487 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1488 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1489 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1490 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1491 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1492 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1493 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1494 | case CMD_SET_ALLOWED_CARRIERS: |
| 1495 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1496 | CarrierRestrictionRules argument = |
| 1497 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1498 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1499 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1500 | break; |
| 1501 | |
| 1502 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1503 | ar = (AsyncResult) msg.obj; |
| 1504 | request = (MainThreadRequest) ar.userObj; |
| 1505 | if (ar.exception == null && ar.result != null) { |
| 1506 | request.result = ar.result; |
| 1507 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1508 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1509 | if (ar.exception instanceof CommandException) { |
| 1510 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1511 | CommandException.Error error = |
| 1512 | ((CommandException) (ar.exception)).getCommandError(); |
| 1513 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1514 | request.result = |
| 1515 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1516 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1517 | } else { |
| 1518 | loge("setAllowedCarriers: Unknown exception"); |
| 1519 | } |
| 1520 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1521 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1522 | break; |
| 1523 | |
| 1524 | case CMD_GET_ALLOWED_CARRIERS: |
| 1525 | request = (MainThreadRequest) msg.obj; |
| 1526 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1527 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1528 | break; |
| 1529 | |
| 1530 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1531 | ar = (AsyncResult) msg.obj; |
| 1532 | request = (MainThreadRequest) ar.userObj; |
| 1533 | if (ar.exception == null && ar.result != null) { |
| 1534 | request.result = ar.result; |
| 1535 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1536 | request.result = new IllegalStateException( |
| 1537 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1538 | if (ar.result == null) { |
| 1539 | loge("getAllowedCarriers: Empty response"); |
| 1540 | } else if (ar.exception instanceof CommandException) { |
| 1541 | loge("getAllowedCarriers: CommandException: " + |
| 1542 | ar.exception); |
| 1543 | } else { |
| 1544 | loge("getAllowedCarriers: Unknown exception"); |
| 1545 | } |
| 1546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1547 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1548 | break; |
| 1549 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1550 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | if (ar.exception == null && ar.result != null) { |
| 1554 | request.result = ar.result; |
| 1555 | } else { |
| 1556 | request.result = new IllegalArgumentException( |
| 1557 | "Failed to retrieve Forbidden Plmns"); |
| 1558 | if (ar.result == null) { |
| 1559 | loge("getForbiddenPlmns: Empty response"); |
| 1560 | } else { |
| 1561 | loge("getForbiddenPlmns: Unknown exception"); |
| 1562 | } |
| 1563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1564 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1565 | break; |
| 1566 | |
| 1567 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1568 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1569 | uiccPort = getUiccPortFromRequest(request); |
| 1570 | if (uiccPort == null) { |
| 1571 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1572 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1573 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1574 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1575 | break; |
| 1576 | } |
| 1577 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1578 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1579 | if (uiccApp == null) { |
| 1580 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1581 | + appType); |
| 1582 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1583 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1584 | break; |
| 1585 | } else { |
| 1586 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1587 | + " specified type -- " + appType); |
| 1588 | } |
| 1589 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1590 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1591 | onCompleted); |
| 1592 | break; |
| 1593 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1594 | case CMD_SWITCH_SLOTS: |
| 1595 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1596 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1597 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1598 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1599 | break; |
| 1600 | |
| 1601 | case EVENT_SWITCH_SLOTS_DONE: |
| 1602 | ar = (AsyncResult) msg.obj; |
| 1603 | request = (MainThreadRequest) ar.userObj; |
| 1604 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1605 | notifyRequester(request); |
| 1606 | break; |
| 1607 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1608 | request = (MainThreadRequest) msg.obj; |
| 1609 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1610 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1611 | break; |
| 1612 | |
| 1613 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1614 | ar = (AsyncResult) msg.obj; |
| 1615 | request = (MainThreadRequest) ar.userObj; |
| 1616 | if (ar.exception != null) { |
| 1617 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1618 | } else { |
| 1619 | int mode = ((int[]) ar.result)[0]; |
| 1620 | if (mode == 0) { |
| 1621 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1622 | } else { |
| 1623 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1624 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1625 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1626 | notifyRequester(request); |
| 1627 | break; |
| 1628 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1629 | request = (MainThreadRequest) msg.obj; |
| 1630 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1631 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1632 | break; |
| 1633 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1634 | ar = (AsyncResult) msg.obj; |
| 1635 | request = (MainThreadRequest) ar.userObj; |
| 1636 | if (ar.exception != null) { |
| 1637 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1638 | } else { |
| 1639 | request.result = ((int[]) ar.result)[0]; |
| 1640 | } |
| 1641 | notifyRequester(request); |
| 1642 | break; |
| 1643 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1644 | request = (MainThreadRequest) msg.obj; |
| 1645 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1646 | int mode = (int) request.argument; |
| 1647 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1648 | break; |
| 1649 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1650 | ar = (AsyncResult) msg.obj; |
| 1651 | request = (MainThreadRequest) ar.userObj; |
| 1652 | request.result = ar.exception == null; |
| 1653 | notifyRequester(request); |
| 1654 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1655 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1656 | request = (MainThreadRequest) msg.obj; |
| 1657 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1658 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1659 | break; |
| 1660 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1661 | ar = (AsyncResult) msg.obj; |
| 1662 | request = (MainThreadRequest) ar.userObj; |
| 1663 | if (ar.exception != null) { |
| 1664 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1665 | } else { |
| 1666 | request.result = ((int[]) ar.result)[0]; |
| 1667 | } |
| 1668 | notifyRequester(request); |
| 1669 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1670 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1671 | request = (MainThreadRequest) msg.obj; |
| 1672 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1673 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1674 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1675 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1676 | break; |
| 1677 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1678 | ar = (AsyncResult) msg.obj; |
| 1679 | request = (MainThreadRequest) ar.userObj; |
| 1680 | request.result = ar.exception == null; |
| 1681 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1682 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1683 | case CMD_GET_ALL_CELL_INFO: |
| 1684 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1685 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1686 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1687 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1688 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1689 | ar = (AsyncResult) msg.obj; |
| 1690 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1691 | // If a timeout occurs, the response will be null |
| 1692 | request.result = (ar.exception == null && ar.result != null) |
| 1693 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1694 | synchronized (request) { |
| 1695 | request.notifyAll(); |
| 1696 | } |
| 1697 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1698 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1699 | request = (MainThreadRequest) msg.obj; |
| 1700 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1701 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1702 | break; |
| 1703 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
| 1706 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1707 | try { |
| 1708 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1709 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1710 | cb.onError( |
| 1711 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1712 | ar.exception.getClass().getName(), |
| 1713 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1714 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1715 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1716 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1717 | } else { |
| 1718 | // use the result as returned |
| 1719 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1720 | } |
| 1721 | } catch (RemoteException re) { |
| 1722 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1723 | } |
| 1724 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1725 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1726 | request = (MainThreadRequest) msg.obj; |
| 1727 | WorkSource ws = (WorkSource) request.argument; |
| 1728 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1729 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1730 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1731 | } |
| 1732 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1733 | ar = (AsyncResult) msg.obj; |
| 1734 | request = (MainThreadRequest) ar.userObj; |
| 1735 | if (ar.exception == null) { |
| 1736 | request.result = ar.result; |
| 1737 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1738 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1739 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1740 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | synchronized (request) { |
| 1744 | request.notifyAll(); |
| 1745 | } |
| 1746 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1747 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1748 | case CMD_MODEM_REBOOT: |
| 1749 | request = (MainThreadRequest) msg.obj; |
| 1750 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1751 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1752 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1753 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1754 | handleNullReturnEvent(msg, "rebootModem"); |
| 1755 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1756 | case CMD_REQUEST_ENABLE_MODEM: |
| 1757 | request = (MainThreadRequest) msg.obj; |
| 1758 | boolean enable = (boolean) request.argument; |
| 1759 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1760 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1761 | PhoneConfigurationManager.getInstance() |
| 1762 | .enablePhone(request.phone, enable, onCompleted); |
| 1763 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1764 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1765 | ar = (AsyncResult) msg.obj; |
| 1766 | request = (MainThreadRequest) ar.userObj; |
| 1767 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1768 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1769 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1770 | if ((boolean) request.result) { |
| 1771 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1772 | updateModemStateMetrics(); |
| 1773 | } else { |
| 1774 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1775 | + ar.exception); |
| 1776 | } |
| 1777 | notifyRequester(request); |
| 1778 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1779 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1780 | case CMD_GET_MODEM_STATUS: |
| 1781 | request = (MainThreadRequest) msg.obj; |
| 1782 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1783 | PhoneConfigurationManager.getInstance() |
| 1784 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1785 | break; |
| 1786 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1787 | ar = (AsyncResult) msg.obj; |
| 1788 | request = (MainThreadRequest) ar.userObj; |
| 1789 | int id = request.phone.getPhoneId(); |
| 1790 | if (ar.exception == null && ar.result != null) { |
| 1791 | request.result = ar.result; |
| 1792 | //update the cache as modem status has changed |
| 1793 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1794 | (boolean) request.result); |
| 1795 | } else { |
| 1796 | // Return true if modem status cannot be retrieved. For most cases, |
| 1797 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1798 | // and disable modem are not supported. Modem is always on. |
| 1799 | // TODO: this should be fixed in R to support a third |
| 1800 | // status UNKNOWN b/131631629 |
| 1801 | request.result = true; |
| 1802 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1803 | + ar.exception); |
| 1804 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1805 | notifyRequester(request); |
| 1806 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1807 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1808 | request = (MainThreadRequest) msg.obj; |
| 1809 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1810 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1811 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1812 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1813 | break; |
| 1814 | } |
| 1815 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1816 | ar = (AsyncResult) msg.obj; |
| 1817 | request = (MainThreadRequest) ar.userObj; |
| 1818 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1819 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1820 | args.second.accept(ar.exception == null); |
| 1821 | notifyRequester(request); |
| 1822 | break; |
| 1823 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1824 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1825 | request = (MainThreadRequest) msg.obj; |
| 1826 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1827 | Phone phone = getPhoneFromRequest(request); |
| 1828 | if (phone != null) { |
| 1829 | phone.getSystemSelectionChannels(onCompleted); |
| 1830 | } else { |
| 1831 | loge("getSystemSelectionChannels: No phone object"); |
| 1832 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1833 | notifyRequester(request); |
| 1834 | } |
| 1835 | break; |
| 1836 | } |
| 1837 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1838 | ar = (AsyncResult) msg.obj; |
| 1839 | request = (MainThreadRequest) ar.userObj; |
| 1840 | if (ar.exception == null && ar.result != null) { |
| 1841 | request.result = ar.result; |
| 1842 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1843 | request.result = new IllegalStateException( |
| 1844 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1845 | if (ar.result == null) { |
| 1846 | loge("getSystemSelectionChannels: Empty response"); |
| 1847 | } else { |
| 1848 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1849 | } |
| 1850 | } |
| 1851 | notifyRequester(request); |
| 1852 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1853 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1854 | ar = (AsyncResult) msg.obj; |
| 1855 | request = (MainThreadRequest) ar.userObj; |
| 1856 | if (ar.exception == null && ar.result != null) { |
| 1857 | request.result = ar.result; |
| 1858 | } else { |
| 1859 | request.result = -1; |
| 1860 | loge("Failed to set Forbidden Plmns"); |
| 1861 | if (ar.result == null) { |
| 1862 | loge("setForbidenPlmns: Empty response"); |
| 1863 | } else if (ar.exception != null) { |
| 1864 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1865 | request.result = -1; |
| 1866 | } else { |
| 1867 | loge("setForbiddenPlmns: Unknown exception"); |
| 1868 | } |
| 1869 | } |
| 1870 | notifyRequester(request); |
| 1871 | break; |
| 1872 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1873 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1874 | uiccPort = getUiccPortFromRequest(request); |
| 1875 | if (uiccPort == null) { |
| 1876 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1877 | request.result = -1; |
| 1878 | notifyRequester(request); |
| 1879 | break; |
| 1880 | } |
| 1881 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1882 | (Pair<Integer, List<String>>) request.argument; |
| 1883 | appType = setFplmnsArgs.first; |
| 1884 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1885 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1886 | if (uiccApp == null) { |
| 1887 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1888 | request.result = -1; |
| 1889 | loge("Failed to get UICC App"); |
| 1890 | notifyRequester(request); |
| 1891 | } else { |
| 1892 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1893 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1894 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1895 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1896 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1897 | case CMD_ERASE_MODEM_CONFIG: |
| 1898 | request = (MainThreadRequest) msg.obj; |
| 1899 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1900 | defaultPhone.eraseModemConfig(onCompleted); |
| 1901 | break; |
| 1902 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1903 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1904 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1905 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1906 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1907 | request = (MainThreadRequest) msg.obj; |
| 1908 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1909 | notifyRequester(request); |
| 1910 | break; |
| 1911 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1912 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1913 | request = (MainThreadRequest) msg.obj; |
| 1914 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1915 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1916 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1917 | changed.first, changed.second, onCompleted); |
| 1918 | break; |
| 1919 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1920 | ar = (AsyncResult) msg.obj; |
| 1921 | request = (MainThreadRequest) ar.userObj; |
| 1922 | if (ar.exception == null) { |
| 1923 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1924 | // If the operation is successful, update the PIN storage |
| 1925 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1926 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1927 | UiccController.getInstance().getPinStorage() |
| 1928 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1929 | } else { |
| 1930 | request.result = msg.arg1; |
| 1931 | } |
| 1932 | notifyRequester(request); |
| 1933 | break; |
| 1934 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1935 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1936 | request = (MainThreadRequest) msg.obj; |
| 1937 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1938 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1939 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1940 | enabled.first, enabled.second, onCompleted); |
| 1941 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1942 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1943 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1944 | ar = (AsyncResult) msg.obj; |
| 1945 | request = (MainThreadRequest) ar.userObj; |
| 1946 | if (ar.exception == null) { |
| 1947 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1948 | // If the operation is successful, update the PIN storage |
| 1949 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1950 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1951 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1952 | UiccController.getInstance().getPinStorage() |
| 1953 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1954 | } else { |
| 1955 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1956 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1957 | } else { |
| 1958 | request.result = msg.arg1; |
| 1959 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1960 | |
| 1961 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1962 | notifyRequester(request); |
| 1963 | break; |
| 1964 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1965 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1966 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1967 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1968 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1969 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1970 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1971 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1972 | |
| 1973 | case CMD_SET_DATA_THROTTLING: { |
| 1974 | request = (MainThreadRequest) msg.obj; |
| 1975 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1976 | DataThrottlingRequest dataThrottlingRequest = |
| 1977 | (DataThrottlingRequest) request.argument; |
| 1978 | Phone phone = getPhoneFromRequest(request); |
| 1979 | if (phone != null) { |
| 1980 | phone.setDataThrottling(onCompleted, |
| 1981 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1982 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1983 | } else { |
| 1984 | loge("setDataThrottling: No phone object"); |
| 1985 | request.result = |
| 1986 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1987 | notifyRequester(request); |
| 1988 | } |
| 1989 | |
| 1990 | break; |
| 1991 | } |
| 1992 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1993 | ar = (AsyncResult) msg.obj; |
| 1994 | request = (MainThreadRequest) ar.userObj; |
| 1995 | |
| 1996 | if (ar.exception == null) { |
| 1997 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1998 | } else if (ar.exception instanceof CommandException) { |
| 1999 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 2000 | CommandException.Error error = |
| 2001 | ((CommandException) (ar.exception)).getCommandError(); |
| 2002 | |
| 2003 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 2004 | request.result = TelephonyManager |
| 2005 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 2006 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2007 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 2008 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2009 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 2010 | } else { |
| 2011 | request.result = |
| 2012 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2013 | } |
| 2014 | } else { |
| 2015 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 2016 | } |
| 2017 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2018 | notifyRequester(request); |
| 2019 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2020 | |
| 2021 | case CMD_SET_SIM_POWER: { |
| 2022 | request = (MainThreadRequest) msg.obj; |
| 2023 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2024 | request = (MainThreadRequest) msg.obj; |
| 2025 | int stateToSet = |
| 2026 | ((Pair<Integer, IIntegerConsumer>) |
| 2027 | request.argument).first; |
| 2028 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2029 | break; |
| 2030 | } |
| 2031 | case EVENT_SET_SIM_POWER_DONE: { |
| 2032 | ar = (AsyncResult) msg.obj; |
| 2033 | request = (MainThreadRequest) ar.userObj; |
| 2034 | IIntegerConsumer callback = |
| 2035 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2036 | if (ar.exception != null) { |
| 2037 | loge("setSimPower exception: " + ar.exception); |
| 2038 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2039 | .RESULT_ERROR_UNKNOWN; |
| 2040 | if (ar.exception instanceof CommandException) { |
| 2041 | CommandException.Error error = |
| 2042 | ((CommandException) (ar.exception)).getCommandError(); |
| 2043 | if (error == CommandException.Error.SIM_ERR) { |
| 2044 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2045 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2046 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2047 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2048 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2049 | } else { |
| 2050 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2051 | } |
| 2052 | } |
| 2053 | try { |
| 2054 | callback.accept(errorCode); |
| 2055 | } catch (RemoteException e) { |
| 2056 | // Ignore if the remote process is no longer available to call back. |
| 2057 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2058 | } |
| 2059 | } else { |
| 2060 | try { |
| 2061 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2062 | } catch (RemoteException e) { |
| 2063 | // Ignore if the remote process is no longer available to call back. |
| 2064 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2065 | } |
| 2066 | } |
| 2067 | break; |
| 2068 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2069 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2070 | request = (MainThreadRequest) msg.obj; |
| 2071 | |
| 2072 | final Phone phone = getPhoneFromRequest(request); |
| 2073 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2074 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2075 | notifyRequester(request); |
| 2076 | break; |
| 2077 | } |
| 2078 | |
| 2079 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2080 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2081 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2082 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2083 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2084 | request.subId, pair.first /*callingUid*/, |
| 2085 | pair.second /*request*/, onCompleted); |
| 2086 | break; |
| 2087 | } |
| 2088 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2089 | ar = (AsyncResult) msg.obj; |
| 2090 | request = (MainThreadRequest) ar.userObj; |
| 2091 | // request.result will be the exception of ar if present, true otherwise. |
| 2092 | // Be cautious not to leave result null which will wait() forever |
| 2093 | request.result = ar.exception != null ? ar.exception : true; |
| 2094 | notifyRequester(request); |
| 2095 | break; |
| 2096 | } |
| 2097 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2098 | request = (MainThreadRequest) msg.obj; |
| 2099 | |
| 2100 | Phone phone = getPhoneFromRequest(request); |
| 2101 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2102 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2103 | notifyRequester(request); |
| 2104 | break; |
| 2105 | } |
| 2106 | |
| 2107 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2108 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2109 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2110 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2111 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2112 | request.subId, pair.first /*callingUid*/, |
| 2113 | pair.second /*request*/, onCompleted); |
| 2114 | break; |
| 2115 | } |
| 2116 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2117 | ar = (AsyncResult) msg.obj; |
| 2118 | request = (MainThreadRequest) ar.userObj; |
| 2119 | request.result = ar.exception != null ? ar.exception : true; |
| 2120 | notifyRequester(request); |
| 2121 | break; |
| 2122 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2123 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2124 | case CMD_GET_SLICING_CONFIG: { |
| 2125 | request = (MainThreadRequest) msg.obj; |
| 2126 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2127 | request.phone.getSlicingConfig(onCompleted); |
| 2128 | break; |
| 2129 | } |
| 2130 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2131 | ar = (AsyncResult) msg.obj; |
| 2132 | request = (MainThreadRequest) ar.userObj; |
| 2133 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2134 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2135 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2136 | Bundle bundle = new Bundle(); |
| 2137 | int resultCode = 0; |
| 2138 | if (ar.exception != null) { |
| 2139 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2140 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2141 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2142 | } else if (ar.result == null) { |
| 2143 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2144 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2145 | } else { |
| 2146 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2147 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2148 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2152 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2153 | } |
| 2154 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2155 | result.send(resultCode, bundle); |
| 2156 | notifyRequester(request); |
| 2157 | break; |
| 2158 | } |
| 2159 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2160 | case CMD_PURCHASE_PREMIUM_CAPABILITY: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2161 | request = (MainThreadRequest) msg.obj; |
| 2162 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2163 | PurchasePremiumCapabilityArgument arg = |
| 2164 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 2165 | SlicePurchaseController.getInstance(request.phone).purchasePremiumCapability( |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2166 | arg.capability, arg.appName, onCompleted); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2167 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2168 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2169 | |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2170 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: { |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2171 | ar = (AsyncResult) msg.obj; |
| 2172 | request = (MainThreadRequest) ar.userObj; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2173 | PurchasePremiumCapabilityArgument arg = |
| 2174 | (PurchasePremiumCapabilityArgument) request.argument; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2175 | try { |
| 2176 | int result = (int) ar.result; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2177 | arg.callback.accept(result); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2178 | log("purchasePremiumCapability: capability=" |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2179 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2180 | + ", result= " |
| 2181 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2182 | } catch (RemoteException e) { |
| 2183 | String logStr = "Purchase premium capability " |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2184 | + TelephonyManager.convertPremiumCapabilityToString(arg.capability) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2185 | + " failed: " + e; |
| 2186 | if (DBG) log(logStr); |
| 2187 | AnomalyReporter.reportAnomaly( |
| 2188 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2189 | } |
| 2190 | break; |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 2191 | } |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2192 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2193 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2194 | request = (MainThreadRequest) msg.obj; |
| 2195 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2196 | UiccController.getInstance().getPinStorage() |
| 2197 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2198 | notifyRequester(request); |
| 2199 | break; |
| 2200 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | default: |
| 2202 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2203 | break; |
| 2204 | } |
| 2205 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2206 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2207 | private void notifyRequester(MainThreadRequest request) { |
| 2208 | synchronized (request) { |
| 2209 | request.notifyAll(); |
| 2210 | } |
| 2211 | } |
| 2212 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2213 | private void handleNullReturnEvent(Message msg, String command) { |
| 2214 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2215 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2216 | if (ar.exception == null) { |
| 2217 | request.result = true; |
| 2218 | } else { |
| 2219 | request.result = false; |
| 2220 | if (ar.exception instanceof CommandException) { |
| 2221 | loge(command + ": CommandException: " + ar.exception); |
| 2222 | } else { |
| 2223 | loge(command + ": Unknown exception"); |
| 2224 | } |
| 2225 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2226 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2227 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | /** |
| 2231 | * Posts the specified command to be executed on the main thread, |
| 2232 | * waits for the request to complete, and returns the result. |
| 2233 | * @see #sendRequestAsync |
| 2234 | */ |
| 2235 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2236 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2237 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | /** |
| 2241 | * Posts the specified command to be executed on the main thread, |
| 2242 | * waits for the request to complete, and returns the result. |
| 2243 | * @see #sendRequestAsync |
| 2244 | */ |
| 2245 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2246 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2247 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | /** |
| 2251 | * Posts the specified command to be executed on the main thread, |
| 2252 | * waits for the request to complete, and returns the result. |
| 2253 | * @see #sendRequestAsync |
| 2254 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2255 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2256 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * Posts the specified command to be executed on the main thread, |
| 2261 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2262 | * if not timeout or null otherwise. |
| 2263 | * @see #sendRequestAsync |
| 2264 | */ |
| 2265 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2266 | long timeoutInMs) { |
| 2267 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | /** |
| 2271 | * Posts the specified command to be executed on the main thread, |
| 2272 | * waits for the request to complete, and returns the result. |
| 2273 | * @see #sendRequestAsync |
| 2274 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2275 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2276 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * Posts the specified command to be executed on the main thread, |
| 2281 | * waits for the request to complete, and returns the result. |
| 2282 | * @see #sendRequestAsync |
| 2283 | */ |
| 2284 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2285 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2286 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2290 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2291 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2292 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2293 | * @see #sendRequestAsync |
| 2294 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2295 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2296 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2298 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2299 | } |
| 2300 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2301 | MainThreadRequest request = null; |
| 2302 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2303 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2304 | } else if (phone != null) { |
| 2305 | request = new MainThreadRequest(argument, phone, workSource); |
| 2306 | } else { |
| 2307 | request = new MainThreadRequest(argument, subId, workSource); |
| 2308 | } |
| 2309 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2310 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2311 | msg.sendToTarget(); |
| 2312 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2313 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2315 | if (timeoutInMs >= 0) { |
| 2316 | // Wait for at least timeoutInMs before returning null request result |
| 2317 | long now = SystemClock.elapsedRealtime(); |
| 2318 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2319 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2320 | try { |
| 2321 | request.wait(deadline - now); |
| 2322 | } catch (InterruptedException e) { |
| 2323 | // Do nothing, go back and check if request is completed or timeout |
| 2324 | } finally { |
| 2325 | now = SystemClock.elapsedRealtime(); |
| 2326 | } |
| 2327 | } |
| 2328 | } else { |
| 2329 | // Wait for the request to complete |
| 2330 | while (request.result == null) { |
| 2331 | try { |
| 2332 | request.wait(); |
| 2333 | } catch (InterruptedException e) { |
| 2334 | // Do nothing, go back and wait until the request is complete |
| 2335 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2339 | if (request.result == null) { |
| 2340 | Log.wtf(LOG_TAG, |
| 2341 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2342 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2343 | return request.result; |
| 2344 | } |
| 2345 | |
| 2346 | /** |
| 2347 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2348 | * Posts the specified command to be executed on the main thread, and |
| 2349 | * returns immediately. |
| 2350 | * @see #sendRequest |
| 2351 | */ |
| 2352 | private void sendRequestAsync(int command) { |
| 2353 | mMainThreadHandler.sendEmptyMessage(command); |
| 2354 | } |
| 2355 | |
| 2356 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2357 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2358 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2359 | */ |
| 2360 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2361 | sendRequestAsync(command, argument, null, null); |
| 2362 | } |
| 2363 | |
| 2364 | /** |
| 2365 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2366 | * @see {@link #sendRequest(int,Object)} |
| 2367 | */ |
| 2368 | private void sendRequestAsync( |
| 2369 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2370 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2371 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2372 | msg.sendToTarget(); |
| 2373 | } |
| 2374 | |
| 2375 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2377 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2378 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2379 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2380 | synchronized (PhoneInterfaceManager.class) { |
| 2381 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2382 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2383 | } else { |
| 2384 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2385 | } |
| 2386 | return sInstance; |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2391 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2394 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2395 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2397 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2398 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2399 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2400 | mTelephonySharedPreferences = |
| 2401 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2402 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2403 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2404 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2405 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2406 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2407 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2408 | Executors.newSingleThreadExecutor(), mApp); |
| 2409 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | publish(); |
| 2411 | } |
| 2412 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2413 | private Phone getDefaultPhone() { |
| 2414 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2415 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2416 | } |
| 2417 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2418 | private void publish() { |
| 2419 | if (DBG) log("publish: " + this); |
| 2420 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2421 | TelephonyFrameworkInitializer |
| 2422 | .getTelephonyServiceManager() |
| 2423 | .getTelephonyServiceRegisterer() |
| 2424 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2427 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2428 | if (request.phone != null) { |
| 2429 | return request.phone; |
| 2430 | } else { |
| 2431 | return getPhoneFromSubId(request.subId); |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | private Phone getPhoneFromSubId(int subId) { |
| 2436 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2437 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2440 | @Nullable |
| 2441 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2442 | Phone phone = getPhoneFromRequest(request); |
| 2443 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2444 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2445 | } |
| 2446 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2447 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2448 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2449 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2450 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2451 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2452 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2453 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2454 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2455 | } |
| 2456 | |
| 2457 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2458 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2459 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2462 | private boolean isImsAvailableOnDevice() { |
| 2463 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2464 | if (pm == null) { |
| 2465 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2466 | // so do not throw error and allow. |
| 2467 | return true; |
| 2468 | } |
| 2469 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2470 | } |
| 2471 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2473 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2476 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | if (DBG) log("dial: " + number); |
| 2478 | // No permission check needed here: This is just a wrapper around the |
| 2479 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2480 | // the UI before it does anything. |
| 2481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2482 | final long identity = Binder.clearCallingIdentity(); |
| 2483 | try { |
| 2484 | String url = createTelUrl(number); |
| 2485 | if (url == null) { |
| 2486 | return; |
| 2487 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2490 | PhoneConstants.State state = mCM.getState(subId); |
| 2491 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2492 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2493 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2494 | mApp.startActivity(intent); |
| 2495 | } |
| 2496 | } finally { |
| 2497 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2502 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2505 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | if (DBG) log("call: " + number); |
| 2507 | |
| 2508 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2509 | // need to do a permission check since we're calling startActivity() |
| 2510 | // from the context of the phone app. |
| 2511 | enforceCallPermission(); |
| 2512 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2513 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | != AppOpsManager.MODE_ALLOWED) { |
| 2515 | return; |
| 2516 | } |
| 2517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | String url = createTelUrl(number); |
| 2521 | if (url == null) { |
| 2522 | return; |
| 2523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2525 | boolean isValid = false; |
| 2526 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2527 | if (slist != null) { |
| 2528 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2529 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2530 | isValid = true; |
| 2531 | break; |
| 2532 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2533 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2534 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | if (!isValid) { |
| 2536 | return; |
| 2537 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2539 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2540 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2541 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2542 | mApp.startActivity(intent); |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(identity); |
| 2545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2548 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2549 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2550 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2551 | } |
| 2552 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2553 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2554 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2555 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2556 | } |
| 2557 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2558 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2559 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | |
| 2561 | final long identity = Binder.clearCallingIdentity(); |
| 2562 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2563 | Phone phone = getPhone(subId); |
| 2564 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2565 | checkSimPin.start(); |
| 2566 | return checkSimPin.unlockSim(null, pin); |
| 2567 | } finally { |
| 2568 | Binder.restoreCallingIdentity(identity); |
| 2569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2572 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | |
| 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2577 | Phone phone = getPhone(subId); |
| 2578 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | checkSimPuk.start(); |
| 2580 | return checkSimPuk.unlockSim(puk, pin); |
| 2581 | } finally { |
| 2582 | Binder.restoreCallingIdentity(identity); |
| 2583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2587 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | * a synchronous one. |
| 2589 | */ |
| 2590 | private static class UnlockSim extends Thread { |
| 2591 | |
| 2592 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2593 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2594 | |
| 2595 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2596 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2597 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | |
| 2599 | // For replies from SimCard interface |
| 2600 | private Handler mHandler; |
| 2601 | |
| 2602 | // For async handler to identify request type |
| 2603 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2604 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2605 | UnlockSim(int phoneId, IccCard simCard) { |
| 2606 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2607 | mSimCard = simCard; |
| 2608 | } |
| 2609 | |
| 2610 | @Override |
| 2611 | public void run() { |
| 2612 | Looper.prepare(); |
| 2613 | synchronized (UnlockSim.this) { |
| 2614 | mHandler = new Handler() { |
| 2615 | @Override |
| 2616 | public void handleMessage(Message msg) { |
| 2617 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2618 | switch (msg.what) { |
| 2619 | case SUPPLY_PIN_COMPLETE: |
| 2620 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2621 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2622 | mRetryCount = msg.arg1; |
| 2623 | if (ar.exception != null) { |
| 2624 | if (ar.exception instanceof CommandException && |
| 2625 | ((CommandException)(ar.exception)).getCommandError() |
| 2626 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2627 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2628 | } //When UiccCardApp dispose,handle message and return exception |
| 2629 | else if (ar.exception instanceof CommandException && |
| 2630 | ((CommandException) (ar.exception)).getCommandError() |
| 2631 | == CommandException.Error.ABORTED) { |
| 2632 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2633 | } else { |
| 2634 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2635 | } |
| 2636 | } else { |
| 2637 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2638 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2639 | mDone = true; |
| 2640 | UnlockSim.this.notifyAll(); |
| 2641 | } |
| 2642 | break; |
| 2643 | } |
| 2644 | } |
| 2645 | }; |
| 2646 | UnlockSim.this.notifyAll(); |
| 2647 | } |
| 2648 | Looper.loop(); |
| 2649 | } |
| 2650 | |
| 2651 | /* |
| 2652 | * Use PIN or PUK to unlock SIM card |
| 2653 | * |
| 2654 | * If PUK is null, unlock SIM card with PIN |
| 2655 | * |
| 2656 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2657 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2658 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | |
| 2660 | while (mHandler == null) { |
| 2661 | try { |
| 2662 | wait(); |
| 2663 | } catch (InterruptedException e) { |
| 2664 | Thread.currentThread().interrupt(); |
| 2665 | } |
| 2666 | } |
| 2667 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2668 | |
| 2669 | if (puk == null) { |
| 2670 | mSimCard.supplyPin(pin, callback); |
| 2671 | } else { |
| 2672 | mSimCard.supplyPuk(puk, pin, callback); |
| 2673 | } |
| 2674 | |
| 2675 | while (!mDone) { |
| 2676 | try { |
| 2677 | Log.d(LOG_TAG, "wait for done"); |
| 2678 | wait(); |
| 2679 | } catch (InterruptedException e) { |
| 2680 | // Restore the interrupted status |
| 2681 | Thread.currentThread().interrupt(); |
| 2682 | } |
| 2683 | } |
| 2684 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2685 | int[] resultArray = new int[2]; |
| 2686 | resultArray[0] = mResult; |
| 2687 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2688 | |
| 2689 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2690 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2693 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2697 | /** |
| 2698 | * This method has been removed due to privacy and stability concerns. |
| 2699 | */ |
| 2700 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2701 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2702 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2703 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2706 | @Override |
| 2707 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2708 | mApp.getSystemService(AppOpsManager.class) |
| 2709 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2710 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2711 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2712 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2713 | // Callers targeting S have no business invoking this method. |
| 2714 | return; |
| 2715 | } |
| 2716 | |
| 2717 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2718 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2719 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2720 | .setCallingPackage(callingPackage) |
| 2721 | .setCallingFeatureId(null) |
| 2722 | .setCallingPid(Binder.getCallingPid()) |
| 2723 | .setCallingUid(Binder.getCallingUid()) |
| 2724 | .setMethod("updateServiceLocation") |
| 2725 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2726 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2727 | .build()); |
| 2728 | // Apps that lack location permission have no business calling this method; |
| 2729 | // however, because no permission was declared in the public API, denials must |
| 2730 | // all be "soft". |
| 2731 | switch (locationResult) { |
| 2732 | case DENIED_HARD: /* fall through */ |
| 2733 | case DENIED_SOFT: |
| 2734 | return; |
| 2735 | } |
| 2736 | |
| 2737 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2740 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2741 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2742 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | } |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2749 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2750 | @Override |
| 2751 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2752 | return isRadioOnWithFeature(callingPackage, null); |
| 2753 | } |
| 2754 | |
| 2755 | |
| 2756 | @Override |
| 2757 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2758 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2759 | callingFeatureId); |
| 2760 | } |
| 2761 | |
| 2762 | @Deprecated |
| 2763 | @Override |
| 2764 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2765 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2768 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2769 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2770 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2772 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2773 | return false; |
| 2774 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2775 | |
| 2776 | final long identity = Binder.clearCallingIdentity(); |
| 2777 | try { |
| 2778 | return isRadioOnForSubscriber(subId); |
| 2779 | } finally { |
| 2780 | Binder.restoreCallingIdentity(identity); |
| 2781 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | final long identity = Binder.clearCallingIdentity(); |
| 2786 | try { |
| 2787 | final Phone phone = getPhone(subId); |
| 2788 | if (phone != null) { |
| 2789 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2790 | } else { |
| 2791 | return false; |
| 2792 | } |
| 2793 | } finally { |
| 2794 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2799 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2800 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2801 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2802 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2803 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2804 | |
| 2805 | final long identity = Binder.clearCallingIdentity(); |
| 2806 | try { |
| 2807 | final Phone phone = getPhone(subId); |
| 2808 | if (phone != null) { |
| 2809 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2810 | } |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2813 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2817 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2820 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2821 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2822 | |
| 2823 | final long identity = Binder.clearCallingIdentity(); |
| 2824 | try { |
| 2825 | final Phone phone = getPhone(subId); |
| 2826 | if (phone == null) { |
| 2827 | return false; |
| 2828 | } |
| 2829 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2830 | toggleRadioOnOffForSubscriber(subId); |
| 2831 | } |
| 2832 | return true; |
| 2833 | } finally { |
| 2834 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2835 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2837 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2838 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2839 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2840 | /* |
| 2841 | * If any of the Radios are available, it will need to be |
| 2842 | * shutdown. So return true if any Radio is available. |
| 2843 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2844 | final long identity = Binder.clearCallingIdentity(); |
| 2845 | try { |
| 2846 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2847 | Phone phone = PhoneFactory.getPhone(i); |
| 2848 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2849 | } |
| 2850 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2851 | return false; |
| 2852 | } finally { |
| 2853 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2854 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2858 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2859 | enforceModifyPermission(); |
| 2860 | |
| 2861 | final long identity = Binder.clearCallingIdentity(); |
| 2862 | try { |
| 2863 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2864 | logv("Shutting down Phone " + i); |
| 2865 | shutdownRadioUsingPhoneId(i); |
| 2866 | } |
| 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2873 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2874 | if (phone != null && phone.isRadioAvailable()) { |
| 2875 | phone.shutdownRadio(); |
| 2876 | } |
| 2877 | } |
| 2878 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2879 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2880 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2885 | if (defaultPhone != null) { |
| 2886 | defaultPhone.setRadioPower(turnOn); |
| 2887 | return true; |
| 2888 | } else { |
| 2889 | loge("There's no default phone."); |
| 2890 | return false; |
| 2891 | } |
| 2892 | } finally { |
| 2893 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2894 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2897 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2899 | |
| 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | final Phone phone = getPhone(subId); |
| 2903 | if (phone != null) { |
| 2904 | phone.setRadioPower(turnOn); |
| 2905 | return true; |
| 2906 | } else { |
| 2907 | return false; |
| 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2914 | /** |
| 2915 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2916 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2917 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2918 | * powering it off, and these radio off votes will be cleared. |
| 2919 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2920 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2921 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2922 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2923 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2924 | * check its vote. |
| 2925 | * |
| 2926 | * @param subId The subscription ID. |
| 2927 | * @param reason The reason for powering off radio. |
| 2928 | * @return true on success and false on failure. |
| 2929 | */ |
| 2930 | public boolean requestRadioPowerOffForReason(int subId, |
| 2931 | @TelephonyManager.RadioPowerReason int reason) { |
| 2932 | enforceModifyPermission(); |
| 2933 | |
| 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | final Phone phone = getPhone(subId); |
| 2937 | if (phone != null) { |
| 2938 | phone.setRadioPowerForReason(false, reason); |
| 2939 | return true; |
| 2940 | } else { |
| 2941 | return false; |
| 2942 | } |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
| 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | /** |
| 2949 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2950 | * {@link requestRadioPowerOffForReason}. |
| 2951 | * |
| 2952 | * @param subId The subscription ID. |
| 2953 | * @param reason The reason for powering off radio. |
| 2954 | * @return true on success and false on failure. |
| 2955 | */ |
| 2956 | public boolean clearRadioPowerOffForReason(int subId, |
| 2957 | @TelephonyManager.RadioPowerReason int reason) { |
| 2958 | enforceModifyPermission(); |
| 2959 | |
| 2960 | final long identity = Binder.clearCallingIdentity(); |
| 2961 | try { |
| 2962 | final Phone phone = getPhone(subId); |
| 2963 | if (phone != null) { |
| 2964 | phone.setRadioPowerForReason(true, reason); |
| 2965 | return true; |
| 2966 | } else { |
| 2967 | return false; |
| 2968 | } |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | /** |
| 2975 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2976 | * |
| 2977 | * @param subId The subscription ID. |
| 2978 | * @param callingPackage The package making the call. |
| 2979 | * @param callingFeatureId The feature in the package. |
| 2980 | * @return List of reasons for powering off radio. |
| 2981 | */ |
| 2982 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 2983 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 2984 | |
| 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | List result = new ArrayList(); |
| 2987 | try { |
| 2988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 2989 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 2990 | return result; |
| 2991 | } |
| 2992 | |
| 2993 | final Phone phone = getPhone(subId); |
| 2994 | if (phone != null) { |
| 2995 | result.addAll(phone.getRadioPowerOffReasons()); |
| 2996 | } |
| 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
| 2999 | } |
| 3000 | return result; |
| 3001 | } |
| 3002 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3003 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3004 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3005 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3007 | |
| 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
| 3010 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 3011 | final Phone phone = getPhone(subId); |
| 3012 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3013 | phone.getDataSettingsManager().setDataEnabled( |
| 3014 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | return true; |
| 3016 | } else { |
| 3017 | return false; |
| 3018 | } |
| 3019 | } finally { |
| 3020 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3021 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3024 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3025 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3026 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3027 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | |
| 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 3032 | final Phone phone = getPhone(subId); |
| 3033 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3034 | phone.getDataSettingsManager().setDataEnabled( |
| 3035 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3036 | return true; |
| 3037 | } else { |
| 3038 | return false; |
| 3039 | } |
| 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3042 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3045 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3046 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
| 3049 | final Phone phone = getPhone(subId); |
| 3050 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3051 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3052 | } else { |
| 3053 | return false; |
| 3054 | } |
| 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3057 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3061 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3064 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | enforceCallPermission(); |
| 3066 | |
| 3067 | final long identity = Binder.clearCallingIdentity(); |
| 3068 | try { |
| 3069 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3070 | return; |
| 3071 | } |
| 3072 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3073 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3077 | }; |
| 3078 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3079 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3081 | |
| 3082 | final long identity = Binder.clearCallingIdentity(); |
| 3083 | try { |
| 3084 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3085 | return false; |
| 3086 | } |
| 3087 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3088 | } finally { |
| 3089 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3090 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3093 | /** |
| 3094 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3095 | * tag on getCallState Binder call. |
| 3096 | */ |
| 3097 | @Deprecated |
| 3098 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3100 | if (CompatChanges.isChangeEnabled( |
| 3101 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3102 | Binder.getCallingUid())) { |
| 3103 | // Do not allow this API to be called on API version 31+, it should only be |
| 3104 | // called on old apps using this Binder call directly. |
| 3105 | throw new SecurityException("This method can only be used for applications " |
| 3106 | + "targeting API version 30 or less."); |
| 3107 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3108 | final long identity = Binder.clearCallingIdentity(); |
| 3109 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3110 | Phone phone = getPhone(getDefaultSubscription()); |
| 3111 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3112 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3113 | } finally { |
| 3114 | Binder.restoreCallingIdentity(identity); |
| 3115 | } |
| 3116 | } |
| 3117 | |
| 3118 | @Override |
| 3119 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3120 | if (CompatChanges.isChangeEnabled( |
| 3121 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3122 | Binder.getCallingUid())) { |
| 3123 | // Check READ_PHONE_STATE for API version 31+ |
| 3124 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3125 | featureId, "getCallStateForSubscription")) { |
| 3126 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3127 | + "targeting API level 31+."); |
| 3128 | } |
| 3129 | } |
| 3130 | final long identity = Binder.clearCallingIdentity(); |
| 3131 | try { |
| 3132 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3134 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3135 | } finally { |
| 3136 | Binder.restoreCallingIdentity(identity); |
| 3137 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3140 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3141 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3142 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3143 | } |
| 3144 | |
| 3145 | @Override |
| 3146 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3147 | final long identity = Binder.clearCallingIdentity(); |
| 3148 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3149 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3151 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | } else { |
| 3153 | return PhoneConstantConversions.convertDataState( |
| 3154 | PhoneConstants.DataState.DISCONNECTED); |
| 3155 | } |
| 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3161 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3162 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3163 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3164 | } |
| 3165 | |
| 3166 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3167 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3168 | final long identity = Binder.clearCallingIdentity(); |
| 3169 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3170 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3171 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3172 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3173 | } else { |
| 3174 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3175 | } |
| 3176 | } finally { |
| 3177 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3178 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3182 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3183 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3184 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3185 | |
| 3186 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3187 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3188 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3189 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3190 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3191 | .setCallingPid(Binder.getCallingPid()) |
| 3192 | .setCallingUid(Binder.getCallingUid()) |
| 3193 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3194 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3195 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3196 | .build()); |
| 3197 | switch (locationResult) { |
| 3198 | case DENIED_HARD: |
| 3199 | throw new SecurityException("Not allowed to access cell location"); |
| 3200 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3201 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3202 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | } |
| 3204 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3205 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | final long identity = Binder.clearCallingIdentity(); |
| 3207 | try { |
| 3208 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3209 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3210 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
| 3213 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3216 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3217 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3218 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3219 | // registered cell info, so return a NULL country instead. |
| 3220 | final long identity = Binder.clearCallingIdentity(); |
| 3221 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3222 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3223 | // Get default phone in this case. |
| 3224 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3225 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3226 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3228 | if (phone == null) return ""; |
| 3229 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3230 | if (sst == null) return ""; |
| 3231 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3232 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3233 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
| 3236 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3239 | /** |
| 3240 | * This method was removed due to potential issues caused by performing partial |
| 3241 | * updates of service state, and lack of a credible use case. |
| 3242 | * |
| 3243 | * This has the ability to break the telephony implementation by disabling notification of |
| 3244 | * changes in device connectivity. DO NOT USE THIS! |
| 3245 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3246 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3247 | public void enableLocationUpdates() { |
| 3248 | mApp.enforceCallingOrSelfPermission( |
| 3249 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3252 | /** |
| 3253 | * This method was removed due to potential issues caused by performing partial |
| 3254 | * updates of service state, and lack of a credible use case. |
| 3255 | * |
| 3256 | * This has the ability to break the telephony implementation by disabling notification of |
| 3257 | * changes in device connectivity. DO NOT USE THIS! |
| 3258 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3259 | @Override |
| 3260 | public void disableLocationUpdates() { |
| 3261 | mApp.enforceCallingOrSelfPermission( |
| 3262 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | @Override |
| 3266 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3267 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3268 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3269 | try { |
| 3270 | mApp.getSystemService(AppOpsManager.class) |
| 3271 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3272 | } catch (SecurityException e) { |
| 3273 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3274 | throw e; |
| 3275 | } |
| 3276 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3277 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3278 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3279 | throw new SecurityException( |
| 3280 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3281 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3282 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3283 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3284 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3285 | return null; |
| 3286 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3287 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3288 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3289 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3290 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3291 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3292 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3293 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3294 | for (CellInfo ci : info) { |
| 3295 | if (ci instanceof CellInfoGsm) { |
| 3296 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3297 | } else if (ci instanceof CellInfoWcdma) { |
| 3298 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3299 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3300 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3301 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3304 | private List<CellInfo> getCachedCellInfo() { |
| 3305 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3306 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3307 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3308 | if (info != null) cellInfos.addAll(info); |
| 3309 | } |
| 3310 | return cellInfos; |
| 3311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3312 | |
| 3313 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3314 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3315 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3316 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3317 | |
| 3318 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3319 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3320 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3321 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3322 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3323 | .setCallingPid(Binder.getCallingPid()) |
| 3324 | .setCallingUid(Binder.getCallingUid()) |
| 3325 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3326 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3327 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3328 | .build()); |
| 3329 | switch (locationResult) { |
| 3330 | case DENIED_HARD: |
| 3331 | throw new SecurityException("Not allowed to access cell info"); |
| 3332 | case DENIED_SOFT: |
| 3333 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3336 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3337 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3338 | return getCachedCellInfo(); |
| 3339 | } |
| 3340 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3341 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3342 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3346 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3347 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3348 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | if (info != null) cellInfos.addAll(info); |
| 3350 | } |
| 3351 | return cellInfos; |
| 3352 | } finally { |
| 3353 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3354 | } |
| 3355 | } |
| 3356 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3357 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3358 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3359 | String callingFeatureId) { |
| 3360 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3361 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3365 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3366 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3367 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3368 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3371 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3372 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3373 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3374 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3375 | |
| 3376 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3377 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3378 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3379 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3380 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3381 | .setCallingPid(Binder.getCallingPid()) |
| 3382 | .setCallingUid(Binder.getCallingUid()) |
| 3383 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3384 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3385 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3386 | .build()); |
| 3387 | switch (locationResult) { |
| 3388 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3389 | if (TelephonyPermissions |
| 3390 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3391 | // Safetynet logging for b/154934934 |
| 3392 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3393 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3394 | throw new SecurityException("Not allowed to access cell info"); |
| 3395 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3396 | if (TelephonyPermissions |
| 3397 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3398 | // Safetynet logging for b/154934934 |
| 3399 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3400 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3401 | try { |
| 3402 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3403 | } catch (RemoteException re) { |
| 3404 | // Drop without consequences |
| 3405 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3406 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3407 | } |
| 3408 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3409 | |
| 3410 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3411 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3412 | |
| 3413 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3414 | } |
| 3415 | |
| 3416 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3417 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3418 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3419 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3423 | Phone phone = getPhone(subId); |
| 3424 | if (phone == null) { |
| 3425 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3426 | } else { |
| 3427 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3428 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | } finally { |
| 3430 | Binder.restoreCallingIdentity(identity); |
| 3431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3434 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3435 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3436 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3437 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3438 | return null; |
| 3439 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3440 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3441 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3442 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3443 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3444 | return null; |
| 3445 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | |
| 3447 | final long identity = Binder.clearCallingIdentity(); |
| 3448 | try { |
| 3449 | return phone.getImei(); |
| 3450 | } finally { |
| 3451 | Binder.restoreCallingIdentity(identity); |
| 3452 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3456 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3457 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3458 | String tac = null; |
| 3459 | if (phone != null) { |
| 3460 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3461 | try { |
| 3462 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3463 | } catch (IndexOutOfBoundsException e) { |
| 3464 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3465 | return null; |
| 3466 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3467 | } |
| 3468 | return tac; |
| 3469 | } |
| 3470 | |
| 3471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3472 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3473 | try { |
| 3474 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3475 | } catch (SecurityException se) { |
| 3476 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3477 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3478 | + Binder.getCallingUid()); |
| 3479 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3480 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3481 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3482 | return null; |
| 3483 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3484 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3485 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3486 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3487 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3488 | return null; |
| 3489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | |
| 3491 | final long identity = Binder.clearCallingIdentity(); |
| 3492 | try { |
| 3493 | return phone.getMeid(); |
| 3494 | } finally { |
| 3495 | Binder.restoreCallingIdentity(identity); |
| 3496 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3500 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3501 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3502 | String manufacturerCode = null; |
| 3503 | if (phone != null) { |
| 3504 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3505 | try { |
| 3506 | manufacturerCode = |
| 3507 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3508 | } catch (IndexOutOfBoundsException e) { |
| 3509 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3510 | return null; |
| 3511 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3512 | } |
| 3513 | return manufacturerCode; |
| 3514 | } |
| 3515 | |
| 3516 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3517 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3518 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3519 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3520 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3521 | return null; |
| 3522 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3523 | int subId = phone.getSubId(); |
| 3524 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3525 | mApp, subId, callingPackage, callingFeatureId, |
| 3526 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3527 | return null; |
| 3528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | return phone.getDeviceSvn(); |
| 3533 | } finally { |
| 3534 | Binder.restoreCallingIdentity(identity); |
| 3535 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3538 | @Override |
| 3539 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | final long identity = Binder.clearCallingIdentity(); |
| 3541 | try { |
| 3542 | final Phone phone = getPhone(subId); |
| 3543 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | @Override |
| 3550 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | final Phone phone = getPhone(subId); |
| 3554 | return phone == null ? null : phone.getCarrierName(); |
| 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3558 | } |
| 3559 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3560 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3561 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | final Phone phone = getPhone(subId); |
| 3565 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3566 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3567 | } finally { |
| 3568 | Binder.restoreCallingIdentity(identity); |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3573 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3577 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3578 | } finally { |
| 3579 | Binder.restoreCallingIdentity(identity); |
| 3580 | } |
| 3581 | } |
| 3582 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3583 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3584 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3585 | if (!isSubscriptionMccMnc) { |
| 3586 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3587 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3588 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3589 | if (phone == null) { |
| 3590 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3591 | } |
| 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3595 | } finally { |
| 3596 | Binder.restoreCallingIdentity(identity); |
| 3597 | } |
| 3598 | } |
| 3599 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3600 | // |
| 3601 | // Internal helper methods. |
| 3602 | // |
| 3603 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3604 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3605 | * Make sure the caller is the calling package itself |
| 3606 | * |
| 3607 | * @throws SecurityException if the caller is not the calling package |
| 3608 | */ |
| 3609 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3610 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3611 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3612 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3613 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3614 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3615 | } catch (PackageManager.NameNotFoundException e) { |
| 3616 | // packageUid is -1 |
| 3617 | } |
| 3618 | if (packageUid != callingUid) { |
| 3619 | throw new SecurityException(message + ": Package " + callingPackage |
| 3620 | + " does not belong to " + callingUid); |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3625 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3626 | * |
| 3627 | * @throws SecurityException if the caller does not have the required permission |
| 3628 | */ |
| 3629 | private void enforceModifyPermission() { |
| 3630 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3631 | } |
| 3632 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3633 | private void enforceActiveEmergencySessionPermission() { |
| 3634 | mApp.enforceCallingOrSelfPermission( |
| 3635 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3636 | } |
| 3637 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3638 | /** |
| 3639 | * Make sure the caller has the CALL_PHONE permission. |
| 3640 | * |
| 3641 | * @throws SecurityException if the caller does not have the required permission |
| 3642 | */ |
| 3643 | private void enforceCallPermission() { |
| 3644 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3645 | } |
| 3646 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3647 | private void enforceSettingsPermission() { |
| 3648 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3649 | } |
| 3650 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3651 | private void enforceRebootPermission() { |
| 3652 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3653 | } |
| 3654 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3655 | private String createTelUrl(String number) { |
| 3656 | if (TextUtils.isEmpty(number)) { |
| 3657 | return null; |
| 3658 | } |
| 3659 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3660 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3661 | } |
| 3662 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3663 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3664 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3665 | } |
| 3666 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3667 | private static void logv(String msg) { |
| 3668 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3669 | } |
| 3670 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3671 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3672 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3673 | } |
| 3674 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3675 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3676 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3677 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3678 | } |
| 3679 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3680 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3681 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | final long identity = Binder.clearCallingIdentity(); |
| 3683 | try { |
| 3684 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3685 | if (phone == null) { |
| 3686 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3687 | } else { |
| 3688 | return phone.getPhoneType(); |
| 3689 | } |
| 3690 | } finally { |
| 3691 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3692 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * Returns the CDMA ERI icon index to display |
| 3697 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3698 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3699 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3700 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3701 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3704 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3705 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3706 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3708 | mApp, subId, callingPackage, callingFeatureId, |
| 3709 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3710 | return -1; |
| 3711 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3712 | |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | final Phone phone = getPhone(subId); |
| 3716 | if (phone != null) { |
| 3717 | return phone.getCdmaEriIconIndex(); |
| 3718 | } else { |
| 3719 | return -1; |
| 3720 | } |
| 3721 | } finally { |
| 3722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3724 | } |
| 3725 | |
| 3726 | /** |
| 3727 | * Returns the CDMA ERI icon mode, |
| 3728 | * 0 - ON |
| 3729 | * 1 - FLASHING |
| 3730 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3731 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3732 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3733 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3734 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3735 | } |
| 3736 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3737 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3738 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3739 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3740 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3741 | mApp, subId, callingPackage, callingFeatureId, |
| 3742 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3743 | return -1; |
| 3744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3745 | |
| 3746 | final long identity = Binder.clearCallingIdentity(); |
| 3747 | try { |
| 3748 | final Phone phone = getPhone(subId); |
| 3749 | if (phone != null) { |
| 3750 | return phone.getCdmaEriIconMode(); |
| 3751 | } else { |
| 3752 | return -1; |
| 3753 | } |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3756 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | /** |
| 3760 | * Returns the CDMA ERI text, |
| 3761 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3763 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3764 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3765 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3768 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3769 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3770 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3772 | mApp, subId, callingPackage, callingFeatureId, |
| 3773 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3774 | return null; |
| 3775 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3776 | |
| 3777 | final long identity = Binder.clearCallingIdentity(); |
| 3778 | try { |
| 3779 | final Phone phone = getPhone(subId); |
| 3780 | if (phone != null) { |
| 3781 | return phone.getCdmaEriText(); |
| 3782 | } else { |
| 3783 | return null; |
| 3784 | } |
| 3785 | } finally { |
| 3786 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3787 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3791 | * Returns the CDMA MDN. |
| 3792 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3793 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3794 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3796 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | |
| 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3801 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | return phone.getLine1Number(); |
| 3803 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3804 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | return null; |
| 3806 | } |
| 3807 | } finally { |
| 3808 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3809 | } |
| 3810 | } |
| 3811 | |
| 3812 | /** |
| 3813 | * Returns the CDMA MIN. |
| 3814 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3815 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3816 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3817 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3818 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | |
| 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | final Phone phone = getPhone(subId); |
| 3823 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3824 | return phone.getCdmaMin(); |
| 3825 | } else { |
| 3826 | return null; |
| 3827 | } |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3830 | } |
| 3831 | } |
| 3832 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3833 | @Override |
| 3834 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3835 | INumberVerificationCallback callback, String callingPackage) { |
| 3836 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3837 | != PERMISSION_GRANTED) { |
| 3838 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3839 | } |
| 3840 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3841 | |
| 3842 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3843 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3844 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3845 | + "calling package: " + callingPackage |
| 3846 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | if (range == null) { |
| 3850 | throw new NullPointerException("Range must be non-null"); |
| 3851 | } |
| 3852 | |
| 3853 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3854 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3855 | |
| 3856 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3857 | } |
| 3858 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3859 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3860 | * Returns true if CDMA provisioning needs to run. |
| 3861 | */ |
| 3862 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3863 | final long identity = Binder.clearCallingIdentity(); |
| 3864 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3865 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | } finally { |
| 3867 | Binder.restoreCallingIdentity(identity); |
| 3868 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3872 | * Sets the voice mail number of a given subId. |
| 3873 | */ |
| 3874 | @Override |
| 3875 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3876 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3877 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3878 | |
| 3879 | final long identity = Binder.clearCallingIdentity(); |
| 3880 | try { |
| 3881 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3882 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3883 | return success; |
| 3884 | } finally { |
| 3885 | Binder.restoreCallingIdentity(identity); |
| 3886 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3887 | } |
| 3888 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3889 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3890 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3891 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3892 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3893 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3894 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3895 | throw new SecurityException("caller must be system dialer"); |
| 3896 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | |
| 3898 | final long identity = Binder.clearCallingIdentity(); |
| 3899 | try { |
| 3900 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3901 | if (phoneAccountHandle == null) { |
| 3902 | return null; |
| 3903 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3904 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | } finally { |
| 3906 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3907 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3911 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3912 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3913 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3914 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3915 | mApp, subId, callingPackage, callingFeatureId, |
| 3916 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3917 | return null; |
| 3918 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3919 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3920 | final long identity = Binder.clearCallingIdentity(); |
| 3921 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3922 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(identity); |
| 3925 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3926 | } |
| 3927 | |
| 3928 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3929 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3930 | VisualVoicemailSmsFilterSettings settings) { |
| 3931 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3932 | |
| 3933 | final long identity = Binder.clearCallingIdentity(); |
| 3934 | try { |
| 3935 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3936 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3937 | } finally { |
| 3938 | Binder.restoreCallingIdentity(identity); |
| 3939 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3940 | } |
| 3941 | |
| 3942 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3943 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3944 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3945 | |
| 3946 | final long identity = Binder.clearCallingIdentity(); |
| 3947 | try { |
| 3948 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3949 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | } finally { |
| 3951 | Binder.restoreCallingIdentity(identity); |
| 3952 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3956 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3957 | String callingPackage, int subId) { |
| 3958 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | |
| 3960 | final long identity = Binder.clearCallingIdentity(); |
| 3961 | try { |
| 3962 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3963 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3964 | } finally { |
| 3965 | Binder.restoreCallingIdentity(identity); |
| 3966 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3970 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3971 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3972 | |
| 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
| 3975 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3976 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
| 3979 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3980 | } |
| 3981 | |
| 3982 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3983 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3984 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3985 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3986 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3987 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3988 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3989 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3990 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3991 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3992 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3993 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3994 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3995 | * Sets the voice activation state of a given subId. |
| 3996 | */ |
| 3997 | @Override |
| 3998 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4000 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4001 | |
| 4002 | final long identity = Binder.clearCallingIdentity(); |
| 4003 | try { |
| 4004 | final Phone phone = getPhone(subId); |
| 4005 | if (phone != null) { |
| 4006 | phone.setVoiceActivationState(activationState); |
| 4007 | } else { |
| 4008 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 4009 | } |
| 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * Sets the data activation state of a given subId. |
| 4017 | */ |
| 4018 | @Override |
| 4019 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4020 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4021 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4022 | |
| 4023 | final long identity = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | final Phone phone = getPhone(subId); |
| 4026 | if (phone != null) { |
| 4027 | phone.setDataActivationState(activationState); |
| 4028 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4029 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4030 | } |
| 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | /** |
| 4037 | * Returns the voice activation state of a given subId. |
| 4038 | */ |
| 4039 | @Override |
| 4040 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4041 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4042 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4043 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4044 | final long identity = Binder.clearCallingIdentity(); |
| 4045 | try { |
| 4046 | if (phone != null) { |
| 4047 | return phone.getVoiceActivationState(); |
| 4048 | } else { |
| 4049 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4050 | } |
| 4051 | } finally { |
| 4052 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4053 | } |
| 4054 | } |
| 4055 | |
| 4056 | /** |
| 4057 | * Returns the data activation state of a given subId. |
| 4058 | */ |
| 4059 | @Override |
| 4060 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4062 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4063 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | if (phone != null) { |
| 4067 | return phone.getDataActivationState(); |
| 4068 | } else { |
| 4069 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4070 | } |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4073 | } |
| 4074 | } |
| 4075 | |
| 4076 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4077 | * Returns the unread count of voicemails for a subId |
| 4078 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4079 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4080 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4081 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4082 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4083 | mApp, subId, callingPackage, callingFeatureId, |
| 4084 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4085 | return 0; |
| 4086 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | final Phone phone = getPhone(subId); |
| 4090 | if (phone != null) { |
| 4091 | return phone.getVoiceMessageCount(); |
| 4092 | } else { |
| 4093 | return 0; |
| 4094 | } |
| 4095 | } finally { |
| 4096 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4101 | * returns true, if the device is in a state where both voice and data |
| 4102 | * are supported simultaneously. This can change based on location or network condition. |
| 4103 | */ |
| 4104 | @Override |
| 4105 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | final Phone phone = getPhone(subId); |
| 4109 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(identity); |
| 4112 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4113 | } |
| 4114 | |
| 4115 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4116 | * Send the dialer code if called from the current default dialer or the caller has |
| 4117 | * carrier privilege. |
| 4118 | * @param inputCode The dialer code to send |
| 4119 | */ |
| 4120 | @Override |
| 4121 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4122 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4123 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4124 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4125 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4126 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4127 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4128 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4129 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4130 | |
| 4131 | final long identity = Binder.clearCallingIdentity(); |
| 4132 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4133 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | } finally { |
| 4135 | Binder.restoreCallingIdentity(identity); |
| 4136 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4137 | } |
| 4138 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4139 | @Override |
| 4140 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4141 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4142 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4143 | mApp, subId, "getNetworkSelectionMode"); |
| 4144 | final long identity = Binder.clearCallingIdentity(); |
| 4145 | try { |
| 4146 | if (!isActiveSubscription(subId)) { |
| 4147 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4148 | } |
| 4149 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4152 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4153 | } |
| 4154 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4155 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4156 | public boolean isInEmergencySmsMode() { |
| 4157 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4158 | final long identity = Binder.clearCallingIdentity(); |
| 4159 | try { |
| 4160 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4161 | if (phone.isInEmergencySmsMode()) { |
| 4162 | return true; |
| 4163 | } |
| 4164 | } |
| 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
| 4168 | return false; |
| 4169 | } |
| 4170 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4171 | /** |
| 4172 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4173 | * @param subId The subscription to use to check the configuration. |
| 4174 | * @param c The callback that will be used to send the result. |
| 4175 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4176 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4177 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4178 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4179 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4180 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4181 | |
| 4182 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4183 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4184 | "IMS not available on device."); |
| 4185 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4186 | final long token = Binder.clearCallingIdentity(); |
| 4187 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4188 | int slotId = getSlotIndexOrException(subId); |
| 4189 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4190 | |
| 4191 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4192 | if (controller != null) { |
| 4193 | ImsManager imsManager = controller.getImsManager(subId); |
| 4194 | if (imsManager != null) { |
| 4195 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4196 | } else { |
| 4197 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4198 | } |
| 4199 | } else { |
| 4200 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4201 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4202 | } catch (ImsException e) { |
| 4203 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(token); |
| 4206 | } |
| 4207 | } |
| 4208 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4209 | /** |
| 4210 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4211 | * @param subId The subscription to use to check the configuration. |
| 4212 | * @param c The callback that will be used to send the result. |
| 4213 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4215 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4216 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4217 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4218 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4219 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4220 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4221 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4222 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4223 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4224 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4225 | if (controller != null) { |
| 4226 | ImsManager imsManager = controller.getImsManager(subId); |
| 4227 | if (imsManager != null) { |
| 4228 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4229 | } else { |
| 4230 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4231 | + "is inactive, ignoring unregister."); |
| 4232 | // If the ImsManager is not valid, just return, since the callback |
| 4233 | // will already have been removed internally. |
| 4234 | } |
| 4235 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4236 | } finally { |
| 4237 | Binder.restoreCallingIdentity(token); |
| 4238 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | } |
| 4240 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4241 | /** |
| 4242 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4243 | */ |
| 4244 | @Override |
| 4245 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4246 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4247 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4248 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4249 | "IMS not available on device."); |
| 4250 | } |
| 4251 | final long token = Binder.clearCallingIdentity(); |
| 4252 | try { |
| 4253 | Phone phone = getPhone(subId); |
| 4254 | if (phone == null) { |
| 4255 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4256 | + subId + "'"); |
| 4257 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4258 | } |
| 4259 | phone.getImsRegistrationState(regState -> { |
| 4260 | try { |
| 4261 | consumer.accept((regState == null) |
| 4262 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4263 | } catch (RemoteException e) { |
| 4264 | // Ignore if the remote process is no longer available to call back. |
| 4265 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4266 | } |
| 4267 | }); |
| 4268 | } finally { |
| 4269 | Binder.restoreCallingIdentity(token); |
| 4270 | } |
| 4271 | } |
| 4272 | |
| 4273 | /** |
| 4274 | * Get the transport type for the IMS service registration state. |
| 4275 | */ |
| 4276 | @Override |
| 4277 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4278 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4279 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4280 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4281 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4282 | "IMS not available on device."); |
| 4283 | } |
| 4284 | final long token = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | Phone phone = getPhone(subId); |
| 4287 | if (phone == null) { |
| 4288 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4289 | + subId + "'"); |
| 4290 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4291 | } |
| 4292 | phone.getImsRegistrationTech(regTech -> { |
| 4293 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4294 | int regTechConverted = (regTech == null) |
| 4295 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4296 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4297 | regTechConverted); |
| 4298 | try { |
| 4299 | consumer.accept(regTechConverted); |
| 4300 | } catch (RemoteException e) { |
| 4301 | // Ignore if the remote process is no longer available to call back. |
| 4302 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4303 | } |
| 4304 | }); |
| 4305 | } finally { |
| 4306 | Binder.restoreCallingIdentity(token); |
| 4307 | } |
| 4308 | } |
| 4309 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4310 | /** |
| 4311 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4312 | * @param subId The subscription to use to check the configuration. |
| 4313 | * @param c The callback that will be used to send the result. |
| 4314 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4315 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4316 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4317 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4318 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4319 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4320 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4321 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4322 | "IMS not available on device."); |
| 4323 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4324 | final long token = Binder.clearCallingIdentity(); |
| 4325 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4326 | int slotId = getSlotIndexOrException(subId); |
| 4327 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4328 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4329 | } catch (ImsException e) { |
| 4330 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4331 | } finally { |
| 4332 | Binder.restoreCallingIdentity(token); |
| 4333 | } |
| 4334 | } |
| 4335 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4336 | /** |
| 4337 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4338 | * @param subId The subscription to use to check the configuration. |
| 4339 | * @param c The callback that will be used to send the result. |
| 4340 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4341 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4342 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4343 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4344 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4345 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4346 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4347 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4348 | |
| 4349 | final long token = Binder.clearCallingIdentity(); |
| 4350 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4351 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4352 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4353 | } catch (ImsException e) { |
| 4354 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4355 | + "is inactive, ignoring unregister."); |
| 4356 | // If the subscription is no longer active, just return, since the callback |
| 4357 | // will already have been removed internally. |
| 4358 | } finally { |
| 4359 | Binder.restoreCallingIdentity(token); |
| 4360 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4364 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4365 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4366 | final long token = Binder.clearCallingIdentity(); |
| 4367 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4368 | int slotId = getSlotIndexOrException(subId); |
| 4369 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4370 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4371 | } catch (com.android.ims.ImsException e) { |
| 4372 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4373 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4374 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4375 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4376 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4377 | } finally { |
| 4378 | Binder.restoreCallingIdentity(token); |
| 4379 | } |
| 4380 | } |
| 4381 | |
| 4382 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4383 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4384 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4385 | final long token = Binder.clearCallingIdentity(); |
| 4386 | try { |
| 4387 | Phone phone = getPhone(subId); |
| 4388 | if (phone == null) return false; |
| 4389 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4390 | } catch (com.android.ims.ImsException e) { |
| 4391 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4392 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4393 | } finally { |
| 4394 | Binder.restoreCallingIdentity(token); |
| 4395 | } |
| 4396 | } |
| 4397 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4398 | /** |
| 4399 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4400 | * subscription. |
| 4401 | * @param subId The subscription to use to check the configuration. |
| 4402 | * @param callback The callback that will be used to send the result. |
| 4403 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4404 | * @param transportType The transport type of the MmTelFeature capability. |
| 4405 | */ |
| 4406 | @Override |
| 4407 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4408 | int transportType) { |
| 4409 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4410 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4411 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4412 | "IMS not available on device."); |
| 4413 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4414 | final long token = Binder.clearCallingIdentity(); |
| 4415 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4416 | int slotId = getSlotIndex(subId); |
| 4417 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4418 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4419 | + subId + "'"); |
| 4420 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4421 | } |
| 4422 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4423 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4424 | transportType, aBoolean -> { |
| 4425 | try { |
| 4426 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4427 | } catch (RemoteException e) { |
| 4428 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4429 | + "running. Ignore"); |
| 4430 | } |
| 4431 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4432 | } catch (ImsException e) { |
| 4433 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4434 | } finally { |
| 4435 | Binder.restoreCallingIdentity(token); |
| 4436 | } |
| 4437 | } |
| 4438 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4439 | /** |
| 4440 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4441 | * @param subId The subscription to use to check the configuration. |
| 4442 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4443 | @Override |
| 4444 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4445 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4446 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4447 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | final long token = Binder.clearCallingIdentity(); |
| 4449 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4450 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4451 | // 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] | 4452 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4453 | } catch (ImsException e) { |
| 4454 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4455 | } finally { |
| 4456 | Binder.restoreCallingIdentity(token); |
| 4457 | } |
| 4458 | } |
| 4459 | |
| 4460 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4461 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4463 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4466 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4467 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4468 | // 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] | 4469 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4470 | } catch (ImsException e) { |
| 4471 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4472 | } finally { |
| 4473 | Binder.restoreCallingIdentity(identity); |
| 4474 | } |
| 4475 | } |
| 4476 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4477 | /** |
| 4478 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4479 | * @param subId The subscription to use to check the configuration. |
| 4480 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4481 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4482 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4483 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4484 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4485 | final long identity = Binder.clearCallingIdentity(); |
| 4486 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4487 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4488 | // 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] | 4489 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4490 | } catch (ImsException e) { |
| 4491 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(identity); |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4498 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4499 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4500 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4501 | final long identity = Binder.clearCallingIdentity(); |
| 4502 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4503 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4504 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4505 | // 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] | 4506 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4507 | } catch (ImsException e) { |
| 4508 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4509 | } finally { |
| 4510 | Binder.restoreCallingIdentity(identity); |
| 4511 | } |
| 4512 | } |
| 4513 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4514 | /** |
| 4515 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4516 | * @param subId The subscription to use to check the configuration. |
| 4517 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4518 | @Override |
| 4519 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4520 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4521 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4524 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4525 | // 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] | 4526 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4527 | } catch (ImsException e) { |
| 4528 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4529 | } finally { |
| 4530 | Binder.restoreCallingIdentity(identity); |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4535 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4537 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4538 | final long identity = Binder.clearCallingIdentity(); |
| 4539 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4540 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4541 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4542 | // 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] | 4543 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4544 | } catch (ImsException e) { |
| 4545 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
| 4549 | } |
| 4550 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4551 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4552 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4553 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4554 | * @param subId The subscription to use to check the configuration. |
| 4555 | */ |
| 4556 | @Override |
| 4557 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4558 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4559 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4562 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4563 | // 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] | 4564 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4565 | } catch (ImsException e) { |
| 4566 | throw new ServiceSpecificException(e.getCode()); |
| 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(identity); |
| 4569 | } |
| 4570 | } |
| 4571 | |
| 4572 | /** |
| 4573 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4574 | * Requires MODIFY_PHONE_STATE permission. |
| 4575 | * @param subId The subscription to use to check the configuration. |
| 4576 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4577 | * false otherwise |
| 4578 | */ |
| 4579 | @Override |
| 4580 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4581 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4582 | "setCrossSimCallingEnabled"); |
| 4583 | final long identity = Binder.clearCallingIdentity(); |
| 4584 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4585 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4586 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4587 | // 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] | 4588 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4589 | } catch (ImsException e) { |
| 4590 | throw new ServiceSpecificException(e.getCode()); |
| 4591 | } finally { |
| 4592 | Binder.restoreCallingIdentity(identity); |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4597 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4598 | * @param subId The subscription to use to check the configuration. |
| 4599 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4600 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4601 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4602 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4603 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4604 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4605 | final long identity = Binder.clearCallingIdentity(); |
| 4606 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4607 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4608 | // 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] | 4609 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (ImsException e) { |
| 4611 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4612 | } finally { |
| 4613 | Binder.restoreCallingIdentity(identity); |
| 4614 | } |
| 4615 | } |
| 4616 | |
| 4617 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4618 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4619 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4620 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4621 | final long identity = Binder.clearCallingIdentity(); |
| 4622 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4623 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4624 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4625 | // 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] | 4626 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4627 | } catch (ImsException e) { |
| 4628 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | @Override |
| 4635 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4636 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4637 | "setVoWiFiNonPersistent"); |
| 4638 | final long identity = Binder.clearCallingIdentity(); |
| 4639 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4640 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4641 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4642 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4643 | } catch (ImsException e) { |
| 4644 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4645 | } finally { |
| 4646 | Binder.restoreCallingIdentity(identity); |
| 4647 | } |
| 4648 | } |
| 4649 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4650 | /** |
| 4651 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4652 | * @param subId The subscription to use to check the configuration. |
| 4653 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4654 | @Override |
| 4655 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4656 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4657 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4660 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4661 | // 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] | 4662 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4663 | } catch (ImsException e) { |
| 4664 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
| 4671 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4673 | "setVoWiFiModeSetting"); |
| 4674 | final long identity = Binder.clearCallingIdentity(); |
| 4675 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4676 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4677 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4678 | // 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] | 4679 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4680 | } catch (ImsException e) { |
| 4681 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(identity); |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | @Override |
| 4688 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4689 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4692 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4693 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4694 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4695 | } catch (ImsException e) { |
| 4696 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4697 | } finally { |
| 4698 | Binder.restoreCallingIdentity(identity); |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | @Override |
| 4703 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4705 | "setVoWiFiRoamingModeSetting"); |
| 4706 | final long identity = Binder.clearCallingIdentity(); |
| 4707 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4708 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4709 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4710 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4711 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4712 | } catch (ImsException e) { |
| 4713 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4714 | } finally { |
| 4715 | Binder.restoreCallingIdentity(identity); |
| 4716 | } |
| 4717 | } |
| 4718 | |
| 4719 | @Override |
| 4720 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4721 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4722 | "setRttCapabilityEnabled"); |
| 4723 | final long identity = Binder.clearCallingIdentity(); |
| 4724 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4725 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4726 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4727 | // 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] | 4728 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4729 | } catch (ImsException e) { |
| 4730 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4731 | } finally { |
| 4732 | Binder.restoreCallingIdentity(identity); |
| 4733 | } |
| 4734 | } |
| 4735 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4736 | /** |
| 4737 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4738 | * @param subId The subscription to use to check the configuration. |
| 4739 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4740 | @Override |
| 4741 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4742 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4743 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4744 | final long identity = Binder.clearCallingIdentity(); |
| 4745 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4746 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4747 | // 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] | 4748 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4749 | } catch (ImsException e) { |
| 4750 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4751 | } finally { |
| 4752 | Binder.restoreCallingIdentity(identity); |
| 4753 | } |
| 4754 | } |
| 4755 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4756 | @Override |
| 4757 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4758 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4759 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4760 | final long identity = Binder.clearCallingIdentity(); |
| 4761 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4762 | if (!isImsAvailableOnDevice()) { |
| 4763 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4764 | "IMS not available on device."); |
| 4765 | } |
| 4766 | int slotId = getSlotIndexOrException(subId); |
| 4767 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4768 | ImsManager.getInstance(mApp, slotId) |
| 4769 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4770 | } catch (ImsException e) { |
| 4771 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4772 | } finally { |
| 4773 | Binder.restoreCallingIdentity(identity); |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | @Override |
| 4778 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4779 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4780 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4781 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4782 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4783 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4784 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4785 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4786 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4787 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4788 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4789 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4790 | + "is inactive, ignoring unregister."); |
| 4791 | // If the subscription is no longer active, just return, since the callback will already |
| 4792 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
| 4795 | } |
| 4796 | } |
| 4797 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4798 | @Override |
| 4799 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4800 | IFeatureProvisioningCallback callback) { |
| 4801 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4802 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4803 | |
| 4804 | final long identity = Binder.clearCallingIdentity(); |
| 4805 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4806 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4807 | } |
| 4808 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4809 | try { |
| 4810 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4811 | if (controller == null) { |
| 4812 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4813 | "Device does not support IMS"); |
| 4814 | } |
| 4815 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4816 | } finally { |
| 4817 | Binder.restoreCallingIdentity(identity); |
| 4818 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | @Override |
| 4822 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4823 | IFeatureProvisioningCallback callback) { |
| 4824 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4825 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4826 | |
| 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4829 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4830 | } |
| 4831 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4832 | try { |
| 4833 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4834 | if (controller == null) { |
| 4835 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4836 | return; |
| 4837 | } |
| 4838 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4839 | } finally { |
| 4840 | Binder.restoreCallingIdentity(identity); |
| 4841 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4842 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4843 | |
| 4844 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4846 | message); |
| 4847 | } |
| 4848 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4849 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4850 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4851 | boolean isProvisioned) { |
| 4852 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4853 | |
| 4854 | final long identity = Binder.clearCallingIdentity(); |
| 4855 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4856 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4857 | if (controller == null) { |
| 4858 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4859 | return; |
| 4860 | } |
| 4861 | controller.setRcsProvisioningStatusForCapability( |
| 4862 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4863 | } finally { |
| 4864 | Binder.restoreCallingIdentity(identity); |
| 4865 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4866 | } |
| 4867 | |
| 4868 | |
| 4869 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4870 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4871 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4872 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4873 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4876 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4877 | if (controller == null) { |
| 4878 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4879 | |
| 4880 | // device does not support IMS, this method will return true always. |
| 4881 | return true; |
| 4882 | } |
| 4883 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4884 | } finally { |
| 4885 | Binder.restoreCallingIdentity(identity); |
| 4886 | } |
| 4887 | } |
| 4888 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4889 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4890 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4891 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4892 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4893 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4896 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4897 | if (controller == null) { |
| 4898 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4899 | return; |
| 4900 | } |
| 4901 | controller.setImsProvisioningStatusForCapability( |
| 4902 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4903 | } finally { |
| 4904 | Binder.restoreCallingIdentity(identity); |
| 4905 | } |
| 4906 | } |
| 4907 | |
| 4908 | @Override |
| 4909 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4910 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4911 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4912 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4913 | final long identity = Binder.clearCallingIdentity(); |
| 4914 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4915 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4916 | if (controller == null) { |
| 4917 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4918 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4919 | // device does not support IMS, this method will return true always. |
| 4920 | return true; |
| 4921 | } |
| 4922 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4923 | } finally { |
| 4924 | Binder.restoreCallingIdentity(identity); |
| 4925 | } |
| 4926 | } |
| 4927 | |
| 4928 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4929 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4930 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4931 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4932 | |
| 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4935 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4936 | if (controller == null) { |
| 4937 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4938 | |
| 4939 | // device does not support IMS, this method will return false |
| 4940 | return false; |
| 4941 | } |
| 4942 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4945 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4949 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4950 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4951 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4952 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4953 | final long identity = Binder.clearCallingIdentity(); |
| 4954 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4955 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4956 | if (controller == null) { |
| 4957 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4958 | |
| 4959 | // device does not support IMS, this method will return false |
| 4960 | return false; |
| 4961 | } |
| 4962 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4963 | } finally { |
| 4964 | Binder.restoreCallingIdentity(identity); |
| 4965 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4966 | } |
| 4967 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4968 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4969 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4970 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4971 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4972 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4973 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4974 | mApp, subId, "getImsProvisioningInt"); |
| 4975 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4976 | final long identity = Binder.clearCallingIdentity(); |
| 4977 | try { |
| 4978 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4979 | int slotId = getSlotIndex(subId); |
| 4980 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4981 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4982 | + subId + "' for key:" + key); |
| 4983 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4984 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4985 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4986 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4987 | if (controller == null) { |
| 4988 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4989 | |
| 4990 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4991 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4992 | } |
| 4993 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4994 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4995 | return retVal; |
| 4996 | } |
| 4997 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4998 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4999 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5000 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 5001 | + subId + "' for key:" + key); |
| 5002 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5003 | } finally { |
| 5004 | Binder.restoreCallingIdentity(identity); |
| 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | @Override |
| 5009 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5010 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5011 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5012 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5013 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5014 | mApp, subId, "getImsProvisioningString"); |
| 5015 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5016 | final long identity = Binder.clearCallingIdentity(); |
| 5017 | try { |
| 5018 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5019 | int slotId = getSlotIndex(subId); |
| 5020 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5021 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 5022 | + subId + "' for key:" + key); |
| 5023 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5024 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5025 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5026 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5027 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5028 | + subId + "' for key:" + key); |
| 5029 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5030 | } finally { |
| 5031 | Binder.restoreCallingIdentity(identity); |
| 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | @Override |
| 5036 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5037 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5038 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5039 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5040 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5041 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5042 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5043 | final long identity = Binder.clearCallingIdentity(); |
| 5044 | try { |
| 5045 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5046 | int slotId = getSlotIndex(subId); |
| 5047 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5048 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5049 | + subId + "' for key:" + key); |
| 5050 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5051 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5052 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5053 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5054 | if (controller == null) { |
| 5055 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5056 | |
| 5057 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5058 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5059 | } |
| 5060 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5061 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5062 | return retVal; |
| 5063 | } |
| 5064 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5065 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5066 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5067 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5068 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5069 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
| 5072 | } |
| 5073 | } |
| 5074 | |
| 5075 | @Override |
| 5076 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5077 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5078 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5079 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5080 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5081 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | try { |
| 5084 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5085 | int slotId = getSlotIndex(subId); |
| 5086 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5087 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5088 | + subId + "' for key:" + key); |
| 5089 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5090 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5091 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5092 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5093 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5094 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5095 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
| 5099 | } |
| 5100 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5101 | /** |
| 5102 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5103 | * for the given slot ID or no ImsResolver instance has been created. |
| 5104 | * @param slotId The slot ID that the IMS service is created for. |
| 5105 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5106 | */ |
| 5107 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5108 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5109 | ImsFeature.FEATURE_MMTEL)) { |
| 5110 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5111 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5112 | } |
| 5113 | } |
| 5114 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5115 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5116 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5117 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5118 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5119 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5120 | } |
| 5121 | return slotId; |
| 5122 | } |
| 5123 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5124 | private int getSlotIndex(int subId) { |
| 5125 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5126 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5127 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5128 | } |
| 5129 | return slotId; |
| 5130 | } |
| 5131 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5132 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5133 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5134 | */ |
| 5135 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5136 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5137 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5138 | try { |
| 5139 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5140 | } catch (SecurityException se) { |
| 5141 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5142 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5143 | + Binder.getCallingUid()); |
| 5144 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5145 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5146 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5147 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5148 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5149 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5150 | mApp, subId, callingPackage, callingFeatureId, |
| 5151 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5152 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5153 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
| 5157 | final Phone phone = getPhone(subId); |
| 5158 | if (phone != null) { |
| 5159 | return phone.getServiceState().getDataNetworkType(); |
| 5160 | } else { |
| 5161 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5162 | } |
| 5163 | } finally { |
| 5164 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | /** |
| 5169 | * Returns the data network type |
| 5170 | */ |
| 5171 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5172 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5173 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5174 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * Returns the data network type for a subId |
| 5179 | */ |
| 5180 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5181 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5182 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5183 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5184 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5185 | mApp, functionName)) { |
| 5186 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5187 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5188 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5189 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
| 5194 | final Phone phone = getPhone(subId); |
| 5195 | if (phone != null) { |
| 5196 | return phone.getServiceState().getDataNetworkType(); |
| 5197 | } else { |
| 5198 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5199 | } |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5202 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5206 | * Returns the Voice network type for a subId |
| 5207 | */ |
| 5208 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5209 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5210 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5211 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5212 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5213 | mApp, functionName)) { |
| 5214 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5215 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5216 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5217 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | final long identity = Binder.clearCallingIdentity(); |
| 5221 | try { |
| 5222 | final Phone phone = getPhone(subId); |
| 5223 | if (phone != null) { |
| 5224 | return phone.getServiceState().getVoiceNetworkType(); |
| 5225 | } else { |
| 5226 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5227 | } |
| 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5230 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | /** |
| 5234 | * @return true if a ICC card is present |
| 5235 | */ |
| 5236 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5237 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5238 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5239 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5243 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5244 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5245 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5246 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5250 | if (phone != null) { |
| 5251 | return phone.getIccCard().hasIccCard(); |
| 5252 | } else { |
| 5253 | return false; |
| 5254 | } |
| 5255 | } finally { |
| 5256 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | /** |
| 5261 | * Return if the current radio is LTE on CDMA. This |
| 5262 | * is a tri-state return value as for a period of time |
| 5263 | * the mode may be unknown. |
| 5264 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5265 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5266 | * @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] | 5267 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5268 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5269 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5270 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5271 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5272 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5275 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5276 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5277 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5278 | try { |
| 5279 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5280 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5281 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5282 | } |
| 5283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | final long identity = Binder.clearCallingIdentity(); |
| 5285 | try { |
| 5286 | final Phone phone = getPhone(subId); |
| 5287 | if (phone == null) { |
| 5288 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5289 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5290 | return TelephonyProperties.lte_on_cdma_device() |
| 5291 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | } |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5295 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5298 | /** |
| 5299 | * {@hide} |
| 5300 | * Returns Default subId, 0 in the case of single standby. |
| 5301 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5302 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5303 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5306 | private int getSlotForDefaultSubscription() { |
| 5307 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5308 | } |
| 5309 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5310 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5311 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5312 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5313 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5314 | private boolean isActiveSubscription(int subId) { |
| 5315 | return mSubscriptionController.isActiveSubId(subId); |
| 5316 | } |
| 5317 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5318 | /** |
| 5319 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5320 | */ |
| 5321 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | final long identity = Binder.clearCallingIdentity(); |
| 5323 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5324 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5326 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | /** |
| 5333 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5334 | */ |
| 5335 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5336 | final long identity = Binder.clearCallingIdentity(); |
| 5337 | try { |
| 5338 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5339 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5340 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5341 | } finally { |
| 5342 | Binder.restoreCallingIdentity(identity); |
| 5343 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5344 | } |
| 5345 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5346 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5347 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5348 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5349 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5350 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5351 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5352 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5353 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5354 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5355 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5356 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5357 | } |
| 5358 | return PhoneFactory.getPhone(phoneId); |
| 5359 | } |
| 5360 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5361 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5362 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5363 | @NonNull IccLogicalChannelRequest request) { |
| 5364 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5365 | /*message=*/ "iccOpenLogicalChannel"); |
| 5366 | |
| 5367 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5368 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5369 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5370 | |
| 5371 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5372 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5373 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5374 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5375 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5376 | Phone phone; |
| 5377 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5379 | mApp, request.subId, message); |
| 5380 | phone = getPhoneFromSubId(request.subId); |
| 5381 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5382 | enforceModifyPermission(); |
| 5383 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5384 | } else { |
| 5385 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5386 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5387 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5391 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | final long identity = Binder.clearCallingIdentity(); |
| 5393 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5394 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5395 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5396 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5397 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5398 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5399 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5400 | loge("The calling package is not allowed to access ISD-R."); |
| 5401 | throw new SecurityException( |
| 5402 | "The calling package is not allowed to access ISD-R."); |
| 5403 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5404 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5407 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5408 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | return response; |
| 5410 | } finally { |
| 5411 | Binder.restoreCallingIdentity(identity); |
| 5412 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5416 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5417 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5418 | /*message=*/"iccCloseLogicalChannel"); |
| 5419 | |
| 5420 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5421 | |
| 5422 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5423 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5424 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5425 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5426 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5427 | // before this feature is enabled, this API should only return false if |
| 5428 | // the operation fails instead of throwing runtime exception for |
| 5429 | // backward-compatibility. |
| 5430 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5431 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5434 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5435 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5436 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5437 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5438 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5439 | Boolean success = false; |
| 5440 | if (result instanceof RuntimeException) { |
| 5441 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5442 | if (shouldThrowExceptionOnFailure) { |
| 5443 | throw (RuntimeException) result; |
| 5444 | } else { |
| 5445 | return false; |
| 5446 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5447 | } else if (result instanceof Boolean) { |
| 5448 | success = (Boolean) result; |
| 5449 | } else { |
| 5450 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5451 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5452 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | return success; |
| 5454 | } finally { |
| 5455 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5456 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5460 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5461 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5463 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5464 | if (DBG) { |
| 5465 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5466 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5467 | + p3 + " data=" + data); |
| 5468 | } |
| 5469 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5470 | command, p1, p2, p3, data); |
| 5471 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5472 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5473 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5474 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5475 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5476 | enforceModifyPermission(); |
| 5477 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5478 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5479 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5480 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5481 | } |
| 5482 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5483 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5484 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5488 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | final long identity = Binder.clearCallingIdentity(); |
| 5490 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5491 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5492 | return ""; |
| 5493 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5496 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5497 | null /* workSource */); |
| 5498 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | // Append the returned status code to the end of the response payload. |
| 5501 | String s = Integer.toHexString( |
| 5502 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5503 | if (response.payload != null) { |
| 5504 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5505 | } |
| 5506 | return s; |
| 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5509 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5510 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5511 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5512 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5513 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5514 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5516 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5518 | if (DBG) { |
| 5519 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5520 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5521 | } |
| 5522 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5523 | cla, command, p1, p2, p3, data); |
| 5524 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5525 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5526 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5527 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5528 | 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] | 5529 | enforceModifyPermission(); |
| 5530 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5531 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5532 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5533 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5534 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5535 | } |
| 5536 | |
| 5537 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5538 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5539 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5540 | } |
| 5541 | |
| 5542 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5543 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5544 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5545 | final long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
| 5547 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5548 | && TextUtils.equals(ISDR_AID, data)) { |
| 5549 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5550 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5551 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5552 | if (bestComponent == null |
| 5553 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5554 | loge("The calling package is not allowed to select ISD-R."); |
| 5555 | throw new SecurityException( |
| 5556 | "The calling package is not allowed to select ISD-R."); |
| 5557 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5558 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5559 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5561 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5562 | null /* workSource */); |
| 5563 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5564 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | // Append the returned status code to the end of the response payload. |
| 5566 | String s = Integer.toHexString( |
| 5567 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5568 | if (response.payload != null) { |
| 5569 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5570 | } |
| 5571 | return s; |
| 5572 | } finally { |
| 5573 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5574 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5575 | } |
| 5576 | |
| 5577 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5578 | 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] | 5579 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5580 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5581 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5582 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | final long identity = Binder.clearCallingIdentity(); |
| 5584 | try { |
| 5585 | if (DBG) { |
| 5586 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5587 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5588 | } |
| 5589 | |
| 5590 | IccIoResult response = |
| 5591 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5592 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5593 | subId); |
| 5594 | |
| 5595 | if (DBG) { |
| 5596 | log("Exchange SIM_IO [R]" + response); |
| 5597 | } |
| 5598 | |
| 5599 | byte[] result = null; |
| 5600 | int length = 2; |
| 5601 | if (response.payload != null) { |
| 5602 | length = 2 + response.payload.length; |
| 5603 | result = new byte[length]; |
| 5604 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5605 | } else { |
| 5606 | result = new byte[length]; |
| 5607 | } |
| 5608 | |
| 5609 | result[length - 1] = (byte) response.sw2; |
| 5610 | result[length - 2] = (byte) response.sw1; |
| 5611 | return result; |
| 5612 | } finally { |
| 5613 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5614 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5615 | } |
| 5616 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5617 | /** |
| 5618 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5619 | * on a particular subscription |
| 5620 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5621 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5622 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5624 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5625 | return null; |
| 5626 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5627 | |
| 5628 | final long identity = Binder.clearCallingIdentity(); |
| 5629 | try { |
| 5630 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5631 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5632 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5633 | return null; |
| 5634 | } |
| 5635 | Object response = sendRequest( |
| 5636 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5637 | if (response instanceof String[]) { |
| 5638 | return (String[]) response; |
| 5639 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5640 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5641 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5642 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5643 | } finally { |
| 5644 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5645 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5646 | } |
| 5647 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5648 | /** |
| 5649 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5650 | * subscription. |
| 5651 | * |
| 5652 | * @param subId the id of the subscription. |
| 5653 | * @param appType the uicc app type, must be USIM or SIM. |
| 5654 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5655 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5656 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5657 | * @return number of fplmns that is successfully written to the SIM. |
| 5658 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5659 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5660 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5661 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5662 | mApp, subId, "setForbiddenPlmns"); |
| 5663 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5664 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5665 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5666 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5667 | } |
| 5668 | if (fplmns == null) { |
| 5669 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5670 | } |
| 5671 | for (String fplmn : fplmns) { |
| 5672 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5673 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5674 | } |
| 5675 | } |
| 5676 | final long identity = Binder.clearCallingIdentity(); |
| 5677 | try { |
| 5678 | Object response = sendRequest( |
| 5679 | CMD_SET_FORBIDDEN_PLMNS, |
| 5680 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5681 | subId); |
| 5682 | return (int) response; |
| 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
| 5686 | } |
| 5687 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5688 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5689 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5691 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5692 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5693 | final long identity = Binder.clearCallingIdentity(); |
| 5694 | try { |
| 5695 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5696 | if (response.payload == null) { |
| 5697 | return ""; |
| 5698 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5700 | // Append the returned status code to the end of the response payload. |
| 5701 | String s = Integer.toHexString( |
| 5702 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5703 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5704 | return s; |
| 5705 | } finally { |
| 5706 | Binder.restoreCallingIdentity(identity); |
| 5707 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5708 | } |
| 5709 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5710 | /** |
| 5711 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5712 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5713 | * |
| 5714 | * @param itemID the ID of the item to read |
| 5715 | * @return the NV item as a String, or null on error. |
| 5716 | */ |
| 5717 | @Override |
| 5718 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5719 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5721 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | |
| 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5726 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5727 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5728 | return value; |
| 5729 | } finally { |
| 5730 | Binder.restoreCallingIdentity(identity); |
| 5731 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | /** |
| 5735 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5736 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5737 | * |
| 5738 | * @param itemID the ID of the item to read |
| 5739 | * @param itemValue the value to write, as a String |
| 5740 | * @return true on success; false on any failure |
| 5741 | */ |
| 5742 | @Override |
| 5743 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5744 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5745 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5746 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5747 | |
| 5748 | final long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
| 5750 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5751 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5752 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5753 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5754 | return success; |
| 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
| 5757 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5758 | } |
| 5759 | |
| 5760 | /** |
| 5761 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5762 | * Used for device configuration by some CDMA operators. |
| 5763 | * |
| 5764 | * @param preferredRoamingList byte array containing the new PRL |
| 5765 | * @return true on success; false on any failure |
| 5766 | */ |
| 5767 | @Override |
| 5768 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5770 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | |
| 5772 | final long identity = Binder.clearCallingIdentity(); |
| 5773 | try { |
| 5774 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5775 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5776 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5777 | return success; |
| 5778 | } finally { |
| 5779 | Binder.restoreCallingIdentity(identity); |
| 5780 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5781 | } |
| 5782 | |
| 5783 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5784 | * 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] | 5785 | * Used for device configuration by some CDMA operators. |
| 5786 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5787 | * @param slotIndex - device slot. |
| 5788 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5789 | * @return true on success; false on any failure |
| 5790 | */ |
| 5791 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5792 | public boolean resetModemConfig(int slotIndex) { |
| 5793 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5794 | if (phone != null) { |
| 5795 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5796 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
| 5800 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5801 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5802 | return success; |
| 5803 | } finally { |
| 5804 | Binder.restoreCallingIdentity(identity); |
| 5805 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5807 | return false; |
| 5808 | } |
| 5809 | |
| 5810 | /** |
| 5811 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5812 | * |
| 5813 | * @param slotIndex - device slot. |
| 5814 | * |
| 5815 | * @return true on success; false on any failure |
| 5816 | */ |
| 5817 | @Override |
| 5818 | public boolean rebootModem(int slotIndex) { |
| 5819 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5820 | if (phone != null) { |
| 5821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5822 | mApp, phone.getSubId(), "rebootModem"); |
| 5823 | |
| 5824 | final long identity = Binder.clearCallingIdentity(); |
| 5825 | try { |
| 5826 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5827 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5828 | return success; |
| 5829 | } finally { |
| 5830 | Binder.restoreCallingIdentity(identity); |
| 5831 | } |
| 5832 | } |
| 5833 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5834 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5835 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5836 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5837 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5838 | * {@link #disableIms(int)}. |
| 5839 | * @param slotIndex device slot. |
| 5840 | */ |
| 5841 | public void resetIms(int slotIndex) { |
| 5842 | enforceModifyPermission(); |
| 5843 | |
| 5844 | final long identity = Binder.clearCallingIdentity(); |
| 5845 | try { |
| 5846 | if (mImsResolver == null) { |
| 5847 | // may happen if the does not support IMS. |
| 5848 | return; |
| 5849 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5850 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5851 | } finally { |
| 5852 | Binder.restoreCallingIdentity(identity); |
| 5853 | } |
| 5854 | } |
| 5855 | |
| 5856 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5857 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5858 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5859 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5860 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5861 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5862 | |
| 5863 | final long identity = Binder.clearCallingIdentity(); |
| 5864 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5865 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5866 | // may happen if the device does not support IMS. |
| 5867 | return; |
| 5868 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5869 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | } finally { |
| 5871 | Binder.restoreCallingIdentity(identity); |
| 5872 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5876 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5877 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5878 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5879 | public void disableIms(int slotId) { |
| 5880 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5884 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5885 | // may happen if the device does not support IMS. |
| 5886 | return; |
| 5887 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5888 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | } finally { |
| 5890 | Binder.restoreCallingIdentity(identity); |
| 5891 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5895 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5896 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5897 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5898 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5899 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5900 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | |
| 5902 | final long identity = Binder.clearCallingIdentity(); |
| 5903 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5904 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5905 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5906 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5907 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5908 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
| 5911 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5912 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5913 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5914 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5915 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5916 | @Override |
| 5917 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5918 | enforceModifyPermission(); |
| 5919 | |
| 5920 | final long identity = Binder.clearCallingIdentity(); |
| 5921 | try { |
| 5922 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5923 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5930 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5931 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5932 | */ |
| 5933 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5934 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5935 | |
| 5936 | final long identity = Binder.clearCallingIdentity(); |
| 5937 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5938 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5939 | // may happen if the device does not support IMS. |
| 5940 | return null; |
| 5941 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5942 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
| 5945 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5946 | } |
| 5947 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5948 | /** |
| 5949 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5950 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5951 | */ |
| 5952 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5953 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5954 | |
| 5955 | final long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5957 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5958 | // may happen if the device does not support IMS. |
| 5959 | return null; |
| 5960 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5961 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
| 5964 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5965 | } |
| 5966 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5967 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5968 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5969 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5970 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5971 | * @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] | 5972 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5973 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5974 | * @param packageName The name of the package that the current configuration will be replaced |
| 5975 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5976 | * @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] | 5977 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5978 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5979 | int[] featureTypes, String packageName) { |
| 5980 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5981 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5983 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5984 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | final long identity = Binder.clearCallingIdentity(); |
| 5987 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5988 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5989 | // may happen if the device does not support IMS. |
| 5990 | return false; |
| 5991 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5992 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5993 | for (int featureType : featureTypes) { |
| 5994 | featureConfig.put(featureType, packageName); |
| 5995 | } |
| 5996 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5997 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
| 6000 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 6004 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 6005 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 6006 | * |
| 6007 | * This should only be used for testing. |
| 6008 | * |
| 6009 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 6010 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 6011 | */ |
| 6012 | @Override |
| 6013 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 6014 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 6015 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 6016 | "clearCarrierImsServiceOverride"); |
| 6017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 6018 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6019 | "clearCarrierImsServiceOverride"); |
| 6020 | |
| 6021 | final long identity = Binder.clearCallingIdentity(); |
| 6022 | try { |
| 6023 | if (mImsResolver == null) { |
| 6024 | // may happen if the device does not support IMS. |
| 6025 | return false; |
| 6026 | } |
| 6027 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
| 6031 | } |
| 6032 | |
| 6033 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6034 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6035 | * |
| 6036 | * @param slotId The slot that the ImsService is associated with. |
| 6037 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6038 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6039 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6040 | * @return the package name of the ImsService configuration. |
| 6041 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6042 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6043 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6044 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6045 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6046 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6047 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6048 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6050 | final long identity = Binder.clearCallingIdentity(); |
| 6051 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6052 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6053 | // may happen if the device does not support IMS. |
| 6054 | return ""; |
| 6055 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6056 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6057 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6058 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6059 | } finally { |
| 6060 | Binder.restoreCallingIdentity(identity); |
| 6061 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6062 | } |
| 6063 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6064 | /** |
| 6065 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6066 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6067 | * @param callback A callback with an integer containing the |
| 6068 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6069 | */ |
| 6070 | @Override |
| 6071 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6072 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6073 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6074 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6075 | "IMS not available on device."); |
| 6076 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6077 | final long token = Binder.clearCallingIdentity(); |
| 6078 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6079 | int slotId = getSlotIndex(subId); |
| 6080 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6081 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6082 | + subId + "'"); |
| 6083 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6084 | } |
| 6085 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6086 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6087 | try { |
| 6088 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6089 | } catch (RemoteException e) { |
| 6090 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6091 | + "Ignore"); |
| 6092 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6093 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6094 | } catch (ImsException e) { |
| 6095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(token); |
| 6098 | } |
| 6099 | } |
| 6100 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6101 | /** |
| 6102 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6103 | */ |
| 6104 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6105 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6109 | // NOTE: Before S, this method only set the default phone. |
| 6110 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6111 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6112 | phone.setImsRegistrationState(registered); |
| 6113 | } |
| 6114 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | } finally { |
| 6116 | Binder.restoreCallingIdentity(identity); |
| 6117 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6118 | } |
| 6119 | |
| 6120 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6121 | * Set the network selection mode to automatic. |
| 6122 | * |
| 6123 | */ |
| 6124 | @Override |
| 6125 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6127 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6128 | |
| 6129 | final long identity = Binder.clearCallingIdentity(); |
| 6130 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6131 | if (!isActiveSubscription(subId)) { |
| 6132 | return; |
| 6133 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6135 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6136 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6140 | } |
| 6141 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6142 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6143 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6144 | * |
| 6145 | * @param subId the id of the subscription. |
| 6146 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6147 | * the operator to attach to. |
| 6148 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6149 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6150 | * normal network selection next time. |
| 6151 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6152 | */ |
| 6153 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6154 | public boolean setNetworkSelectionModeManual( |
| 6155 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6156 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6157 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6158 | |
| 6159 | if (!isActiveSubscription(subId)) { |
| 6160 | return false; |
| 6161 | } |
| 6162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6165 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6167 | if (DBG) { |
| 6168 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6169 | + " operator: " + operatorInfo); |
| 6170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
| 6174 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6175 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6176 | /** |
| 6177 | * Get the manual network selection |
| 6178 | * |
| 6179 | * @param subId the id of the subscription. |
| 6180 | * |
| 6181 | * @return the previously saved user selected PLMN |
| 6182 | */ |
| 6183 | @Override |
| 6184 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6185 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6186 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6187 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
| 6191 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6192 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6193 | } |
| 6194 | |
| 6195 | final Phone phone = getPhone(subId); |
| 6196 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6197 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6198 | } |
| 6199 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6200 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6201 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6202 | } finally { |
| 6203 | Binder.restoreCallingIdentity(identity); |
| 6204 | } |
| 6205 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6206 | |
| 6207 | /** |
| 6208 | * Scans for available networks. |
| 6209 | */ |
| 6210 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6211 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6212 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6213 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6214 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6215 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6216 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6217 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6218 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6219 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6220 | .setCallingPid(Binder.getCallingPid()) |
| 6221 | .setCallingUid(Binder.getCallingUid()) |
| 6222 | .setMethod("getCellNetworkScanResults") |
| 6223 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6224 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6225 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6226 | .build()); |
| 6227 | switch (locationResult) { |
| 6228 | case DENIED_HARD: |
| 6229 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6230 | case DENIED_SOFT: |
| 6231 | return null; |
| 6232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6234 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6235 | try { |
| 6236 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6237 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6245 | * Get the call forwarding info, given the call forwarding reason. |
| 6246 | */ |
| 6247 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6248 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6249 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6250 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6251 | long identity = Binder.clearCallingIdentity(); |
| 6252 | try { |
| 6253 | if (DBG) { |
| 6254 | log("getCallForwarding: subId " + subId |
| 6255 | + " callForwardingReason" + callForwardingReason); |
| 6256 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6257 | |
| 6258 | Phone phone = getPhone(subId); |
| 6259 | if (phone == null) { |
| 6260 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6261 | callback.onError( |
| 6262 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6263 | } catch (RemoteException e) { |
| 6264 | // ignore |
| 6265 | } |
| 6266 | return; |
| 6267 | } |
| 6268 | |
| 6269 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6270 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6271 | @Override |
| 6272 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6273 | try { |
| 6274 | callback.onCallForwardingInfoAvailable(info); |
| 6275 | } catch (RemoteException e) { |
| 6276 | // ignore |
| 6277 | } |
| 6278 | } |
| 6279 | |
| 6280 | @Override |
| 6281 | public void onError(int error) { |
| 6282 | try { |
| 6283 | callback.onError(error); |
| 6284 | } catch (RemoteException e) { |
| 6285 | // ignore |
| 6286 | } |
| 6287 | } |
| 6288 | }); |
| 6289 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6290 | } finally { |
| 6291 | Binder.restoreCallingIdentity(identity); |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | /** |
| 6296 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6297 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6298 | */ |
| 6299 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6300 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6301 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6302 | enforceModifyPermission(); |
| 6303 | long identity = Binder.clearCallingIdentity(); |
| 6304 | try { |
| 6305 | if (DBG) { |
| 6306 | log("setCallForwarding: subId " + subId |
| 6307 | + " callForwardingInfo" + callForwardingInfo); |
| 6308 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6309 | |
| 6310 | Phone phone = getPhone(subId); |
| 6311 | if (phone == null) { |
| 6312 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6313 | callback.accept( |
| 6314 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6315 | } catch (RemoteException e) { |
| 6316 | // ignore |
| 6317 | } |
| 6318 | return; |
| 6319 | } |
| 6320 | |
| 6321 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6322 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6323 | |
| 6324 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6325 | } finally { |
| 6326 | Binder.restoreCallingIdentity(identity); |
| 6327 | } |
| 6328 | } |
| 6329 | |
| 6330 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6331 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6332 | */ |
| 6333 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6334 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6335 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6336 | long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6338 | Phone phone = getPhone(subId); |
| 6339 | if (phone == null) { |
| 6340 | try { |
| 6341 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6342 | } catch (RemoteException e) { |
| 6343 | // ignore |
| 6344 | } |
| 6345 | return; |
| 6346 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6347 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6348 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6349 | boolean requireUssd = c.getBoolean( |
| 6350 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6351 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6352 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6353 | if (requireUssd) { |
| 6354 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6355 | getSubscriptionCarrierId(subId)); |
| 6356 | String newUssdCommand = ""; |
| 6357 | try { |
| 6358 | newUssdCommand = carrierXmlParser.getFeature( |
| 6359 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6360 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6361 | } catch (NullPointerException e) { |
| 6362 | loge("Failed to generate USSD number" + e); |
| 6363 | } |
| 6364 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6365 | mMainThreadHandler, callback, carrierXmlParser, |
| 6366 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6367 | final String ussdCommand = newUssdCommand; |
| 6368 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6369 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6370 | }); |
| 6371 | } else { |
| 6372 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6373 | callback::accept); |
| 6374 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6375 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
| 6379 | } |
| 6380 | |
| 6381 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6382 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6383 | */ |
| 6384 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6385 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6386 | enforceModifyPermission(); |
| 6387 | long identity = Binder.clearCallingIdentity(); |
| 6388 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6389 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6390 | |
| 6391 | Phone phone = getPhone(subId); |
| 6392 | if (phone == null) { |
| 6393 | try { |
| 6394 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6395 | } catch (RemoteException e) { |
| 6396 | // ignore |
| 6397 | } |
| 6398 | return; |
| 6399 | } |
| 6400 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6401 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6402 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6403 | boolean requireUssd = c.getBoolean( |
| 6404 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6405 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6406 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6407 | if (requireUssd) { |
| 6408 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6409 | getSubscriptionCarrierId(subId)); |
| 6410 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6411 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6412 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6413 | String newUssdCommand = ""; |
| 6414 | try { |
| 6415 | newUssdCommand = carrierXmlParser.getFeature( |
| 6416 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6417 | .makeCommand(ssAction, null); |
| 6418 | } catch (NullPointerException e) { |
| 6419 | loge("Failed to generate USSD number" + e); |
| 6420 | } |
| 6421 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6422 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6423 | final String ussdCommand = newUssdCommand; |
| 6424 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6425 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6426 | }); |
| 6427 | } else { |
| 6428 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6429 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6430 | |
| 6431 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6432 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | } |
| 6436 | } |
| 6437 | |
| 6438 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6439 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6440 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6441 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6442 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6443 | * location related information which will be sent if the caller already possess |
| 6444 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6445 | * @param request contains the radio access networks with bands/channels to scan |
| 6446 | * @param messenger callback messenger for scan results or errors |
| 6447 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6448 | * @return the id of the requested scan which can be used to stop the scan. |
| 6449 | */ |
| 6450 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6451 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6452 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6453 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6455 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6456 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6457 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6458 | if (!renounceFineLocationAccess) { |
| 6459 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6460 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6461 | .setCallingPackage(callingPackage) |
| 6462 | .setCallingFeatureId(callingFeatureId) |
| 6463 | .setCallingPid(Binder.getCallingPid()) |
| 6464 | .setCallingUid(Binder.getCallingUid()) |
| 6465 | .setMethod("requestNetworkScan") |
| 6466 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6467 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6468 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6469 | .build()); |
| 6470 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6471 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6472 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6473 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6474 | if (e != null) { |
| 6475 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6476 | throw e; |
| 6477 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6478 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6479 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6480 | } |
| 6481 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6482 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6483 | int callingUid = Binder.getCallingUid(); |
| 6484 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6485 | final long identity = Binder.clearCallingIdentity(); |
| 6486 | try { |
| 6487 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6488 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6489 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6490 | } finally { |
| 6491 | Binder.restoreCallingIdentity(identity); |
| 6492 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6493 | } |
| 6494 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6495 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6496 | NetworkScanRequest request, int subId, String callingPackage) { |
Rambo Wang | 3dee30a | 2022-10-20 16:52:29 +0000 | [diff] [blame] | 6497 | boolean hasCarrierPriv; |
| 6498 | final long identity = Binder.clearCallingIdentity(); |
| 6499 | try { |
| 6500 | hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
| 6501 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6502 | } finally { |
| 6503 | Binder.restoreCallingIdentity(identity); |
| 6504 | } |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6505 | boolean hasNetworkScanPermission = |
| 6506 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6507 | == PERMISSION_GRANTED; |
| 6508 | |
| 6509 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6510 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6511 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6515 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6516 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6517 | return new SecurityException("Specific channels must not be" |
| 6518 | + " scanned without location access."); |
| 6519 | } |
| 6520 | } |
| 6521 | } |
| 6522 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6523 | return null; |
| 6524 | } |
| 6525 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6526 | /** |
| 6527 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6528 | * |
| 6529 | * @param subId id of the subscription |
| 6530 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6531 | */ |
| 6532 | @Override |
| 6533 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6535 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6536 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6537 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6538 | final long identity = Binder.clearCallingIdentity(); |
| 6539 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6540 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6547 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6548 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6549 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6550 | */ |
| 6551 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6552 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6553 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6554 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6555 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | |
| 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6559 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6560 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6561 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6562 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6563 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
| 6566 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6570 | * Get the allowed network types for certain reason. |
| 6571 | * |
| 6572 | * @param subId the id of the subscription. |
| 6573 | * @param reason the reason the allowed network type change is taking place |
| 6574 | * @return the allowed network types. |
| 6575 | */ |
| 6576 | @Override |
| 6577 | public long getAllowedNetworkTypesForReason(int subId, |
| 6578 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6579 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6580 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6581 | final long identity = Binder.clearCallingIdentity(); |
| 6582 | try { |
| 6583 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6584 | } finally { |
| 6585 | Binder.restoreCallingIdentity(identity); |
| 6586 | } |
| 6587 | } |
| 6588 | |
| 6589 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6590 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6591 | * @param subId subscription id of the sim card |
| 6592 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6593 | * This can be passed following states |
| 6594 | * <ol> |
| 6595 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6596 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6597 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6598 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6599 | * </ol> |
| 6600 | * @return operation result. |
| 6601 | */ |
| 6602 | @Override |
| 6603 | public int setNrDualConnectivityState(int subId, |
| 6604 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6606 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6607 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6608 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6609 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6610 | } |
| 6611 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6612 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
| 6615 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6616 | nrDualConnectivityState, subId, |
| 6617 | workSource); |
| 6618 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6619 | return result; |
| 6620 | } finally { |
| 6621 | Binder.restoreCallingIdentity(identity); |
| 6622 | } |
| 6623 | } |
| 6624 | |
| 6625 | /** |
| 6626 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6627 | * @return true if dual connectivity is enabled else false |
| 6628 | */ |
| 6629 | @Override |
| 6630 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6631 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6632 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6633 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6634 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6635 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6636 | return false; |
| 6637 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6638 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6639 | final long identity = Binder.clearCallingIdentity(); |
| 6640 | try { |
| 6641 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6642 | null, subId, workSource); |
| 6643 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6644 | return isEnabled; |
| 6645 | } finally { |
| 6646 | Binder.restoreCallingIdentity(identity); |
| 6647 | } |
| 6648 | } |
| 6649 | |
| 6650 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6651 | * Set the allowed network types of the device and |
| 6652 | * provide the reason triggering the allowed network change. |
| 6653 | * |
| 6654 | * @param subId the id of the subscription. |
| 6655 | * @param reason the reason the allowed network type change is taking place |
| 6656 | * @param allowedNetworkTypes the allowed network types. |
| 6657 | * @return true on success; false on any failure. |
| 6658 | */ |
| 6659 | @Override |
| 6660 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6661 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6662 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6664 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6665 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6666 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6667 | return false; |
| 6668 | } |
| 6669 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6670 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6671 | return false; |
| 6672 | } |
| 6673 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6674 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6675 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6676 | |
| 6677 | |
| 6678 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6679 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6680 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6681 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6682 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6683 | final long identity = Binder.clearCallingIdentity(); |
| 6684 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6685 | Boolean success = (Boolean) sendRequest( |
| 6686 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6687 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6688 | |
| 6689 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6690 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6691 | } finally { |
| 6692 | Binder.restoreCallingIdentity(identity); |
| 6693 | } |
| 6694 | } |
| 6695 | |
| 6696 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6697 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6698 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6699 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6700 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6701 | * @hide |
| 6702 | */ |
| 6703 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6704 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6705 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6707 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6709 | if (phone != null) { |
| 6710 | return phone.hasMatchedTetherApnSetting(); |
| 6711 | } else { |
| 6712 | return false; |
| 6713 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | } finally { |
| 6715 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6716 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6717 | } |
| 6718 | |
| 6719 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6720 | * Get the user enabled state of Mobile Data. |
| 6721 | * |
| 6722 | * TODO: remove and use isUserDataEnabled. |
| 6723 | * This can't be removed now because some vendor codes |
| 6724 | * calls through ITelephony directly while they should |
| 6725 | * use TelephonyManager. |
| 6726 | * |
| 6727 | * @return true on enabled |
| 6728 | */ |
| 6729 | @Override |
| 6730 | public boolean getDataEnabled(int subId) { |
| 6731 | return isUserDataEnabled(subId); |
| 6732 | } |
| 6733 | |
| 6734 | /** |
| 6735 | * Get whether mobile data is enabled per user setting. |
| 6736 | * |
| 6737 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6738 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6739 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6740 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6741 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6742 | * |
| 6743 | * @return {@code true} if data is enabled else {@code false} |
| 6744 | */ |
| 6745 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6746 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6747 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6748 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6749 | try { |
| 6750 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6751 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6752 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6753 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6754 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6755 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6757 | mApp, subId, functionName); |
| 6758 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | |
| 6761 | final long identity = Binder.clearCallingIdentity(); |
| 6762 | try { |
| 6763 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6764 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6765 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6766 | if (phone != null) { |
| 6767 | boolean retVal = phone.isUserDataEnabled(); |
| 6768 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6769 | return retVal; |
| 6770 | } else { |
| 6771 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6772 | return false; |
| 6773 | } |
| 6774 | } finally { |
| 6775 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6780 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6781 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6782 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6783 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6784 | * @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] | 6785 | */ |
| 6786 | @Override |
| 6787 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6788 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6789 | try { |
| 6790 | try { |
| 6791 | mApp.enforceCallingOrSelfPermission( |
| 6792 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6793 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6794 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6795 | try { |
| 6796 | mApp.enforceCallingOrSelfPermission( |
| 6797 | android.Manifest.permission.READ_PHONE_STATE, |
| 6798 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6799 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6800 | mApp.enforceCallingOrSelfPermission( |
| 6801 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6802 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6803 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6804 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6805 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6807 | |
| 6808 | final long identity = Binder.clearCallingIdentity(); |
| 6809 | try { |
| 6810 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6812 | if (phone != null) { |
Sarah Chin | e04784a | 2022-10-31 20:32:34 -0700 | [diff] [blame] | 6813 | boolean retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6814 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6815 | return retVal; |
| 6816 | } else { |
| 6817 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6818 | return false; |
| 6819 | } |
| 6820 | } finally { |
| 6821 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6822 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6823 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6824 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6825 | /** |
| 6826 | * Check if data is enabled for a specific reason |
| 6827 | * @param subId Subscription index |
| 6828 | * @param reason the reason the data enable change is taking place |
| 6829 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6830 | */ |
| 6831 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6832 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6833 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6834 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6835 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6836 | try { |
| 6837 | mApp.enforceCallingOrSelfPermission( |
| 6838 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6839 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6840 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6841 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6842 | functionName); |
| 6843 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6844 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6845 | try { |
| 6846 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6847 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6848 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6849 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6850 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6851 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | |
| 6855 | final long identity = Binder.clearCallingIdentity(); |
| 6856 | try { |
| 6857 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6858 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6859 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6860 | + " reason=" + reason); |
| 6861 | } |
| 6862 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6863 | if (phone != null) { |
| 6864 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6865 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6866 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6867 | return retVal; |
| 6868 | } else { |
| 6869 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6870 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6871 | + subId + " retVal=false"); |
| 6872 | } |
| 6873 | return false; |
| 6874 | } |
| 6875 | } finally { |
| 6876 | Binder.restoreCallingIdentity(identity); |
| 6877 | } |
| 6878 | } |
| 6879 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6881 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6882 | // No permission needed; this only lets the caller inspect their own status. |
| 6883 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6884 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6885 | |
| 6886 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6887 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6888 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6889 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6890 | } |
| 6891 | |
| 6892 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6893 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6894 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6895 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6896 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6897 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6898 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6899 | if (cpt == null) { |
| 6900 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6901 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6902 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6903 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6904 | } |
| 6905 | |
| 6906 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6907 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6908 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6909 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6910 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6911 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6912 | Phone phone = getPhone(subId); |
| 6913 | if (phone == null) { |
| 6914 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6915 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6916 | } |
| 6917 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6918 | if (cpt == null) { |
| 6919 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6920 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6921 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6922 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6923 | } |
| 6924 | |
| 6925 | @Override |
| 6926 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6927 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6928 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6929 | } |
| 6930 | |
| 6931 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6932 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6933 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6934 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6935 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6936 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6937 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6938 | if (phone == null) { |
| 6939 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6940 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6941 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6942 | if (cpt == null) { |
| 6943 | continue; |
| 6944 | } |
| 6945 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6946 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6947 | break; |
| 6948 | } |
| 6949 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6950 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6951 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6952 | |
| 6953 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6954 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6955 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6956 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6957 | if (phone == null) { |
| 6958 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6959 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6960 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6961 | if (cpt == null) { |
| 6962 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6963 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6964 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6965 | } |
| 6966 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6967 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6968 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6969 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6970 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6971 | if (phone == null) { |
| 6972 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6973 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6974 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6975 | if (cpt == null) { |
| 6976 | return Collections.emptyList(); |
| 6977 | } |
| 6978 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6979 | } |
| 6980 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6981 | @Override |
| 6982 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6983 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6984 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6985 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6986 | try { |
| 6987 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6988 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6989 | } |
| 6990 | } finally { |
| 6991 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6992 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6993 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6994 | } |
| 6995 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6996 | @Override |
| 6997 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6998 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6999 | |
| 7000 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 7001 | if (phone == null) { |
| 7002 | return null; |
| 7003 | } |
| 7004 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 7005 | if (cpt == null) { |
| 7006 | return null; |
| 7007 | } |
| 7008 | return cpt.getCarrierServicePackageName(); |
| 7009 | } |
| 7010 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 7011 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7012 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7013 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 7014 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7015 | return null; |
| 7016 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 7017 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7018 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7019 | return null; |
| 7020 | } |
| 7021 | return iccId; |
| 7022 | } |
| 7023 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 7024 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7025 | public void setCallComposerStatus(int subId, int status) { |
| 7026 | enforceModifyPermission(); |
| 7027 | |
| 7028 | final long identity = Binder.clearCallingIdentity(); |
| 7029 | try { |
| 7030 | Phone phone = getPhone(subId); |
| 7031 | if (phone != null) { |
| 7032 | Phone defaultPhone = phone.getImsPhone(); |
| 7033 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7034 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7035 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7036 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7037 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7038 | } |
| 7039 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7040 | } catch (ImsException e) { |
| 7041 | throw new ServiceSpecificException(e.getCode()); |
| 7042 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7043 | Binder.restoreCallingIdentity(identity); |
| 7044 | } |
| 7045 | } |
| 7046 | |
| 7047 | @Override |
| 7048 | public int getCallComposerStatus(int subId) { |
| 7049 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7050 | |
| 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
| 7053 | Phone phone = getPhone(subId); |
| 7054 | if (phone != null) { |
| 7055 | Phone defaultPhone = phone.getImsPhone(); |
| 7056 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7057 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7058 | return imsPhone.getCallComposerStatus(); |
| 7059 | } |
| 7060 | } |
| 7061 | } finally { |
| 7062 | Binder.restoreCallingIdentity(identity); |
| 7063 | } |
| 7064 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7065 | } |
| 7066 | |
| 7067 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7068 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7069 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7070 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7071 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | final long identity = Binder.clearCallingIdentity(); |
| 7074 | try { |
| 7075 | final String iccId = getIccId(subId); |
| 7076 | final Phone phone = getPhone(subId); |
| 7077 | if (phone == null) { |
| 7078 | return false; |
| 7079 | } |
| 7080 | final String subscriberId = phone.getSubscriberId(); |
| 7081 | |
| 7082 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7083 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7084 | + subscriberId + " to " + number); |
| 7085 | } |
| 7086 | |
| 7087 | if (TextUtils.isEmpty(iccId)) { |
| 7088 | return false; |
| 7089 | } |
| 7090 | |
| 7091 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7092 | |
| 7093 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7094 | if (alphaTag == null) { |
| 7095 | editor.remove(alphaTagPrefKey); |
| 7096 | } else { |
| 7097 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7098 | } |
| 7099 | |
| 7100 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7101 | // track all merged IMSIs based on line number |
| 7102 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7103 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7104 | if (number == null) { |
| 7105 | editor.remove(numberPrefKey); |
| 7106 | editor.remove(subscriberPrefKey); |
| 7107 | } else { |
| 7108 | editor.putString(numberPrefKey, number); |
| 7109 | editor.putString(subscriberPrefKey, subscriberId); |
| 7110 | } |
| 7111 | |
| 7112 | editor.commit(); |
| 7113 | return true; |
| 7114 | } finally { |
| 7115 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7116 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7117 | } |
| 7118 | |
| 7119 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7120 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7121 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7122 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7123 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7124 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7125 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7126 | return null; |
| 7127 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7128 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7129 | final long identity = Binder.clearCallingIdentity(); |
| 7130 | try { |
| 7131 | String iccId = getIccId(subId); |
| 7132 | if (iccId != null) { |
| 7133 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7134 | if (DBG_MERGE) { |
| 7135 | log("getLine1NumberForDisplay returning " |
| 7136 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7137 | } |
| 7138 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7139 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7140 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7141 | return null; |
| 7142 | } finally { |
| 7143 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7144 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7145 | } |
| 7146 | |
| 7147 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7148 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7149 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7150 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7151 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7152 | return null; |
| 7153 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7154 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7155 | final long identity = Binder.clearCallingIdentity(); |
| 7156 | try { |
| 7157 | String iccId = getIccId(subId); |
| 7158 | if (iccId != null) { |
| 7159 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7160 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7161 | } |
| 7162 | return null; |
| 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7165 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7166 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7167 | |
| 7168 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7169 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7170 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7171 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7172 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7173 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7174 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7175 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7176 | return null; |
| 7177 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7178 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7179 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7180 | // the process, where TelephonyManager was instantiated. |
| 7181 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7182 | final long identity = Binder.clearCallingIdentity(); |
| 7183 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7184 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7185 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7186 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7187 | |
| 7188 | // Figure out what subscribers are currently active |
| 7189 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7190 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7191 | // Only consider subs which match the current subId |
| 7192 | // This logic can be simplified. See b/131189269 for progress. |
| 7193 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7194 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7195 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | |
| 7197 | // First pass, find a number override for an active subscriber |
| 7198 | String mergeNumber = null; |
| 7199 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7200 | for (String key : prefs.keySet()) { |
| 7201 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7202 | final String subscriberId = (String) prefs.get(key); |
| 7203 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7204 | final String iccId = key.substring( |
| 7205 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7206 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7207 | mergeNumber = (String) prefs.get(numberKey); |
| 7208 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7209 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7210 | + " for active subscriber " + subscriberId); |
| 7211 | } |
| 7212 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7213 | break; |
| 7214 | } |
| 7215 | } |
| 7216 | } |
| 7217 | } |
| 7218 | |
| 7219 | // Shortcut when no active merged subscribers |
| 7220 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7221 | return null; |
| 7222 | } |
| 7223 | |
| 7224 | // Second pass, find all subscribers under that line override |
| 7225 | final ArraySet<String> result = new ArraySet<>(); |
| 7226 | for (String key : prefs.keySet()) { |
| 7227 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7228 | final String number = (String) prefs.get(key); |
| 7229 | if (mergeNumber.equals(number)) { |
| 7230 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7231 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7232 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7233 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7234 | result.add(subscriberId); |
| 7235 | } |
| 7236 | } |
| 7237 | } |
| 7238 | } |
| 7239 | |
| 7240 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7241 | Arrays.sort(resultArray); |
| 7242 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7243 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7244 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7245 | } |
| 7246 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7247 | } finally { |
| 7248 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7249 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7250 | } |
| 7251 | |
| 7252 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7253 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7254 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7255 | |
| 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
| 7258 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7259 | TelephonyManager.class); |
| 7260 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7261 | if (subscriberId == null) { |
| 7262 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7263 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7264 | + subId); |
| 7265 | } |
| 7266 | return null; |
| 7267 | } |
| 7268 | |
| 7269 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7270 | .getSubscriptionInfo(subId); |
| 7271 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7272 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7273 | if (groupUuid == null) { |
| 7274 | return new String[]{subscriberId}; |
| 7275 | } |
| 7276 | |
| 7277 | // Get all subscriberIds from the group. |
| 7278 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7279 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7280 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7281 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7282 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7283 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7284 | if (subscriberId != null) { |
| 7285 | mergedSubscriberIds.add(subscriberId); |
| 7286 | } |
| 7287 | } |
| 7288 | |
| 7289 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7290 | } finally { |
| 7291 | Binder.restoreCallingIdentity(identity); |
| 7292 | |
| 7293 | } |
| 7294 | } |
| 7295 | |
| 7296 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7297 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7298 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7299 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7300 | |
| 7301 | final long identity = Binder.clearCallingIdentity(); |
| 7302 | try { |
| 7303 | final Phone phone = getPhone(subId); |
| 7304 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7305 | } finally { |
| 7306 | Binder.restoreCallingIdentity(identity); |
| 7307 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7308 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7309 | |
| 7310 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7311 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7312 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7313 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7314 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7315 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7316 | |
| 7317 | final long identity = Binder.clearCallingIdentity(); |
| 7318 | try { |
| 7319 | final Phone phone = getPhone(subId); |
| 7320 | if (phone == null) { |
| 7321 | return false; |
| 7322 | } |
| 7323 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7324 | cdmaNonRoamingList); |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7327 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7331 | @Deprecated |
| 7332 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7333 | enforceModifyPermission(); |
| 7334 | |
| 7335 | int returnValue = 0; |
| 7336 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7337 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7338 | if(result.exception == null) { |
| 7339 | if (result.result != null) { |
| 7340 | byte[] responseData = (byte[])(result.result); |
| 7341 | if(responseData.length > oemResp.length) { |
| 7342 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7343 | responseData.length + "bytes. Buffer Size is " + |
| 7344 | oemResp.length + "bytes."); |
| 7345 | } |
| 7346 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7347 | returnValue = responseData.length; |
| 7348 | } |
| 7349 | } else { |
| 7350 | CommandException ex = (CommandException) result.exception; |
| 7351 | returnValue = ex.getCommandError().ordinal(); |
| 7352 | if(returnValue > 0) returnValue *= -1; |
| 7353 | } |
| 7354 | } catch (RuntimeException e) { |
| 7355 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7356 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7357 | if(returnValue > 0) returnValue *= -1; |
| 7358 | } |
| 7359 | |
| 7360 | return returnValue; |
| 7361 | } |
| 7362 | |
| 7363 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7364 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7365 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7366 | try { |
| 7367 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7368 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7369 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7370 | } catch (SecurityException e) { |
| 7371 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7372 | throw e; |
| 7373 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7374 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7375 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7376 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7377 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | final long identity = Binder.clearCallingIdentity(); |
| 7379 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7380 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7381 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7382 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7383 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | } finally { |
| 7385 | Binder.restoreCallingIdentity(identity); |
| 7386 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7387 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7388 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7389 | |
| 7390 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7391 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7392 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7393 | try { |
| 7394 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7395 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7396 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7397 | } |
| 7398 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7399 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7400 | } |
| 7401 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7402 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7403 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7404 | throw new SecurityException("App must be the dialer role holder to" |
| 7405 | + " upload a call composer pic"); |
| 7406 | } |
| 7407 | |
| 7408 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7409 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7410 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7411 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7412 | boolean readUntilEnd = false; |
| 7413 | int totalBytesRead = 0; |
| 7414 | byte[] buffer = new byte[16 * 1024]; |
| 7415 | while (true) { |
| 7416 | int numRead; |
| 7417 | try { |
| 7418 | numRead = input.read(buffer); |
| 7419 | } catch (IOException e) { |
| 7420 | try { |
| 7421 | fd.checkError(); |
| 7422 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7423 | null); |
| 7424 | } catch (IOException e1) { |
| 7425 | // This means that the other side closed explicitly with an error. If this |
| 7426 | // happens, log and ignore. |
| 7427 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7428 | } |
| 7429 | break; |
| 7430 | } |
| 7431 | if (numRead == -1) { |
| 7432 | readUntilEnd = true; |
| 7433 | break; |
| 7434 | } |
| 7435 | totalBytesRead += numRead; |
| 7436 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7437 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7438 | try { |
| 7439 | input.close(); |
| 7440 | } catch (IOException e) { |
| 7441 | // ignore |
| 7442 | } |
| 7443 | break; |
| 7444 | } |
| 7445 | output.write(buffer, 0, numRead); |
| 7446 | } |
| 7447 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7448 | // close is above, where the picture size is too big. |
| 7449 | |
| 7450 | try { |
| 7451 | fd.checkError(); |
| 7452 | } catch (IOException e) { |
| 7453 | loge("Remote end for call composer closed with an error: " + e); |
| 7454 | return; |
| 7455 | } |
| 7456 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7457 | if (!readUntilEnd) { |
| 7458 | loge("Did not finish reading entire image; aborting"); |
| 7459 | return; |
| 7460 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7461 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7462 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7463 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7464 | new CallComposerPictureTransfer.Factory() {}, |
| 7465 | imageData, |
| 7466 | (result) -> { |
| 7467 | if (result.first != null) { |
| 7468 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7469 | Bundle outputResult = new Bundle(); |
| 7470 | outputResult.putParcelable( |
| 7471 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7472 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7473 | outputResult); |
| 7474 | } else { |
| 7475 | callback.send(result.second, null); |
| 7476 | } |
| 7477 | } |
| 7478 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7479 | }); |
| 7480 | } |
| 7481 | |
| 7482 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7483 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7484 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7485 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | |
| 7487 | final long identity = Binder.clearCallingIdentity(); |
| 7488 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7489 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7490 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7491 | } finally { |
| 7492 | Binder.restoreCallingIdentity(identity); |
| 7493 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7497 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7498 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7499 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7500 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7501 | return false; |
| 7502 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7503 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | final long identity = Binder.clearCallingIdentity(); |
| 7505 | try { |
| 7506 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7507 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7508 | // In the long run, we may instead need to check if there exists a connection service |
| 7509 | // which can support video calling. |
| 7510 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7511 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | return imsManager.isVtEnabledByPlatform() |
| 7513 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7514 | && imsManager.isVtEnabledByUser(); |
| 7515 | } finally { |
| 7516 | Binder.restoreCallingIdentity(identity); |
| 7517 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7518 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7519 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7520 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7521 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7522 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7523 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7524 | mApp, subId, callingPackage, callingFeatureId, |
| 7525 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | return false; |
| 7527 | } |
| 7528 | |
| 7529 | final long identity = Binder.clearCallingIdentity(); |
| 7530 | try { |
| 7531 | CarrierConfigManager configManager = |
| 7532 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7533 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7535 | } finally { |
| 7536 | Binder.restoreCallingIdentity(identity); |
| 7537 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7538 | } |
| 7539 | |
| 7540 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7541 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7543 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7544 | return false; |
| 7545 | } |
| 7546 | |
| 7547 | final long identity = Binder.clearCallingIdentity(); |
| 7548 | try { |
| 7549 | CarrierConfigManager configManager = |
| 7550 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7551 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7552 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7553 | } finally { |
| 7554 | Binder.restoreCallingIdentity(identity); |
| 7555 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7556 | } |
| 7557 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7558 | @Override |
| 7559 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7560 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7561 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7562 | } |
| 7563 | |
| 7564 | @Override |
| 7565 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7566 | final long identity = Binder.clearCallingIdentity(); |
| 7567 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7568 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | } finally { |
| 7570 | Binder.restoreCallingIdentity(identity); |
| 7571 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7572 | } |
| 7573 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7574 | /** |
| 7575 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7576 | * support for the feature and device firmware support. |
| 7577 | * |
| 7578 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7579 | */ |
| 7580 | @Override |
| 7581 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7582 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7583 | final Phone phone = getPhone(subscriptionId); |
| 7584 | if (phone == null) { |
| 7585 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7586 | return false; |
| 7587 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7588 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7589 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7590 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7591 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7592 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | return isCarrierSupported && isDeviceSupported; |
| 7594 | } finally { |
| 7595 | Binder.restoreCallingIdentity(identity); |
| 7596 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7597 | } |
| 7598 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7599 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7600 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7601 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7602 | * 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] | 7603 | */ |
| 7604 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7607 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7608 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7609 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7610 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7611 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7612 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7616 | } |
| 7617 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7618 | @Deprecated |
| 7619 | @Override |
| 7620 | public String getDeviceId(String callingPackage) { |
| 7621 | return getDeviceIdWithFeature(callingPackage, null); |
| 7622 | } |
| 7623 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7624 | /** |
| 7625 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7626 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7627 | * |
| 7628 | * <p>Requires Permission: |
| 7629 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7630 | */ |
| 7631 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7632 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7633 | try { |
| 7634 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7635 | } catch (SecurityException se) { |
| 7636 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7637 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7638 | + Binder.getCallingUid()); |
| 7639 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7640 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7641 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7642 | return null; |
| 7643 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7644 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7645 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7646 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7647 | return null; |
| 7648 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7649 | |
| 7650 | final long identity = Binder.clearCallingIdentity(); |
| 7651 | try { |
| 7652 | return phone.getDeviceId(); |
| 7653 | } finally { |
| 7654 | Binder.restoreCallingIdentity(identity); |
| 7655 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7656 | } |
| 7657 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7658 | /** |
| 7659 | * {@hide} |
| 7660 | * Returns the IMS Registration Status on a particular subid |
| 7661 | * |
| 7662 | * @param subId |
| 7663 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7664 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7665 | Phone phone = getPhone(subId); |
| 7666 | if (phone != null) { |
| 7667 | return phone.isImsRegistered(); |
| 7668 | } else { |
| 7669 | return false; |
| 7670 | } |
| 7671 | } |
| 7672 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7673 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7674 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7675 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7676 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7677 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7678 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7679 | } |
| 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
| 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7689 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7690 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7691 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7692 | mApp, |
| 7693 | subscriptionId, |
| 7694 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7695 | final long identity = Binder.clearCallingIdentity(); |
| 7696 | try { |
| 7697 | Phone phone = getPhone(subscriptionId); |
| 7698 | if (phone == null) { |
| 7699 | return null; |
| 7700 | } |
| 7701 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7702 | } finally { |
| 7703 | Binder.restoreCallingIdentity(identity); |
| 7704 | } |
| 7705 | } |
| 7706 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7707 | /** |
| 7708 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7709 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7710 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
| 7713 | Phone phone = getPhone(subId); |
| 7714 | if (phone != null) { |
| 7715 | return phone.isWifiCallingEnabled(); |
| 7716 | } else { |
| 7717 | return false; |
| 7718 | } |
| 7719 | } finally { |
| 7720 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7721 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7722 | } |
| 7723 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7724 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7725 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7726 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7727 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | final long identity = Binder.clearCallingIdentity(); |
| 7729 | try { |
| 7730 | Phone phone = getPhone(subId); |
| 7731 | if (phone != null) { |
| 7732 | return phone.isVideoEnabled(); |
| 7733 | } else { |
| 7734 | return false; |
| 7735 | } |
| 7736 | } finally { |
| 7737 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7738 | } |
| 7739 | } |
| 7740 | |
| 7741 | /** |
| 7742 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7743 | * defined in {@link ImsRegistrationImplBase}. |
| 7744 | */ |
| 7745 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7746 | final long identity = Binder.clearCallingIdentity(); |
| 7747 | try { |
| 7748 | Phone phone = getPhone(subId); |
| 7749 | if (phone != null) { |
| 7750 | return phone.getImsRegistrationTech(); |
| 7751 | } else { |
| 7752 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7753 | } |
| 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7756 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7757 | } |
| 7758 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7759 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7760 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7761 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7762 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7763 | return; |
| 7764 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7765 | Phone defaultPhone = getDefaultPhone(); |
| 7766 | if (defaultPhone != null) { |
| 7767 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7768 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7769 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7770 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7771 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7772 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7773 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7774 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7775 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7776 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7777 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7778 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7779 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7780 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7781 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7782 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7783 | // There has been issues when Sms raw table somehow stores orphan |
| 7784 | // fragments. They lead to garbled message when new fragments come |
| 7785 | // in and combined with those stale ones. In case this happens again, |
| 7786 | // user can reset all network settings which will clean up this table. |
| 7787 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7788 | // Clean up IMS settings as well here. |
| 7789 | int slotId = getSlotIndex(subId); |
| 7790 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7791 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7792 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7793 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7794 | if (defaultPhone == null) { |
| 7795 | return; |
| 7796 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7797 | // Erase modem config if erase modem on network setting is enabled. |
| 7798 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7799 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7800 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7801 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7802 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7803 | |
| 7804 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7805 | } finally { |
| 7806 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7807 | } |
| 7808 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7809 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7810 | @VisibleForTesting |
| 7811 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7812 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7813 | return; |
| 7814 | } |
| 7815 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7816 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7817 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7818 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7819 | "user=" + defaultNetworkType); |
| 7820 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7821 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7822 | defaultNetworkType, null); |
| 7823 | } |
| 7824 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7825 | private void cleanUpSmsRawTable(Context context) { |
| 7826 | ContentResolver resolver = context.getContentResolver(); |
| 7827 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7828 | resolver.delete(uri, null, null); |
| 7829 | } |
| 7830 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7831 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7832 | public String getSimLocaleForSubscriber(int subId) { |
| 7833 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7834 | final Phone phone = getPhone(subId); |
| 7835 | if (phone == null) { |
| 7836 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7837 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7838 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | final long identity = Binder.clearCallingIdentity(); |
| 7840 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7841 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7842 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7843 | if (info == null) { |
| 7844 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7845 | return null; |
| 7846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7847 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7848 | // preferences (EF-PL and EF-LI)... |
| 7849 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7850 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7851 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7852 | if (localeFromDefaultSim != null) { |
| 7853 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7854 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7855 | + localeFromDefaultSim); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7856 | return matchLocaleFromSupportedLocaleList(phone, localeFromDefaultSim); |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7857 | } else { |
| 7858 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7859 | } |
| 7860 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7861 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7862 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7863 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7864 | // the SIM and carrier preferences does not include a country we add the country |
| 7865 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7866 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7867 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7868 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7869 | return matchLocaleFromSupportedLocaleList(phone, mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7870 | } |
| 7871 | |
| 7872 | if (DBG) log("No locale found - returning null"); |
| 7873 | return null; |
| 7874 | } finally { |
| 7875 | Binder.restoreCallingIdentity(identity); |
| 7876 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7877 | } |
| 7878 | |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7879 | @VisibleForTesting |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7880 | String matchLocaleFromSupportedLocaleList(Phone phone, @NonNull Locale inputLocale) { |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7881 | String[] supportedLocale = com.android.internal.app.LocalePicker.getSupportedLocales( |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7882 | phone.getContext()); |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7883 | for (String localeTag : supportedLocale) { |
tom hsu | 60a8dc5 | 2022-10-27 00:10:04 +0800 | [diff] [blame] | 7884 | if (LocaleList.matchesLanguageAndScript(inputLocale, Locale.forLanguageTag(localeTag)) |
| 7885 | && TextUtils.equals(inputLocale.getCountry(), |
tom hsu | 0b59d29 | 2022-09-29 23:49:21 +0800 | [diff] [blame] | 7886 | Locale.forLanguageTag(localeTag).getCountry())) { |
| 7887 | return localeTag; |
| 7888 | } |
| 7889 | } |
| 7890 | return inputLocale.toLanguageTag(); |
| 7891 | } |
| 7892 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7893 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7894 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7895 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7896 | } |
| 7897 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7898 | /** |
| 7899 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7900 | */ |
| 7901 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7902 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7903 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7904 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7905 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7906 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7907 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7908 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7909 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7910 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7911 | * representing the state of the modem. |
| 7912 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7913 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7914 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7915 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7916 | */ |
| 7917 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7918 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7919 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7920 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7921 | |
| 7922 | final long identity = Binder.clearCallingIdentity(); |
| 7923 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7924 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7925 | } finally { |
| 7926 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7927 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7928 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7929 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7930 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7931 | // less than total activity duration. |
| 7932 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7933 | if (info == null) { |
| 7934 | return false; |
| 7935 | } |
| 7936 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7937 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7938 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7939 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7940 | return (info.isValid() |
| 7941 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7942 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7943 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7944 | && (totalTxTimeMs <= activityDurationMs)); |
| 7945 | } |
| 7946 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7947 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7948 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7949 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7950 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7951 | |
| 7952 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7953 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7954 | } |
| 7955 | |
| 7956 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7957 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7958 | rat, |
| 7959 | freq, |
| 7960 | info.getReceiveTimeMillis(rat, freq) |
| 7961 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7962 | } |
| 7963 | |
| 7964 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7965 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7966 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7967 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7968 | |
| 7969 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7970 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7971 | } |
| 7972 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7973 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7974 | rat, |
| 7975 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7976 | } |
| 7977 | |
| 7978 | /** |
| 7979 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7980 | * @param info recent ModemActivityInfo |
| 7981 | */ |
| 7982 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7983 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7984 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7985 | boolean matched; |
| 7986 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7987 | matched = false; |
| 7988 | int rat = info.getSpecificInfoRat(i); |
| 7989 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7990 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7991 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7992 | //if it already exists |
| 7993 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7994 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7995 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7996 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7997 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7998 | updateLastModemActivityInfo(info, rat, freq); |
| 7999 | matched = true; |
| 8000 | } |
| 8001 | } else { |
| 8002 | updateLastModemActivityInfo(info, rat); |
| 8003 | matched = true; |
| 8004 | } |
| 8005 | } |
| 8006 | } |
| 8007 | |
| 8008 | if (!matched) { |
| 8009 | mDeltaSpecificInfo = |
| 8010 | new ActivityStatsTechSpecificInfo( |
| 8011 | rat, |
| 8012 | freq, |
| 8013 | info.getTransmitTimeMillis(rat, freq), |
| 8014 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 8015 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 8016 | } |
| 8017 | } |
| 8018 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 8019 | mLastModemActivitySpecificInfo = |
| 8020 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 8021 | merged.toArray(mLastModemActivitySpecificInfo); |
| 8022 | |
| 8023 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 8024 | mLastModemActivityInfo.setSleepTimeMillis( |
| 8025 | info.getSleepTimeMillis() |
| 8026 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 8027 | mLastModemActivityInfo.setIdleTimeMillis( |
| 8028 | info.getIdleTimeMillis() |
| 8029 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 8030 | } |
| 8031 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8032 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8033 | * Returns the service state information on specified subscription. |
| 8034 | */ |
| 8035 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8036 | public ServiceState getServiceStateForSubscriber(int subId, |
| 8037 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 8038 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8039 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8040 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8041 | return null; |
| 8042 | } |
| 8043 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8044 | boolean hasFinePermission = false; |
| 8045 | boolean hasCoarsePermission = false; |
| 8046 | if (!renounceFineLocationAccess) { |
| 8047 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8048 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8049 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8050 | .setCallingPackage(callingPackage) |
| 8051 | .setCallingFeatureId(callingFeatureId) |
| 8052 | .setCallingPid(Binder.getCallingPid()) |
| 8053 | .setCallingUid(Binder.getCallingUid()) |
| 8054 | .setMethod("getServiceStateForSubscriber") |
| 8055 | .setLogAsInfo(true) |
| 8056 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8057 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8058 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8059 | .build()); |
| 8060 | hasFinePermission = |
| 8061 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8062 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8063 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8064 | if (!renounceCoarseLocationAccess) { |
| 8065 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8066 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8067 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8068 | .setCallingPackage(callingPackage) |
| 8069 | .setCallingFeatureId(callingFeatureId) |
| 8070 | .setCallingPid(Binder.getCallingPid()) |
| 8071 | .setCallingUid(Binder.getCallingUid()) |
| 8072 | .setMethod("getServiceStateForSubscriber") |
| 8073 | .setLogAsInfo(true) |
| 8074 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8075 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8076 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8077 | .build()); |
| 8078 | hasCoarsePermission = |
| 8079 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8080 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8081 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8082 | final Phone phone = getPhone(subId); |
| 8083 | if (phone == null) { |
| 8084 | return null; |
| 8085 | } |
| 8086 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8087 | final long identity = Binder.clearCallingIdentity(); |
| 8088 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8089 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8090 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8092 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8093 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8094 | Rlog.d(LOG_TAG, |
| 8095 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8096 | return null; |
| 8097 | } |
| 8098 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8099 | ServiceState ss = phone.getServiceState(); |
| 8100 | |
| 8101 | // Scrub out the location info in ServiceState depending on what level of access |
| 8102 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8103 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8104 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8105 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| 8108 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8109 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8110 | |
| 8111 | /** |
| 8112 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8113 | * |
| 8114 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8115 | * voicemail ringtone. |
| 8116 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8117 | * PhoneAccount. |
| 8118 | */ |
| 8119 | @Override |
| 8120 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8121 | final long identity = Binder.clearCallingIdentity(); |
| 8122 | try { |
| 8123 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8124 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8125 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8126 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8127 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8128 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8129 | } finally { |
| 8130 | Binder.restoreCallingIdentity(identity); |
| 8131 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8132 | } |
| 8133 | |
| 8134 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8135 | * Sets the per-account voicemail ringtone. |
| 8136 | * |
| 8137 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8138 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8139 | * |
| 8140 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8141 | * voicemail ringtone. |
| 8142 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8143 | * PhoneAccount. |
| 8144 | */ |
| 8145 | @Override |
| 8146 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8147 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8148 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8149 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8150 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8151 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8153 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8154 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8156 | |
| 8157 | final long identity = Binder.clearCallingIdentity(); |
| 8158 | try { |
| 8159 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8160 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8161 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8162 | } |
| 8163 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8164 | } finally { |
| 8165 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8166 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8167 | } |
| 8168 | |
| 8169 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8170 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8171 | * |
| 8172 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8173 | * voicemail vibration setting. |
| 8174 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8175 | */ |
| 8176 | @Override |
| 8177 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8178 | final long identity = Binder.clearCallingIdentity(); |
| 8179 | try { |
| 8180 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8181 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8182 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8183 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8184 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8185 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8186 | } finally { |
| 8187 | Binder.restoreCallingIdentity(identity); |
| 8188 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8189 | } |
| 8190 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8191 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8192 | * Sets the per-account voicemail vibration. |
| 8193 | * |
| 8194 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8195 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8196 | * |
| 8197 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8198 | * voicemail vibration setting. |
| 8199 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8200 | * specific PhoneAccount. |
| 8201 | */ |
| 8202 | @Override |
| 8203 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8204 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8205 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8206 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8207 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8208 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8209 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8210 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8211 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8212 | } |
| 8213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | final long identity = Binder.clearCallingIdentity(); |
| 8215 | try { |
| 8216 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8217 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8218 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8219 | } |
| 8220 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8223 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8224 | } |
| 8225 | |
| 8226 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8227 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8228 | * |
| 8229 | * @throws SecurityException if the caller does not have the required permission |
| 8230 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8231 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8232 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8233 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8237 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8238 | * permission. |
| 8239 | * |
| 8240 | * @throws SecurityException if the caller does not have the required permission |
| 8241 | */ |
| 8242 | private void enforceSendSmsPermission() { |
| 8243 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8244 | } |
| 8245 | |
| 8246 | /** |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame^] | 8247 | * Make sure either called from same process as self (phone) or IPC caller has interact across |
| 8248 | * users permission. |
| 8249 | * |
| 8250 | * @throws SecurityException if the caller does not have the required permission |
| 8251 | */ |
| 8252 | private void enforceInteractAcrossUsersPermission(String message) { |
| 8253 | mApp.enforceCallingOrSelfPermission(permission.INTERACT_ACROSS_USERS, message); |
| 8254 | } |
| 8255 | |
| 8256 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8257 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8258 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8259 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8260 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8261 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
| 8264 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8265 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8266 | if (componentName == null) { |
| 8267 | throw new SecurityException( |
| 8268 | "Caller not current active visual voicemail package[null]"); |
| 8269 | } |
| 8270 | String vvmPackage = componentName.getPackageName(); |
| 8271 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8272 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8273 | } |
| 8274 | } finally { |
| 8275 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8276 | } |
| 8277 | } |
| 8278 | |
| 8279 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8280 | * Return the application ID for the app type. |
| 8281 | * |
| 8282 | * @param subId the subscription ID that this request applies to. |
| 8283 | * @param appType the uicc app type. |
| 8284 | * @return Application ID for specificied app type, or null if no uicc. |
| 8285 | */ |
| 8286 | @Override |
| 8287 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8288 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8289 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8290 | |
| 8291 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8292 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | if (phone == null) { |
| 8294 | return null; |
| 8295 | } |
| 8296 | String aid = null; |
| 8297 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8298 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8299 | .getApplicationByType(appType).getAid(); |
| 8300 | } catch (Exception e) { |
| 8301 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8302 | } |
| 8303 | return aid; |
| 8304 | } finally { |
| 8305 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8306 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8307 | } |
| 8308 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8309 | /** |
| 8310 | * Return the Electronic Serial Number. |
| 8311 | * |
| 8312 | * @param subId the subscription ID that this request applies to. |
| 8313 | * @return ESN or null if error. |
| 8314 | */ |
| 8315 | @Override |
| 8316 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8317 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8318 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8319 | |
| 8320 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8321 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8322 | if (phone == null) { |
| 8323 | return null; |
| 8324 | } |
| 8325 | String esn = null; |
| 8326 | try { |
| 8327 | esn = phone.getEsn(); |
| 8328 | } catch (Exception e) { |
| 8329 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8330 | } |
| 8331 | return esn; |
| 8332 | } finally { |
| 8333 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8334 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8335 | } |
| 8336 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8337 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8338 | * Return the Preferred Roaming List Version. |
| 8339 | * |
| 8340 | * @param subId the subscription ID that this request applies to. |
| 8341 | * @return PRLVersion or null if error. |
| 8342 | */ |
| 8343 | @Override |
| 8344 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8345 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8346 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8347 | |
| 8348 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8349 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8350 | if (phone == null) { |
| 8351 | return null; |
| 8352 | } |
| 8353 | String cdmaPrlVersion = null; |
| 8354 | try { |
| 8355 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8356 | } catch (Exception e) { |
| 8357 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8358 | } |
| 8359 | return cdmaPrlVersion; |
| 8360 | } finally { |
| 8361 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8362 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8363 | } |
| 8364 | |
| 8365 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8366 | * Get snapshot of Telephony histograms |
| 8367 | * @return List of Telephony histograms |
| 8368 | * @hide |
| 8369 | */ |
| 8370 | @Override |
| 8371 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8373 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8374 | |
| 8375 | final long identity = Binder.clearCallingIdentity(); |
| 8376 | try { |
| 8377 | return RIL.getTelephonyRILTimingHistograms(); |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
| 8380 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8381 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8382 | |
| 8383 | /** |
| 8384 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8385 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8386 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8387 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8388 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8389 | * @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] | 8390 | */ |
| 8391 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8392 | @TelephonyManager.SetCarrierRestrictionResult |
| 8393 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8394 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8395 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8396 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8397 | if (carrierRestrictionRules == null) { |
| 8398 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8399 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8401 | final long identity = Binder.clearCallingIdentity(); |
| 8402 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8403 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8404 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8405 | } finally { |
| 8406 | Binder.restoreCallingIdentity(identity); |
| 8407 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8408 | } |
| 8409 | |
| 8410 | /** |
| 8411 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8412 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8413 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8414 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8415 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8416 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8417 | */ |
| 8418 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8419 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8420 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8421 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8422 | |
| 8423 | final long identity = Binder.clearCallingIdentity(); |
| 8424 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8425 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8426 | if (response instanceof CarrierRestrictionRules) { |
| 8427 | return (CarrierRestrictionRules) response; |
| 8428 | } |
| 8429 | // Response is an Exception of some kind, |
| 8430 | // which is signalled to the user as a NULL retval |
| 8431 | return null; |
| 8432 | } catch (Exception e) { |
| 8433 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8434 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | } finally { |
| 8436 | Binder.restoreCallingIdentity(identity); |
| 8437 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8438 | } |
| 8439 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8440 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8441 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8442 | * @param subId the subscription ID that this action applies to. |
| 8443 | * @param enabled control enable or disable radio. |
| 8444 | * {@hide} |
| 8445 | */ |
| 8446 | @Override |
| 8447 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8448 | enforceModifyPermission(); |
| 8449 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8450 | |
| 8451 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8452 | if (phone == null) { |
| 8453 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8454 | return; |
| 8455 | } |
| 8456 | try { |
| 8457 | phone.carrierActionSetRadioEnabled(enabled); |
| 8458 | } catch (Exception e) { |
| 8459 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8460 | } finally { |
| 8461 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8462 | } |
| 8463 | } |
| 8464 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8465 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8466 | * Enable or disable Voice over NR (VoNR) |
| 8467 | * @param subId the subscription ID that this action applies to. |
| 8468 | * @param enabled enable or disable VoNR. |
| 8469 | * @return operation result. |
| 8470 | */ |
| 8471 | @Override |
| 8472 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8473 | enforceModifyPermission(); |
| 8474 | final Phone phone = getPhone(subId); |
| 8475 | |
| 8476 | final long identity = Binder.clearCallingIdentity(); |
| 8477 | if (phone == null) { |
| 8478 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8479 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8480 | } |
| 8481 | |
| 8482 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8483 | try { |
| 8484 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8485 | workSource); |
| 8486 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8487 | |
| 8488 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8489 | if (DBG) { |
| 8490 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8491 | } |
| 8492 | SubscriptionManager.setSubscriptionProperty( |
| 8493 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8494 | (enabled ? "1" : "0")); |
| 8495 | } |
| 8496 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8497 | return result; |
| 8498 | } finally { |
| 8499 | Binder.restoreCallingIdentity(identity); |
| 8500 | } |
| 8501 | } |
| 8502 | |
| 8503 | /** |
| 8504 | * Is voice over NR enabled |
| 8505 | * @return true if VoNR is enabled else false |
| 8506 | */ |
| 8507 | @Override |
| 8508 | public boolean isVoNrEnabled(int subId) { |
| 8509 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8510 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8511 | final long identity = Binder.clearCallingIdentity(); |
| 8512 | try { |
| 8513 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8514 | null, subId, workSource); |
| 8515 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8516 | return isEnabled; |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(identity); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8523 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8524 | * network status based on which carrier apps could apply actions accordingly, |
| 8525 | * enable/disable default url handler for example. |
| 8526 | * |
| 8527 | * @param subId the subscription ID that this action applies to. |
| 8528 | * @param report control start/stop reporting the default network status. |
| 8529 | * {@hide} |
| 8530 | */ |
| 8531 | @Override |
| 8532 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8533 | enforceModifyPermission(); |
| 8534 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8535 | |
| 8536 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8537 | if (phone == null) { |
| 8538 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8539 | return; |
| 8540 | } |
| 8541 | try { |
| 8542 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8543 | } catch (Exception e) { |
| 8544 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8545 | } finally { |
| 8546 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8547 | } |
| 8548 | } |
| 8549 | |
| 8550 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8551 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8552 | * @param subId the subscription ID that this action applies to. |
| 8553 | * {@hide} |
| 8554 | */ |
| 8555 | @Override |
| 8556 | public void carrierActionResetAll(int subId) { |
| 8557 | enforceModifyPermission(); |
| 8558 | final Phone phone = getPhone(subId); |
| 8559 | if (phone == null) { |
| 8560 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8561 | return; |
| 8562 | } |
| 8563 | try { |
| 8564 | phone.carrierActionResetAll(); |
| 8565 | } catch (Exception e) { |
| 8566 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8567 | } |
| 8568 | } |
| 8569 | |
| 8570 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8571 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8572 | * bug report is being generated. |
| 8573 | */ |
| 8574 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8575 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8576 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8577 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8578 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8579 | + Binder.getCallingPid() |
| 8580 | + ", uid=" + Binder.getCallingUid() |
| 8581 | + "without permission " |
| 8582 | + android.Manifest.permission.DUMP); |
| 8583 | return; |
| 8584 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8585 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8586 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8587 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8588 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8589 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8590 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8591 | @NonNull String[] args) { |
| 8592 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8593 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8594 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8595 | } |
| 8596 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8597 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8598 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8599 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8600 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8601 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8602 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8603 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8604 | */ |
| 8605 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8606 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8607 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8608 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8609 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8610 | try { |
| 8611 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8612 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8613 | } catch (SecurityException se) { |
| 8614 | enforceModifyPermission(); |
| 8615 | } |
| 8616 | } else { |
| 8617 | enforceModifyPermission(); |
| 8618 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8619 | |
| 8620 | final long identity = Binder.clearCallingIdentity(); |
| 8621 | try { |
| 8622 | Phone phone = getPhone(subId); |
| 8623 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8624 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8625 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8626 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8627 | phone.getDataSettingsManager().setDataEnabled( |
| 8628 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8629 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8630 | } |
| 8631 | } finally { |
| 8632 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8633 | } |
| 8634 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8635 | |
| 8636 | /** |
| 8637 | * Get Client request stats |
| 8638 | * @return List of Client Request Stats |
| 8639 | * @hide |
| 8640 | */ |
| 8641 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8642 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8643 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8644 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8645 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8646 | return null; |
| 8647 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8648 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8650 | final long identity = Binder.clearCallingIdentity(); |
| 8651 | try { |
| 8652 | if (phone != null) { |
| 8653 | return phone.getClientRequestStats(); |
| 8654 | } |
| 8655 | |
| 8656 | return null; |
| 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
| 8659 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8660 | } |
| 8661 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8662 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8663 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8664 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8665 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8666 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8667 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8668 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8669 | // commands that plumb through the RIL as root, like so: |
| 8670 | // $ adb root |
| 8671 | // $ adb shell cmd phone ... |
| 8672 | packageName = "root"; |
| 8673 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8674 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8675 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8676 | |
| 8677 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8678 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8679 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8680 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8681 | * @param state State of SIM (power down, power up, pass through) |
| 8682 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8683 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8684 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8685 | * |
| 8686 | **/ |
| 8687 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8688 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8689 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8690 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8691 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8692 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8694 | final long identity = Binder.clearCallingIdentity(); |
| 8695 | try { |
| 8696 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8697 | phone.setSimPowerState(state, null, workSource); |
| 8698 | } |
| 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
| 8701 | } |
| 8702 | } |
| 8703 | |
| 8704 | /** |
| 8705 | * Set SIM card power state. |
| 8706 | * |
| 8707 | * @param slotIndex SIM slot id. |
| 8708 | * @param state State of SIM (power down, power up, pass through) |
| 8709 | * @param callback callback to trigger after success or failure |
| 8710 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8711 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8712 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8713 | * |
| 8714 | **/ |
| 8715 | @Override |
| 8716 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8717 | IIntegerConsumer callback) { |
| 8718 | enforceModifyPermission(); |
| 8719 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8720 | |
| 8721 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8722 | |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | if (phone != null) { |
| 8726 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8727 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8728 | } |
| 8729 | } finally { |
| 8730 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8731 | } |
| 8732 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8733 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8734 | private boolean isUssdApiAllowed(int subId) { |
| 8735 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8736 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8737 | if (configManager == null) { |
| 8738 | return false; |
| 8739 | } |
| 8740 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8741 | if (pb == null) { |
| 8742 | return false; |
| 8743 | } |
| 8744 | return pb.getBoolean( |
| 8745 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8746 | } |
| 8747 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8748 | /** |
| 8749 | * Check if phone is in emergency callback mode |
| 8750 | * @return true if phone is in emergency callback mode |
| 8751 | * @param subId sub id |
| 8752 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8753 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8754 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8755 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8756 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8757 | |
| 8758 | final long identity = Binder.clearCallingIdentity(); |
| 8759 | try { |
| 8760 | if (phone != null) { |
| 8761 | return phone.isInEcm(); |
| 8762 | } else { |
| 8763 | return false; |
| 8764 | } |
| 8765 | } finally { |
| 8766 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8767 | } |
| 8768 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8769 | |
| 8770 | /** |
| 8771 | * Get the current signal strength information for the given subscription. |
| 8772 | * Because this information is not updated when the device is in a low power state |
| 8773 | * it should not be relied-upon to be current. |
| 8774 | * @param subId Subscription index |
| 8775 | * @return the most recent cached signal strength info from the modem |
| 8776 | */ |
| 8777 | @Override |
| 8778 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8779 | final long identity = Binder.clearCallingIdentity(); |
| 8780 | try { |
| 8781 | Phone p = getPhone(subId); |
| 8782 | if (p == null) { |
| 8783 | return null; |
| 8784 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8786 | return p.getSignalStrength(); |
| 8787 | } finally { |
| 8788 | Binder.restoreCallingIdentity(identity); |
| 8789 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8790 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8791 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8792 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8793 | * Get the current modem radio state for the given slot. |
| 8794 | * @param slotIndex slot index. |
| 8795 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8796 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8797 | * @return the current radio power state from the modem |
| 8798 | */ |
| 8799 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8800 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8801 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8802 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8804 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8805 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8806 | } |
| 8807 | |
| 8808 | final long identity = Binder.clearCallingIdentity(); |
| 8809 | try { |
| 8810 | return phone.getRadioPowerState(); |
| 8811 | } finally { |
| 8812 | Binder.restoreCallingIdentity(identity); |
| 8813 | } |
| 8814 | } |
| 8815 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8816 | } |
| 8817 | |
| 8818 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8819 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8820 | * |
| 8821 | * <p>Requires one of the following permissions: |
| 8822 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8823 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8824 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8825 | * privileges. |
| 8826 | * |
| 8827 | * @param subId subscription id |
| 8828 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8829 | * {@code false}. |
| 8830 | */ |
| 8831 | @Override |
| 8832 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8833 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8834 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8835 | try { |
| 8836 | mApp.enforceCallingOrSelfPermission( |
| 8837 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8838 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8839 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8840 | mApp.enforceCallingOrSelfPermission( |
| 8841 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8842 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8843 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8844 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8845 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8846 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8847 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8848 | boolean isEnabled = false; |
| 8849 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8850 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8851 | Phone phone = getPhone(subId); |
| 8852 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8853 | } finally { |
| 8854 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8855 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8856 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8857 | } |
| 8858 | |
| 8859 | |
| 8860 | /** |
| 8861 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8862 | * |
| 8863 | * <p> Requires permission: |
| 8864 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8865 | * privileges. |
| 8866 | * |
| 8867 | * @param subId subscription id |
| 8868 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8869 | */ |
| 8870 | @Override |
| 8871 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8873 | mApp, subId, "setDataRoamingEnabled"); |
| 8874 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8875 | final long identity = Binder.clearCallingIdentity(); |
| 8876 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8877 | Phone phone = getPhone(subId); |
| 8878 | if (phone != null) { |
| 8879 | phone.setDataRoamingEnabled(isEnabled); |
| 8880 | } |
| 8881 | } finally { |
| 8882 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8883 | } |
| 8884 | } |
| 8885 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8886 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8887 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8888 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8889 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8890 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8891 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8892 | boolean isAllowed = true; |
| 8893 | final long identity = Binder.clearCallingIdentity(); |
| 8894 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8895 | Phone phone = getPhone(subId); |
| 8896 | if (phone != null) { |
| 8897 | isAllowed = phone.isCspPlmnEnabled(); |
| 8898 | } |
| 8899 | } finally { |
| 8900 | Binder.restoreCallingIdentity(identity); |
| 8901 | } |
| 8902 | return isAllowed; |
| 8903 | } |
| 8904 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8905 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8906 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8907 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8908 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8909 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8910 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8911 | if (phone == null) { |
| 8912 | return false; |
| 8913 | } |
| 8914 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8915 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8916 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8917 | } |
| 8918 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8919 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8920 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8921 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8922 | mApp.getSystemService(AppOpsManager.class) |
| 8923 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8924 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8925 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8926 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8927 | try { |
| 8928 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8929 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8930 | } catch (SecurityException e) { |
| 8931 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8932 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8933 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8934 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8935 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8936 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8937 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8938 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8939 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8940 | Binder.getCallingUid())) { |
| 8941 | isIccIdAccessRestricted = true; |
| 8942 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8943 | final long identity = Binder.clearCallingIdentity(); |
| 8944 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8945 | UiccController uiccController = UiccController.getInstance(); |
| 8946 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8947 | if (hasReadPermission) { |
| 8948 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8949 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8950 | |
| 8951 | // Remove private info if the caller doesn't have access |
| 8952 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8953 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8954 | //setting the value after compatibility check |
| 8955 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8956 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8957 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8958 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8959 | if (card == null) { |
| 8960 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8961 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8962 | continue; |
| 8963 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8964 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8965 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8966 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8967 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8968 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8969 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8970 | for (UiccPortInfo portInfo : portInfos) { |
| 8971 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8972 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8973 | if (port == null) { |
| 8974 | // assume no access if port is null |
| 8975 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8976 | continue; |
| 8977 | } |
| 8978 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8979 | uiccPortInfos.add(portInfo); |
| 8980 | } else { |
| 8981 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8982 | } |
| 8983 | } |
| 8984 | filteredInfos.add(new UiccCardInfo( |
| 8985 | cardInfo.isEuicc(), |
| 8986 | cardInfo.getCardId(), |
| 8987 | null, |
| 8988 | cardInfo.getPhysicalSlotIndex(), |
| 8989 | cardInfo.isRemovable(), |
| 8990 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8991 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8992 | } |
| 8993 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8994 | } finally { |
| 8995 | Binder.restoreCallingIdentity(identity); |
| 8996 | } |
| 8997 | } |
| 8998 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8999 | /** |
| 9000 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 9001 | * generally private and require carrier privileges to view. |
| 9002 | * |
| 9003 | * @hide |
| 9004 | */ |
| 9005 | @NonNull |
| 9006 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 9007 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 9008 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 9009 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 9010 | } |
| 9011 | return new UiccCardInfo( |
| 9012 | cardInfo.isEuicc(), |
| 9013 | cardInfo.getCardId(), |
| 9014 | null, |
| 9015 | cardInfo.getPhysicalSlotIndex(), |
| 9016 | cardInfo.isRemovable(), |
| 9017 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 9018 | portinfo |
| 9019 | ); |
| 9020 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9021 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9022 | /** |
| 9023 | * @hide |
| 9024 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 9025 | * These values are generally private and require carrier privileges to view. |
| 9026 | */ |
| 9027 | @NonNull |
| 9028 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 9029 | return new UiccPortInfo( |
| 9030 | UiccPortInfo.ICCID_REDACTED, |
| 9031 | portInfo.getPortIndex(), |
| 9032 | portInfo.getLogicalSlotIndex(), |
| 9033 | portInfo.isActive() |
| 9034 | ); |
| 9035 | } |
| 9036 | @Override |
| 9037 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9038 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9039 | mApp.getSystemService(AppOpsManager.class) |
| 9040 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 9041 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9042 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9043 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9044 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 9045 | // we are reading iccId which is PII data. |
| 9046 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9047 | |
| 9048 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 9049 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 9050 | Binder.getCallingUid())) { |
| 9051 | isLogicalSlotAccessRestricted = true; |
| 9052 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9053 | final long identity = Binder.clearCallingIdentity(); |
| 9054 | try { |
| 9055 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9056 | if (slots == null || slots.length == 0) { |
| 9057 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9058 | return null; |
| 9059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9060 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9061 | for (int i = 0; i < slots.length; i++) { |
| 9062 | UiccSlot slot = slots[i]; |
| 9063 | if (slot == null) { |
| 9064 | continue; |
| 9065 | } |
| 9066 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9067 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9068 | UiccCard card = slot.getUiccCard(); |
| 9069 | if (card != null) { |
| 9070 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9071 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9072 | cardId = slot.getEid(); |
| 9073 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9074 | // If cardId is null, use iccId of default port as cardId. |
| 9075 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9076 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9077 | } |
| 9078 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9079 | if (cardId != null) { |
| 9080 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9081 | // if cardId is an EID, it's all digits so this is fine |
| 9082 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9083 | } |
| 9084 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9085 | int cardState = 0; |
| 9086 | switch (slot.getCardState()) { |
| 9087 | case CARDSTATE_ABSENT: |
| 9088 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9089 | break; |
| 9090 | case CARDSTATE_PRESENT: |
| 9091 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9092 | break; |
| 9093 | case CARDSTATE_ERROR: |
| 9094 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9095 | break; |
| 9096 | case CARDSTATE_RESTRICTED: |
| 9097 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9098 | break; |
| 9099 | default: |
| 9100 | break; |
| 9101 | |
| 9102 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9103 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9104 | int[] portIndexes = slot.getPortList(); |
| 9105 | for (int portIdx : portIndexes) { |
| 9106 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9107 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9108 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9109 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9111 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9112 | slot.isEuicc(), |
| 9113 | cardId, |
| 9114 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9115 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9116 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9117 | //setting the value after compatibility check |
| 9118 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9119 | } |
| 9120 | return infos; |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9123 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9124 | } |
| 9125 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9126 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9127 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9128 | boolean hasReadPermission) { |
| 9129 | String iccId = slot.getIccId(portIndex); |
| 9130 | if (hasReadPermission) { // if has read permission |
| 9131 | return iccId; |
| 9132 | } else { |
| 9133 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9134 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9135 | // if no read permission, checking carrier privilege access |
| 9136 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9137 | return iccId; |
| 9138 | } |
| 9139 | } |
| 9140 | } |
| 9141 | // No read permission or carrier privilege access. |
| 9142 | return UiccPortInfo.ICCID_REDACTED; |
| 9143 | } |
| 9144 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9145 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9146 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9147 | public boolean switchSlots(int[] physicalSlots) { |
| 9148 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9149 | |
| 9150 | final long identity = Binder.clearCallingIdentity(); |
| 9151 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9152 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9153 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9154 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9155 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9156 | physicalSlots[i], i)); |
| 9157 | } |
| 9158 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9159 | } finally { |
| 9160 | Binder.restoreCallingIdentity(identity); |
| 9161 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9162 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9163 | |
| 9164 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9165 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9166 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9167 | enforceModifyPermission(); |
| 9168 | |
| 9169 | final long identity = Binder.clearCallingIdentity(); |
| 9170 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9171 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9172 | } finally { |
| 9173 | Binder.restoreCallingIdentity(identity); |
| 9174 | } |
| 9175 | } |
| 9176 | |
| 9177 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9178 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9179 | final long identity = Binder.clearCallingIdentity(); |
| 9180 | try { |
| 9181 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9182 | } finally { |
| 9183 | Binder.restoreCallingIdentity(identity); |
| 9184 | } |
| 9185 | } |
| 9186 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9187 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9188 | * A test API to reload the UICC profile. |
| 9189 | * |
| 9190 | * <p>Requires that the calling app has permission |
| 9191 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9192 | * @hide |
| 9193 | */ |
| 9194 | @Override |
| 9195 | public void refreshUiccProfile(int subId) { |
| 9196 | enforceModifyPermission(); |
| 9197 | |
| 9198 | final long identity = Binder.clearCallingIdentity(); |
| 9199 | try { |
| 9200 | Phone phone = getPhone(subId); |
| 9201 | if (phone == null) { |
| 9202 | return; |
| 9203 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9204 | UiccPort uiccPort = phone.getUiccPort(); |
| 9205 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9206 | return; |
| 9207 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9208 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9209 | if (uiccProfile == null) { |
| 9210 | return; |
| 9211 | } |
| 9212 | uiccProfile.refresh(); |
| 9213 | } finally { |
| 9214 | Binder.restoreCallingIdentity(identity); |
| 9215 | } |
| 9216 | } |
| 9217 | |
| 9218 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9219 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9220 | */ |
| 9221 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9222 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9223 | } |
| 9224 | |
| 9225 | /** |
| 9226 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9227 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9228 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9229 | */ |
| 9230 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9231 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9232 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9233 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9234 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9235 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9236 | return isDataRoamingEnabled; |
| 9237 | } |
| 9238 | |
| 9239 | /** |
| 9240 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9241 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9242 | */ |
| 9243 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9244 | List<Integer> list = TelephonyProperties.default_network(); |
| 9245 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9246 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9247 | return list.get(phoneId); |
| 9248 | } |
| 9249 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9250 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9251 | |
| 9252 | @Override |
| 9253 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9254 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9255 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9256 | |
| 9257 | final long identity = Binder.clearCallingIdentity(); |
| 9258 | try { |
| 9259 | final Phone phone = getPhone(subId); |
| 9260 | if (phone == null) { |
| 9261 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9262 | return; |
| 9263 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9264 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9265 | if (cpt != null) { |
| 9266 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9267 | } |
| 9268 | // 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] | 9269 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9270 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9271 | if (carrierPrivilegeRules == null) { |
| 9272 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9273 | } else { |
| 9274 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9276 | } finally { |
| 9277 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9278 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9279 | } |
| 9280 | |
| 9281 | @Override |
| 9282 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9283 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9284 | |
| 9285 | final long identity = Binder.clearCallingIdentity(); |
| 9286 | try { |
| 9287 | final Phone phone = getPhone(subId); |
| 9288 | if (phone == null) { |
| 9289 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9290 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9291 | } |
| 9292 | return phone.getCarrierIdListVersion(); |
| 9293 | } finally { |
| 9294 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9295 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9296 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9297 | |
| 9298 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9299 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9300 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9301 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9302 | mApp, subId, callingPackage, callingFeatureId, |
| 9303 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9304 | return -1; |
| 9305 | } |
| 9306 | |
| 9307 | final long identity = Binder.clearCallingIdentity(); |
| 9308 | try { |
| 9309 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9310 | } finally { |
| 9311 | Binder.restoreCallingIdentity(identity); |
| 9312 | } |
| 9313 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9314 | |
| 9315 | @Override |
| 9316 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9317 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9318 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9319 | mApp, subId, "getCdmaRoamingMode"); |
| 9320 | |
| 9321 | final long identity = Binder.clearCallingIdentity(); |
| 9322 | try { |
| 9323 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
| 9328 | |
| 9329 | @Override |
| 9330 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9332 | mApp, subId, "setCdmaRoamingMode"); |
| 9333 | |
| 9334 | final long identity = Binder.clearCallingIdentity(); |
| 9335 | try { |
| 9336 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9337 | } finally { |
| 9338 | Binder.restoreCallingIdentity(identity); |
| 9339 | } |
| 9340 | } |
| 9341 | |
| 9342 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9343 | public int getCdmaSubscriptionMode(int subId) { |
| 9344 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9345 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9346 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9347 | |
| 9348 | final long identity = Binder.clearCallingIdentity(); |
| 9349 | try { |
| 9350 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9351 | } finally { |
| 9352 | Binder.restoreCallingIdentity(identity); |
| 9353 | } |
| 9354 | } |
| 9355 | |
| 9356 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9357 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9358 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9359 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9360 | |
| 9361 | final long identity = Binder.clearCallingIdentity(); |
| 9362 | try { |
| 9363 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9364 | } finally { |
| 9365 | Binder.restoreCallingIdentity(identity); |
| 9366 | } |
| 9367 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9368 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9369 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9370 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9371 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9372 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9373 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9374 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9375 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9376 | } |
| 9377 | final long identity = Binder.clearCallingIdentity(); |
| 9378 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9379 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9380 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9381 | if (phone.getEmergencyNumberTracker() != null |
| 9382 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9383 | emergencyNumberListInternal.put( |
| 9384 | phone.getSubId(), |
| 9385 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9386 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9387 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9388 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9389 | } finally { |
| 9390 | Binder.restoreCallingIdentity(identity); |
| 9391 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9392 | } |
| 9393 | |
| 9394 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9395 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9396 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9397 | if (!exactMatch) { |
| 9398 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9399 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9400 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9401 | } |
| 9402 | final long identity = Binder.clearCallingIdentity(); |
| 9403 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9404 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9405 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9406 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9407 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9408 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9409 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9410 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9411 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9412 | } |
| 9413 | return false; |
| 9414 | } finally { |
| 9415 | Binder.restoreCallingIdentity(identity); |
| 9416 | } |
| 9417 | } |
| 9418 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9419 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9420 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9421 | */ |
| 9422 | @Override |
| 9423 | public void startEmergencyCallbackMode() { |
| 9424 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9425 | "startEmergencyCallbackMode"); |
| 9426 | enforceModifyPermission(); |
| 9427 | final long identity = Binder.clearCallingIdentity(); |
| 9428 | try { |
| 9429 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9430 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9431 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9432 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9433 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9434 | gsmCdmaPhone.obtainMessage( |
| 9435 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9436 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9437 | } |
| 9438 | } |
| 9439 | } finally { |
| 9440 | Binder.restoreCallingIdentity(identity); |
| 9441 | } |
| 9442 | } |
| 9443 | |
| 9444 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9445 | * Update emergency number list for test mode. |
| 9446 | */ |
| 9447 | @Override |
| 9448 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9449 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9450 | "updateEmergencyNumberListTestMode"); |
| 9451 | |
| 9452 | final long identity = Binder.clearCallingIdentity(); |
| 9453 | try { |
| 9454 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9455 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9456 | if (tracker != null) { |
| 9457 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9458 | } |
| 9459 | } |
| 9460 | } finally { |
| 9461 | Binder.restoreCallingIdentity(identity); |
| 9462 | } |
| 9463 | } |
| 9464 | |
| 9465 | /** |
| 9466 | * Get the full emergency number list for test mode. |
| 9467 | */ |
| 9468 | @Override |
| 9469 | public List<String> getEmergencyNumberListTestMode() { |
| 9470 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9471 | "getEmergencyNumberListTestMode"); |
| 9472 | |
| 9473 | final long identity = Binder.clearCallingIdentity(); |
| 9474 | try { |
| 9475 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9476 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9477 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9478 | if (tracker != null) { |
| 9479 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9480 | emergencyNumbers.add(num.getNumber()); |
| 9481 | } |
| 9482 | } |
| 9483 | } |
| 9484 | return new ArrayList<>(emergencyNumbers); |
| 9485 | } finally { |
| 9486 | Binder.restoreCallingIdentity(identity); |
| 9487 | } |
| 9488 | } |
| 9489 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9490 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9491 | public int getEmergencyNumberDbVersion(int subId) { |
| 9492 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9493 | |
| 9494 | final long identity = Binder.clearCallingIdentity(); |
| 9495 | try { |
| 9496 | final Phone phone = getPhone(subId); |
| 9497 | if (phone == null) { |
| 9498 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9499 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9500 | } |
| 9501 | return phone.getEmergencyNumberDbVersion(); |
| 9502 | } finally { |
| 9503 | Binder.restoreCallingIdentity(identity); |
| 9504 | } |
| 9505 | } |
| 9506 | |
| 9507 | @Override |
| 9508 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9509 | enforceModifyPermission(); |
| 9510 | |
| 9511 | final long identity = Binder.clearCallingIdentity(); |
| 9512 | try { |
| 9513 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9514 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9515 | if (tracker != null) { |
| 9516 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9517 | } |
| 9518 | } |
| 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
| 9521 | } |
| 9522 | } |
| 9523 | |
| 9524 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9525 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9526 | enforceActiveEmergencySessionPermission(); |
| 9527 | |
| 9528 | final long identity = Binder.clearCallingIdentity(); |
| 9529 | try { |
| 9530 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9531 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9532 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9533 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9534 | } |
| 9535 | } |
| 9536 | } finally { |
| 9537 | Binder.restoreCallingIdentity(identity); |
| 9538 | } |
| 9539 | } |
| 9540 | |
| 9541 | @Override |
| 9542 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9543 | enforceActiveEmergencySessionPermission(); |
| 9544 | |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9548 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9549 | if (tracker != null) { |
| 9550 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9551 | } |
| 9552 | } |
| 9553 | } finally { |
| 9554 | Binder.restoreCallingIdentity(identity); |
| 9555 | } |
| 9556 | } |
| 9557 | |
| 9558 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9559 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9560 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9561 | Phone phone = getPhone(subId); |
| 9562 | if (phone == null) { |
| 9563 | return null; |
| 9564 | } |
| 9565 | final long identity = Binder.clearCallingIdentity(); |
| 9566 | try { |
| 9567 | UiccProfile profile = UiccController.getInstance() |
| 9568 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9569 | if (profile != null) { |
| 9570 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9571 | } |
| 9572 | } finally { |
| 9573 | Binder.restoreCallingIdentity(identity); |
| 9574 | } |
| 9575 | return null; |
| 9576 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9577 | |
| 9578 | /** |
| 9579 | * Enable or disable a modem stack. |
| 9580 | */ |
| 9581 | @Override |
| 9582 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9583 | enforceModifyPermission(); |
| 9584 | |
| 9585 | final long identity = Binder.clearCallingIdentity(); |
| 9586 | try { |
| 9587 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9588 | if (phone == null) { |
| 9589 | return false; |
| 9590 | } else { |
| 9591 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9592 | } |
| 9593 | } finally { |
| 9594 | Binder.restoreCallingIdentity(identity); |
| 9595 | } |
| 9596 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9597 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9598 | /** |
| 9599 | * Whether a modem stack is enabled or not. |
| 9600 | */ |
| 9601 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9602 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9603 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9604 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9605 | if (phone == null) return false; |
| 9606 | |
| 9607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9608 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9609 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9610 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9611 | } |
| 9612 | |
| 9613 | final long identity = Binder.clearCallingIdentity(); |
| 9614 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9615 | try { |
| 9616 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9617 | } catch (NoSuchElementException ex) { |
| 9618 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9619 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9625 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9626 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9627 | enforceModifyPermission(); |
| 9628 | |
| 9629 | final long identity = Binder.clearCallingIdentity(); |
| 9630 | try { |
| 9631 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9632 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9633 | .commit(); |
| 9634 | } finally { |
| 9635 | Binder.restoreCallingIdentity(identity); |
| 9636 | } |
| 9637 | } |
| 9638 | |
| 9639 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9640 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9641 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9642 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9643 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9644 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9645 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9646 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9647 | |
| 9648 | final long identity = Binder.clearCallingIdentity(); |
| 9649 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9650 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9651 | } finally { |
| 9652 | Binder.restoreCallingIdentity(identity); |
| 9653 | } |
| 9654 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9655 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9656 | @TelephonyManager.IsMultiSimSupportedResult |
| 9657 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9658 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9659 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9660 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9661 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9662 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9663 | } |
| 9664 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9665 | // supported by the modem, indicate that it is restricted. |
| 9666 | PhoneCapability staticCapability = |
| 9667 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9668 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9669 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9670 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9671 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9672 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9673 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9674 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9675 | } |
| 9676 | // Check if support of multiple SIMs is restricted by carrier |
| 9677 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9678 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9679 | } |
| 9680 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9681 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9682 | } |
| 9683 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9684 | /** |
| 9685 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9686 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9687 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9688 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9689 | * @param numOfSims number of active sims we want to switch to |
| 9690 | */ |
| 9691 | @Override |
| 9692 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9693 | if (numOfSims == 1) { |
| 9694 | enforceModifyPermission(); |
| 9695 | } else { |
| 9696 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9697 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9698 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9699 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9700 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9701 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9702 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9703 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9704 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9705 | return; |
| 9706 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9707 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9708 | } finally { |
| 9709 | Binder.restoreCallingIdentity(identity); |
| 9710 | } |
| 9711 | } |
| 9712 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9713 | @Override |
| 9714 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9715 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9716 | Phone phone = getPhone(subId); |
| 9717 | if (phone == null) { |
| 9718 | return false; |
| 9719 | } |
| 9720 | final long identity = Binder.clearCallingIdentity(); |
| 9721 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9722 | UiccPort uiccPort = phone.getUiccPort(); |
| 9723 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9724 | return false; |
| 9725 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9726 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9727 | if (uiccProfile == null) { |
| 9728 | return false; |
| 9729 | } |
| 9730 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9731 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9732 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9733 | } |
| 9734 | return false; |
| 9735 | } finally { |
| 9736 | Binder.restoreCallingIdentity(identity); |
| 9737 | } |
| 9738 | } |
| 9739 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9740 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9741 | * Get whether making changes to modem configurations will trigger reboot. |
| 9742 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9743 | */ |
| 9744 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9745 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9746 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9747 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9748 | mApp, subId, callingPackage, callingFeatureId, |
| 9749 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9750 | return false; |
| 9751 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9752 | final long identity = Binder.clearCallingIdentity(); |
| 9753 | try { |
| 9754 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9755 | } finally { |
| 9756 | Binder.restoreCallingIdentity(identity); |
| 9757 | } |
| 9758 | } |
| 9759 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9760 | private void updateModemStateMetrics() { |
| 9761 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9762 | // TODO: check the state for each modem if the api is ready. |
| 9763 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9764 | } |
| 9765 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9766 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9767 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9768 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9769 | // Verify that the callingPackage belongs to the calling UID |
| 9770 | mApp.getSystemService(AppOpsManager.class) |
| 9771 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9772 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9773 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9774 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9775 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9776 | if (slotInfos != null) { |
| 9777 | for (int i = 0; i < slotInfos.length; i++) { |
| 9778 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9779 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9780 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9781 | portInfo.getLogicalSlotIndex())); |
| 9782 | } |
| 9783 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9784 | } |
| 9785 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9786 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9787 | } finally { |
| 9788 | Binder.restoreCallingIdentity(identity); |
| 9789 | } |
| 9790 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9791 | |
| 9792 | /** |
| 9793 | * Get the IRadio HAL Version |
| 9794 | */ |
| 9795 | @Override |
| 9796 | public int getRadioHalVersion() { |
| 9797 | Phone phone = getDefaultPhone(); |
| 9798 | if (phone == null) return -1; |
| 9799 | HalVersion hv = phone.getHalVersion(); |
| 9800 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9801 | return hv.major * 100 + hv.minor; |
| 9802 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9803 | |
| 9804 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9805 | * Get the current calling package name. |
| 9806 | * @return the current calling package name |
| 9807 | */ |
| 9808 | @Override |
| 9809 | public String getCurrentPackageName() { |
| 9810 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9811 | } |
| 9812 | |
| 9813 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9814 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9815 | * corresponding network requests on a subId. |
| 9816 | * |
| 9817 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9818 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9819 | * 2) APN is un-metered for this subscription, or |
| 9820 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9821 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9822 | * |
| 9823 | * @return whether data is allowed for a apn type. |
| 9824 | * |
| 9825 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9826 | */ |
| 9827 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9828 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9829 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9830 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9831 | |
| 9832 | // Now that all security checks passes, perform the operation as ourselves. |
| 9833 | final long identity = Binder.clearCallingIdentity(); |
| 9834 | try { |
| 9835 | Phone phone = getPhone(subId); |
| 9836 | if (phone == null) return false; |
| 9837 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9838 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9839 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9840 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9841 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9842 | phone.getServiceState().getDataRoaming()); |
| 9843 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9844 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9845 | } finally { |
| 9846 | Binder.restoreCallingIdentity(identity); |
| 9847 | } |
| 9848 | } |
| 9849 | |
| 9850 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9851 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9852 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9853 | |
| 9854 | // Now that all security checks passes, perform the operation as ourselves. |
| 9855 | final long identity = Binder.clearCallingIdentity(); |
| 9856 | try { |
| 9857 | Phone phone = getPhone(subId); |
| 9858 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9859 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9860 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9861 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9862 | } finally { |
| 9863 | Binder.restoreCallingIdentity(identity); |
| 9864 | } |
| 9865 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9866 | |
| 9867 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9868 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9869 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9870 | enforceModifyPermission(); |
| 9871 | long token = Binder.clearCallingIdentity(); |
| 9872 | try { |
| 9873 | Phone phone = getPhone(subscriptionId); |
| 9874 | if (phone == null) { |
| 9875 | try { |
| 9876 | if (resultCallback != null) { |
| 9877 | resultCallback.accept(false); |
| 9878 | } |
| 9879 | } catch (RemoteException e) { |
| 9880 | // ignore |
| 9881 | } |
| 9882 | return; |
| 9883 | } |
| 9884 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9885 | Pair.create(specifiers, (x) -> { |
| 9886 | try { |
| 9887 | if (resultCallback != null) { |
| 9888 | resultCallback.accept(x); |
| 9889 | } |
| 9890 | } catch (RemoteException e) { |
| 9891 | // ignore |
| 9892 | } |
| 9893 | }); |
| 9894 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9895 | } finally { |
| 9896 | Binder.restoreCallingIdentity(token); |
| 9897 | } |
| 9898 | } |
| 9899 | |
| 9900 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9901 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9902 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9903 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9904 | mApp, subId, "getSystemSelectionChannels"); |
| 9905 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9906 | final long identity = Binder.clearCallingIdentity(); |
| 9907 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9908 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9909 | if (result instanceof IllegalStateException) { |
| 9910 | throw (IllegalStateException) result; |
| 9911 | } |
| 9912 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9913 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9914 | return specifiers; |
| 9915 | } finally { |
| 9916 | Binder.restoreCallingIdentity(identity); |
| 9917 | } |
| 9918 | } |
| 9919 | |
| 9920 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9921 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9922 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9923 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9924 | } |
| 9925 | |
| 9926 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9927 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9928 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9929 | if (callingPackage == null) { |
| 9930 | callingPackage = getCurrentPackageName(); |
| 9931 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9932 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9933 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9934 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9935 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9936 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9937 | } |
| 9938 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9939 | Intent intent = new Intent(); |
| 9940 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9941 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9942 | // Bring up choose default SMS subscription dialog right now |
| 9943 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9944 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9945 | mApp.startActivity(intent); |
| 9946 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9947 | |
| 9948 | @Override |
| 9949 | public String getMmsUAProfUrl(int subId) { |
| 9950 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9951 | final long identity = Binder.clearCallingIdentity(); |
| 9952 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9953 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9954 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9955 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9956 | return carrierUAProfUrl; |
| 9957 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9958 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9959 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9960 | } finally { |
| 9961 | Binder.restoreCallingIdentity(identity); |
| 9962 | } |
| 9963 | } |
| 9964 | |
| 9965 | @Override |
| 9966 | public String getMmsUserAgent(int subId) { |
| 9967 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9968 | final long identity = Binder.clearCallingIdentity(); |
| 9969 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9970 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9971 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9972 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9973 | return carrierUserAgent; |
| 9974 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9975 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9976 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9977 | } finally { |
| 9978 | Binder.restoreCallingIdentity(identity); |
| 9979 | } |
| 9980 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9981 | |
| 9982 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9983 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9984 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9985 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9986 | final long identity = Binder.clearCallingIdentity(); |
| 9987 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9988 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9989 | if (phone == null) return false; |
| 9990 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 9991 | return phone.getDataSettingsManager().isMobileDataPolicyEnabled(policy); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9992 | } finally { |
| 9993 | Binder.restoreCallingIdentity(identity); |
| 9994 | } |
| 9995 | } |
| 9996 | |
| 9997 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9998 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9999 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10000 | enforceModifyPermission(); |
| 10001 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10002 | final long identity = Binder.clearCallingIdentity(); |
| 10003 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 10004 | Phone phone = getPhone(subscriptionId); |
| 10005 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10006 | |
Ling Ma | f188d50 | 2022-09-16 15:22:36 -0700 | [diff] [blame] | 10007 | phone.getDataSettingsManager().setMobileDataPolicy(policy, enabled); |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 10008 | } finally { |
| 10009 | Binder.restoreCallingIdentity(identity); |
| 10010 | } |
| 10011 | } |
| 10012 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10013 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 10014 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 10015 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 10016 | * otherwise. |
| 10017 | */ |
| 10018 | @Override |
| 10019 | public void setCepEnabled(boolean isCepEnabled) { |
| 10020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 10021 | |
| 10022 | final long identity = Binder.clearCallingIdentity(); |
| 10023 | try { |
| 10024 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 10025 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10026 | Phone defaultPhone = phone.getImsPhone(); |
| 10027 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 10028 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 10029 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10030 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 10031 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 10032 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 10033 | + imsPhone.getMsisdn()); |
| 10034 | } |
| 10035 | } |
| 10036 | } finally { |
| 10037 | Binder.restoreCallingIdentity(identity); |
| 10038 | } |
| 10039 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10040 | |
| 10041 | /** |
| 10042 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10043 | * |
| 10044 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10045 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10046 | * before being read. |
| 10047 | */ |
| 10048 | @Override |
| 10049 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10050 | isCompressed) { |
| 10051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10052 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10053 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10054 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10055 | } |
| 10056 | if (!isImsAvailableOnDevice()) { |
| 10057 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10058 | "IMS not available on device."); |
| 10059 | } |
| 10060 | |
| 10061 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10062 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10063 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10064 | } finally { |
| 10065 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10066 | } |
| 10067 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10068 | |
| 10069 | @Override |
| 10070 | public boolean isIccLockEnabled(int subId) { |
| 10071 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10072 | |
| 10073 | // Now that all security checks passes, perform the operation as ourselves. |
| 10074 | final long identity = Binder.clearCallingIdentity(); |
| 10075 | try { |
| 10076 | Phone phone = getPhone(subId); |
| 10077 | if (phone != null && phone.getIccCard() != null) { |
| 10078 | return phone.getIccCard().getIccLockEnabled(); |
| 10079 | } else { |
| 10080 | return false; |
| 10081 | } |
| 10082 | } finally { |
| 10083 | Binder.restoreCallingIdentity(identity); |
| 10084 | } |
| 10085 | } |
| 10086 | |
| 10087 | /** |
| 10088 | * Set the ICC pin lock enabled or disabled. |
| 10089 | * |
| 10090 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10091 | * three cases: |
| 10092 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10093 | * successfully. |
| 10094 | * - Positive number and zero for remaining password attempts. |
| 10095 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10096 | * |
| 10097 | */ |
| 10098 | @Override |
| 10099 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10100 | enforceModifyPermission(); |
| 10101 | |
| 10102 | Phone phone = getPhone(subId); |
| 10103 | if (phone == null) { |
| 10104 | return 0; |
| 10105 | } |
| 10106 | // Now that all security checks passes, perform the operation as ourselves. |
| 10107 | final long identity = Binder.clearCallingIdentity(); |
| 10108 | try { |
| 10109 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10110 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10111 | return attemptsRemaining; |
| 10112 | |
| 10113 | } catch (Exception e) { |
| 10114 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10115 | } finally { |
| 10116 | Binder.restoreCallingIdentity(identity); |
| 10117 | } |
| 10118 | return 0; |
| 10119 | } |
| 10120 | |
| 10121 | /** |
| 10122 | * Change the ICC password used in ICC pin lock. |
| 10123 | * |
| 10124 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10125 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10126 | * - Positive number and zero for remaining password attempts. |
| 10127 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10128 | * |
| 10129 | */ |
| 10130 | @Override |
| 10131 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10132 | enforceModifyPermission(); |
| 10133 | |
| 10134 | Phone phone = getPhone(subId); |
| 10135 | if (phone == null) { |
| 10136 | return 0; |
| 10137 | } |
| 10138 | // Now that all security checks passes, perform the operation as ourselves. |
| 10139 | final long identity = Binder.clearCallingIdentity(); |
| 10140 | try { |
| 10141 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10142 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10143 | return attemptsRemaining; |
| 10144 | |
| 10145 | } catch (Exception e) { |
| 10146 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10147 | } finally { |
| 10148 | Binder.restoreCallingIdentity(identity); |
| 10149 | } |
| 10150 | return 0; |
| 10151 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10152 | |
| 10153 | /** |
| 10154 | * Request for receiving user activity notification |
| 10155 | */ |
| 10156 | @Override |
| 10157 | public void requestUserActivityNotification() { |
| 10158 | if (!mNotifyUserActivity.get() |
| 10159 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10160 | mNotifyUserActivity.set(true); |
| 10161 | } |
| 10162 | } |
| 10163 | |
| 10164 | /** |
| 10165 | * Called when userActivity is signalled in the power manager. |
| 10166 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10167 | */ |
| 10168 | @Override |
| 10169 | public void userActivity() { |
| 10170 | // *************************************** |
| 10171 | // * Inherited from PhoneWindowManager * |
| 10172 | // *************************************** |
| 10173 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10174 | // WITH ITS LOCKS HELD. |
| 10175 | // |
| 10176 | // This code must be VERY careful about the locks |
| 10177 | // it acquires. |
| 10178 | // In fact, the current code acquires way too many, |
| 10179 | // and probably has lurking deadlocks. |
| 10180 | |
| 10181 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10182 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10183 | } |
| 10184 | |
| 10185 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10186 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10187 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10188 | } |
| 10189 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10190 | |
| 10191 | @Override |
| 10192 | public boolean canConnectTo5GInDsdsMode() { |
| 10193 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10194 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10195 | |
| 10196 | @Override |
| 10197 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10198 | String callingFeatureId) { |
| 10199 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10200 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10201 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10202 | } |
| 10203 | |
| 10204 | Phone phone = getPhone(subId); |
| 10205 | if (phone == null) { |
| 10206 | throw new RuntimeException("phone is not available"); |
| 10207 | } |
| 10208 | // Now that all security checks passes, perform the operation as ourselves. |
| 10209 | final long identity = Binder.clearCallingIdentity(); |
| 10210 | try { |
| 10211 | return phone.getEquivalentHomePlmns(); |
| 10212 | } finally { |
| 10213 | Binder.restoreCallingIdentity(identity); |
| 10214 | } |
| 10215 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10216 | |
| 10217 | @Override |
| 10218 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10219 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10220 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10221 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10222 | if (radioInterfaceCapabilities == null) { |
| 10223 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10224 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10225 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10226 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10227 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10228 | @Override |
| 10229 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10230 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10231 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10232 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10233 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10234 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10235 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10236 | if (DBG) { |
| 10237 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10238 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10239 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10240 | } |
| 10241 | |
| 10242 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10243 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10244 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10245 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10246 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10247 | if (callback != null) { |
| 10248 | try { |
| 10249 | callback.onAuthenticationFailure( |
| 10250 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10251 | } catch (RemoteException exception) { |
| 10252 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10253 | } |
| 10254 | return; |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | final long token = Binder.clearCallingIdentity(); |
| 10259 | try { |
| 10260 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10261 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10262 | forceBootStrapping, callback)); |
| 10263 | } finally { |
| 10264 | Binder.restoreCallingIdentity(token); |
| 10265 | } |
| 10266 | } |
| 10267 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10268 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10269 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10270 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10271 | * requested radio power state will actually be set. See {@link |
| 10272 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10273 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10274 | * @param enable {@code true} if trying to turn radio on. |
| 10275 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10276 | * false}. |
| 10277 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10278 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10279 | boolean isPhoneAvailable = false; |
| 10280 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10281 | Phone phone = PhoneFactory.getPhone(i); |
| 10282 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10283 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10284 | isPhoneAvailable = true; |
| 10285 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10286 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10287 | |
| 10288 | // return true if successfully informed the phone object about the thermal radio power |
| 10289 | // request. |
| 10290 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10291 | } |
| 10292 | |
| 10293 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10294 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10295 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10296 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10297 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10298 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10299 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10300 | } |
| 10301 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10302 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10303 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10304 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10305 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10306 | } |
| 10307 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10308 | setDataEnabledForReason( |
| 10309 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10310 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10311 | if (isDataThrottlingSupported) { |
| 10312 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10313 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10314 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10315 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10316 | } else if (thermalMitigationResult |
| 10317 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10318 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10319 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10320 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10321 | } |
| 10322 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10323 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10324 | |
| 10325 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10326 | } |
| 10327 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10328 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10329 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10330 | for (String pckg : context.getResources() |
| 10331 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10332 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10333 | } |
| 10334 | } |
| 10335 | |
| 10336 | return sThermalMitigationAllowlistedPackages; |
| 10337 | } |
| 10338 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10339 | private boolean isAnyPhoneInEmergencyState() { |
| 10340 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10341 | if (tm.isInEmergencyCall()) { |
| 10342 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10343 | return true; |
| 10344 | } |
| 10345 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10346 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10347 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10348 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10349 | + phone.isInEcm()); |
| 10350 | return true; |
| 10351 | } |
| 10352 | } |
| 10353 | |
| 10354 | return false; |
| 10355 | } |
| 10356 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10357 | /** |
| 10358 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10359 | * @param packageName name of package to be allowlisted |
| 10360 | * @param context |
| 10361 | */ |
| 10362 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10363 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10364 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10365 | } |
| 10366 | |
| 10367 | /** |
| 10368 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10369 | * @param packageName name of package to remove from allowlist |
| 10370 | * @param context |
| 10371 | */ |
| 10372 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10373 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10374 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10375 | } |
| 10376 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10377 | /** |
| 10378 | * Thermal mitigation request to control functionalities at modem. |
| 10379 | * |
| 10380 | * @param subId the id of the subscription. |
| 10381 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10382 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10383 | * |
| 10384 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10385 | */ |
| 10386 | @Override |
| 10387 | @ThermalMitigationResult |
| 10388 | public int sendThermalMitigationRequest( |
| 10389 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10390 | ThermalMitigationRequest thermalMitigationRequest, |
| 10391 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10392 | enforceModifyPermission(); |
| 10393 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10395 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10396 | .contains(callingPackage)) { |
| 10397 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10398 | + "calling package: " + callingPackage); |
| 10399 | } |
| 10400 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10401 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10402 | final long identity = Binder.clearCallingIdentity(); |
| 10403 | |
| 10404 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10405 | try { |
| 10406 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10407 | switch (thermalMitigationAction) { |
| 10408 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10409 | thermalMitigationResult = |
| 10410 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10411 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10412 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10413 | break; |
| 10414 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10415 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10416 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10417 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10418 | } |
| 10419 | |
| 10420 | // Ensure that radio is on. If not able to power on due to phone being |
| 10421 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10422 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10423 | thermalMitigationResult = |
| 10424 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10425 | break; |
| 10426 | } |
| 10427 | |
| 10428 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10429 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10430 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10431 | break; |
| 10432 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10433 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10434 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10435 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10436 | } |
| 10437 | |
| 10438 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10439 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10440 | Phone phone = getPhone(subId); |
| 10441 | if (phone == null) { |
| 10442 | thermalMitigationResult = |
| 10443 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10444 | break; |
| 10445 | } |
| 10446 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10447 | TelephonyConnectionService service = |
| 10448 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10449 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10450 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10451 | thermalMitigationResult = |
| 10452 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10453 | break; |
| 10454 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10455 | thermalMitigationResult = |
| 10456 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10457 | break; |
| 10458 | } |
| 10459 | } else { |
| 10460 | thermalMitigationResult = |
| 10461 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10462 | break; |
| 10463 | } |
| 10464 | |
| 10465 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10466 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10467 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10468 | thermalMitigationResult = |
| 10469 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10470 | break; |
| 10471 | } |
| 10472 | thermalMitigationResult = |
| 10473 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10474 | break; |
| 10475 | default: |
| 10476 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10477 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10478 | } |
| 10479 | } catch (IllegalArgumentException e) { |
| 10480 | throw e; |
| 10481 | } catch (Exception e) { |
| 10482 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10483 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10484 | } finally { |
| 10485 | Binder.restoreCallingIdentity(identity); |
| 10486 | } |
| 10487 | |
| 10488 | if (DBG) { |
| 10489 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10490 | + thermalMitigationResult); |
| 10491 | } |
| 10492 | |
| 10493 | return thermalMitigationResult; |
| 10494 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10495 | |
| 10496 | /** |
| 10497 | * Set the GbaService Package Name that Telephony will bind to. |
| 10498 | * |
| 10499 | * @param subId The sim that the GbaService is associated with. |
| 10500 | * @param packageName The name of the package to be replaced with. |
| 10501 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10502 | */ |
| 10503 | @Override |
| 10504 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10505 | enforceModifyPermission(); |
| 10506 | |
| 10507 | final long identity = Binder.clearCallingIdentity(); |
| 10508 | try { |
| 10509 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10510 | } finally { |
| 10511 | Binder.restoreCallingIdentity(identity); |
| 10512 | } |
| 10513 | } |
| 10514 | |
| 10515 | /** |
| 10516 | * Return the package name of the currently bound GbaService. |
| 10517 | * |
| 10518 | * @param subId The sim that the GbaService is associated with. |
| 10519 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10520 | */ |
| 10521 | @Override |
| 10522 | public String getBoundGbaService(int subId) { |
| 10523 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10524 | |
| 10525 | final long identity = Binder.clearCallingIdentity(); |
| 10526 | try { |
| 10527 | return getGbaManager(subId).getServicePackage(); |
| 10528 | } finally { |
| 10529 | Binder.restoreCallingIdentity(identity); |
| 10530 | } |
| 10531 | } |
| 10532 | |
| 10533 | /** |
| 10534 | * Set the release time for telephony to unbind GbaService. |
| 10535 | * |
| 10536 | * @param subId The sim that the GbaService is associated with. |
| 10537 | * @param interval The release time to unbind GbaService by millisecond. |
| 10538 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10539 | */ |
| 10540 | @Override |
| 10541 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10542 | enforceModifyPermission(); |
| 10543 | |
| 10544 | final long identity = Binder.clearCallingIdentity(); |
| 10545 | try { |
| 10546 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10547 | } finally { |
| 10548 | Binder.restoreCallingIdentity(identity); |
| 10549 | } |
| 10550 | } |
| 10551 | |
| 10552 | /** |
| 10553 | * Return the release time for telephony to unbind GbaService. |
| 10554 | * |
| 10555 | * @param subId The sim that the GbaService is associated with. |
| 10556 | * @return The release time to unbind GbaService by millisecond. |
| 10557 | */ |
| 10558 | @Override |
| 10559 | public int getGbaReleaseTime(int subId) { |
| 10560 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10561 | |
| 10562 | final long identity = Binder.clearCallingIdentity(); |
| 10563 | try { |
| 10564 | return getGbaManager(subId).getReleaseTime(); |
| 10565 | } finally { |
| 10566 | Binder.restoreCallingIdentity(identity); |
| 10567 | } |
| 10568 | } |
| 10569 | |
| 10570 | private GbaManager getGbaManager(int subId) { |
| 10571 | GbaManager instance = GbaManager.getInstance(subId); |
| 10572 | if (instance == null) { |
| 10573 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10574 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10575 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10576 | } |
| 10577 | return instance; |
| 10578 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10579 | |
| 10580 | /** |
| 10581 | * indicate whether the device and the carrier can support |
| 10582 | * RCS VoLTE single registration. |
| 10583 | */ |
| 10584 | @Override |
| 10585 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10586 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10587 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10588 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10589 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10590 | |
| 10591 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10592 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10593 | } |
| 10594 | |
| 10595 | final long identity = Binder.clearCallingIdentity(); |
| 10596 | try { |
| 10597 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10598 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10599 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10600 | if (isCapable != null) { |
| 10601 | return isCapable; |
| 10602 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10603 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10604 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10605 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10606 | } finally { |
| 10607 | Binder.restoreCallingIdentity(identity); |
| 10608 | } |
| 10609 | } |
| 10610 | |
| 10611 | /** |
| 10612 | * Register RCS provisioning callback. |
| 10613 | */ |
| 10614 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10615 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10616 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10617 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10618 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10619 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10620 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10621 | |
| 10622 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10623 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10624 | } |
| 10625 | if (!isImsAvailableOnDevice()) { |
| 10626 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10627 | "IMS not available on device."); |
| 10628 | } |
| 10629 | |
| 10630 | final long identity = Binder.clearCallingIdentity(); |
| 10631 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10632 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10633 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10634 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10635 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10636 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10637 | } finally { |
| 10638 | Binder.restoreCallingIdentity(identity); |
| 10639 | } |
| 10640 | } |
| 10641 | |
| 10642 | /** |
| 10643 | * Unregister RCS provisioning callback. |
| 10644 | */ |
| 10645 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10646 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10647 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10648 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10649 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10650 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10651 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10652 | |
| 10653 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10654 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10655 | } |
| 10656 | if (!isImsAvailableOnDevice()) { |
| 10657 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10658 | "IMS not available on device."); |
| 10659 | } |
| 10660 | |
| 10661 | final long identity = Binder.clearCallingIdentity(); |
| 10662 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10663 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10664 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10665 | } finally { |
| 10666 | Binder.restoreCallingIdentity(identity); |
| 10667 | } |
| 10668 | } |
| 10669 | |
| 10670 | /** |
| 10671 | * trigger RCS reconfiguration. |
| 10672 | */ |
| 10673 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10674 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10675 | "triggerRcsReconfiguration", |
| 10676 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10677 | |
| 10678 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10679 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10680 | } |
| 10681 | if (!isImsAvailableOnDevice()) { |
| 10682 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10683 | "IMS not available on device."); |
| 10684 | } |
| 10685 | |
| 10686 | final long identity = Binder.clearCallingIdentity(); |
| 10687 | try { |
| 10688 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10689 | } finally { |
| 10690 | Binder.restoreCallingIdentity(identity); |
| 10691 | } |
| 10692 | } |
| 10693 | |
| 10694 | /** |
| 10695 | * Provide the client configuration parameters of the RCS application. |
| 10696 | */ |
| 10697 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10698 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10699 | "setRcsClientConfiguration", |
| 10700 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10701 | |
| 10702 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10703 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10704 | } |
| 10705 | if (!isImsAvailableOnDevice()) { |
| 10706 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10707 | "IMS not available on device."); |
| 10708 | } |
| 10709 | |
| 10710 | final long identity = Binder.clearCallingIdentity(); |
| 10711 | |
| 10712 | try { |
| 10713 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10714 | if (configBinder == null) { |
| 10715 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10716 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10717 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10718 | } else { |
| 10719 | configBinder.setRcsClientConfiguration(rcc); |
| 10720 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10721 | |
| 10722 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10723 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10724 | } catch (RemoteException e) { |
| 10725 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10726 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10727 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10728 | } finally { |
| 10729 | Binder.restoreCallingIdentity(identity); |
| 10730 | } |
| 10731 | } |
| 10732 | |
| 10733 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10734 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10735 | */ |
| 10736 | @Override |
| 10737 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10738 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10739 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10740 | |
| 10741 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10742 | } |
| 10743 | |
| 10744 | /** |
| 10745 | * Gets the test mode for RCS VoLTE single registration. |
| 10746 | */ |
| 10747 | @Override |
| 10748 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10749 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10750 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10751 | |
| 10752 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10753 | } |
| 10754 | |
| 10755 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10756 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10757 | */ |
| 10758 | @Override |
| 10759 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10760 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10761 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10762 | enforceModifyPermission(); |
| 10763 | |
| 10764 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10765 | : Boolean.parseBoolean(enabledStr); |
| 10766 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10767 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10768 | } |
| 10769 | |
| 10770 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10771 | * Sends a device to device communication message. Only usable via shell. |
| 10772 | * @param message message to send. |
| 10773 | * @param value message value. |
| 10774 | */ |
| 10775 | @Override |
| 10776 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10777 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10778 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10779 | enforceModifyPermission(); |
| 10780 | |
| 10781 | final long identity = Binder.clearCallingIdentity(); |
| 10782 | try { |
| 10783 | TelephonyConnectionService service = |
| 10784 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10785 | if (service == null) { |
| 10786 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10787 | return; |
| 10788 | } |
| 10789 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10790 | } finally { |
| 10791 | Binder.restoreCallingIdentity(identity); |
| 10792 | } |
| 10793 | } |
| 10794 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10795 | /** |
| 10796 | * Sets the specified device to device transport active. |
| 10797 | * @param transport The transport to set active. |
| 10798 | */ |
| 10799 | @Override |
| 10800 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10801 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10802 | "setActiveDeviceToDeviceTransport"); |
| 10803 | enforceModifyPermission(); |
| 10804 | |
| 10805 | final long identity = Binder.clearCallingIdentity(); |
| 10806 | try { |
| 10807 | TelephonyConnectionService service = |
| 10808 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10809 | if (service == null) { |
| 10810 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10811 | return; |
| 10812 | } |
| 10813 | service.setActiveDeviceToDeviceTransport(transport); |
| 10814 | } finally { |
| 10815 | Binder.restoreCallingIdentity(identity); |
| 10816 | } |
| 10817 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10818 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10819 | @Override |
| 10820 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10821 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10822 | "setDeviceToDeviceForceEnabled"); |
| 10823 | |
| 10824 | final long identity = Binder.clearCallingIdentity(); |
| 10825 | try { |
| 10826 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10827 | p -> { |
| 10828 | Phone thePhone = p.getImsPhone(); |
| 10829 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10830 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10831 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10832 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10833 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10834 | (ImsPhoneCallTracker) tracker; |
| 10835 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10836 | } |
| 10837 | } |
| 10838 | } |
| 10839 | ); |
| 10840 | } finally { |
| 10841 | Binder.restoreCallingIdentity(identity); |
| 10842 | } |
| 10843 | } |
| 10844 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10845 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10846 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10847 | */ |
| 10848 | @Override |
| 10849 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10850 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10851 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10852 | } |
| 10853 | |
| 10854 | /** |
| 10855 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10856 | */ |
| 10857 | @Override |
| 10858 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10859 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10860 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10861 | enforceModifyPermission(); |
| 10862 | |
| 10863 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10864 | : Boolean.parseBoolean(enabledStr); |
| 10865 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10866 | subId, enabled); |
| 10867 | } |
| 10868 | |
| 10869 | /** |
| 10870 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10871 | */ |
| 10872 | @Override |
| 10873 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10874 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10875 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10876 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10877 | |
| 10878 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10879 | * Overrides the ims feature validation result |
| 10880 | */ |
| 10881 | @Override |
| 10882 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10883 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10884 | "setImsFeatureValidationOverride"); |
| 10885 | |
| 10886 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10887 | : Boolean.parseBoolean(enabledStr); |
| 10888 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10889 | subId, enabled); |
| 10890 | } |
| 10891 | |
| 10892 | /** |
| 10893 | * Gets the ims feature validation override value |
| 10894 | */ |
| 10895 | @Override |
| 10896 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10897 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10898 | "getImsFeatureValidationOverride"); |
| 10899 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10900 | } |
| 10901 | |
| 10902 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10903 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10904 | * their mobile plan. |
| 10905 | */ |
| 10906 | @Override |
| 10907 | public String getMobileProvisioningUrl() { |
| 10908 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10909 | final long identity = Binder.clearCallingIdentity(); |
| 10910 | try { |
| 10911 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10912 | } finally { |
| 10913 | Binder.restoreCallingIdentity(identity); |
| 10914 | } |
| 10915 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10916 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10917 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10918 | * Get the EAB contact from the EAB database. |
| 10919 | */ |
| 10920 | @Override |
| 10921 | public String getContactFromEab(String contact) { |
| 10922 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10923 | enforceModifyPermission(); |
| 10924 | final long identity = Binder.clearCallingIdentity(); |
| 10925 | try { |
| 10926 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10927 | } finally { |
| 10928 | Binder.restoreCallingIdentity(identity); |
| 10929 | } |
| 10930 | } |
| 10931 | |
| 10932 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10933 | * Get the EAB capability from the EAB database. |
| 10934 | */ |
| 10935 | @Override |
| 10936 | public String getCapabilityFromEab(String contact) { |
| 10937 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10938 | enforceModifyPermission(); |
| 10939 | final long identity = Binder.clearCallingIdentity(); |
| 10940 | try { |
| 10941 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10942 | } finally { |
| 10943 | Binder.restoreCallingIdentity(identity); |
| 10944 | } |
| 10945 | } |
| 10946 | |
| 10947 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10948 | * Remove the EAB contacts from the EAB database. |
| 10949 | */ |
| 10950 | @Override |
| 10951 | public int removeContactFromEab(int subId, String contacts) { |
| 10952 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10953 | enforceModifyPermission(); |
| 10954 | final long identity = Binder.clearCallingIdentity(); |
| 10955 | try { |
| 10956 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10957 | } finally { |
| 10958 | Binder.restoreCallingIdentity(identity); |
| 10959 | } |
| 10960 | } |
| 10961 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10962 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10963 | public boolean getDeviceUceEnabled() { |
| 10964 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10965 | final long identity = Binder.clearCallingIdentity(); |
| 10966 | try { |
| 10967 | return mApp.getDeviceUceEnabled(); |
| 10968 | } finally { |
| 10969 | Binder.restoreCallingIdentity(identity); |
| 10970 | } |
| 10971 | } |
| 10972 | |
| 10973 | @Override |
| 10974 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10975 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10976 | final long identity = Binder.clearCallingIdentity(); |
| 10977 | try { |
| 10978 | mApp.setDeviceUceEnabled(isEnabled); |
| 10979 | } finally { |
| 10980 | Binder.restoreCallingIdentity(identity); |
| 10981 | } |
| 10982 | } |
| 10983 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10984 | /** |
| 10985 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10986 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10987 | */ |
| 10988 | // Used for SHELL command only right now. |
| 10989 | @Override |
| 10990 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10991 | List<String> featureTags) { |
| 10992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10993 | "addUceRegistrationOverrideShell"); |
| 10994 | final long identity = Binder.clearCallingIdentity(); |
| 10995 | try { |
| 10996 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10997 | new ArraySet<>(featureTags)); |
| 10998 | } catch (ImsException e) { |
| 10999 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11000 | } finally { |
| 11001 | Binder.restoreCallingIdentity(identity); |
| 11002 | } |
| 11003 | } |
| 11004 | |
| 11005 | /** |
| 11006 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 11007 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11008 | */ |
| 11009 | // Used for SHELL command only right now. |
| 11010 | @Override |
| 11011 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 11012 | List<String> featureTags) { |
| 11013 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11014 | "removeUceRegistrationOverrideShell"); |
| 11015 | final long identity = Binder.clearCallingIdentity(); |
| 11016 | try { |
| 11017 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 11018 | new ArraySet<>(featureTags)); |
| 11019 | } catch (ImsException e) { |
| 11020 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11021 | } finally { |
| 11022 | Binder.restoreCallingIdentity(identity); |
| 11023 | } |
| 11024 | } |
| 11025 | |
| 11026 | /** |
| 11027 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 11028 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11029 | */ |
| 11030 | // Used for SHELL command only right now. |
| 11031 | @Override |
| 11032 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 11033 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11034 | "clearUceRegistrationOverrideShell"); |
| 11035 | final long identity = Binder.clearCallingIdentity(); |
| 11036 | try { |
| 11037 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11038 | } catch (ImsException e) { |
| 11039 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(identity); |
| 11042 | } |
| 11043 | } |
| 11044 | |
| 11045 | /** |
| 11046 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11047 | */ |
| 11048 | // Used for SHELL command only right now. |
| 11049 | @Override |
| 11050 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11051 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11052 | "getLatestRcsContactUceCapabilityShell"); |
| 11053 | final long identity = Binder.clearCallingIdentity(); |
| 11054 | try { |
| 11055 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11056 | } catch (ImsException e) { |
| 11057 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11058 | } finally { |
| 11059 | Binder.restoreCallingIdentity(identity); |
| 11060 | } |
| 11061 | } |
| 11062 | |
| 11063 | /** |
| 11064 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11065 | * device does not have an active PUBLISH. |
| 11066 | */ |
| 11067 | // Used for SHELL command only right now. |
| 11068 | @Override |
| 11069 | public String getLastUcePidfXmlShell(int subId) { |
| 11070 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11071 | final long identity = Binder.clearCallingIdentity(); |
| 11072 | try { |
| 11073 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11074 | } catch (ImsException e) { |
| 11075 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11076 | } finally { |
| 11077 | Binder.restoreCallingIdentity(identity); |
| 11078 | } |
| 11079 | } |
| 11080 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11081 | /** |
| 11082 | * Remove UCE requests cannot be sent to the network status. |
| 11083 | */ |
| 11084 | // Used for SHELL command only right now. |
| 11085 | @Override |
| 11086 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11087 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11088 | final long identity = Binder.clearCallingIdentity(); |
| 11089 | try { |
| 11090 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11091 | } catch (ImsException e) { |
| 11092 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11093 | } finally { |
| 11094 | Binder.restoreCallingIdentity(identity); |
| 11095 | } |
| 11096 | } |
| 11097 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11098 | /** |
| 11099 | * Remove UCE requests cannot be sent to the network status. |
| 11100 | */ |
| 11101 | // Used for SHELL command only. |
| 11102 | @Override |
| 11103 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11104 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11105 | final long identity = Binder.clearCallingIdentity(); |
| 11106 | try { |
| 11107 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11108 | } catch (ImsException e) { |
| 11109 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11110 | } finally { |
| 11111 | Binder.restoreCallingIdentity(identity); |
| 11112 | } |
| 11113 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11114 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11115 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11116 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11117 | String callingPackage) { |
| 11118 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11119 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11120 | |
| 11121 | final int callingUid = Binder.getCallingUid(); |
| 11122 | // Verify that tha callingPackage belongs to the calling UID |
| 11123 | mApp.getSystemService(AppOpsManager.class) |
| 11124 | .checkPackage(callingUid, callingPackage); |
| 11125 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11126 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11127 | |
| 11128 | final long identity = Binder.clearCallingIdentity(); |
| 11129 | try { |
| 11130 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11131 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11132 | |
| 11133 | if (result instanceof IllegalStateException) { |
| 11134 | throw (IllegalStateException) result; |
| 11135 | } |
| 11136 | } finally { |
| 11137 | Binder.restoreCallingIdentity(identity); |
| 11138 | } |
| 11139 | } |
| 11140 | |
| 11141 | @Override |
| 11142 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11143 | String callingPackage) { |
| 11144 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11145 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11146 | |
| 11147 | final int callingUid = Binder.getCallingUid(); |
| 11148 | // Verify that tha callingPackage belongs to the calling UID |
| 11149 | mApp.getSystemService(AppOpsManager.class) |
| 11150 | .checkPackage(callingUid, callingPackage); |
| 11151 | |
| 11152 | final long identity = Binder.clearCallingIdentity(); |
| 11153 | try { |
| 11154 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11155 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11156 | |
| 11157 | if (result instanceof IllegalStateException) { |
| 11158 | throw (IllegalStateException) result; |
| 11159 | } |
| 11160 | } finally { |
| 11161 | Binder.restoreCallingIdentity(identity); |
| 11162 | } |
| 11163 | } |
| 11164 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11165 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11166 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11167 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11168 | // phone/system process do not have further restriction on request |
| 11169 | return; |
| 11170 | } |
| 11171 | |
| 11172 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11173 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11174 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11175 | context.enforceCallingOrSelfPermission( |
| 11176 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11177 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11178 | } |
| 11179 | |
| 11180 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11181 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11182 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11183 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11184 | || info.isEnabled()) { |
| 11185 | throw new IllegalArgumentException( |
| 11186 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11187 | } |
| 11188 | |
| 11189 | // Thresholds length for each RAN need in range. This has been validated in |
| 11190 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11191 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11192 | final int[] thresholds = info.getThresholds(); |
| 11193 | Objects.requireNonNull(thresholds); |
| 11194 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11195 | || thresholds.length |
| 11196 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11197 | throw new IllegalArgumentException( |
| 11198 | "thresholds length is out of range: " + thresholds.length); |
| 11199 | } |
| 11200 | } |
| 11201 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11202 | |
| 11203 | /** |
| 11204 | * Gets the current phone capability. |
| 11205 | * |
| 11206 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11207 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11208 | * It's used to evaluate possible phone config change, for example from single |
| 11209 | * SIM device to multi-SIM device. |
| 11210 | */ |
| 11211 | @Override |
| 11212 | public PhoneCapability getPhoneCapability() { |
| 11213 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11214 | final long identity = Binder.clearCallingIdentity(); |
| 11215 | try { |
| 11216 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11217 | } finally { |
| 11218 | Binder.restoreCallingIdentity(identity); |
| 11219 | } |
| 11220 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11221 | |
| 11222 | /** |
| 11223 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11224 | * required to be done shortly after the API is invoked. |
| 11225 | */ |
| 11226 | @Override |
| 11227 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11228 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11229 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11230 | enforceRebootPermission(); |
| 11231 | |
| 11232 | final long identity = Binder.clearCallingIdentity(); |
| 11233 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11234 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11235 | } finally { |
| 11236 | Binder.restoreCallingIdentity(identity); |
| 11237 | } |
| 11238 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11239 | |
| 11240 | /** |
| 11241 | * Request to get the current slicing configuration including URSP rules and |
| 11242 | * NSSAIs (configured, allowed and rejected). |
| 11243 | * |
| 11244 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11245 | */ |
| 11246 | @Override |
| 11247 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11248 | TelephonyPermissions |
| 11249 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11250 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11251 | |
| 11252 | final long identity = Binder.clearCallingIdentity(); |
| 11253 | try { |
| 11254 | Phone phone = getDefaultPhone(); |
| 11255 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11256 | } finally { |
| 11257 | Binder.restoreCallingIdentity(identity); |
| 11258 | } |
| 11259 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11260 | |
| 11261 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11262 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11263 | * |
| 11264 | * @param capability The premium capability to check. |
| 11265 | * @param subId The subId to check the premium capability for. |
| 11266 | * |
| 11267 | * @return Whether the given premium capability is available to purchase. |
| 11268 | */ |
| 11269 | @Override |
| 11270 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11271 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11272 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11273 | log("Premium capability " |
| 11274 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11275 | + " is not available for purchase due to missing permissions."); |
| 11276 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11277 | + "permission READ_BASIC_PHONE_STATE."); |
| 11278 | } |
| 11279 | |
| 11280 | Phone phone = getPhone(subId); |
| 11281 | final long identity = Binder.clearCallingIdentity(); |
| 11282 | try { |
Sarah Chin | 46355ba | 2022-11-01 23:51:16 -0700 | [diff] [blame] | 11283 | return SlicePurchaseController.getInstance(phone) |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11284 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11285 | } finally { |
| 11286 | Binder.restoreCallingIdentity(identity); |
| 11287 | } |
| 11288 | } |
| 11289 | |
| 11290 | /** |
| 11291 | * Purchase the given premium capability from the carrier. |
| 11292 | * |
| 11293 | * @param capability The premium capability to purchase. |
| 11294 | * @param callback The result of the purchase request. |
| 11295 | * @param subId The subId to purchase the premium capability for. |
| 11296 | */ |
| 11297 | @Override |
| 11298 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11299 | log("purchasePremiumCapability: capability=" |
| 11300 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11301 | + getCurrentPackageName()); |
| 11302 | |
| 11303 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11304 | mApp, "purchasePremiumCapability")) { |
| 11305 | log("purchasePremiumCapability " |
| 11306 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11307 | + " failed due to missing permissions."); |
| 11308 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11309 | + "READ_BASIC_PHONE_STATE."); |
| 11310 | } |
| 11311 | |
| 11312 | Phone phone = getPhone(subId); |
Sarah Chin | 71b3a85 | 2022-09-28 15:54:19 -0700 | [diff] [blame] | 11313 | String appName; |
| 11314 | try { |
| 11315 | appName = mApp.getPackageManager().getApplicationLabel(mApp.getPackageManager() |
| 11316 | .getApplicationInfo(getCurrentPackageName(), 0)).toString(); |
| 11317 | } catch (PackageManager.NameNotFoundException e) { |
| 11318 | appName = "An application"; |
| 11319 | } |
| 11320 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, |
| 11321 | new PurchasePremiumCapabilityArgument(capability, appName, callback), phone, null); |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11322 | } |
| 11323 | |
| 11324 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11325 | * Register an IMS connection state callback |
| 11326 | */ |
| 11327 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11328 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11329 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11330 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11331 | // ImsMmTelManager |
| 11332 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11333 | TelephonyPermissions |
| 11334 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11335 | mApp, subId, "registerImsStateCallback"); |
| 11336 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11337 | // ImsRcsManager or SipDelegateManager |
| 11338 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11339 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11340 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11341 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11342 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11343 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11344 | } |
| 11345 | |
| 11346 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11347 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11348 | "IMS not available on device."); |
| 11349 | } |
| 11350 | |
| 11351 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11352 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11353 | } |
| 11354 | |
| 11355 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11356 | if (controller == null) { |
| 11357 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11358 | "IMS not available on device."); |
| 11359 | } |
| 11360 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11361 | if (callingPackage == null) { |
| 11362 | callingPackage = getCurrentPackageName(); |
| 11363 | } |
| 11364 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11365 | final long token = Binder.clearCallingIdentity(); |
| 11366 | try { |
| 11367 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11368 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11369 | } catch (ImsException e) { |
| 11370 | throw new ServiceSpecificException(e.getCode()); |
| 11371 | } finally { |
| 11372 | Binder.restoreCallingIdentity(token); |
| 11373 | } |
| 11374 | } |
| 11375 | |
| 11376 | /** |
| 11377 | * Unregister an IMS connection state callback |
| 11378 | */ |
| 11379 | @Override |
| 11380 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11381 | final long token = Binder.clearCallingIdentity(); |
| 11382 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11383 | if (controller == null) { |
| 11384 | return; |
| 11385 | } |
| 11386 | try { |
| 11387 | controller.unregisterImsStateCallback(cb); |
| 11388 | } finally { |
| 11389 | Binder.restoreCallingIdentity(token); |
| 11390 | } |
| 11391 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11392 | |
| 11393 | /** |
| 11394 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11395 | * |
| 11396 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11397 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11398 | * SecurityException. |
| 11399 | * If there is current registered network this value will be same as the registered cell |
| 11400 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11401 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11402 | * it will be cleared and null will be returned. |
| 11403 | * |
| 11404 | */ |
| 11405 | @Override |
| 11406 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11407 | String callingFeatureId) { |
| 11408 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11409 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11410 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11411 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11412 | .setCallingPackage(callingPackage) |
| 11413 | .setCallingFeatureId(callingFeatureId) |
| 11414 | .setCallingPid(Binder.getCallingPid()) |
| 11415 | .setCallingUid(Binder.getCallingUid()) |
| 11416 | .setMethod("getLastKnownCellIdentity") |
| 11417 | .setLogAsInfo(true) |
| 11418 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11419 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11420 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11421 | .build()); |
| 11422 | |
| 11423 | boolean hasFinePermission = |
| 11424 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11425 | if (!hasFinePermission |
| 11426 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11427 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11428 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11429 | } |
| 11430 | |
| 11431 | final long identity = Binder.clearCallingIdentity(); |
| 11432 | try { |
| 11433 | Phone phone = getPhone(subId); |
| 11434 | if (phone == null) return null; |
| 11435 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11436 | if (sst == null) return null; |
| 11437 | return sst.getLastKnownCellIdentity(); |
| 11438 | } finally { |
| 11439 | Binder.restoreCallingIdentity(identity); |
| 11440 | } |
| 11441 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11442 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11443 | /** |
| 11444 | * Sets the modem service class Name that Telephony will bind to. |
| 11445 | * |
| 11446 | * @param serviceName The class name of the modem service. |
| 11447 | * @return true if the operation is succeed, otherwise false. |
| 11448 | */ |
| 11449 | public boolean setModemService(String serviceName) { |
| 11450 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11451 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11452 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11453 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11454 | "setModemService"); |
| 11455 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11456 | } |
| 11457 | |
| 11458 | /** |
| 11459 | * Return the class name of the currently bounded modem service. |
| 11460 | * |
| 11461 | * @return the class name of the modem service. |
| 11462 | */ |
| 11463 | public String getModemService() { |
| 11464 | String result; |
| 11465 | Log.d(LOG_TAG, "getModemService"); |
| 11466 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11467 | TelephonyPermissions |
| 11468 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11469 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11470 | "getModemService"); |
| 11471 | result = mPhoneConfigurationManager.getModemService(); |
| 11472 | Log.d(LOG_TAG, "result = " + result); |
| 11473 | return result; |
| 11474 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11475 | |
| 11476 | @Override |
| 11477 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11478 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11479 | mApp.enforceCallingOrSelfPermission( |
| 11480 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11481 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11482 | |
| 11483 | final long identity = Binder.clearCallingIdentity(); |
| 11484 | try { |
| 11485 | Phone phone = getPhone(subId); |
| 11486 | if (phone == null) return; |
| 11487 | phone.setVoiceServiceStateOverride(hasService); |
| 11488 | } finally { |
| 11489 | Binder.restoreCallingIdentity(identity); |
| 11490 | } |
| 11491 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11492 | |
| 11493 | /** |
| 11494 | * set removable eSIM as default eUICC. |
| 11495 | * |
| 11496 | * @hide |
| 11497 | */ |
| 11498 | @Override |
| 11499 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11500 | enforceModifyPermission(); |
| 11501 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11502 | |
| 11503 | final long identity = Binder.clearCallingIdentity(); |
| 11504 | try { |
| 11505 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11506 | } finally { |
| 11507 | Binder.restoreCallingIdentity(identity); |
| 11508 | } |
| 11509 | } |
| 11510 | |
| 11511 | /** |
| 11512 | * Returns whether the removable eSIM is default eUICC or not. |
| 11513 | * |
| 11514 | * @hide |
| 11515 | */ |
| 11516 | @Override |
| 11517 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11518 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11519 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11520 | |
| 11521 | final long identity = Binder.clearCallingIdentity(); |
| 11522 | try { |
| 11523 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11524 | } finally { |
| 11525 | Binder.restoreCallingIdentity(identity); |
| 11526 | } |
| 11527 | } |
| 11528 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame^] | 11529 | /** |
| 11530 | * Get the component name of the default app to direct respond-via-message intent for the |
| 11531 | * user associated with this subscription, update the cache if there is no respond-via-message |
| 11532 | * application currently configured for this user. |
| 11533 | * @return component name of the app and class to direct Respond Via Message intent to, or |
| 11534 | * {@code null} if the functionality is not supported. |
| 11535 | * @hide |
| 11536 | */ |
| 11537 | @Override |
| 11538 | public @Nullable ComponentName getDefaultRespondViaMessageApplication(int subId, |
| 11539 | boolean updateIfNeeded) { |
| 11540 | enforceInteractAcrossUsersPermission("getDefaultRespondViaMessageApplication"); |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11541 | |
Aishwarya Mallampati | fbc70d3 | 2022-11-10 20:33:02 +0000 | [diff] [blame^] | 11542 | Context context = getPhone(subId).getContext(); |
| 11543 | UserHandle userHandle = null; |
| 11544 | final long identity = Binder.clearCallingIdentity(); |
| 11545 | try { |
| 11546 | userHandle = TelephonyUtils.getSubscriptionUserHandle(context, subId); |
| 11547 | } finally { |
| 11548 | Binder.restoreCallingIdentity(identity); |
| 11549 | } |
| 11550 | return SmsApplication.getDefaultRespondViaMessageApplicationAsUser(context, |
| 11551 | updateIfNeeded, userHandle); |
| 11552 | } |
| 11553 | } |