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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 56 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 57 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 58 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 59 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 61 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 62 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 63 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 65 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 66 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 67 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 68 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 69 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 70 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 71 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 74 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 75 | import android.telephony.AccessNetworkConstants; |
| 76 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 77 | import android.telephony.Annotation.ApnType; |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 78 | import android.telephony.Annotation.DataActivityType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 79 | import android.telephony.Annotation.ThermalMitigationResult; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 80 | import android.telephony.AnomalyReporter; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 81 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 82 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 83 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 84 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 85 | import android.telephony.CellIdentityCdma; |
| 86 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 88 | import android.telephony.CellInfoGsm; |
| 89 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 90 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 91 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 92 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 93 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 94 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 95 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 96 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 97 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 98 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 99 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 100 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 101 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 102 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 103 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 104 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 105 | import android.telephony.SignalStrengthUpdateRequest; |
| 106 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 107 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 108 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 109 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 110 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 111 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 112 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 113 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 114 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 115 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 116 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 117 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 118 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 119 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 120 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 121 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 122 | import android.telephony.gba.GbaAuthRequest; |
| 123 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 124 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 125 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 126 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 127 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 128 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 135 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 136 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 138 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 140 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 141 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 144 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 145 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 146 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 147 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 148 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 163 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.data.DataUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 192 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccIoResult; |
| 197 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 205 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 206 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 207 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 208 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 209 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 210 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 211 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 212 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 213 | import com.android.phone.slicestore.SliceStore; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 215 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 218 | import com.android.services.telephony.TelecomAccountRegistry; |
| 219 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 220 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 221 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 223 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.io.IOException; |
| 225 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 226 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 228 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 229 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 230 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 231 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 232 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 234 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 235 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 236 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 237 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 238 | import java.util.Set; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 239 | import java.util.UUID; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 240 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 241 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 242 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Implementation of the ITelephony interface. |
| 246 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 247 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 249 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 250 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 251 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | |
| 253 | // Message codes used with mMainThreadHandler |
| 254 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 255 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 256 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 257 | private static final int CMD_OPEN_CHANNEL = 9; |
| 258 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 259 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 260 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 261 | private static final int CMD_NV_READ_ITEM = 13; |
| 262 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 263 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 264 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 265 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 266 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 267 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 268 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 269 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 270 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 271 | private static final int CMD_SEND_ENVELOPE = 25; |
| 272 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 273 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 274 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 275 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 276 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 277 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 278 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 279 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 280 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 281 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 282 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 283 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 284 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 285 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 286 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 287 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 288 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 289 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 290 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 291 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 292 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 293 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 294 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 295 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 296 | private static final int CMD_SWITCH_SLOTS = 50; |
| 297 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 298 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 299 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 300 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 301 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 302 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 303 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 304 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 305 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 306 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 307 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 308 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 309 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 310 | private static final int CMD_MODEM_REBOOT = 64; |
| 311 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 312 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 313 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 314 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 315 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 317 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 318 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 319 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 320 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 321 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 322 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 323 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 324 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 325 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 326 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 327 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 328 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 329 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 330 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 331 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 332 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 333 | private static final int CMD_GET_CALL_WAITING = 87; |
| 334 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 335 | private static final int CMD_SET_CALL_WAITING = 89; |
| 336 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 337 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 338 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 339 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 340 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 341 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 342 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 343 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 344 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 346 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 347 | private static final int CMD_SET_SIM_POWER = 101; |
| 348 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 349 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 350 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 351 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 352 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 353 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 354 | 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] | 355 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 356 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 357 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 358 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 359 | private static final int CMD_ENABLE_VONR = 113; |
| 360 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 361 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 362 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 363 | private static final int CMD_PURCHASE_PREMIUM_CAPABILITY = 117; |
| 364 | private static final int EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE = 118; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 366 | // Parameters of select command. |
| 367 | private static final int SELECT_COMMAND = 0xA4; |
| 368 | private static final int SELECT_P1 = 0x04; |
| 369 | private static final int SELECT_P2 = 0; |
| 370 | private static final int SELECT_P3 = 0x10; |
| 371 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 372 | /** The singleton instance. */ |
| 373 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 374 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 376 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 378 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 379 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 380 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 381 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 382 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 383 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 384 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 385 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 386 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 388 | /** User Activity */ |
| 389 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 390 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 391 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 392 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 393 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 394 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 395 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 396 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 397 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 398 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 399 | // String to store multi SIM allowed |
| 400 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 401 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 402 | // The AID of ISD-R. |
| 403 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 404 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 405 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 406 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 407 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 408 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 409 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 410 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 411 | 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] | 412 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 413 | private static final String PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID = |
| 414 | "24bf97a6-e8a6-44d8-a6a4-255d7548733c"; |
| 415 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 416 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 417 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 418 | */ |
| 419 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 420 | "reset_network_erase_modem_config_enabled"; |
| 421 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 422 | 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] | 423 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 424 | /** |
| 425 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 426 | * one ICCID active at the same time. |
| 427 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 428 | * |
| 429 | * @hide |
| 430 | */ |
| 431 | @ChangeId |
| 432 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 433 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 434 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 435 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 436 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 437 | * operation fails. |
| 438 | */ |
| 439 | @ChangeId |
| 440 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 441 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 442 | |
| 443 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 444 | * A request object to use for transmitting data to an ICC. |
| 445 | */ |
| 446 | private static final class IccAPDUArgument { |
| 447 | public int channel, cla, command, p1, p2, p3; |
| 448 | public String data; |
| 449 | |
| 450 | public IccAPDUArgument(int channel, int cla, int command, |
| 451 | int p1, int p2, int p3, String data) { |
| 452 | this.channel = channel; |
| 453 | this.cla = cla; |
| 454 | this.command = command; |
| 455 | this.p1 = p1; |
| 456 | this.p2 = p2; |
| 457 | this.p3 = p3; |
| 458 | this.data = data; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 463 | * A request object to use for transmitting data to an ICC. |
| 464 | */ |
| 465 | private static final class ManualNetworkSelectionArgument { |
| 466 | public OperatorInfo operatorInfo; |
| 467 | public boolean persistSelection; |
| 468 | |
| 469 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 470 | this.operatorInfo = operatorInfo; |
| 471 | this.persistSelection = persistSelection; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 477 | * request after sending. The main thread will notify the request when it is complete. |
| 478 | */ |
| 479 | private static final class MainThreadRequest { |
| 480 | /** The argument to use for the request */ |
| 481 | public Object argument; |
| 482 | /** The result of the request that is run on the main thread */ |
| 483 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 484 | // The subscriber id that this request applies to. Defaults to |
| 485 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 486 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 488 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 489 | public Phone phone; |
| 490 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 491 | public WorkSource workSource; |
| 492 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | public MainThreadRequest(Object argument) { |
| 494 | this.argument = argument; |
| 495 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 496 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 497 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 498 | this.argument = argument; |
| 499 | if (phone != null) { |
| 500 | this.phone = phone; |
| 501 | } |
| 502 | this.workSource = workSource; |
| 503 | } |
| 504 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 505 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 506 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 507 | if (subId != null) { |
| 508 | this.subId = subId; |
| 509 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 510 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 514 | private static final class IncomingThirdPartyCallArgs { |
| 515 | public final ComponentName component; |
| 516 | public final String callId; |
| 517 | public final String callerDisplayName; |
| 518 | |
| 519 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 520 | String callerDisplayName) { |
| 521 | this.component = component; |
| 522 | this.callId = callId; |
| 523 | this.callerDisplayName = callerDisplayName; |
| 524 | } |
| 525 | } |
| 526 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | /** |
| 528 | * A handler that processes messages on the main thread in the phone process. Since many |
| 529 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 530 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 531 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 532 | * on, which will be notified when the operation completes and will contain the result of the |
| 533 | * request. |
| 534 | * |
| 535 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 536 | * note that request.result must be set to something non-null for the calling thread to |
| 537 | * unblock. |
| 538 | */ |
| 539 | private final class MainThreadHandler extends Handler { |
| 540 | @Override |
| 541 | public void handleMessage(Message msg) { |
| 542 | MainThreadRequest request; |
| 543 | Message onCompleted; |
| 544 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 545 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 547 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 548 | |
| 549 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | case CMD_HANDLE_USSD_REQUEST: { |
| 551 | request = (MainThreadRequest) msg.obj; |
| 552 | final Phone phone = getPhoneFromRequest(request); |
| 553 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 554 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 555 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 556 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | if (!isUssdApiAllowed(request.subId)) { |
| 558 | // Carrier does not support use of this API, return failure. |
| 559 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 560 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 561 | Bundle returnData = new Bundle(); |
| 562 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 563 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 564 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 565 | request.result = true; |
| 566 | notifyRequester(request); |
| 567 | return; |
| 568 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 569 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 570 | try { |
| 571 | request.result = phone != null |
| 572 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 573 | } catch (CallStateException cse) { |
| 574 | request.result = false; |
| 575 | } |
| 576 | // Wake up the requesting thread |
| 577 | notifyRequester(request); |
| 578 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 581 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 583 | final Phone phone = getPhoneFromRequest(request); |
| 584 | request.result = phone != null ? |
| 585 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 586 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 587 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 588 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 589 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 590 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 591 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 592 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 593 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 595 | uiccPort = getUiccPortFromRequest(request); |
| 596 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 598 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 599 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 600 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 602 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 603 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 604 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 605 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 606 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 607 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 610 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | ar = (AsyncResult) msg.obj; |
| 612 | request = (MainThreadRequest) ar.userObj; |
| 613 | if (ar.exception == null && ar.result != null) { |
| 614 | request.result = ar.result; |
| 615 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 616 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | if (ar.result == null) { |
| 618 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 619 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 621 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | } else { |
| 623 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 624 | } |
| 625 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 626 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | break; |
| 628 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 630 | request = (MainThreadRequest) msg.obj; |
| 631 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 632 | uiccPort = getUiccPortFromRequest(request); |
| 633 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 634 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 635 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 636 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | } else { |
| 638 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 639 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 640 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 641 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 642 | iccArgument.p2, |
| 643 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 644 | } |
| 645 | break; |
| 646 | |
| 647 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 648 | ar = (AsyncResult) msg.obj; |
| 649 | request = (MainThreadRequest) ar.userObj; |
| 650 | if (ar.exception == null && ar.result != null) { |
| 651 | request.result = ar.result; |
| 652 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 653 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 654 | if (ar.result == null) { |
| 655 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 656 | } else if (ar.exception instanceof CommandException) { |
| 657 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 658 | ar.exception); |
| 659 | } else { |
| 660 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 661 | } |
| 662 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | break; |
| 665 | |
| 666 | case CMD_EXCHANGE_SIM_IO: |
| 667 | request = (MainThreadRequest) msg.obj; |
| 668 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 669 | uiccPort = getUiccPortFromRequest(request); |
| 670 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 672 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | } else { |
| 675 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 676 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 677 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 679 | iccArgument.data, onCompleted); |
| 680 | } |
| 681 | break; |
| 682 | |
| 683 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 684 | ar = (AsyncResult) msg.obj; |
| 685 | request = (MainThreadRequest) ar.userObj; |
| 686 | if (ar.exception == null && ar.result != null) { |
| 687 | request.result = ar.result; |
| 688 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 689 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 691 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 692 | break; |
| 693 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 694 | case CMD_SEND_ENVELOPE: |
| 695 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 696 | uiccPort = getUiccPortFromRequest(request); |
| 697 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 698 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 699 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 701 | } else { |
| 702 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 703 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 704 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | break; |
| 706 | |
| 707 | case EVENT_SEND_ENVELOPE_DONE: |
| 708 | ar = (AsyncResult) msg.obj; |
| 709 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 710 | if (ar.exception == null && ar.result != null) { |
| 711 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 712 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 713 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 714 | if (ar.result == null) { |
| 715 | loge("sendEnvelopeWithStatus: Empty response"); |
| 716 | } else if (ar.exception instanceof CommandException) { |
| 717 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 718 | ar.exception); |
| 719 | } else { |
| 720 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 721 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 722 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 723 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | case CMD_OPEN_CHANNEL: |
| 727 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 728 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 729 | IccLogicalChannelRequest openChannelRequest = |
| 730 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 731 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 732 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 733 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 734 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 735 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 736 | } else { |
| 737 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 738 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 739 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 740 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | case EVENT_OPEN_CHANNEL_DONE: |
| 744 | ar = (AsyncResult) msg.obj; |
| 745 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 746 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 747 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 748 | int[] result = (int[]) ar.result; |
| 749 | int channelId = result[0]; |
| 750 | byte[] selectResponse = null; |
| 751 | if (result.length > 1) { |
| 752 | selectResponse = new byte[result.length - 1]; |
| 753 | for (int i = 1; i < result.length; ++i) { |
| 754 | selectResponse[i - 1] = (byte) result[i]; |
| 755 | } |
| 756 | } |
| 757 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 758 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 759 | |
| 760 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 761 | if (uiccPort == null) { |
| 762 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 763 | } else { |
| 764 | IccLogicalChannelRequest channelRequest = |
| 765 | (IccLogicalChannelRequest) request.argument; |
| 766 | channelRequest.channel = channelId; |
| 767 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 768 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 769 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 770 | if (ar.result == null) { |
| 771 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 772 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 773 | if (ar.exception != null) { |
| 774 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 775 | } |
| 776 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 777 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 778 | if (ar.exception instanceof CommandException) { |
| 779 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 780 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 781 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 782 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 783 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 784 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 788 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 789 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 790 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 791 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case CMD_CLOSE_CHANNEL: |
| 795 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 796 | uiccPort = getUiccPortFromRequest(request); |
| 797 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 799 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 800 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 801 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 802 | } else { |
| 803 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 804 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 805 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 806 | break; |
| 807 | |
| 808 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 809 | ar = (AsyncResult) msg.obj; |
| 810 | request = (MainThreadRequest) ar.userObj; |
| 811 | if (ar.exception == null) { |
| 812 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 813 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 814 | if (uiccPort == null) { |
| 815 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 816 | } else { |
| 817 | final int channelId = (Integer) request.argument; |
| 818 | uiccPort.onLogicalChannelClosed(channelId); |
| 819 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 820 | } else { |
| 821 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 822 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 823 | if (ar.exception instanceof CommandException) { |
| 824 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 825 | CommandException.Error error = |
| 826 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 827 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 828 | // should only throw exceptions from the binder threads. |
| 829 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 830 | "iccCloseLogicalChannel: invalid argument "); |
| 831 | } |
| 832 | } else { |
| 833 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 834 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 835 | request.result = (exception != null) ? exception : |
| 836 | new IllegalStateException( |
| 837 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 838 | } |
| 839 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case CMD_NV_READ_ITEM: |
| 843 | request = (MainThreadRequest) msg.obj; |
| 844 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 845 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 846 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 847 | break; |
| 848 | |
| 849 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | ar = (AsyncResult) msg.obj; |
| 851 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 852 | if (ar.exception == null && ar.result != null) { |
| 853 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 854 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 855 | request.result = ""; |
| 856 | if (ar.result == null) { |
| 857 | loge("nvReadItem: Empty response"); |
| 858 | } else if (ar.exception instanceof CommandException) { |
| 859 | loge("nvReadItem: CommandException: " + |
| 860 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 861 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 862 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 865 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 866 | break; |
| 867 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 868 | case CMD_NV_WRITE_ITEM: |
| 869 | request = (MainThreadRequest) msg.obj; |
| 870 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 871 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 872 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 873 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 874 | break; |
| 875 | |
| 876 | case EVENT_NV_WRITE_ITEM_DONE: |
| 877 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 878 | break; |
| 879 | |
| 880 | case CMD_NV_WRITE_CDMA_PRL: |
| 881 | request = (MainThreadRequest) msg.obj; |
| 882 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 883 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 887 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 888 | break; |
| 889 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 890 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 892 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 893 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 894 | break; |
| 895 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 896 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 897 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 898 | break; |
| 899 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 900 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 901 | request = (MainThreadRequest) msg.obj; |
| 902 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 903 | request); |
| 904 | Phone phone = getPhoneFromRequest(request); |
| 905 | if (phone != null) { |
| 906 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 907 | } else { |
| 908 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 909 | request.result = false; |
| 910 | notifyRequester(request); |
| 911 | } |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 916 | ar = (AsyncResult) msg.obj; |
| 917 | request = (MainThreadRequest) ar.userObj; |
| 918 | if (ar.exception == null && ar.result != null) { |
| 919 | request.result = ar.result; |
| 920 | } else { |
| 921 | // request.result must be set to something non-null |
| 922 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 923 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 924 | request.result = ar.result; |
| 925 | } else { |
| 926 | request.result = false; |
| 927 | } |
| 928 | if (ar.result == null) { |
| 929 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 930 | } else if (ar.exception instanceof CommandException) { |
| 931 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 932 | + ar.exception); |
| 933 | } else { |
| 934 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 935 | } |
| 936 | } |
| 937 | notifyRequester(request); |
| 938 | break; |
| 939 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 940 | case CMD_IS_VONR_ENABLED: { |
| 941 | request = (MainThreadRequest) msg.obj; |
| 942 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 943 | request); |
| 944 | Phone phone = getPhoneFromRequest(request); |
| 945 | if (phone != null) { |
| 946 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 947 | } else { |
| 948 | loge("isVoNrEnabled: No phone object"); |
| 949 | request.result = false; |
| 950 | notifyRequester(request); |
| 951 | } |
| 952 | break; |
| 953 | } |
| 954 | |
| 955 | case EVENT_IS_VONR_ENABLED_DONE: |
| 956 | ar = (AsyncResult) msg.obj; |
| 957 | request = (MainThreadRequest) ar.userObj; |
| 958 | if (ar.exception == null && ar.result != null) { |
| 959 | request.result = ar.result; |
| 960 | } else { |
| 961 | // request.result must be set to something non-null |
| 962 | // for the calling thread to unblock |
| 963 | if (ar.result != null) { |
| 964 | request.result = ar.result; |
| 965 | } else { |
| 966 | request.result = false; |
| 967 | } |
| 968 | if (ar.result == null) { |
| 969 | loge("isVoNrEnabled: Empty response"); |
| 970 | } else if (ar.exception instanceof CommandException) { |
| 971 | loge("isVoNrEnabled: CommandException: " |
| 972 | + ar.exception); |
| 973 | } else { |
| 974 | loge("isVoNrEnabled: Unknown exception"); |
| 975 | } |
| 976 | } |
| 977 | notifyRequester(request); |
| 978 | break; |
| 979 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 980 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 981 | request = (MainThreadRequest) msg.obj; |
| 982 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 983 | Phone phone = getPhoneFromRequest(request); |
| 984 | if (phone != null) { |
| 985 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 986 | request.workSource); |
| 987 | } else { |
| 988 | loge("enableNrDualConnectivity: No phone object"); |
| 989 | request.result = |
| 990 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 991 | notifyRequester(request); |
| 992 | } |
| 993 | break; |
| 994 | } |
| 995 | |
| 996 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 997 | ar = (AsyncResult) msg.obj; |
| 998 | request = (MainThreadRequest) ar.userObj; |
| 999 | if (ar.exception == null) { |
| 1000 | request.result = |
| 1001 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 1002 | } else { |
| 1003 | request.result = |
| 1004 | TelephonyManager |
| 1005 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1006 | if (ar.exception instanceof CommandException) { |
| 1007 | CommandException.Error error = |
| 1008 | ((CommandException) (ar.exception)).getCommandError(); |
| 1009 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1010 | request.result = |
| 1011 | TelephonyManager |
| 1012 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1013 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1014 | request.result = |
| 1015 | TelephonyManager |
| 1016 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1017 | } |
| 1018 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1019 | + ar.exception); |
| 1020 | } else { |
| 1021 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1022 | } |
| 1023 | } |
| 1024 | notifyRequester(request); |
| 1025 | break; |
| 1026 | } |
| 1027 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1028 | case CMD_ENABLE_VONR: { |
| 1029 | request = (MainThreadRequest) msg.obj; |
| 1030 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1031 | Phone phone = getPhoneFromRequest(request); |
| 1032 | if (phone != null) { |
| 1033 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1034 | request.workSource); |
| 1035 | } else { |
| 1036 | loge("setVoNrEnabled: No phone object"); |
| 1037 | request.result = |
| 1038 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1039 | notifyRequester(request); |
| 1040 | } |
| 1041 | break; |
| 1042 | } |
| 1043 | |
| 1044 | case EVENT_ENABLE_VONR_DONE: { |
| 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
| 1047 | if (ar.exception == null) { |
| 1048 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1049 | } else { |
| 1050 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1051 | if (ar.exception instanceof CommandException) { |
| 1052 | CommandException.Error error = |
| 1053 | ((CommandException) (ar.exception)).getCommandError(); |
| 1054 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1055 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1056 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1057 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1058 | } else { |
| 1059 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1060 | } |
| 1061 | loge("setVoNrEnabled" + ": CommandException: " |
| 1062 | + ar.exception); |
| 1063 | } else { |
| 1064 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1065 | } |
| 1066 | } |
| 1067 | notifyRequester(request); |
| 1068 | break; |
| 1069 | } |
| 1070 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1071 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1072 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1073 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1074 | request); |
| 1075 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1076 | break; |
| 1077 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1078 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1079 | ar = (AsyncResult) msg.obj; |
| 1080 | request = (MainThreadRequest) ar.userObj; |
| 1081 | if (ar.exception == null && ar.result != null) { |
| 1082 | request.result = ar.result; // Integer |
| 1083 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1084 | // request.result must be set to something non-null |
| 1085 | // for the calling thread to unblock |
| 1086 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1087 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1088 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1089 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1090 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1091 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1092 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1093 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1094 | } |
| 1095 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1096 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1097 | break; |
| 1098 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1099 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1100 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1101 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1102 | request); |
| 1103 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1104 | (Pair<Integer, Long>) request.argument; |
| 1105 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1106 | reasonWithNetworkTypes.first, |
| 1107 | reasonWithNetworkTypes.second, |
| 1108 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1109 | break; |
| 1110 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1111 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1112 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1113 | break; |
| 1114 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1115 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1116 | request = (MainThreadRequest)msg.obj; |
| 1117 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1118 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | |
| 1121 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1122 | ar = (AsyncResult)msg.obj; |
| 1123 | request = (MainThreadRequest)ar.userObj; |
| 1124 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1125 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1128 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1129 | request = (MainThreadRequest) msg.obj; |
| 1130 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1131 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1132 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1133 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1134 | break; |
| 1135 | |
| 1136 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1137 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1138 | break; |
| 1139 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1140 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1141 | request = (MainThreadRequest) msg.obj; |
| 1142 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1143 | request); |
| 1144 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1145 | break; |
| 1146 | |
| 1147 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1148 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1149 | break; |
| 1150 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | case CMD_PERFORM_NETWORK_SCAN: |
| 1152 | request = (MainThreadRequest) msg.obj; |
| 1153 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1154 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1155 | break; |
| 1156 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | request = (MainThreadRequest) msg.obj; |
| 1159 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1160 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1161 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1162 | request.argument; |
| 1163 | int callForwardingReason = args.first; |
| 1164 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | } |
| 1167 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1168 | ar = (AsyncResult) msg.obj; |
| 1169 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1170 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1171 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1172 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1173 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1174 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1175 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1176 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1177 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1178 | // any service for voice call. |
| 1179 | if ((callForwardInfo.serviceClass |
| 1180 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1181 | callForwardingInfo = new CallForwardingInfo( |
| 1182 | callForwardInfo.status |
| 1183 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | callForwardInfo.reason, |
| 1185 | callForwardInfo.number, |
| 1186 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | // Didn't find a call forward info for voice call. |
| 1191 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1192 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1193 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1194 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1195 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1196 | } else { |
| 1197 | if (ar.result == null) { |
| 1198 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1199 | } |
| 1200 | if (ar.exception != null) { |
| 1201 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1202 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1203 | int errorCode = TelephonyManager |
| 1204 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | if (ar.exception instanceof CommandException) { |
| 1206 | CommandException.Error error = |
| 1207 | ((CommandException) (ar.exception)).getCommandError(); |
| 1208 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1209 | errorCode = TelephonyManager |
| 1210 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1212 | errorCode = TelephonyManager |
| 1213 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | } |
| 1215 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1220 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1221 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1222 | request = (MainThreadRequest) msg.obj; |
| 1223 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1227 | request.argument).first; |
| 1228 | request.phone.setCallForwardingOption( |
| 1229 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1230 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | callForwardingInfoToSet.getReason(), |
| 1233 | callForwardingInfoToSet.getNumber(), |
| 1234 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 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 EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | ar = (AsyncResult) msg.obj; |
| 1240 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | Consumer<Integer> callback = |
| 1242 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1243 | request.argument).second; |
| 1244 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1245 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1247 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | if (ar.exception instanceof CommandException) { |
| 1249 | CommandException.Error error = |
| 1250 | ((CommandException) (ar.exception)).getCommandError(); |
| 1251 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1252 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1253 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1255 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1256 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | callback.accept(errorCode); |
| 1260 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1261 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1263 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | request = (MainThreadRequest) msg.obj; |
| 1268 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1269 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1270 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | ar = (AsyncResult) msg.obj; |
| 1275 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1277 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1279 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | // Service Class is a bit mask per 3gpp 27.007. |
| 1281 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1282 | if (callForwardResults.length > 1 |
| 1283 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1284 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1285 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1286 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1287 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1288 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1289 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | } |
| 1291 | } else { |
| 1292 | if (ar.result == null) { |
| 1293 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1294 | } |
| 1295 | if (ar.exception != null) { |
| 1296 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1297 | } |
| 1298 | if (ar.exception instanceof CommandException) { |
| 1299 | CommandException.Error error = |
| 1300 | ((CommandException) (ar.exception)).getCommandError(); |
| 1301 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1302 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1304 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1305 | callWaitingStatus = |
| 1306 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | } |
| 1308 | } |
| 1309 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1310 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | request = (MainThreadRequest) msg.obj; |
| 1316 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1318 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1319 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1320 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | ar = (AsyncResult) msg.obj; |
| 1324 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1326 | Consumer<Integer> callback = |
| 1327 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1328 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | if (ar.exception instanceof CommandException) { |
| 1331 | CommandException.Error error = |
| 1332 | ((CommandException) (ar.exception)).getCommandError(); |
| 1333 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1334 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1335 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1336 | callback.accept( |
| 1337 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1338 | } else { |
| 1339 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1340 | } |
| 1341 | } else { |
| 1342 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1343 | } |
| 1344 | } else { |
| 1345 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1346 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1347 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1348 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1349 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1350 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1351 | ar = (AsyncResult) msg.obj; |
| 1352 | request = (MainThreadRequest) ar.userObj; |
| 1353 | CellNetworkScanResult cellScanResult; |
| 1354 | if (ar.exception == null && ar.result != null) { |
| 1355 | cellScanResult = new CellNetworkScanResult( |
| 1356 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1357 | (List<OperatorInfo>) ar.result); |
| 1358 | } else { |
| 1359 | if (ar.result == null) { |
| 1360 | loge("getCellNetworkScanResults: Empty response"); |
| 1361 | } |
| 1362 | if (ar.exception != null) { |
| 1363 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1364 | } |
| 1365 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1366 | if (ar.exception instanceof CommandException) { |
| 1367 | CommandException.Error error = |
| 1368 | ((CommandException) (ar.exception)).getCommandError(); |
| 1369 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1370 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1371 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1372 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1373 | } |
| 1374 | } |
| 1375 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1376 | } |
| 1377 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1378 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1379 | break; |
| 1380 | |
| 1381 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1382 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1383 | ManualNetworkSelectionArgument selArg = |
| 1384 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1385 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1386 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1387 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1388 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1389 | break; |
| 1390 | |
| 1391 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | if (ar.exception == null) { |
| 1395 | request.result = true; |
| 1396 | } else { |
| 1397 | request.result = false; |
| 1398 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1399 | } |
| 1400 | notifyRequester(request); |
| 1401 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1402 | break; |
| 1403 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1404 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1405 | request = (MainThreadRequest) msg.obj; |
| 1406 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1407 | if (defaultPhone != null) { |
| 1408 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1409 | } else { |
| 1410 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1411 | Bundle bundle = new Bundle(); |
| 1412 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1413 | new ModemActivityInfo(0, 0, 0, |
| 1414 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1415 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1416 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1417 | break; |
| 1418 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1419 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1422 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1423 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1424 | if (mLastModemActivityInfo == null) { |
| 1425 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1426 | mLastModemActivitySpecificInfo[0] = |
| 1427 | new ActivityStatsTechSpecificInfo( |
| 1428 | 0, |
| 1429 | 0, |
| 1430 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1431 | 0); |
| 1432 | mLastModemActivityInfo = |
| 1433 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1434 | } |
| 1435 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1436 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1437 | // Update the last modem activity info and the result of the request. |
| 1438 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1439 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1440 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1441 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1442 | mLastModemActivityInfo = |
| 1443 | new ModemActivityInfo( |
| 1444 | mLastModemActivityInfo.getTimestampMillis(), |
| 1445 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1446 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1447 | mLastModemActivitySpecificInfo); |
| 1448 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1449 | } else { |
| 1450 | if (ar.result == null) { |
| 1451 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1452 | error = TelephonyManager.ModemActivityInfoException |
| 1453 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1454 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1455 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1456 | error = TelephonyManager.ModemActivityInfoException |
| 1457 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1458 | } else { |
| 1459 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1460 | error = TelephonyManager.ModemActivityInfoException |
| 1461 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1464 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1465 | if (mLastModemActivityInfo != null) { |
| 1466 | bundle.putParcelable( |
| 1467 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1468 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1469 | } else { |
| 1470 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1471 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1472 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1473 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1474 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1475 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1476 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1477 | case CMD_SET_ALLOWED_CARRIERS: |
| 1478 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1479 | CarrierRestrictionRules argument = |
| 1480 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1481 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1482 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1483 | break; |
| 1484 | |
| 1485 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1486 | ar = (AsyncResult) msg.obj; |
| 1487 | request = (MainThreadRequest) ar.userObj; |
| 1488 | if (ar.exception == null && ar.result != null) { |
| 1489 | request.result = ar.result; |
| 1490 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1491 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1492 | if (ar.exception instanceof CommandException) { |
| 1493 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1494 | CommandException.Error error = |
| 1495 | ((CommandException) (ar.exception)).getCommandError(); |
| 1496 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1497 | request.result = |
| 1498 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1499 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1500 | } else { |
| 1501 | loge("setAllowedCarriers: Unknown exception"); |
| 1502 | } |
| 1503 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1504 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1505 | break; |
| 1506 | |
| 1507 | case CMD_GET_ALLOWED_CARRIERS: |
| 1508 | request = (MainThreadRequest) msg.obj; |
| 1509 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1510 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1511 | break; |
| 1512 | |
| 1513 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1514 | ar = (AsyncResult) msg.obj; |
| 1515 | request = (MainThreadRequest) ar.userObj; |
| 1516 | if (ar.exception == null && ar.result != null) { |
| 1517 | request.result = ar.result; |
| 1518 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1519 | request.result = new IllegalStateException( |
| 1520 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1521 | if (ar.result == null) { |
| 1522 | loge("getAllowedCarriers: Empty response"); |
| 1523 | } else if (ar.exception instanceof CommandException) { |
| 1524 | loge("getAllowedCarriers: CommandException: " + |
| 1525 | ar.exception); |
| 1526 | } else { |
| 1527 | loge("getAllowedCarriers: Unknown exception"); |
| 1528 | } |
| 1529 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1530 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1531 | break; |
| 1532 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1533 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1534 | ar = (AsyncResult) msg.obj; |
| 1535 | request = (MainThreadRequest) ar.userObj; |
| 1536 | if (ar.exception == null && ar.result != null) { |
| 1537 | request.result = ar.result; |
| 1538 | } else { |
| 1539 | request.result = new IllegalArgumentException( |
| 1540 | "Failed to retrieve Forbidden Plmns"); |
| 1541 | if (ar.result == null) { |
| 1542 | loge("getForbiddenPlmns: Empty response"); |
| 1543 | } else { |
| 1544 | loge("getForbiddenPlmns: Unknown exception"); |
| 1545 | } |
| 1546 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1547 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1548 | break; |
| 1549 | |
| 1550 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1551 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1552 | uiccPort = getUiccPortFromRequest(request); |
| 1553 | if (uiccPort == null) { |
| 1554 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1555 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1556 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1557 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1558 | break; |
| 1559 | } |
| 1560 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1561 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1562 | if (uiccApp == null) { |
| 1563 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1564 | + appType); |
| 1565 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1566 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1567 | break; |
| 1568 | } else { |
| 1569 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1570 | + " specified type -- " + appType); |
| 1571 | } |
| 1572 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1573 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1574 | onCompleted); |
| 1575 | break; |
| 1576 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1577 | case CMD_SWITCH_SLOTS: |
| 1578 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1579 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1580 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1581 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1582 | break; |
| 1583 | |
| 1584 | case EVENT_SWITCH_SLOTS_DONE: |
| 1585 | ar = (AsyncResult) msg.obj; |
| 1586 | request = (MainThreadRequest) ar.userObj; |
| 1587 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1588 | notifyRequester(request); |
| 1589 | break; |
| 1590 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1591 | request = (MainThreadRequest) msg.obj; |
| 1592 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1593 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1594 | break; |
| 1595 | |
| 1596 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1597 | ar = (AsyncResult) msg.obj; |
| 1598 | request = (MainThreadRequest) ar.userObj; |
| 1599 | if (ar.exception != null) { |
| 1600 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1601 | } else { |
| 1602 | int mode = ((int[]) ar.result)[0]; |
| 1603 | if (mode == 0) { |
| 1604 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1605 | } else { |
| 1606 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1607 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1608 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1609 | notifyRequester(request); |
| 1610 | break; |
| 1611 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1612 | request = (MainThreadRequest) msg.obj; |
| 1613 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1614 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1615 | break; |
| 1616 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1617 | ar = (AsyncResult) msg.obj; |
| 1618 | request = (MainThreadRequest) ar.userObj; |
| 1619 | if (ar.exception != null) { |
| 1620 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1621 | } else { |
| 1622 | request.result = ((int[]) ar.result)[0]; |
| 1623 | } |
| 1624 | notifyRequester(request); |
| 1625 | break; |
| 1626 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1627 | request = (MainThreadRequest) msg.obj; |
| 1628 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1629 | int mode = (int) request.argument; |
| 1630 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1631 | break; |
| 1632 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1633 | ar = (AsyncResult) msg.obj; |
| 1634 | request = (MainThreadRequest) ar.userObj; |
| 1635 | request.result = ar.exception == null; |
| 1636 | notifyRequester(request); |
| 1637 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1638 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1639 | request = (MainThreadRequest) msg.obj; |
| 1640 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1641 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1642 | break; |
| 1643 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1644 | ar = (AsyncResult) msg.obj; |
| 1645 | request = (MainThreadRequest) ar.userObj; |
| 1646 | if (ar.exception != null) { |
| 1647 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1648 | } else { |
| 1649 | request.result = ((int[]) ar.result)[0]; |
| 1650 | } |
| 1651 | notifyRequester(request); |
| 1652 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1654 | request = (MainThreadRequest) msg.obj; |
| 1655 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1656 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1657 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1658 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1661 | ar = (AsyncResult) msg.obj; |
| 1662 | request = (MainThreadRequest) ar.userObj; |
| 1663 | request.result = ar.exception == null; |
| 1664 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1665 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1666 | case CMD_GET_ALL_CELL_INFO: |
| 1667 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1668 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1669 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1670 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1671 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1672 | ar = (AsyncResult) msg.obj; |
| 1673 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1674 | // If a timeout occurs, the response will be null |
| 1675 | request.result = (ar.exception == null && ar.result != null) |
| 1676 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1677 | synchronized (request) { |
| 1678 | request.notifyAll(); |
| 1679 | } |
| 1680 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1681 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1682 | request = (MainThreadRequest) msg.obj; |
| 1683 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1684 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1685 | break; |
| 1686 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1687 | ar = (AsyncResult) msg.obj; |
| 1688 | request = (MainThreadRequest) ar.userObj; |
| 1689 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1690 | try { |
| 1691 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1692 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1693 | cb.onError( |
| 1694 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1695 | ar.exception.getClass().getName(), |
| 1696 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1697 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1698 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1699 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1700 | } else { |
| 1701 | // use the result as returned |
| 1702 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1703 | } |
| 1704 | } catch (RemoteException re) { |
| 1705 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1706 | } |
| 1707 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1708 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1709 | request = (MainThreadRequest) msg.obj; |
| 1710 | WorkSource ws = (WorkSource) request.argument; |
| 1711 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1712 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1713 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1714 | } |
| 1715 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | if (ar.exception == null) { |
| 1719 | request.result = ar.result; |
| 1720 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1721 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1722 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1723 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | synchronized (request) { |
| 1727 | request.notifyAll(); |
| 1728 | } |
| 1729 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1730 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1731 | case CMD_MODEM_REBOOT: |
| 1732 | request = (MainThreadRequest) msg.obj; |
| 1733 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1734 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1735 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1736 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1737 | handleNullReturnEvent(msg, "rebootModem"); |
| 1738 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1739 | case CMD_REQUEST_ENABLE_MODEM: |
| 1740 | request = (MainThreadRequest) msg.obj; |
| 1741 | boolean enable = (boolean) request.argument; |
| 1742 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1743 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1744 | PhoneConfigurationManager.getInstance() |
| 1745 | .enablePhone(request.phone, enable, onCompleted); |
| 1746 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1747 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1748 | ar = (AsyncResult) msg.obj; |
| 1749 | request = (MainThreadRequest) ar.userObj; |
| 1750 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1751 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1752 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1753 | if ((boolean) request.result) { |
| 1754 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1755 | updateModemStateMetrics(); |
| 1756 | } else { |
| 1757 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1758 | + ar.exception); |
| 1759 | } |
| 1760 | notifyRequester(request); |
| 1761 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1762 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1763 | case CMD_GET_MODEM_STATUS: |
| 1764 | request = (MainThreadRequest) msg.obj; |
| 1765 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1766 | PhoneConfigurationManager.getInstance() |
| 1767 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1768 | break; |
| 1769 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1770 | ar = (AsyncResult) msg.obj; |
| 1771 | request = (MainThreadRequest) ar.userObj; |
| 1772 | int id = request.phone.getPhoneId(); |
| 1773 | if (ar.exception == null && ar.result != null) { |
| 1774 | request.result = ar.result; |
| 1775 | //update the cache as modem status has changed |
| 1776 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1777 | (boolean) request.result); |
| 1778 | } else { |
| 1779 | // Return true if modem status cannot be retrieved. For most cases, |
| 1780 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1781 | // and disable modem are not supported. Modem is always on. |
| 1782 | // TODO: this should be fixed in R to support a third |
| 1783 | // status UNKNOWN b/131631629 |
| 1784 | request.result = true; |
| 1785 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1786 | + ar.exception); |
| 1787 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1788 | notifyRequester(request); |
| 1789 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1790 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1791 | request = (MainThreadRequest) msg.obj; |
| 1792 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1793 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1794 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1795 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1796 | break; |
| 1797 | } |
| 1798 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1799 | ar = (AsyncResult) msg.obj; |
| 1800 | request = (MainThreadRequest) ar.userObj; |
| 1801 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1802 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1803 | args.second.accept(ar.exception == null); |
| 1804 | notifyRequester(request); |
| 1805 | break; |
| 1806 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1807 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1808 | request = (MainThreadRequest) msg.obj; |
| 1809 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1810 | Phone phone = getPhoneFromRequest(request); |
| 1811 | if (phone != null) { |
| 1812 | phone.getSystemSelectionChannels(onCompleted); |
| 1813 | } else { |
| 1814 | loge("getSystemSelectionChannels: No phone object"); |
| 1815 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1816 | notifyRequester(request); |
| 1817 | } |
| 1818 | break; |
| 1819 | } |
| 1820 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1821 | ar = (AsyncResult) msg.obj; |
| 1822 | request = (MainThreadRequest) ar.userObj; |
| 1823 | if (ar.exception == null && ar.result != null) { |
| 1824 | request.result = ar.result; |
| 1825 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1826 | request.result = new IllegalStateException( |
| 1827 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1828 | if (ar.result == null) { |
| 1829 | loge("getSystemSelectionChannels: Empty response"); |
| 1830 | } else { |
| 1831 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1832 | } |
| 1833 | } |
| 1834 | notifyRequester(request); |
| 1835 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1836 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1837 | ar = (AsyncResult) msg.obj; |
| 1838 | request = (MainThreadRequest) ar.userObj; |
| 1839 | if (ar.exception == null && ar.result != null) { |
| 1840 | request.result = ar.result; |
| 1841 | } else { |
| 1842 | request.result = -1; |
| 1843 | loge("Failed to set Forbidden Plmns"); |
| 1844 | if (ar.result == null) { |
| 1845 | loge("setForbidenPlmns: Empty response"); |
| 1846 | } else if (ar.exception != null) { |
| 1847 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1848 | request.result = -1; |
| 1849 | } else { |
| 1850 | loge("setForbiddenPlmns: Unknown exception"); |
| 1851 | } |
| 1852 | } |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1856 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1857 | uiccPort = getUiccPortFromRequest(request); |
| 1858 | if (uiccPort == null) { |
| 1859 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1860 | request.result = -1; |
| 1861 | notifyRequester(request); |
| 1862 | break; |
| 1863 | } |
| 1864 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1865 | (Pair<Integer, List<String>>) request.argument; |
| 1866 | appType = setFplmnsArgs.first; |
| 1867 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1868 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1869 | if (uiccApp == null) { |
| 1870 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1871 | request.result = -1; |
| 1872 | loge("Failed to get UICC App"); |
| 1873 | notifyRequester(request); |
| 1874 | } else { |
| 1875 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1876 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1877 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1878 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1879 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1880 | case CMD_ERASE_MODEM_CONFIG: |
| 1881 | request = (MainThreadRequest) msg.obj; |
| 1882 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1883 | defaultPhone.eraseModemConfig(onCompleted); |
| 1884 | break; |
| 1885 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1886 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1887 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1888 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1889 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1890 | request = (MainThreadRequest) msg.obj; |
| 1891 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1892 | notifyRequester(request); |
| 1893 | break; |
| 1894 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1895 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1896 | request = (MainThreadRequest) msg.obj; |
| 1897 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1898 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1899 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1900 | changed.first, changed.second, onCompleted); |
| 1901 | break; |
| 1902 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1903 | ar = (AsyncResult) msg.obj; |
| 1904 | request = (MainThreadRequest) ar.userObj; |
| 1905 | if (ar.exception == null) { |
| 1906 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1907 | // If the operation is successful, update the PIN storage |
| 1908 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1909 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1910 | UiccController.getInstance().getPinStorage() |
| 1911 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1912 | } else { |
| 1913 | request.result = msg.arg1; |
| 1914 | } |
| 1915 | notifyRequester(request); |
| 1916 | break; |
| 1917 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1918 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1919 | request = (MainThreadRequest) msg.obj; |
| 1920 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1921 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1922 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1923 | enabled.first, enabled.second, onCompleted); |
| 1924 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1925 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1926 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1927 | ar = (AsyncResult) msg.obj; |
| 1928 | request = (MainThreadRequest) ar.userObj; |
| 1929 | if (ar.exception == null) { |
| 1930 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1931 | // If the operation is successful, update the PIN storage |
| 1932 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1933 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1934 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1935 | UiccController.getInstance().getPinStorage() |
| 1936 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1937 | } else { |
| 1938 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1939 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1940 | } else { |
| 1941 | request.result = msg.arg1; |
| 1942 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1943 | |
| 1944 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1945 | notifyRequester(request); |
| 1946 | break; |
| 1947 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1948 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1949 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1950 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1951 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1952 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1953 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1954 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1955 | |
| 1956 | case CMD_SET_DATA_THROTTLING: { |
| 1957 | request = (MainThreadRequest) msg.obj; |
| 1958 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1959 | DataThrottlingRequest dataThrottlingRequest = |
| 1960 | (DataThrottlingRequest) request.argument; |
| 1961 | Phone phone = getPhoneFromRequest(request); |
| 1962 | if (phone != null) { |
| 1963 | phone.setDataThrottling(onCompleted, |
| 1964 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1965 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1966 | } else { |
| 1967 | loge("setDataThrottling: No phone object"); |
| 1968 | request.result = |
| 1969 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1970 | notifyRequester(request); |
| 1971 | } |
| 1972 | |
| 1973 | break; |
| 1974 | } |
| 1975 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1976 | ar = (AsyncResult) msg.obj; |
| 1977 | request = (MainThreadRequest) ar.userObj; |
| 1978 | |
| 1979 | if (ar.exception == null) { |
| 1980 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1981 | } else if (ar.exception instanceof CommandException) { |
| 1982 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1983 | CommandException.Error error = |
| 1984 | ((CommandException) (ar.exception)).getCommandError(); |
| 1985 | |
| 1986 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1987 | request.result = TelephonyManager |
| 1988 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1989 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1990 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1991 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1992 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1993 | } else { |
| 1994 | request.result = |
| 1995 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1996 | } |
| 1997 | } else { |
| 1998 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1999 | } |
| 2000 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 2001 | notifyRequester(request); |
| 2002 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2003 | |
| 2004 | case CMD_SET_SIM_POWER: { |
| 2005 | request = (MainThreadRequest) msg.obj; |
| 2006 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2007 | request = (MainThreadRequest) msg.obj; |
| 2008 | int stateToSet = |
| 2009 | ((Pair<Integer, IIntegerConsumer>) |
| 2010 | request.argument).first; |
| 2011 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2012 | break; |
| 2013 | } |
| 2014 | case EVENT_SET_SIM_POWER_DONE: { |
| 2015 | ar = (AsyncResult) msg.obj; |
| 2016 | request = (MainThreadRequest) ar.userObj; |
| 2017 | IIntegerConsumer callback = |
| 2018 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2019 | if (ar.exception != null) { |
| 2020 | loge("setSimPower exception: " + ar.exception); |
| 2021 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2022 | .RESULT_ERROR_UNKNOWN; |
| 2023 | if (ar.exception instanceof CommandException) { |
| 2024 | CommandException.Error error = |
| 2025 | ((CommandException) (ar.exception)).getCommandError(); |
| 2026 | if (error == CommandException.Error.SIM_ERR) { |
| 2027 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2028 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2029 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2030 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2031 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2032 | } else { |
| 2033 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2034 | } |
| 2035 | } |
| 2036 | try { |
| 2037 | callback.accept(errorCode); |
| 2038 | } catch (RemoteException e) { |
| 2039 | // Ignore if the remote process is no longer available to call back. |
| 2040 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2041 | } |
| 2042 | } else { |
| 2043 | try { |
| 2044 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2045 | } catch (RemoteException e) { |
| 2046 | // Ignore if the remote process is no longer available to call back. |
| 2047 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2048 | } |
| 2049 | } |
| 2050 | break; |
| 2051 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2052 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2053 | request = (MainThreadRequest) msg.obj; |
| 2054 | |
| 2055 | final Phone phone = getPhoneFromRequest(request); |
| 2056 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2057 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2058 | notifyRequester(request); |
| 2059 | break; |
| 2060 | } |
| 2061 | |
| 2062 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2063 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2064 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2065 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2066 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2067 | request.subId, pair.first /*callingUid*/, |
| 2068 | pair.second /*request*/, onCompleted); |
| 2069 | break; |
| 2070 | } |
| 2071 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2072 | ar = (AsyncResult) msg.obj; |
| 2073 | request = (MainThreadRequest) ar.userObj; |
| 2074 | // request.result will be the exception of ar if present, true otherwise. |
| 2075 | // Be cautious not to leave result null which will wait() forever |
| 2076 | request.result = ar.exception != null ? ar.exception : true; |
| 2077 | notifyRequester(request); |
| 2078 | break; |
| 2079 | } |
| 2080 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2081 | request = (MainThreadRequest) msg.obj; |
| 2082 | |
| 2083 | Phone phone = getPhoneFromRequest(request); |
| 2084 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2085 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2086 | notifyRequester(request); |
| 2087 | break; |
| 2088 | } |
| 2089 | |
| 2090 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2091 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2092 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2093 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2094 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2095 | request.subId, pair.first /*callingUid*/, |
| 2096 | pair.second /*request*/, onCompleted); |
| 2097 | break; |
| 2098 | } |
| 2099 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2100 | ar = (AsyncResult) msg.obj; |
| 2101 | request = (MainThreadRequest) ar.userObj; |
| 2102 | request.result = ar.exception != null ? ar.exception : true; |
| 2103 | notifyRequester(request); |
| 2104 | break; |
| 2105 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2106 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2107 | case CMD_GET_SLICING_CONFIG: { |
| 2108 | request = (MainThreadRequest) msg.obj; |
| 2109 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2110 | request.phone.getSlicingConfig(onCompleted); |
| 2111 | break; |
| 2112 | } |
| 2113 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2114 | ar = (AsyncResult) msg.obj; |
| 2115 | request = (MainThreadRequest) ar.userObj; |
| 2116 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2117 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2118 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2119 | Bundle bundle = new Bundle(); |
| 2120 | int resultCode = 0; |
| 2121 | if (ar.exception != null) { |
| 2122 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2123 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2124 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2125 | } else if (ar.result == null) { |
| 2126 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2127 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2128 | } else { |
| 2129 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2130 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2131 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2135 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2136 | } |
| 2137 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2138 | result.send(resultCode, bundle); |
| 2139 | notifyRequester(request); |
| 2140 | break; |
| 2141 | } |
| 2142 | |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 2143 | case CMD_PURCHASE_PREMIUM_CAPABILITY: |
| 2144 | request = (MainThreadRequest) msg.obj; |
| 2145 | onCompleted = obtainMessage(EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE, request); |
| 2146 | SliceStore.getInstance(request.phone).purchasePremiumCapability( |
| 2147 | ((Pair<Integer, IIntegerConsumer>) request.argument).first, |
| 2148 | onCompleted); |
| 2149 | break; |
| 2150 | |
| 2151 | case EVENT_PURCHASE_PREMIUM_CAPABILITY_DONE: |
| 2152 | ar = (AsyncResult) msg.obj; |
| 2153 | request = (MainThreadRequest) ar.userObj; |
| 2154 | Pair<Integer, IIntegerConsumer> pair = |
| 2155 | (Pair<Integer, IIntegerConsumer>) request.argument; |
| 2156 | try { |
| 2157 | int result = (int) ar.result; |
| 2158 | pair.second.accept(result); |
| 2159 | log("purchasePremiumCapability: capability=" |
| 2160 | + TelephonyManager.convertPremiumCapabilityToString(pair.first) |
| 2161 | + ", result= " |
| 2162 | + TelephonyManager.convertPurchaseResultToString(result)); |
| 2163 | } catch (RemoteException e) { |
| 2164 | String logStr = "Purchase premium capability " |
| 2165 | + TelephonyManager.convertPremiumCapabilityToString(pair.first) |
| 2166 | + " failed: " + e; |
| 2167 | if (DBG) log(logStr); |
| 2168 | AnomalyReporter.reportAnomaly( |
| 2169 | UUID.fromString(PURCHASE_PREMIUM_CAPABILITY_ERROR_UUID), logStr); |
| 2170 | } |
| 2171 | break; |
| 2172 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2173 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2174 | request = (MainThreadRequest) msg.obj; |
| 2175 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2176 | UiccController.getInstance().getPinStorage() |
| 2177 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2178 | notifyRequester(request); |
| 2179 | break; |
| 2180 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2181 | default: |
| 2182 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2183 | break; |
| 2184 | } |
| 2185 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2186 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2187 | private void notifyRequester(MainThreadRequest request) { |
| 2188 | synchronized (request) { |
| 2189 | request.notifyAll(); |
| 2190 | } |
| 2191 | } |
| 2192 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2193 | private void handleNullReturnEvent(Message msg, String command) { |
| 2194 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2195 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2196 | if (ar.exception == null) { |
| 2197 | request.result = true; |
| 2198 | } else { |
| 2199 | request.result = false; |
| 2200 | if (ar.exception instanceof CommandException) { |
| 2201 | loge(command + ": CommandException: " + ar.exception); |
| 2202 | } else { |
| 2203 | loge(command + ": Unknown exception"); |
| 2204 | } |
| 2205 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2206 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | /** |
| 2211 | * Posts the specified command to be executed on the main thread, |
| 2212 | * waits for the request to complete, and returns the result. |
| 2213 | * @see #sendRequestAsync |
| 2214 | */ |
| 2215 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2216 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2217 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | /** |
| 2221 | * Posts the specified command to be executed on the main thread, |
| 2222 | * waits for the request to complete, and returns the result. |
| 2223 | * @see #sendRequestAsync |
| 2224 | */ |
| 2225 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2226 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2227 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2235 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2236 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2237 | } |
| 2238 | |
| 2239 | /** |
| 2240 | * Posts the specified command to be executed on the main thread, |
| 2241 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2242 | * if not timeout or null otherwise. |
| 2243 | * @see #sendRequestAsync |
| 2244 | */ |
| 2245 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2246 | long timeoutInMs) { |
| 2247 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -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 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2255 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2256 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | /** |
| 2260 | * Posts the specified command to be executed on the main thread, |
| 2261 | * waits for the request to complete, and returns the result. |
| 2262 | * @see #sendRequestAsync |
| 2263 | */ |
| 2264 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2265 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2266 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2270 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2271 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2272 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2273 | * @see #sendRequestAsync |
| 2274 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2275 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2276 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2278 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2279 | } |
| 2280 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2281 | MainThreadRequest request = null; |
| 2282 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2283 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2284 | } else if (phone != null) { |
| 2285 | request = new MainThreadRequest(argument, phone, workSource); |
| 2286 | } else { |
| 2287 | request = new MainThreadRequest(argument, subId, workSource); |
| 2288 | } |
| 2289 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2291 | msg.sendToTarget(); |
| 2292 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2293 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2295 | if (timeoutInMs >= 0) { |
| 2296 | // Wait for at least timeoutInMs before returning null request result |
| 2297 | long now = SystemClock.elapsedRealtime(); |
| 2298 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2299 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2300 | try { |
| 2301 | request.wait(deadline - now); |
| 2302 | } catch (InterruptedException e) { |
| 2303 | // Do nothing, go back and check if request is completed or timeout |
| 2304 | } finally { |
| 2305 | now = SystemClock.elapsedRealtime(); |
| 2306 | } |
| 2307 | } |
| 2308 | } else { |
| 2309 | // Wait for the request to complete |
| 2310 | while (request.result == null) { |
| 2311 | try { |
| 2312 | request.wait(); |
| 2313 | } catch (InterruptedException e) { |
| 2314 | // Do nothing, go back and wait until the request is complete |
| 2315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2316 | } |
| 2317 | } |
| 2318 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2319 | if (request.result == null) { |
| 2320 | Log.wtf(LOG_TAG, |
| 2321 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2322 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | return request.result; |
| 2324 | } |
| 2325 | |
| 2326 | /** |
| 2327 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2328 | * Posts the specified command to be executed on the main thread, and |
| 2329 | * returns immediately. |
| 2330 | * @see #sendRequest |
| 2331 | */ |
| 2332 | private void sendRequestAsync(int command) { |
| 2333 | mMainThreadHandler.sendEmptyMessage(command); |
| 2334 | } |
| 2335 | |
| 2336 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2337 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2338 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2339 | */ |
| 2340 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2341 | sendRequestAsync(command, argument, null, null); |
| 2342 | } |
| 2343 | |
| 2344 | /** |
| 2345 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2346 | * @see {@link #sendRequest(int,Object)} |
| 2347 | */ |
| 2348 | private void sendRequestAsync( |
| 2349 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2350 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2351 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2352 | msg.sendToTarget(); |
| 2353 | } |
| 2354 | |
| 2355 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2357 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2358 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2359 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | synchronized (PhoneInterfaceManager.class) { |
| 2361 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2362 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | } else { |
| 2364 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2365 | } |
| 2366 | return sInstance; |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2371 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2374 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2375 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2377 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2378 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2379 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2380 | mTelephonySharedPreferences = |
| 2381 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2382 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2383 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2384 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2385 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2386 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2387 | publish(); |
| 2388 | } |
| 2389 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2390 | private Phone getDefaultPhone() { |
| 2391 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2392 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2393 | } |
| 2394 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | private void publish() { |
| 2396 | if (DBG) log("publish: " + this); |
| 2397 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2398 | TelephonyFrameworkInitializer |
| 2399 | .getTelephonyServiceManager() |
| 2400 | .getTelephonyServiceRegisterer() |
| 2401 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2404 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2405 | if (request.phone != null) { |
| 2406 | return request.phone; |
| 2407 | } else { |
| 2408 | return getPhoneFromSubId(request.subId); |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | private Phone getPhoneFromSubId(int subId) { |
| 2413 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2414 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2415 | } |
| 2416 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2417 | @Nullable |
| 2418 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2419 | Phone phone = getPhoneFromRequest(request); |
| 2420 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2421 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2422 | } |
| 2423 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2424 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2425 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2426 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2429 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2430 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2431 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2432 | } |
| 2433 | |
| 2434 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2435 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2436 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2439 | private boolean isImsAvailableOnDevice() { |
| 2440 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2441 | if (pm == null) { |
| 2442 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2443 | // so do not throw error and allow. |
| 2444 | return true; |
| 2445 | } |
| 2446 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2447 | } |
| 2448 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2449 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2450 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2453 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | if (DBG) log("dial: " + number); |
| 2455 | // No permission check needed here: This is just a wrapper around the |
| 2456 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2457 | // the UI before it does anything. |
| 2458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | final long identity = Binder.clearCallingIdentity(); |
| 2460 | try { |
| 2461 | String url = createTelUrl(number); |
| 2462 | if (url == null) { |
| 2463 | return; |
| 2464 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2466 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2467 | PhoneConstants.State state = mCM.getState(subId); |
| 2468 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2469 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2470 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2471 | mApp.startActivity(intent); |
| 2472 | } |
| 2473 | } finally { |
| 2474 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2479 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2482 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | if (DBG) log("call: " + number); |
| 2484 | |
| 2485 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2486 | // need to do a permission check since we're calling startActivity() |
| 2487 | // from the context of the phone app. |
| 2488 | enforceCallPermission(); |
| 2489 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2490 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | != AppOpsManager.MODE_ALLOWED) { |
| 2492 | return; |
| 2493 | } |
| 2494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
| 2497 | String url = createTelUrl(number); |
| 2498 | if (url == null) { |
| 2499 | return; |
| 2500 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2502 | boolean isValid = false; |
| 2503 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2504 | if (slist != null) { |
| 2505 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2506 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2507 | isValid = true; |
| 2508 | break; |
| 2509 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2510 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2511 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | if (!isValid) { |
| 2513 | return; |
| 2514 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2515 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2516 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2517 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2518 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2519 | mApp.startActivity(intent); |
| 2520 | } finally { |
| 2521 | Binder.restoreCallingIdentity(identity); |
| 2522 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2525 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2526 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2527 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2528 | } |
| 2529 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2530 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2531 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2532 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2533 | } |
| 2534 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2535 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2536 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2540 | Phone phone = getPhone(subId); |
| 2541 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2542 | checkSimPin.start(); |
| 2543 | return checkSimPin.unlockSim(null, pin); |
| 2544 | } finally { |
| 2545 | Binder.restoreCallingIdentity(identity); |
| 2546 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | } |
| 2548 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2549 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2551 | |
| 2552 | final long identity = Binder.clearCallingIdentity(); |
| 2553 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2554 | Phone phone = getPhone(subId); |
| 2555 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2556 | checkSimPuk.start(); |
| 2557 | return checkSimPuk.unlockSim(puk, pin); |
| 2558 | } finally { |
| 2559 | Binder.restoreCallingIdentity(identity); |
| 2560 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2564 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2565 | * a synchronous one. |
| 2566 | */ |
| 2567 | private static class UnlockSim extends Thread { |
| 2568 | |
| 2569 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2570 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2571 | |
| 2572 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2573 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2574 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2575 | |
| 2576 | // For replies from SimCard interface |
| 2577 | private Handler mHandler; |
| 2578 | |
| 2579 | // For async handler to identify request type |
| 2580 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2581 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2582 | UnlockSim(int phoneId, IccCard simCard) { |
| 2583 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2584 | mSimCard = simCard; |
| 2585 | } |
| 2586 | |
| 2587 | @Override |
| 2588 | public void run() { |
| 2589 | Looper.prepare(); |
| 2590 | synchronized (UnlockSim.this) { |
| 2591 | mHandler = new Handler() { |
| 2592 | @Override |
| 2593 | public void handleMessage(Message msg) { |
| 2594 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2595 | switch (msg.what) { |
| 2596 | case SUPPLY_PIN_COMPLETE: |
| 2597 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2598 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2599 | mRetryCount = msg.arg1; |
| 2600 | if (ar.exception != null) { |
| 2601 | if (ar.exception instanceof CommandException && |
| 2602 | ((CommandException)(ar.exception)).getCommandError() |
| 2603 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2604 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2605 | } //When UiccCardApp dispose,handle message and return exception |
| 2606 | else if (ar.exception instanceof CommandException && |
| 2607 | ((CommandException) (ar.exception)).getCommandError() |
| 2608 | == CommandException.Error.ABORTED) { |
| 2609 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2610 | } else { |
| 2611 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2612 | } |
| 2613 | } else { |
| 2614 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | mDone = true; |
| 2617 | UnlockSim.this.notifyAll(); |
| 2618 | } |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | }; |
| 2623 | UnlockSim.this.notifyAll(); |
| 2624 | } |
| 2625 | Looper.loop(); |
| 2626 | } |
| 2627 | |
| 2628 | /* |
| 2629 | * Use PIN or PUK to unlock SIM card |
| 2630 | * |
| 2631 | * If PUK is null, unlock SIM card with PIN |
| 2632 | * |
| 2633 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2634 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2635 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2636 | |
| 2637 | while (mHandler == null) { |
| 2638 | try { |
| 2639 | wait(); |
| 2640 | } catch (InterruptedException e) { |
| 2641 | Thread.currentThread().interrupt(); |
| 2642 | } |
| 2643 | } |
| 2644 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2645 | |
| 2646 | if (puk == null) { |
| 2647 | mSimCard.supplyPin(pin, callback); |
| 2648 | } else { |
| 2649 | mSimCard.supplyPuk(puk, pin, callback); |
| 2650 | } |
| 2651 | |
| 2652 | while (!mDone) { |
| 2653 | try { |
| 2654 | Log.d(LOG_TAG, "wait for done"); |
| 2655 | wait(); |
| 2656 | } catch (InterruptedException e) { |
| 2657 | // Restore the interrupted status |
| 2658 | Thread.currentThread().interrupt(); |
| 2659 | } |
| 2660 | } |
| 2661 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2662 | int[] resultArray = new int[2]; |
| 2663 | resultArray[0] = mResult; |
| 2664 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2665 | |
| 2666 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2667 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2670 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2674 | /** |
| 2675 | * This method has been removed due to privacy and stability concerns. |
| 2676 | */ |
| 2677 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2679 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2680 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2683 | @Override |
| 2684 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2685 | mApp.getSystemService(AppOpsManager.class) |
| 2686 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2687 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2688 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2689 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2690 | // Callers targeting S have no business invoking this method. |
| 2691 | return; |
| 2692 | } |
| 2693 | |
| 2694 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2695 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2696 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2697 | .setCallingPackage(callingPackage) |
| 2698 | .setCallingFeatureId(null) |
| 2699 | .setCallingPid(Binder.getCallingPid()) |
| 2700 | .setCallingUid(Binder.getCallingUid()) |
| 2701 | .setMethod("updateServiceLocation") |
| 2702 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2703 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2704 | .build()); |
| 2705 | // Apps that lack location permission have no business calling this method; |
| 2706 | // however, because no permission was declared in the public API, denials must |
| 2707 | // all be "soft". |
| 2708 | switch (locationResult) { |
| 2709 | case DENIED_HARD: /* fall through */ |
| 2710 | case DENIED_SOFT: |
| 2711 | return; |
| 2712 | } |
| 2713 | |
| 2714 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2717 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2719 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2720 | } |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2726 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2727 | @Override |
| 2728 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2729 | return isRadioOnWithFeature(callingPackage, null); |
| 2730 | } |
| 2731 | |
| 2732 | |
| 2733 | @Override |
| 2734 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2735 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2736 | callingFeatureId); |
| 2737 | } |
| 2738 | |
| 2739 | @Deprecated |
| 2740 | @Override |
| 2741 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2742 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2743 | } |
| 2744 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2745 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2746 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2747 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2749 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2750 | return false; |
| 2751 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2752 | |
| 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | return isRadioOnForSubscriber(subId); |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
| 2758 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
| 2764 | final Phone phone = getPhone(subId); |
| 2765 | if (phone != null) { |
| 2766 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2767 | } else { |
| 2768 | return false; |
| 2769 | } |
| 2770 | } finally { |
| 2771 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2772 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2776 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2777 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2779 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | final Phone phone = getPhone(subId); |
| 2785 | if (phone != null) { |
| 2786 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2787 | } |
| 2788 | } finally { |
| 2789 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2790 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2794 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2797 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2798 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | final Phone phone = getPhone(subId); |
| 2803 | if (phone == null) { |
| 2804 | return false; |
| 2805 | } |
| 2806 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2807 | toggleRadioOnOffForSubscriber(subId); |
| 2808 | } |
| 2809 | return true; |
| 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2814 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2815 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2816 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2817 | /* |
| 2818 | * If any of the Radios are available, it will need to be |
| 2819 | * shutdown. So return true if any Radio is available. |
| 2820 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | final long identity = Binder.clearCallingIdentity(); |
| 2822 | try { |
| 2823 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2824 | Phone phone = PhoneFactory.getPhone(i); |
| 2825 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2826 | } |
| 2827 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2828 | return false; |
| 2829 | } finally { |
| 2830 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2831 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2835 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | enforceModifyPermission(); |
| 2837 | |
| 2838 | final long identity = Binder.clearCallingIdentity(); |
| 2839 | try { |
| 2840 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2841 | logv("Shutting down Phone " + i); |
| 2842 | shutdownRadioUsingPhoneId(i); |
| 2843 | } |
| 2844 | } finally { |
| 2845 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2850 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2851 | if (phone != null && phone.isRadioAvailable()) { |
| 2852 | phone.shutdownRadio(); |
| 2853 | } |
| 2854 | } |
| 2855 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2856 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2857 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | |
| 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
| 2861 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2862 | if (defaultPhone != null) { |
| 2863 | defaultPhone.setRadioPower(turnOn); |
| 2864 | return true; |
| 2865 | } else { |
| 2866 | loge("There's no default phone."); |
| 2867 | return false; |
| 2868 | } |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2871 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2874 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | |
| 2877 | final long identity = Binder.clearCallingIdentity(); |
| 2878 | try { |
| 2879 | final Phone phone = getPhone(subId); |
| 2880 | if (phone != null) { |
| 2881 | phone.setRadioPower(turnOn); |
| 2882 | return true; |
| 2883 | } else { |
| 2884 | return false; |
| 2885 | } |
| 2886 | } finally { |
| 2887 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2889 | } |
| 2890 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2891 | /** |
| 2892 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2893 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2894 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2895 | * powering it off, and these radio off votes will be cleared. |
| 2896 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2897 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2898 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2899 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2900 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2901 | * check its vote. |
| 2902 | * |
| 2903 | * @param subId The subscription ID. |
| 2904 | * @param reason The reason for powering off radio. |
| 2905 | * @return true on success and false on failure. |
| 2906 | */ |
| 2907 | public boolean requestRadioPowerOffForReason(int subId, |
| 2908 | @TelephonyManager.RadioPowerReason int reason) { |
| 2909 | enforceModifyPermission(); |
| 2910 | |
| 2911 | final long identity = Binder.clearCallingIdentity(); |
| 2912 | try { |
| 2913 | final Phone phone = getPhone(subId); |
| 2914 | if (phone != null) { |
| 2915 | phone.setRadioPowerForReason(false, reason); |
| 2916 | return true; |
| 2917 | } else { |
| 2918 | return false; |
| 2919 | } |
| 2920 | } finally { |
| 2921 | Binder.restoreCallingIdentity(identity); |
| 2922 | } |
| 2923 | } |
| 2924 | |
| 2925 | /** |
| 2926 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2927 | * {@link requestRadioPowerOffForReason}. |
| 2928 | * |
| 2929 | * @param subId The subscription ID. |
| 2930 | * @param reason The reason for powering off radio. |
| 2931 | * @return true on success and false on failure. |
| 2932 | */ |
| 2933 | public boolean clearRadioPowerOffForReason(int subId, |
| 2934 | @TelephonyManager.RadioPowerReason int reason) { |
| 2935 | enforceModifyPermission(); |
| 2936 | |
| 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | final Phone phone = getPhone(subId); |
| 2940 | if (phone != null) { |
| 2941 | phone.setRadioPowerForReason(true, reason); |
| 2942 | return true; |
| 2943 | } else { |
| 2944 | return false; |
| 2945 | } |
| 2946 | } finally { |
| 2947 | Binder.restoreCallingIdentity(identity); |
| 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | /** |
| 2952 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2953 | * |
| 2954 | * @param subId The subscription ID. |
| 2955 | * @param callingPackage The package making the call. |
| 2956 | * @param callingFeatureId The feature in the package. |
| 2957 | * @return List of reasons for powering off radio. |
| 2958 | */ |
| 2959 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 2960 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 2961 | |
| 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | List result = new ArrayList(); |
| 2964 | try { |
| 2965 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 2966 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 2967 | return result; |
| 2968 | } |
| 2969 | |
| 2970 | final Phone phone = getPhone(subId); |
| 2971 | if (phone != null) { |
| 2972 | result.addAll(phone.getRadioPowerOffReasons()); |
| 2973 | } |
| 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
| 2977 | return result; |
| 2978 | } |
| 2979 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2980 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2981 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2982 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2983 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2984 | |
| 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2988 | final Phone phone = getPhone(subId); |
| 2989 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 2990 | phone.getDataSettingsManager().setDataEnabled( |
| 2991 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | return true; |
| 2993 | } else { |
| 2994 | return false; |
| 2995 | } |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2998 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3001 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3002 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 3003 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 3009 | final Phone phone = getPhone(subId); |
| 3010 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3011 | phone.getDataSettingsManager().setDataEnabled( |
| 3012 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | return true; |
| 3014 | } else { |
| 3015 | return false; |
| 3016 | } |
| 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3019 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3020 | } |
| 3021 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3022 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 3023 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | final long identity = Binder.clearCallingIdentity(); |
| 3025 | try { |
| 3026 | final Phone phone = getPhone(subId); |
| 3027 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 3028 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | } else { |
| 3030 | return false; |
| 3031 | } |
| 3032 | } finally { |
| 3033 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3034 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3035 | } |
| 3036 | |
| 3037 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3038 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3039 | } |
| 3040 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3041 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3042 | enforceCallPermission(); |
| 3043 | |
| 3044 | final long identity = Binder.clearCallingIdentity(); |
| 3045 | try { |
| 3046 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3047 | return; |
| 3048 | } |
| 3049 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3050 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
| 3053 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3054 | }; |
| 3055 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3056 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3057 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | |
| 3059 | final long identity = Binder.clearCallingIdentity(); |
| 3060 | try { |
| 3061 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3062 | return false; |
| 3063 | } |
| 3064 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3065 | } finally { |
| 3066 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3067 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3070 | /** |
| 3071 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3072 | * tag on getCallState Binder call. |
| 3073 | */ |
| 3074 | @Deprecated |
| 3075 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3076 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3077 | if (CompatChanges.isChangeEnabled( |
| 3078 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3079 | Binder.getCallingUid())) { |
| 3080 | // Do not allow this API to be called on API version 31+, it should only be |
| 3081 | // called on old apps using this Binder call directly. |
| 3082 | throw new SecurityException("This method can only be used for applications " |
| 3083 | + "targeting API version 30 or less."); |
| 3084 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3087 | Phone phone = getPhone(getDefaultSubscription()); |
| 3088 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3089 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(identity); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | @Override |
| 3096 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3097 | if (CompatChanges.isChangeEnabled( |
| 3098 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3099 | Binder.getCallingUid())) { |
| 3100 | // Check READ_PHONE_STATE for API version 31+ |
| 3101 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3102 | featureId, "getCallStateForSubscription")) { |
| 3103 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3104 | + "targeting API level 31+."); |
| 3105 | } |
| 3106 | } |
| 3107 | final long identity = Binder.clearCallingIdentity(); |
| 3108 | try { |
| 3109 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3110 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3111 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3112 | } finally { |
| 3113 | Binder.restoreCallingIdentity(identity); |
| 3114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3117 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3118 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3119 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3120 | } |
| 3121 | |
| 3122 | @Override |
| 3123 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3126 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3127 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 3128 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3129 | } else { |
| 3130 | return PhoneConstantConversions.convertDataState( |
| 3131 | PhoneConstants.DataState.DISCONNECTED); |
| 3132 | } |
| 3133 | } finally { |
| 3134 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3135 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3138 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3139 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3140 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3141 | } |
| 3142 | |
| 3143 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3144 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3147 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3148 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3149 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | } else { |
| 3151 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3152 | } |
| 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3159 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3160 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3161 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3162 | |
| 3163 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3164 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3165 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3166 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3167 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3168 | .setCallingPid(Binder.getCallingPid()) |
| 3169 | .setCallingUid(Binder.getCallingUid()) |
| 3170 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3171 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3172 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3173 | .build()); |
| 3174 | switch (locationResult) { |
| 3175 | case DENIED_HARD: |
| 3176 | throw new SecurityException("Not allowed to access cell location"); |
| 3177 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3178 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3179 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3180 | } |
| 3181 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3182 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3183 | final long identity = Binder.clearCallingIdentity(); |
| 3184 | try { |
| 3185 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3186 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3187 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(identity); |
| 3190 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3193 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3194 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3195 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3196 | // registered cell info, so return a NULL country instead. |
| 3197 | final long identity = Binder.clearCallingIdentity(); |
| 3198 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3199 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3200 | // Get default phone in this case. |
| 3201 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3202 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3203 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3204 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3205 | if (phone == null) return ""; |
| 3206 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3207 | if (sst == null) return ""; |
| 3208 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3209 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3210 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
| 3213 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3216 | /** |
| 3217 | * This method was removed due to potential issues caused by performing partial |
| 3218 | * updates of service state, and lack of a credible use case. |
| 3219 | * |
| 3220 | * This has the ability to break the telephony implementation by disabling notification of |
| 3221 | * changes in device connectivity. DO NOT USE THIS! |
| 3222 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3223 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3224 | public void enableLocationUpdates() { |
| 3225 | mApp.enforceCallingOrSelfPermission( |
| 3226 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3229 | /** |
| 3230 | * This method was removed due to potential issues caused by performing partial |
| 3231 | * updates of service state, and lack of a credible use case. |
| 3232 | * |
| 3233 | * This has the ability to break the telephony implementation by disabling notification of |
| 3234 | * changes in device connectivity. DO NOT USE THIS! |
| 3235 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3236 | @Override |
| 3237 | public void disableLocationUpdates() { |
| 3238 | mApp.enforceCallingOrSelfPermission( |
| 3239 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | @Override |
| 3243 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3244 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3245 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3246 | try { |
| 3247 | mApp.getSystemService(AppOpsManager.class) |
| 3248 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3249 | } catch (SecurityException e) { |
| 3250 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3251 | throw e; |
| 3252 | } |
| 3253 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3254 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3255 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3256 | throw new SecurityException( |
| 3257 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3258 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3259 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3260 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3261 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3262 | return null; |
| 3263 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3264 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3265 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3266 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3267 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3268 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3269 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3270 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3271 | for (CellInfo ci : info) { |
| 3272 | if (ci instanceof CellInfoGsm) { |
| 3273 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3274 | } else if (ci instanceof CellInfoWcdma) { |
| 3275 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3276 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3277 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3278 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3281 | private List<CellInfo> getCachedCellInfo() { |
| 3282 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3283 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3284 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3285 | if (info != null) cellInfos.addAll(info); |
| 3286 | } |
| 3287 | return cellInfos; |
| 3288 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3289 | |
| 3290 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3291 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3292 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3293 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3294 | |
| 3295 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3296 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3297 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3298 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3299 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3300 | .setCallingPid(Binder.getCallingPid()) |
| 3301 | .setCallingUid(Binder.getCallingUid()) |
| 3302 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3303 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3304 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3305 | .build()); |
| 3306 | switch (locationResult) { |
| 3307 | case DENIED_HARD: |
| 3308 | throw new SecurityException("Not allowed to access cell info"); |
| 3309 | case DENIED_SOFT: |
| 3310 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3313 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3314 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3315 | return getCachedCellInfo(); |
| 3316 | } |
| 3317 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3318 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3319 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3320 | final long identity = Binder.clearCallingIdentity(); |
| 3321 | try { |
| 3322 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3323 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3324 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3325 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3326 | if (info != null) cellInfos.addAll(info); |
| 3327 | } |
| 3328 | return cellInfos; |
| 3329 | } finally { |
| 3330 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3331 | } |
| 3332 | } |
| 3333 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3334 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3335 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3336 | String callingFeatureId) { |
| 3337 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3338 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3342 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3343 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3344 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3345 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3348 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3349 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3350 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3351 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3352 | |
| 3353 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3354 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3355 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3356 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3357 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3358 | .setCallingPid(Binder.getCallingPid()) |
| 3359 | .setCallingUid(Binder.getCallingUid()) |
| 3360 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3361 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3362 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3363 | .build()); |
| 3364 | switch (locationResult) { |
| 3365 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3366 | if (TelephonyPermissions |
| 3367 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3368 | // Safetynet logging for b/154934934 |
| 3369 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3370 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3371 | throw new SecurityException("Not allowed to access cell info"); |
| 3372 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3373 | if (TelephonyPermissions |
| 3374 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3375 | // Safetynet logging for b/154934934 |
| 3376 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3377 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3378 | try { |
| 3379 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3380 | } catch (RemoteException re) { |
| 3381 | // Drop without consequences |
| 3382 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3383 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3386 | |
| 3387 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3388 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3389 | |
| 3390 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3391 | } |
| 3392 | |
| 3393 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3394 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3395 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3396 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3397 | |
| 3398 | final long identity = Binder.clearCallingIdentity(); |
| 3399 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3400 | Phone phone = getPhone(subId); |
| 3401 | if (phone == null) { |
| 3402 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3403 | } else { |
| 3404 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3405 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3406 | } finally { |
| 3407 | Binder.restoreCallingIdentity(identity); |
| 3408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3409 | } |
| 3410 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3411 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3412 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3413 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3414 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3415 | return null; |
| 3416 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3417 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3418 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3419 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3420 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3421 | return null; |
| 3422 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3423 | |
| 3424 | final long identity = Binder.clearCallingIdentity(); |
| 3425 | try { |
| 3426 | return phone.getImei(); |
| 3427 | } finally { |
| 3428 | Binder.restoreCallingIdentity(identity); |
| 3429 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3433 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3434 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3435 | String tac = null; |
| 3436 | if (phone != null) { |
| 3437 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3438 | try { |
| 3439 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3440 | } catch (IndexOutOfBoundsException e) { |
| 3441 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3442 | return null; |
| 3443 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3444 | } |
| 3445 | return tac; |
| 3446 | } |
| 3447 | |
| 3448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3449 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3450 | try { |
| 3451 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3452 | } catch (SecurityException se) { |
| 3453 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3454 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3455 | + Binder.getCallingUid()); |
| 3456 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3457 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3458 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3459 | return null; |
| 3460 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3461 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3462 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3463 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3464 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3465 | return null; |
| 3466 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3467 | |
| 3468 | final long identity = Binder.clearCallingIdentity(); |
| 3469 | try { |
| 3470 | return phone.getMeid(); |
| 3471 | } finally { |
| 3472 | Binder.restoreCallingIdentity(identity); |
| 3473 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3477 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3478 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3479 | String manufacturerCode = null; |
| 3480 | if (phone != null) { |
| 3481 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3482 | try { |
| 3483 | manufacturerCode = |
| 3484 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3485 | } catch (IndexOutOfBoundsException e) { |
| 3486 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3487 | return null; |
| 3488 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3489 | } |
| 3490 | return manufacturerCode; |
| 3491 | } |
| 3492 | |
| 3493 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3494 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3495 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3496 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3497 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3498 | return null; |
| 3499 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3500 | int subId = phone.getSubId(); |
| 3501 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3502 | mApp, subId, callingPackage, callingFeatureId, |
| 3503 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3504 | return null; |
| 3505 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3506 | |
| 3507 | final long identity = Binder.clearCallingIdentity(); |
| 3508 | try { |
| 3509 | return phone.getDeviceSvn(); |
| 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
| 3512 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3515 | @Override |
| 3516 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | final long identity = Binder.clearCallingIdentity(); |
| 3518 | try { |
| 3519 | final Phone phone = getPhone(subId); |
| 3520 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
| 3523 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | @Override |
| 3527 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3528 | final long identity = Binder.clearCallingIdentity(); |
| 3529 | try { |
| 3530 | final Phone phone = getPhone(subId); |
| 3531 | return phone == null ? null : phone.getCarrierName(); |
| 3532 | } finally { |
| 3533 | Binder.restoreCallingIdentity(identity); |
| 3534 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3537 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3538 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | final Phone phone = getPhone(subId); |
| 3542 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3543 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3550 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3554 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3555 | } finally { |
| 3556 | Binder.restoreCallingIdentity(identity); |
| 3557 | } |
| 3558 | } |
| 3559 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3560 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3561 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3562 | if (!isSubscriptionMccMnc) { |
| 3563 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3564 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3565 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3566 | if (phone == null) { |
| 3567 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3568 | } |
| 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3572 | } finally { |
| 3573 | Binder.restoreCallingIdentity(identity); |
| 3574 | } |
| 3575 | } |
| 3576 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3577 | // |
| 3578 | // Internal helper methods. |
| 3579 | // |
| 3580 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3581 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3582 | * Make sure the caller is the calling package itself |
| 3583 | * |
| 3584 | * @throws SecurityException if the caller is not the calling package |
| 3585 | */ |
| 3586 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3587 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3588 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3589 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3590 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3591 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3592 | } catch (PackageManager.NameNotFoundException e) { |
| 3593 | // packageUid is -1 |
| 3594 | } |
| 3595 | if (packageUid != callingUid) { |
| 3596 | throw new SecurityException(message + ": Package " + callingPackage |
| 3597 | + " does not belong to " + callingUid); |
| 3598 | } |
| 3599 | } |
| 3600 | |
| 3601 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3602 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3603 | * |
| 3604 | * @throws SecurityException if the caller does not have the required permission |
| 3605 | */ |
| 3606 | private void enforceModifyPermission() { |
| 3607 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3608 | } |
| 3609 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3610 | private void enforceActiveEmergencySessionPermission() { |
| 3611 | mApp.enforceCallingOrSelfPermission( |
| 3612 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3613 | } |
| 3614 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3615 | /** |
| 3616 | * Make sure the caller has the CALL_PHONE permission. |
| 3617 | * |
| 3618 | * @throws SecurityException if the caller does not have the required permission |
| 3619 | */ |
| 3620 | private void enforceCallPermission() { |
| 3621 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3622 | } |
| 3623 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3624 | private void enforceSettingsPermission() { |
| 3625 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3628 | private void enforceRebootPermission() { |
| 3629 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3630 | } |
| 3631 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3632 | private String createTelUrl(String number) { |
| 3633 | if (TextUtils.isEmpty(number)) { |
| 3634 | return null; |
| 3635 | } |
| 3636 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3637 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3640 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3641 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3642 | } |
| 3643 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3644 | private static void logv(String msg) { |
| 3645 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3646 | } |
| 3647 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3648 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3649 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3650 | } |
| 3651 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3652 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3653 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3654 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3655 | } |
| 3656 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3657 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3658 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
| 3661 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3662 | if (phone == null) { |
| 3663 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3664 | } else { |
| 3665 | return phone.getPhoneType(); |
| 3666 | } |
| 3667 | } finally { |
| 3668 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * Returns the CDMA ERI icon index to display |
| 3674 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3675 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3676 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3677 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3678 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3679 | } |
| 3680 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3681 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3682 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3683 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3685 | mApp, subId, callingPackage, callingFeatureId, |
| 3686 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3687 | return -1; |
| 3688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3689 | |
| 3690 | final long identity = Binder.clearCallingIdentity(); |
| 3691 | try { |
| 3692 | final Phone phone = getPhone(subId); |
| 3693 | if (phone != null) { |
| 3694 | return phone.getCdmaEriIconIndex(); |
| 3695 | } else { |
| 3696 | return -1; |
| 3697 | } |
| 3698 | } finally { |
| 3699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3700 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | /** |
| 3704 | * Returns the CDMA ERI icon mode, |
| 3705 | * 0 - ON |
| 3706 | * 1 - FLASHING |
| 3707 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3708 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3709 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3710 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3711 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3712 | } |
| 3713 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3714 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3715 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3716 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3718 | mApp, subId, callingPackage, callingFeatureId, |
| 3719 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3720 | return -1; |
| 3721 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | |
| 3723 | final long identity = Binder.clearCallingIdentity(); |
| 3724 | try { |
| 3725 | final Phone phone = getPhone(subId); |
| 3726 | if (phone != null) { |
| 3727 | return phone.getCdmaEriIconMode(); |
| 3728 | } else { |
| 3729 | return -1; |
| 3730 | } |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3733 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3734 | } |
| 3735 | |
| 3736 | /** |
| 3737 | * Returns the CDMA ERI text, |
| 3738 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3740 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3741 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3742 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3745 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3746 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3747 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3748 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3749 | mApp, subId, callingPackage, callingFeatureId, |
| 3750 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3751 | return null; |
| 3752 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | |
| 3754 | final long identity = Binder.clearCallingIdentity(); |
| 3755 | try { |
| 3756 | final Phone phone = getPhone(subId); |
| 3757 | if (phone != null) { |
| 3758 | return phone.getCdmaEriText(); |
| 3759 | } else { |
| 3760 | return null; |
| 3761 | } |
| 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3768 | * Returns the CDMA MDN. |
| 3769 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3770 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3771 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3773 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3774 | |
| 3775 | final long identity = Binder.clearCallingIdentity(); |
| 3776 | try { |
| 3777 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3778 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3779 | return phone.getLine1Number(); |
| 3780 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3781 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3782 | return null; |
| 3783 | } |
| 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3786 | } |
| 3787 | } |
| 3788 | |
| 3789 | /** |
| 3790 | * Returns the CDMA MIN. |
| 3791 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3792 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3793 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3795 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | |
| 3797 | final long identity = Binder.clearCallingIdentity(); |
| 3798 | try { |
| 3799 | final Phone phone = getPhone(subId); |
| 3800 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3801 | return phone.getCdmaMin(); |
| 3802 | } else { |
| 3803 | return null; |
| 3804 | } |
| 3805 | } finally { |
| 3806 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3807 | } |
| 3808 | } |
| 3809 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3810 | @Override |
| 3811 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3812 | INumberVerificationCallback callback, String callingPackage) { |
| 3813 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3814 | != PERMISSION_GRANTED) { |
| 3815 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3816 | } |
| 3817 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3818 | |
| 3819 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3820 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3821 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3822 | + "calling package: " + callingPackage |
| 3823 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | if (range == null) { |
| 3827 | throw new NullPointerException("Range must be non-null"); |
| 3828 | } |
| 3829 | |
| 3830 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3831 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3832 | |
| 3833 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3834 | } |
| 3835 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3836 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3837 | * Returns true if CDMA provisioning needs to run. |
| 3838 | */ |
| 3839 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3840 | final long identity = Binder.clearCallingIdentity(); |
| 3841 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3842 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(identity); |
| 3845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3849 | * Sets the voice mail number of a given subId. |
| 3850 | */ |
| 3851 | @Override |
| 3852 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3853 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3854 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3855 | |
| 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3859 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3860 | return success; |
| 3861 | } finally { |
| 3862 | Binder.restoreCallingIdentity(identity); |
| 3863 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3864 | } |
| 3865 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3866 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3867 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3868 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3869 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3870 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3871 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3872 | throw new SecurityException("caller must be system dialer"); |
| 3873 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | |
| 3875 | final long identity = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3878 | if (phoneAccountHandle == null) { |
| 3879 | return null; |
| 3880 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3881 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3884 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3888 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3889 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3890 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3891 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3892 | mApp, subId, callingPackage, callingFeatureId, |
| 3893 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3894 | return null; |
| 3895 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3899 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3900 | } finally { |
| 3901 | Binder.restoreCallingIdentity(identity); |
| 3902 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3906 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3907 | VisualVoicemailSmsFilterSettings settings) { |
| 3908 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3909 | |
| 3910 | final long identity = Binder.clearCallingIdentity(); |
| 3911 | try { |
| 3912 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3913 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3914 | } finally { |
| 3915 | Binder.restoreCallingIdentity(identity); |
| 3916 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3920 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3921 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3922 | |
| 3923 | final long identity = Binder.clearCallingIdentity(); |
| 3924 | try { |
| 3925 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3926 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | } finally { |
| 3928 | Binder.restoreCallingIdentity(identity); |
| 3929 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3933 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3934 | String callingPackage, int subId) { |
| 3935 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3936 | |
| 3937 | final long identity = Binder.clearCallingIdentity(); |
| 3938 | try { |
| 3939 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3940 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3941 | } finally { |
| 3942 | Binder.restoreCallingIdentity(identity); |
| 3943 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3947 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3949 | |
| 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
| 3952 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3953 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3954 | } finally { |
| 3955 | Binder.restoreCallingIdentity(identity); |
| 3956 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3960 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3961 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3962 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3963 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3964 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3965 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3966 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3967 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3968 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3969 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3970 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3971 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3972 | * Sets the voice activation state of a given subId. |
| 3973 | */ |
| 3974 | @Override |
| 3975 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3977 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3978 | |
| 3979 | final long identity = Binder.clearCallingIdentity(); |
| 3980 | try { |
| 3981 | final Phone phone = getPhone(subId); |
| 3982 | if (phone != null) { |
| 3983 | phone.setVoiceActivationState(activationState); |
| 3984 | } else { |
| 3985 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3986 | } |
| 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | /** |
| 3993 | * Sets the data activation state of a given subId. |
| 3994 | */ |
| 3995 | @Override |
| 3996 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3998 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3999 | |
| 4000 | final long identity = Binder.clearCallingIdentity(); |
| 4001 | try { |
| 4002 | final Phone phone = getPhone(subId); |
| 4003 | if (phone != null) { |
| 4004 | phone.setDataActivationState(activationState); |
| 4005 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 4006 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4007 | } |
| 4008 | } finally { |
| 4009 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4010 | } |
| 4011 | } |
| 4012 | |
| 4013 | /** |
| 4014 | * Returns the voice activation state of a given subId. |
| 4015 | */ |
| 4016 | @Override |
| 4017 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4019 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4020 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | if (phone != null) { |
| 4024 | return phone.getVoiceActivationState(); |
| 4025 | } else { |
| 4026 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4027 | } |
| 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4030 | } |
| 4031 | } |
| 4032 | |
| 4033 | /** |
| 4034 | * Returns the data activation state of a given subId. |
| 4035 | */ |
| 4036 | @Override |
| 4037 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4038 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4039 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4040 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4041 | final long identity = Binder.clearCallingIdentity(); |
| 4042 | try { |
| 4043 | if (phone != null) { |
| 4044 | return phone.getDataActivationState(); |
| 4045 | } else { |
| 4046 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4047 | } |
| 4048 | } finally { |
| 4049 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4050 | } |
| 4051 | } |
| 4052 | |
| 4053 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4054 | * Returns the unread count of voicemails for a subId |
| 4055 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4056 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4057 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4058 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4059 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4060 | mApp, subId, callingPackage, callingFeatureId, |
| 4061 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4062 | return 0; |
| 4063 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4064 | final long identity = Binder.clearCallingIdentity(); |
| 4065 | try { |
| 4066 | final Phone phone = getPhone(subId); |
| 4067 | if (phone != null) { |
| 4068 | return phone.getVoiceMessageCount(); |
| 4069 | } else { |
| 4070 | return 0; |
| 4071 | } |
| 4072 | } finally { |
| 4073 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4074 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4078 | * returns true, if the device is in a state where both voice and data |
| 4079 | * are supported simultaneously. This can change based on location or network condition. |
| 4080 | */ |
| 4081 | @Override |
| 4082 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | final Phone phone = getPhone(subId); |
| 4086 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4093 | * Send the dialer code if called from the current default dialer or the caller has |
| 4094 | * carrier privilege. |
| 4095 | * @param inputCode The dialer code to send |
| 4096 | */ |
| 4097 | @Override |
| 4098 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4099 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4100 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4101 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4102 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4103 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4104 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4105 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4106 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4107 | |
| 4108 | final long identity = Binder.clearCallingIdentity(); |
| 4109 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4110 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | } finally { |
| 4112 | Binder.restoreCallingIdentity(identity); |
| 4113 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4114 | } |
| 4115 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4116 | @Override |
| 4117 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4118 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4119 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4120 | mApp, subId, "getNetworkSelectionMode"); |
| 4121 | final long identity = Binder.clearCallingIdentity(); |
| 4122 | try { |
| 4123 | if (!isActiveSubscription(subId)) { |
| 4124 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4125 | } |
| 4126 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4129 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4133 | public boolean isInEmergencySmsMode() { |
| 4134 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4135 | final long identity = Binder.clearCallingIdentity(); |
| 4136 | try { |
| 4137 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4138 | if (phone.isInEmergencySmsMode()) { |
| 4139 | return true; |
| 4140 | } |
| 4141 | } |
| 4142 | } finally { |
| 4143 | Binder.restoreCallingIdentity(identity); |
| 4144 | } |
| 4145 | return false; |
| 4146 | } |
| 4147 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4148 | /** |
| 4149 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4150 | * @param subId The subscription to use to check the configuration. |
| 4151 | * @param c The callback that will be used to send the result. |
| 4152 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4153 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4154 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4155 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4156 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4157 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4158 | |
| 4159 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4160 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4161 | "IMS not available on device."); |
| 4162 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4163 | final long token = Binder.clearCallingIdentity(); |
| 4164 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4165 | int slotId = getSlotIndexOrException(subId); |
| 4166 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4167 | |
| 4168 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4169 | if (controller != null) { |
| 4170 | ImsManager imsManager = controller.getImsManager(subId); |
| 4171 | if (imsManager != null) { |
| 4172 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4173 | } else { |
| 4174 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4175 | } |
| 4176 | } else { |
| 4177 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4178 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4179 | } catch (ImsException e) { |
| 4180 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(token); |
| 4183 | } |
| 4184 | } |
| 4185 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4186 | /** |
| 4187 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4188 | * @param subId The subscription to use to check the configuration. |
| 4189 | * @param c The callback that will be used to send the result. |
| 4190 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4192 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4193 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4194 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4195 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4196 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4197 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4198 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4199 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4200 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4201 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4202 | if (controller != null) { |
| 4203 | ImsManager imsManager = controller.getImsManager(subId); |
| 4204 | if (imsManager != null) { |
| 4205 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4206 | } else { |
| 4207 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4208 | + "is inactive, ignoring unregister."); |
| 4209 | // If the ImsManager is not valid, just return, since the callback |
| 4210 | // will already have been removed internally. |
| 4211 | } |
| 4212 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(token); |
| 4215 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4218 | /** |
| 4219 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4220 | */ |
| 4221 | @Override |
| 4222 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4223 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4224 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4225 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4226 | "IMS not available on device."); |
| 4227 | } |
| 4228 | final long token = Binder.clearCallingIdentity(); |
| 4229 | try { |
| 4230 | Phone phone = getPhone(subId); |
| 4231 | if (phone == null) { |
| 4232 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4233 | + subId + "'"); |
| 4234 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4235 | } |
| 4236 | phone.getImsRegistrationState(regState -> { |
| 4237 | try { |
| 4238 | consumer.accept((regState == null) |
| 4239 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4240 | } catch (RemoteException e) { |
| 4241 | // Ignore if the remote process is no longer available to call back. |
| 4242 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4243 | } |
| 4244 | }); |
| 4245 | } finally { |
| 4246 | Binder.restoreCallingIdentity(token); |
| 4247 | } |
| 4248 | } |
| 4249 | |
| 4250 | /** |
| 4251 | * Get the transport type for the IMS service registration state. |
| 4252 | */ |
| 4253 | @Override |
| 4254 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4255 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4256 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4257 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4258 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4259 | "IMS not available on device."); |
| 4260 | } |
| 4261 | final long token = Binder.clearCallingIdentity(); |
| 4262 | try { |
| 4263 | Phone phone = getPhone(subId); |
| 4264 | if (phone == null) { |
| 4265 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4266 | + subId + "'"); |
| 4267 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4268 | } |
| 4269 | phone.getImsRegistrationTech(regTech -> { |
| 4270 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4271 | int regTechConverted = (regTech == null) |
| 4272 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4273 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4274 | regTechConverted); |
| 4275 | try { |
| 4276 | consumer.accept(regTechConverted); |
| 4277 | } catch (RemoteException e) { |
| 4278 | // Ignore if the remote process is no longer available to call back. |
| 4279 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4280 | } |
| 4281 | }); |
| 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(token); |
| 4284 | } |
| 4285 | } |
| 4286 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4287 | /** |
| 4288 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4289 | * @param subId The subscription to use to check the configuration. |
| 4290 | * @param c The callback that will be used to send the result. |
| 4291 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4292 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4293 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4294 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4295 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4296 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4297 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4298 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4299 | "IMS not available on device."); |
| 4300 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4301 | final long token = Binder.clearCallingIdentity(); |
| 4302 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4303 | int slotId = getSlotIndexOrException(subId); |
| 4304 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4305 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4306 | } catch (ImsException e) { |
| 4307 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4308 | } finally { |
| 4309 | Binder.restoreCallingIdentity(token); |
| 4310 | } |
| 4311 | } |
| 4312 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4313 | /** |
| 4314 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4315 | * @param subId The subscription to use to check the configuration. |
| 4316 | * @param c The callback that will be used to send the result. |
| 4317 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4318 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4319 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4320 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4321 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4322 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4323 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4324 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4325 | |
| 4326 | final long token = Binder.clearCallingIdentity(); |
| 4327 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4328 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4329 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4330 | } catch (ImsException e) { |
| 4331 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4332 | + "is inactive, ignoring unregister."); |
| 4333 | // If the subscription is no longer active, just return, since the callback |
| 4334 | // will already have been removed internally. |
| 4335 | } finally { |
| 4336 | Binder.restoreCallingIdentity(token); |
| 4337 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4338 | } |
| 4339 | |
| 4340 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4341 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4342 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4343 | final long token = Binder.clearCallingIdentity(); |
| 4344 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4345 | int slotId = getSlotIndexOrException(subId); |
| 4346 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4347 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4348 | } catch (com.android.ims.ImsException e) { |
| 4349 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4350 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4351 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4352 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4353 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4354 | } finally { |
| 4355 | Binder.restoreCallingIdentity(token); |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4360 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4361 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4362 | final long token = Binder.clearCallingIdentity(); |
| 4363 | try { |
| 4364 | Phone phone = getPhone(subId); |
| 4365 | if (phone == null) return false; |
| 4366 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4367 | } catch (com.android.ims.ImsException e) { |
| 4368 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4369 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4370 | } finally { |
| 4371 | Binder.restoreCallingIdentity(token); |
| 4372 | } |
| 4373 | } |
| 4374 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4375 | /** |
| 4376 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4377 | * subscription. |
| 4378 | * @param subId The subscription to use to check the configuration. |
| 4379 | * @param callback The callback that will be used to send the result. |
| 4380 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4381 | * @param transportType The transport type of the MmTelFeature capability. |
| 4382 | */ |
| 4383 | @Override |
| 4384 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4385 | int transportType) { |
| 4386 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4387 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4388 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4389 | "IMS not available on device."); |
| 4390 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4391 | final long token = Binder.clearCallingIdentity(); |
| 4392 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4393 | int slotId = getSlotIndex(subId); |
| 4394 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4395 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4396 | + subId + "'"); |
| 4397 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4398 | } |
| 4399 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4400 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4401 | transportType, aBoolean -> { |
| 4402 | try { |
| 4403 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4404 | } catch (RemoteException e) { |
| 4405 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4406 | + "running. Ignore"); |
| 4407 | } |
| 4408 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4409 | } catch (ImsException e) { |
| 4410 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(token); |
| 4413 | } |
| 4414 | } |
| 4415 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4416 | /** |
| 4417 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4418 | * @param subId The subscription to use to check the configuration. |
| 4419 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4420 | @Override |
| 4421 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4422 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4423 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4424 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4425 | final long token = Binder.clearCallingIdentity(); |
| 4426 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4427 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4428 | // 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] | 4429 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4430 | } catch (ImsException e) { |
| 4431 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4432 | } finally { |
| 4433 | Binder.restoreCallingIdentity(token); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4438 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4440 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4441 | final long identity = Binder.clearCallingIdentity(); |
| 4442 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4443 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4444 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4445 | // 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] | 4446 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4447 | } catch (ImsException e) { |
| 4448 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
| 4451 | } |
| 4452 | } |
| 4453 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4454 | /** |
| 4455 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4456 | * @param subId The subscription to use to check the configuration. |
| 4457 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4458 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4459 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4460 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4461 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4462 | final long identity = Binder.clearCallingIdentity(); |
| 4463 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4464 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4465 | // 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] | 4466 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4467 | } catch (ImsException e) { |
| 4468 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4475 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4476 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4477 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4480 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4481 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4482 | // 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] | 4483 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4484 | } catch (ImsException e) { |
| 4485 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4486 | } finally { |
| 4487 | Binder.restoreCallingIdentity(identity); |
| 4488 | } |
| 4489 | } |
| 4490 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4491 | /** |
| 4492 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4493 | * @param subId The subscription to use to check the configuration. |
| 4494 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4495 | @Override |
| 4496 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4497 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4498 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4499 | final long identity = Binder.clearCallingIdentity(); |
| 4500 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4501 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4502 | // 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] | 4503 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4504 | } catch (ImsException e) { |
| 4505 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4512 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4514 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4515 | final long identity = Binder.clearCallingIdentity(); |
| 4516 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4517 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4518 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4519 | // 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] | 4520 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4521 | } catch (ImsException e) { |
| 4522 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4523 | } finally { |
| 4524 | Binder.restoreCallingIdentity(identity); |
| 4525 | } |
| 4526 | } |
| 4527 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4528 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4529 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4530 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4531 | * @param subId The subscription to use to check the configuration. |
| 4532 | */ |
| 4533 | @Override |
| 4534 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4535 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4536 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4539 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4540 | // 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] | 4541 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4542 | } catch (ImsException e) { |
| 4543 | throw new ServiceSpecificException(e.getCode()); |
| 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(identity); |
| 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | /** |
| 4550 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4551 | * Requires MODIFY_PHONE_STATE permission. |
| 4552 | * @param subId The subscription to use to check the configuration. |
| 4553 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4554 | * false otherwise |
| 4555 | */ |
| 4556 | @Override |
| 4557 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4559 | "setCrossSimCallingEnabled"); |
| 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. The |
| 4564 | // 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] | 4565 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4566 | } catch (ImsException e) { |
| 4567 | throw new ServiceSpecificException(e.getCode()); |
| 4568 | } finally { |
| 4569 | Binder.restoreCallingIdentity(identity); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4574 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4575 | * @param subId The subscription to use to check the configuration. |
| 4576 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4577 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4578 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4579 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4580 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4581 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | final long identity = Binder.clearCallingIdentity(); |
| 4583 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4584 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4585 | // 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] | 4586 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4587 | } catch (ImsException e) { |
| 4588 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4589 | } finally { |
| 4590 | Binder.restoreCallingIdentity(identity); |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4595 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4597 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4598 | final long identity = Binder.clearCallingIdentity(); |
| 4599 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4600 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4601 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4602 | // 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] | 4603 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4604 | } catch (ImsException e) { |
| 4605 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4606 | } finally { |
| 4607 | Binder.restoreCallingIdentity(identity); |
| 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | @Override |
| 4612 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4614 | "setVoWiFiNonPersistent"); |
| 4615 | final long identity = Binder.clearCallingIdentity(); |
| 4616 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4617 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4618 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4619 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4620 | } catch (ImsException e) { |
| 4621 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
| 4624 | } |
| 4625 | } |
| 4626 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4627 | /** |
| 4628 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4629 | * @param subId The subscription to use to check the configuration. |
| 4630 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | @Override |
| 4632 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4633 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4634 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4635 | final long identity = Binder.clearCallingIdentity(); |
| 4636 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4637 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4638 | // 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] | 4639 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4640 | } catch (ImsException e) { |
| 4641 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4642 | } finally { |
| 4643 | Binder.restoreCallingIdentity(identity); |
| 4644 | } |
| 4645 | } |
| 4646 | |
| 4647 | @Override |
| 4648 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4649 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4650 | "setVoWiFiModeSetting"); |
| 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4653 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4654 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4655 | // 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] | 4656 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4657 | } catch (ImsException e) { |
| 4658 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
| 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | @Override |
| 4665 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4666 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4667 | final long identity = Binder.clearCallingIdentity(); |
| 4668 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4669 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4670 | // 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] | 4671 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4672 | } catch (ImsException e) { |
| 4673 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
| 4676 | } |
| 4677 | } |
| 4678 | |
| 4679 | @Override |
| 4680 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4681 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4682 | "setVoWiFiRoamingModeSetting"); |
| 4683 | final long identity = Binder.clearCallingIdentity(); |
| 4684 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4685 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4686 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4687 | // 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] | 4688 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4689 | } catch (ImsException e) { |
| 4690 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
| 4694 | } |
| 4695 | |
| 4696 | @Override |
| 4697 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4699 | "setRttCapabilityEnabled"); |
| 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4702 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4703 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4704 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4705 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4706 | } catch (ImsException e) { |
| 4707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4708 | } finally { |
| 4709 | Binder.restoreCallingIdentity(identity); |
| 4710 | } |
| 4711 | } |
| 4712 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4713 | /** |
| 4714 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4715 | * @param subId The subscription to use to check the configuration. |
| 4716 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4717 | @Override |
| 4718 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4719 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4720 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4723 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4724 | // 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] | 4725 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4726 | } catch (ImsException e) { |
| 4727 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4728 | } finally { |
| 4729 | Binder.restoreCallingIdentity(identity); |
| 4730 | } |
| 4731 | } |
| 4732 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4733 | @Override |
| 4734 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4735 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4736 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4737 | final long identity = Binder.clearCallingIdentity(); |
| 4738 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4739 | if (!isImsAvailableOnDevice()) { |
| 4740 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4741 | "IMS not available on device."); |
| 4742 | } |
| 4743 | int slotId = getSlotIndexOrException(subId); |
| 4744 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4745 | ImsManager.getInstance(mApp, slotId) |
| 4746 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4747 | } catch (ImsException e) { |
| 4748 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | @Override |
| 4755 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4756 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4757 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4758 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4759 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4760 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4761 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4762 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4763 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4764 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4765 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4766 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4767 | + "is inactive, ignoring unregister."); |
| 4768 | // If the subscription is no longer active, just return, since the callback will already |
| 4769 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4770 | } finally { |
| 4771 | Binder.restoreCallingIdentity(identity); |
| 4772 | } |
| 4773 | } |
| 4774 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4775 | @Override |
| 4776 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4777 | IFeatureProvisioningCallback callback) { |
| 4778 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4779 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4780 | |
| 4781 | final long identity = Binder.clearCallingIdentity(); |
| 4782 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4783 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4784 | } |
| 4785 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4786 | try { |
| 4787 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4788 | if (controller == null) { |
| 4789 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4790 | "Device does not support IMS"); |
| 4791 | } |
| 4792 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
| 4795 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | @Override |
| 4799 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4800 | IFeatureProvisioningCallback callback) { |
| 4801 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4802 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 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 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4813 | return; |
| 4814 | } |
| 4815 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4816 | } finally { |
| 4817 | Binder.restoreCallingIdentity(identity); |
| 4818 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4819 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4820 | |
| 4821 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4823 | message); |
| 4824 | } |
| 4825 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4826 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4827 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4828 | boolean isProvisioned) { |
| 4829 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4830 | |
| 4831 | final long identity = Binder.clearCallingIdentity(); |
| 4832 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4833 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4834 | if (controller == null) { |
| 4835 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4836 | return; |
| 4837 | } |
| 4838 | controller.setRcsProvisioningStatusForCapability( |
| 4839 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4840 | } finally { |
| 4841 | Binder.restoreCallingIdentity(identity); |
| 4842 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | |
| 4846 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4847 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4848 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4849 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4850 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4853 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4854 | if (controller == null) { |
| 4855 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4856 | |
| 4857 | // device does not support IMS, this method will return true always. |
| 4858 | return true; |
| 4859 | } |
| 4860 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
| 4863 | } |
| 4864 | } |
| 4865 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4866 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4867 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4868 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4869 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4870 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4873 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4874 | if (controller == null) { |
| 4875 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4876 | return; |
| 4877 | } |
| 4878 | controller.setImsProvisioningStatusForCapability( |
| 4879 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
| 4882 | } |
| 4883 | } |
| 4884 | |
| 4885 | @Override |
| 4886 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4887 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4888 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4889 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4892 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4893 | if (controller == null) { |
| 4894 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4895 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4896 | // device does not support IMS, this method will return true always. |
| 4897 | return true; |
| 4898 | } |
| 4899 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
| 4902 | } |
| 4903 | } |
| 4904 | |
| 4905 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4906 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4907 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4908 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4909 | |
| 4910 | final long identity = Binder.clearCallingIdentity(); |
| 4911 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4912 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4913 | if (controller == null) { |
| 4914 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4915 | |
| 4916 | // device does not support IMS, this method will return false |
| 4917 | return false; |
| 4918 | } |
| 4919 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4922 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4926 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4927 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4928 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4929 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4930 | final long identity = Binder.clearCallingIdentity(); |
| 4931 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4932 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4933 | if (controller == null) { |
| 4934 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4935 | |
| 4936 | // device does not support IMS, this method will return false |
| 4937 | return false; |
| 4938 | } |
| 4939 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4940 | } finally { |
| 4941 | Binder.restoreCallingIdentity(identity); |
| 4942 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4943 | } |
| 4944 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4945 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4946 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4947 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4948 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4949 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4950 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4951 | mApp, subId, "getImsProvisioningInt"); |
| 4952 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4953 | final long identity = Binder.clearCallingIdentity(); |
| 4954 | try { |
| 4955 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4956 | int slotId = getSlotIndex(subId); |
| 4957 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4958 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4959 | + subId + "' for key:" + key); |
| 4960 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4961 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4962 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4963 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4964 | if (controller == null) { |
| 4965 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4966 | |
| 4967 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4968 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4969 | } |
| 4970 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4971 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4972 | return retVal; |
| 4973 | } |
| 4974 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4975 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4976 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4977 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4978 | + subId + "' for key:" + key); |
| 4979 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(identity); |
| 4982 | } |
| 4983 | } |
| 4984 | |
| 4985 | @Override |
| 4986 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4987 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4988 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4989 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4990 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4991 | mApp, subId, "getImsProvisioningString"); |
| 4992 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4993 | final long identity = Binder.clearCallingIdentity(); |
| 4994 | try { |
| 4995 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4996 | int slotId = getSlotIndex(subId); |
| 4997 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4998 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4999 | + subId + "' for key:" + key); |
| 5000 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 5001 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5002 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5003 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5004 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 5005 | + subId + "' for key:" + key); |
| 5006 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5007 | } finally { |
| 5008 | Binder.restoreCallingIdentity(identity); |
| 5009 | } |
| 5010 | } |
| 5011 | |
| 5012 | @Override |
| 5013 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5014 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5015 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5016 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5017 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5018 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5019 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5020 | final long identity = Binder.clearCallingIdentity(); |
| 5021 | try { |
| 5022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5023 | int slotId = getSlotIndex(subId); |
| 5024 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5025 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 5026 | + subId + "' for key:" + key); |
| 5027 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5028 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5029 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 5030 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 5031 | if (controller == null) { |
| 5032 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 5033 | |
| 5034 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 5035 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5036 | } |
| 5037 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5038 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5039 | return retVal; |
| 5040 | } |
| 5041 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5042 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5043 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5044 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5045 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5046 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | @Override |
| 5053 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5054 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5055 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5056 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5057 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5058 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
| 5061 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5062 | int slotId = getSlotIndex(subId); |
| 5063 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5064 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5065 | + subId + "' for key:" + key); |
| 5066 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5067 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5068 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5069 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5070 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5071 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5072 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5073 | } finally { |
| 5074 | Binder.restoreCallingIdentity(identity); |
| 5075 | } |
| 5076 | } |
| 5077 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5078 | /** |
| 5079 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5080 | * for the given slot ID or no ImsResolver instance has been created. |
| 5081 | * @param slotId The slot ID that the IMS service is created for. |
| 5082 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5083 | */ |
| 5084 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5085 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5086 | ImsFeature.FEATURE_MMTEL)) { |
| 5087 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5088 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5089 | } |
| 5090 | } |
| 5091 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5092 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5093 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5094 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5095 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5096 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5097 | } |
| 5098 | return slotId; |
| 5099 | } |
| 5100 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5101 | private int getSlotIndex(int subId) { |
| 5102 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5103 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5104 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5105 | } |
| 5106 | return slotId; |
| 5107 | } |
| 5108 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5109 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5110 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5111 | */ |
| 5112 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5113 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5114 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5115 | try { |
| 5116 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5117 | } catch (SecurityException se) { |
| 5118 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5119 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5120 | + Binder.getCallingUid()); |
| 5121 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5122 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5123 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5124 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5125 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5126 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5127 | mApp, subId, callingPackage, callingFeatureId, |
| 5128 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5129 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5130 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5131 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
| 5134 | final Phone phone = getPhone(subId); |
| 5135 | if (phone != null) { |
| 5136 | return phone.getServiceState().getDataNetworkType(); |
| 5137 | } else { |
| 5138 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5139 | } |
| 5140 | } finally { |
| 5141 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5142 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5143 | } |
| 5144 | |
| 5145 | /** |
| 5146 | * Returns the data network type |
| 5147 | */ |
| 5148 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5149 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5150 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5151 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | /** |
| 5155 | * Returns the data network type for a subId |
| 5156 | */ |
| 5157 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5158 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5159 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5160 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5161 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5162 | mApp, functionName)) { |
| 5163 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5164 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5165 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5166 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5169 | final long identity = Binder.clearCallingIdentity(); |
| 5170 | try { |
| 5171 | final Phone phone = getPhone(subId); |
| 5172 | if (phone != null) { |
| 5173 | return phone.getServiceState().getDataNetworkType(); |
| 5174 | } else { |
| 5175 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5176 | } |
| 5177 | } finally { |
| 5178 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5179 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5183 | * Returns the Voice network type for a subId |
| 5184 | */ |
| 5185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5186 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5187 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5188 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5189 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5190 | mApp, functionName)) { |
| 5191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5192 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5193 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5194 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | final long identity = Binder.clearCallingIdentity(); |
| 5198 | try { |
| 5199 | final Phone phone = getPhone(subId); |
| 5200 | if (phone != null) { |
| 5201 | return phone.getServiceState().getVoiceNetworkType(); |
| 5202 | } else { |
| 5203 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5204 | } |
| 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5207 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5208 | } |
| 5209 | |
| 5210 | /** |
| 5211 | * @return true if a ICC card is present |
| 5212 | */ |
| 5213 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5214 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5215 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5216 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5217 | } |
| 5218 | |
| 5219 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5220 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5221 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5222 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5223 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | final long identity = Binder.clearCallingIdentity(); |
| 5225 | try { |
| 5226 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5227 | if (phone != null) { |
| 5228 | return phone.getIccCard().hasIccCard(); |
| 5229 | } else { |
| 5230 | return false; |
| 5231 | } |
| 5232 | } finally { |
| 5233 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5234 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | /** |
| 5238 | * Return if the current radio is LTE on CDMA. This |
| 5239 | * is a tri-state return value as for a period of time |
| 5240 | * the mode may be unknown. |
| 5241 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5242 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5243 | * @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] | 5244 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5245 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5246 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5247 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5248 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5249 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5250 | } |
| 5251 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5252 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5253 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5254 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5255 | try { |
| 5256 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5257 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5258 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5259 | } |
| 5260 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
| 5263 | final Phone phone = getPhone(subId); |
| 5264 | if (phone == null) { |
| 5265 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5266 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5267 | return TelephonyProperties.lte_on_cdma_device() |
| 5268 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | } |
| 5270 | } finally { |
| 5271 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5272 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5275 | /** |
| 5276 | * {@hide} |
| 5277 | * Returns Default subId, 0 in the case of single standby. |
| 5278 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5279 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5280 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5281 | } |
| 5282 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5283 | private int getSlotForDefaultSubscription() { |
| 5284 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5285 | } |
| 5286 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5287 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5288 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5289 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5290 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5291 | private boolean isActiveSubscription(int subId) { |
| 5292 | return mSubscriptionController.isActiveSubId(subId); |
| 5293 | } |
| 5294 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5295 | /** |
| 5296 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5297 | */ |
| 5298 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | final long identity = Binder.clearCallingIdentity(); |
| 5300 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5301 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5302 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5303 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5304 | } finally { |
| 5305 | Binder.restoreCallingIdentity(identity); |
| 5306 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5307 | } |
| 5308 | |
| 5309 | /** |
| 5310 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5311 | */ |
| 5312 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
| 5315 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5316 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5317 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5318 | } finally { |
| 5319 | Binder.restoreCallingIdentity(identity); |
| 5320 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5321 | } |
| 5322 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5323 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5324 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5325 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5326 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5327 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5328 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5329 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5330 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5331 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5332 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5333 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5334 | } |
| 5335 | return PhoneFactory.getPhone(phoneId); |
| 5336 | } |
| 5337 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5338 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5339 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5340 | @NonNull IccLogicalChannelRequest request) { |
| 5341 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5342 | /*message=*/ "iccOpenLogicalChannel"); |
| 5343 | |
| 5344 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5345 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5346 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5347 | |
| 5348 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5349 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5350 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5351 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5352 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5353 | Phone phone; |
| 5354 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5355 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5356 | mApp, request.subId, message); |
| 5357 | phone = getPhoneFromSubId(request.subId); |
| 5358 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5359 | enforceModifyPermission(); |
| 5360 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5361 | } else { |
| 5362 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5363 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5364 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5365 | } |
| 5366 | |
| 5367 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5368 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5371 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5372 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5373 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5374 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5375 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5376 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | loge("The calling package is not allowed to access ISD-R."); |
| 5378 | throw new SecurityException( |
| 5379 | "The calling package is not allowed to access ISD-R."); |
| 5380 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5381 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5382 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5383 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5384 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5385 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5386 | return response; |
| 5387 | } finally { |
| 5388 | Binder.restoreCallingIdentity(identity); |
| 5389 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5393 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5394 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5395 | /*message=*/"iccCloseLogicalChannel"); |
| 5396 | |
| 5397 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5398 | |
| 5399 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5400 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5401 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5402 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5403 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5404 | // before this feature is enabled, this API should only return false if |
| 5405 | // the operation fails instead of throwing runtime exception for |
| 5406 | // backward-compatibility. |
| 5407 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5408 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | final long identity = Binder.clearCallingIdentity(); |
| 5410 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5411 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5412 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5414 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5415 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5416 | Boolean success = false; |
| 5417 | if (result instanceof RuntimeException) { |
| 5418 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5419 | if (shouldThrowExceptionOnFailure) { |
| 5420 | throw (RuntimeException) result; |
| 5421 | } else { |
| 5422 | return false; |
| 5423 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5424 | } else if (result instanceof Boolean) { |
| 5425 | success = (Boolean) result; |
| 5426 | } else { |
| 5427 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5428 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5429 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | return success; |
| 5431 | } finally { |
| 5432 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5433 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5437 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5438 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5439 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5440 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5441 | if (DBG) { |
| 5442 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5443 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5444 | + p3 + " data=" + data); |
| 5445 | } |
| 5446 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5447 | command, p1, p2, p3, data); |
| 5448 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5449 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5450 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5451 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5452 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5453 | enforceModifyPermission(); |
| 5454 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5455 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5456 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5457 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5458 | } |
| 5459 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5460 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5461 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5462 | } |
| 5463 | |
| 5464 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5465 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5468 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | return ""; |
| 5470 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5473 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5474 | null /* workSource */); |
| 5475 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | // Append the returned status code to the end of the response payload. |
| 5478 | String s = Integer.toHexString( |
| 5479 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5480 | if (response.payload != null) { |
| 5481 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5482 | } |
| 5483 | return s; |
| 5484 | } finally { |
| 5485 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5486 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5487 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5488 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5489 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5490 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5491 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5493 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5494 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5495 | if (DBG) { |
| 5496 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5497 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5498 | } |
| 5499 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5500 | cla, command, p1, p2, p3, data); |
| 5501 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5502 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5503 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5504 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5505 | 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] | 5506 | enforceModifyPermission(); |
| 5507 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5508 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5509 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5510 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5511 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
| 5514 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5515 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5516 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5520 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5521 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5525 | && TextUtils.equals(ISDR_AID, data)) { |
| 5526 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5527 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5528 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5529 | if (bestComponent == null |
| 5530 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5531 | loge("The calling package is not allowed to select ISD-R."); |
| 5532 | throw new SecurityException( |
| 5533 | "The calling package is not allowed to select ISD-R."); |
| 5534 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5535 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5537 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5538 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5539 | null /* workSource */); |
| 5540 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | // Append the returned status code to the end of the response payload. |
| 5543 | String s = Integer.toHexString( |
| 5544 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5545 | if (response.payload != null) { |
| 5546 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5547 | } |
| 5548 | return s; |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5551 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5555 | 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] | 5556 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5558 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5559 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | final long identity = Binder.clearCallingIdentity(); |
| 5561 | try { |
| 5562 | if (DBG) { |
| 5563 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5564 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5565 | } |
| 5566 | |
| 5567 | IccIoResult response = |
| 5568 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5569 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5570 | subId); |
| 5571 | |
| 5572 | if (DBG) { |
| 5573 | log("Exchange SIM_IO [R]" + response); |
| 5574 | } |
| 5575 | |
| 5576 | byte[] result = null; |
| 5577 | int length = 2; |
| 5578 | if (response.payload != null) { |
| 5579 | length = 2 + response.payload.length; |
| 5580 | result = new byte[length]; |
| 5581 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5582 | } else { |
| 5583 | result = new byte[length]; |
| 5584 | } |
| 5585 | |
| 5586 | result[length - 1] = (byte) response.sw2; |
| 5587 | result[length - 2] = (byte) response.sw1; |
| 5588 | return result; |
| 5589 | } finally { |
| 5590 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5591 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5592 | } |
| 5593 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5594 | /** |
| 5595 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5596 | * on a particular subscription |
| 5597 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5598 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5599 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5600 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5601 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5602 | return null; |
| 5603 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5604 | |
| 5605 | final long identity = Binder.clearCallingIdentity(); |
| 5606 | try { |
| 5607 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5608 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5609 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5610 | return null; |
| 5611 | } |
| 5612 | Object response = sendRequest( |
| 5613 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5614 | if (response instanceof String[]) { |
| 5615 | return (String[]) response; |
| 5616 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5617 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5618 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5619 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5620 | } finally { |
| 5621 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5622 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5623 | } |
| 5624 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5625 | /** |
| 5626 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5627 | * subscription. |
| 5628 | * |
| 5629 | * @param subId the id of the subscription. |
| 5630 | * @param appType the uicc app type, must be USIM or SIM. |
| 5631 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5632 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5633 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5634 | * @return number of fplmns that is successfully written to the SIM. |
| 5635 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5636 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5637 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5639 | mApp, subId, "setForbiddenPlmns"); |
| 5640 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5641 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5642 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5643 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5644 | } |
| 5645 | if (fplmns == null) { |
| 5646 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5647 | } |
| 5648 | for (String fplmn : fplmns) { |
| 5649 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5650 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5651 | } |
| 5652 | } |
| 5653 | final long identity = Binder.clearCallingIdentity(); |
| 5654 | try { |
| 5655 | Object response = sendRequest( |
| 5656 | CMD_SET_FORBIDDEN_PLMNS, |
| 5657 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5658 | subId); |
| 5659 | return (int) response; |
| 5660 | } finally { |
| 5661 | Binder.restoreCallingIdentity(identity); |
| 5662 | } |
| 5663 | } |
| 5664 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5665 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5666 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5668 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5669 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | final long identity = Binder.clearCallingIdentity(); |
| 5671 | try { |
| 5672 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5673 | if (response.payload == null) { |
| 5674 | return ""; |
| 5675 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | // Append the returned status code to the end of the response payload. |
| 5678 | String s = Integer.toHexString( |
| 5679 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5680 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5681 | return s; |
| 5682 | } finally { |
| 5683 | Binder.restoreCallingIdentity(identity); |
| 5684 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5685 | } |
| 5686 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5687 | /** |
| 5688 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5689 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5690 | * |
| 5691 | * @param itemID the ID of the item to read |
| 5692 | * @return the NV item as a String, or null on error. |
| 5693 | */ |
| 5694 | @Override |
| 5695 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5696 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5697 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5698 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | |
| 5700 | final long identity = Binder.clearCallingIdentity(); |
| 5701 | try { |
| 5702 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5703 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5705 | return value; |
| 5706 | } finally { |
| 5707 | Binder.restoreCallingIdentity(identity); |
| 5708 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | /** |
| 5712 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5713 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5714 | * |
| 5715 | * @param itemID the ID of the item to read |
| 5716 | * @param itemValue the value to write, as a String |
| 5717 | * @return true on success; false on any failure |
| 5718 | */ |
| 5719 | @Override |
| 5720 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5721 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5723 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | |
| 5725 | final long identity = Binder.clearCallingIdentity(); |
| 5726 | try { |
| 5727 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5728 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5729 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5730 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5731 | return success; |
| 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
| 5734 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | /** |
| 5738 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5739 | * Used for device configuration by some CDMA operators. |
| 5740 | * |
| 5741 | * @param preferredRoamingList byte array containing the new PRL |
| 5742 | * @return true on success; false on any failure |
| 5743 | */ |
| 5744 | @Override |
| 5745 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5747 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | |
| 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
| 5751 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5752 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5753 | if (DBG) log("nvWriteCdmaPrl: " + (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 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5761 | * 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] | 5762 | * Used for device configuration by some CDMA operators. |
| 5763 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5764 | * @param slotIndex - device slot. |
| 5765 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5766 | * @return true on success; false on any failure |
| 5767 | */ |
| 5768 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5769 | public boolean resetModemConfig(int slotIndex) { |
| 5770 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5771 | if (phone != null) { |
| 5772 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5773 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5775 | final long identity = Binder.clearCallingIdentity(); |
| 5776 | try { |
| 5777 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5778 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5779 | return success; |
| 5780 | } finally { |
| 5781 | Binder.restoreCallingIdentity(identity); |
| 5782 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5783 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5784 | return false; |
| 5785 | } |
| 5786 | |
| 5787 | /** |
| 5788 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5789 | * |
| 5790 | * @param slotIndex - device slot. |
| 5791 | * |
| 5792 | * @return true on success; false on any failure |
| 5793 | */ |
| 5794 | @Override |
| 5795 | public boolean rebootModem(int slotIndex) { |
| 5796 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5797 | if (phone != null) { |
| 5798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5799 | mApp, phone.getSubId(), "rebootModem"); |
| 5800 | |
| 5801 | final long identity = Binder.clearCallingIdentity(); |
| 5802 | try { |
| 5803 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5804 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5805 | return success; |
| 5806 | } finally { |
| 5807 | Binder.restoreCallingIdentity(identity); |
| 5808 | } |
| 5809 | } |
| 5810 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5811 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5812 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5813 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5814 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5815 | * {@link #disableIms(int)}. |
| 5816 | * @param slotIndex device slot. |
| 5817 | */ |
| 5818 | public void resetIms(int slotIndex) { |
| 5819 | enforceModifyPermission(); |
| 5820 | |
| 5821 | final long identity = Binder.clearCallingIdentity(); |
| 5822 | try { |
| 5823 | if (mImsResolver == null) { |
| 5824 | // may happen if the does not support IMS. |
| 5825 | return; |
| 5826 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5827 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5834 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5835 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5836 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5837 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | |
| 5840 | final long identity = Binder.clearCallingIdentity(); |
| 5841 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5842 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5843 | // may happen if the device does not support IMS. |
| 5844 | return; |
| 5845 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5846 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5847 | } finally { |
| 5848 | Binder.restoreCallingIdentity(identity); |
| 5849 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5853 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5854 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5855 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5856 | public void disableIms(int slotId) { |
| 5857 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5861 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5862 | // may happen if the device does not support IMS. |
| 5863 | return; |
| 5864 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5865 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
| 5868 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5872 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5873 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5874 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5875 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5876 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5877 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | |
| 5879 | final long identity = Binder.clearCallingIdentity(); |
| 5880 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5881 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5882 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5883 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5884 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5885 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | } finally { |
| 5887 | Binder.restoreCallingIdentity(identity); |
| 5888 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5889 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5890 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5891 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5892 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5893 | @Override |
| 5894 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5895 | enforceModifyPermission(); |
| 5896 | |
| 5897 | final long identity = Binder.clearCallingIdentity(); |
| 5898 | try { |
| 5899 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5900 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5901 | } finally { |
| 5902 | Binder.restoreCallingIdentity(identity); |
| 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5907 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5908 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5909 | */ |
| 5910 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5911 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5912 | |
| 5913 | final long identity = Binder.clearCallingIdentity(); |
| 5914 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5915 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5916 | // may happen if the device does not support IMS. |
| 5917 | return null; |
| 5918 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5919 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5920 | } finally { |
| 5921 | Binder.restoreCallingIdentity(identity); |
| 5922 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5923 | } |
| 5924 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5925 | /** |
| 5926 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5927 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5928 | */ |
| 5929 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5930 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5931 | |
| 5932 | final long identity = Binder.clearCallingIdentity(); |
| 5933 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5934 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5935 | // may happen if the device does not support IMS. |
| 5936 | return null; |
| 5937 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5938 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(identity); |
| 5941 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5942 | } |
| 5943 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5944 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5945 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5946 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5947 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5948 | * @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] | 5949 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5950 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5951 | * @param packageName The name of the package that the current configuration will be replaced |
| 5952 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5953 | * @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] | 5954 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5955 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5956 | int[] featureTypes, String packageName) { |
| 5957 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5958 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5960 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5961 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5962 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | final long identity = Binder.clearCallingIdentity(); |
| 5964 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5965 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5966 | // may happen if the device does not support IMS. |
| 5967 | return false; |
| 5968 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5969 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5970 | for (int featureType : featureTypes) { |
| 5971 | featureConfig.put(featureType, packageName); |
| 5972 | } |
| 5973 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5974 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | } finally { |
| 5976 | Binder.restoreCallingIdentity(identity); |
| 5977 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5978 | } |
| 5979 | |
| 5980 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5981 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5982 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5983 | * |
| 5984 | * This should only be used for testing. |
| 5985 | * |
| 5986 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5987 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5988 | */ |
| 5989 | @Override |
| 5990 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5991 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5993 | "clearCarrierImsServiceOverride"); |
| 5994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5995 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5996 | "clearCarrierImsServiceOverride"); |
| 5997 | |
| 5998 | final long identity = Binder.clearCallingIdentity(); |
| 5999 | try { |
| 6000 | if (mImsResolver == null) { |
| 6001 | // may happen if the device does not support IMS. |
| 6002 | return false; |
| 6003 | } |
| 6004 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6011 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6012 | * |
| 6013 | * @param slotId The slot that the ImsService is associated with. |
| 6014 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 6015 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6016 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6017 | * @return the package name of the ImsService configuration. |
| 6018 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6019 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 6020 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6021 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6022 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6023 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6024 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 6025 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 6026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | final long identity = Binder.clearCallingIdentity(); |
| 6028 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6029 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 6030 | // may happen if the device does not support IMS. |
| 6031 | return ""; |
| 6032 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 6033 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 6034 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 6035 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | } finally { |
| 6037 | Binder.restoreCallingIdentity(identity); |
| 6038 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6041 | /** |
| 6042 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6043 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6044 | * @param callback A callback with an integer containing the |
| 6045 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6046 | */ |
| 6047 | @Override |
| 6048 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6049 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6050 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6051 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6052 | "IMS not available on device."); |
| 6053 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6054 | final long token = Binder.clearCallingIdentity(); |
| 6055 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6056 | int slotId = getSlotIndex(subId); |
| 6057 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6058 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6059 | + subId + "'"); |
| 6060 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6061 | } |
| 6062 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6063 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6064 | try { |
| 6065 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6066 | } catch (RemoteException e) { |
| 6067 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6068 | + "Ignore"); |
| 6069 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6070 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6071 | } catch (ImsException e) { |
| 6072 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6073 | } finally { |
| 6074 | Binder.restoreCallingIdentity(token); |
| 6075 | } |
| 6076 | } |
| 6077 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6078 | /** |
| 6079 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6080 | */ |
| 6081 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6082 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6083 | |
| 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6086 | // NOTE: Before S, this method only set the default phone. |
| 6087 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6088 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6089 | phone.setImsRegistrationState(registered); |
| 6090 | } |
| 6091 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6098 | * Set the network selection mode to automatic. |
| 6099 | * |
| 6100 | */ |
| 6101 | @Override |
| 6102 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6104 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 | |
| 6106 | final long identity = Binder.clearCallingIdentity(); |
| 6107 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6108 | if (!isActiveSubscription(subId)) { |
| 6109 | return; |
| 6110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6111 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6112 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6113 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6114 | } finally { |
| 6115 | Binder.restoreCallingIdentity(identity); |
| 6116 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6117 | } |
| 6118 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6119 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6120 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6121 | * |
| 6122 | * @param subId the id of the subscription. |
| 6123 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6124 | * the operator to attach to. |
| 6125 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6126 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6127 | * normal network selection next time. |
| 6128 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6129 | */ |
| 6130 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6131 | public boolean setNetworkSelectionModeManual( |
| 6132 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6133 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6134 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6135 | |
| 6136 | if (!isActiveSubscription(subId)) { |
| 6137 | return false; |
| 6138 | } |
| 6139 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6140 | final long identity = Binder.clearCallingIdentity(); |
| 6141 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6142 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6144 | if (DBG) { |
| 6145 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6146 | + " operator: " + operatorInfo); |
| 6147 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6148 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6149 | } finally { |
| 6150 | Binder.restoreCallingIdentity(identity); |
| 6151 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6152 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6153 | /** |
| 6154 | * Get the manual network selection |
| 6155 | * |
| 6156 | * @param subId the id of the subscription. |
| 6157 | * |
| 6158 | * @return the previously saved user selected PLMN |
| 6159 | */ |
| 6160 | @Override |
| 6161 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6162 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6163 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6164 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6165 | |
| 6166 | final long identity = Binder.clearCallingIdentity(); |
| 6167 | try { |
| 6168 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6169 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | final Phone phone = getPhone(subId); |
| 6173 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6174 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6175 | } |
| 6176 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6177 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6178 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6179 | } finally { |
| 6180 | Binder.restoreCallingIdentity(identity); |
| 6181 | } |
| 6182 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6183 | |
| 6184 | /** |
| 6185 | * Scans for available networks. |
| 6186 | */ |
| 6187 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6188 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6191 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6192 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6193 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6194 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6195 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6196 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6197 | .setCallingPid(Binder.getCallingPid()) |
| 6198 | .setCallingUid(Binder.getCallingUid()) |
| 6199 | .setMethod("getCellNetworkScanResults") |
| 6200 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6201 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6202 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6203 | .build()); |
| 6204 | switch (locationResult) { |
| 6205 | case DENIED_HARD: |
| 6206 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6207 | case DENIED_SOFT: |
| 6208 | return null; |
| 6209 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6210 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6211 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6212 | try { |
| 6213 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6214 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6215 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | } finally { |
| 6217 | Binder.restoreCallingIdentity(identity); |
| 6218 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6222 | * Get the call forwarding info, given the call forwarding reason. |
| 6223 | */ |
| 6224 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6225 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6226 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6227 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6228 | long identity = Binder.clearCallingIdentity(); |
| 6229 | try { |
| 6230 | if (DBG) { |
| 6231 | log("getCallForwarding: subId " + subId |
| 6232 | + " callForwardingReason" + callForwardingReason); |
| 6233 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6234 | |
| 6235 | Phone phone = getPhone(subId); |
| 6236 | if (phone == null) { |
| 6237 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6238 | callback.onError( |
| 6239 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6240 | } catch (RemoteException e) { |
| 6241 | // ignore |
| 6242 | } |
| 6243 | return; |
| 6244 | } |
| 6245 | |
| 6246 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6247 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6248 | @Override |
| 6249 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6250 | try { |
| 6251 | callback.onCallForwardingInfoAvailable(info); |
| 6252 | } catch (RemoteException e) { |
| 6253 | // ignore |
| 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | @Override |
| 6258 | public void onError(int error) { |
| 6259 | try { |
| 6260 | callback.onError(error); |
| 6261 | } catch (RemoteException e) { |
| 6262 | // ignore |
| 6263 | } |
| 6264 | } |
| 6265 | }); |
| 6266 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6267 | } finally { |
| 6268 | Binder.restoreCallingIdentity(identity); |
| 6269 | } |
| 6270 | } |
| 6271 | |
| 6272 | /** |
| 6273 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6274 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6275 | */ |
| 6276 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6277 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6278 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6279 | enforceModifyPermission(); |
| 6280 | long identity = Binder.clearCallingIdentity(); |
| 6281 | try { |
| 6282 | if (DBG) { |
| 6283 | log("setCallForwarding: subId " + subId |
| 6284 | + " callForwardingInfo" + callForwardingInfo); |
| 6285 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6286 | |
| 6287 | Phone phone = getPhone(subId); |
| 6288 | if (phone == null) { |
| 6289 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6290 | callback.accept( |
| 6291 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6292 | } catch (RemoteException e) { |
| 6293 | // ignore |
| 6294 | } |
| 6295 | return; |
| 6296 | } |
| 6297 | |
| 6298 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6299 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6300 | |
| 6301 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6302 | } finally { |
| 6303 | Binder.restoreCallingIdentity(identity); |
| 6304 | } |
| 6305 | } |
| 6306 | |
| 6307 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6308 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6309 | */ |
| 6310 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6311 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6312 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6313 | long identity = Binder.clearCallingIdentity(); |
| 6314 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6315 | Phone phone = getPhone(subId); |
| 6316 | if (phone == null) { |
| 6317 | try { |
| 6318 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6319 | } catch (RemoteException e) { |
| 6320 | // ignore |
| 6321 | } |
| 6322 | return; |
| 6323 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6324 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6325 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6326 | boolean requireUssd = c.getBoolean( |
| 6327 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6328 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6329 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6330 | if (requireUssd) { |
| 6331 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6332 | getSubscriptionCarrierId(subId)); |
| 6333 | String newUssdCommand = ""; |
| 6334 | try { |
| 6335 | newUssdCommand = carrierXmlParser.getFeature( |
| 6336 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6337 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6338 | } catch (NullPointerException e) { |
| 6339 | loge("Failed to generate USSD number" + e); |
| 6340 | } |
| 6341 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6342 | mMainThreadHandler, callback, carrierXmlParser, |
| 6343 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6344 | final String ussdCommand = newUssdCommand; |
| 6345 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6346 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6347 | }); |
| 6348 | } else { |
| 6349 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6350 | callback::accept); |
| 6351 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6352 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6353 | } finally { |
| 6354 | Binder.restoreCallingIdentity(identity); |
| 6355 | } |
| 6356 | } |
| 6357 | |
| 6358 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6359 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6360 | */ |
| 6361 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6362 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6363 | enforceModifyPermission(); |
| 6364 | long identity = Binder.clearCallingIdentity(); |
| 6365 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6366 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6367 | |
| 6368 | Phone phone = getPhone(subId); |
| 6369 | if (phone == null) { |
| 6370 | try { |
| 6371 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6372 | } catch (RemoteException e) { |
| 6373 | // ignore |
| 6374 | } |
| 6375 | return; |
| 6376 | } |
| 6377 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6378 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6379 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6380 | boolean requireUssd = c.getBoolean( |
| 6381 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6382 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6383 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6384 | if (requireUssd) { |
| 6385 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6386 | getSubscriptionCarrierId(subId)); |
| 6387 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6388 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6389 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6390 | String newUssdCommand = ""; |
| 6391 | try { |
| 6392 | newUssdCommand = carrierXmlParser.getFeature( |
| 6393 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6394 | .makeCommand(ssAction, null); |
| 6395 | } catch (NullPointerException e) { |
| 6396 | loge("Failed to generate USSD number" + e); |
| 6397 | } |
| 6398 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6399 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6400 | final String ussdCommand = newUssdCommand; |
| 6401 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6402 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6403 | }); |
| 6404 | } else { |
| 6405 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6406 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6407 | |
| 6408 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6409 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6416 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6417 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6418 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6419 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6420 | * location related information which will be sent if the caller already possess |
| 6421 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6422 | * @param request contains the radio access networks with bands/channels to scan |
| 6423 | * @param messenger callback messenger for scan results or errors |
| 6424 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6425 | * @return the id of the requested scan which can be used to stop the scan. |
| 6426 | */ |
| 6427 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6428 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6429 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6430 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6432 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6433 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6434 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6435 | if (!renounceFineLocationAccess) { |
| 6436 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6437 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6438 | .setCallingPackage(callingPackage) |
| 6439 | .setCallingFeatureId(callingFeatureId) |
| 6440 | .setCallingPid(Binder.getCallingPid()) |
| 6441 | .setCallingUid(Binder.getCallingUid()) |
| 6442 | .setMethod("requestNetworkScan") |
| 6443 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6444 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6445 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6446 | .build()); |
| 6447 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6448 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6449 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6450 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6451 | if (e != null) { |
| 6452 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6453 | throw e; |
| 6454 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6455 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6456 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6457 | } |
| 6458 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6460 | int callingUid = Binder.getCallingUid(); |
| 6461 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6462 | final long identity = Binder.clearCallingIdentity(); |
| 6463 | try { |
| 6464 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6465 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6466 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6467 | } finally { |
| 6468 | Binder.restoreCallingIdentity(identity); |
| 6469 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6470 | } |
| 6471 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6472 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6473 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6474 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6475 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6476 | boolean hasNetworkScanPermission = |
| 6477 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6478 | == PERMISSION_GRANTED; |
| 6479 | |
| 6480 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6481 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6482 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6483 | } |
| 6484 | |
| 6485 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6486 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6487 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6488 | return new SecurityException("Specific channels must not be" |
| 6489 | + " scanned without location access."); |
| 6490 | } |
| 6491 | } |
| 6492 | } |
| 6493 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6494 | return null; |
| 6495 | } |
| 6496 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6497 | /** |
| 6498 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6499 | * |
| 6500 | * @param subId id of the subscription |
| 6501 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6502 | */ |
| 6503 | @Override |
| 6504 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6505 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6506 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6507 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6508 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6509 | final long identity = Binder.clearCallingIdentity(); |
| 6510 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6511 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6512 | } finally { |
| 6513 | Binder.restoreCallingIdentity(identity); |
| 6514 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6515 | } |
| 6516 | |
| 6517 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6518 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6519 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6520 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6521 | */ |
| 6522 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6523 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6524 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6525 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6526 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6527 | |
| 6528 | final long identity = Binder.clearCallingIdentity(); |
| 6529 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6530 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6531 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6532 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6533 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6534 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6535 | } finally { |
| 6536 | Binder.restoreCallingIdentity(identity); |
| 6537 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6538 | } |
| 6539 | |
| 6540 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6541 | * Get the allowed network types for certain reason. |
| 6542 | * |
| 6543 | * @param subId the id of the subscription. |
| 6544 | * @param reason the reason the allowed network type change is taking place |
| 6545 | * @return the allowed network types. |
| 6546 | */ |
| 6547 | @Override |
| 6548 | public long getAllowedNetworkTypesForReason(int subId, |
| 6549 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6550 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6551 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6552 | final long identity = Binder.clearCallingIdentity(); |
| 6553 | try { |
| 6554 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6555 | } finally { |
| 6556 | Binder.restoreCallingIdentity(identity); |
| 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6561 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6562 | * @param subId subscription id of the sim card |
| 6563 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6564 | * This can be passed following states |
| 6565 | * <ol> |
| 6566 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6567 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6568 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6569 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6570 | * </ol> |
| 6571 | * @return operation result. |
| 6572 | */ |
| 6573 | @Override |
| 6574 | public int setNrDualConnectivityState(int subId, |
| 6575 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6577 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6578 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6579 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6580 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6581 | } |
| 6582 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6583 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6584 | final long identity = Binder.clearCallingIdentity(); |
| 6585 | try { |
| 6586 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6587 | nrDualConnectivityState, subId, |
| 6588 | workSource); |
| 6589 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6590 | return result; |
| 6591 | } finally { |
| 6592 | Binder.restoreCallingIdentity(identity); |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | /** |
| 6597 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6598 | * @return true if dual connectivity is enabled else false |
| 6599 | */ |
| 6600 | @Override |
| 6601 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6602 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6603 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6604 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6605 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6606 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6607 | return false; |
| 6608 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6609 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6610 | final long identity = Binder.clearCallingIdentity(); |
| 6611 | try { |
| 6612 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6613 | null, subId, workSource); |
| 6614 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6615 | return isEnabled; |
| 6616 | } finally { |
| 6617 | Binder.restoreCallingIdentity(identity); |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6622 | * Set the allowed network types of the device and |
| 6623 | * provide the reason triggering the allowed network change. |
| 6624 | * |
| 6625 | * @param subId the id of the subscription. |
| 6626 | * @param reason the reason the allowed network type change is taking place |
| 6627 | * @param allowedNetworkTypes the allowed network types. |
| 6628 | * @return true on success; false on any failure. |
| 6629 | */ |
| 6630 | @Override |
| 6631 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6632 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6633 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6635 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6636 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6637 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6638 | return false; |
| 6639 | } |
| 6640 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6641 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6642 | return false; |
| 6643 | } |
| 6644 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6645 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6646 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6647 | |
| 6648 | |
| 6649 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6650 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6651 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6652 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6653 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6654 | final long identity = Binder.clearCallingIdentity(); |
| 6655 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6656 | Boolean success = (Boolean) sendRequest( |
| 6657 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6658 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6659 | |
| 6660 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6661 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6662 | } finally { |
| 6663 | Binder.restoreCallingIdentity(identity); |
| 6664 | } |
| 6665 | } |
| 6666 | |
| 6667 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6668 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6669 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6670 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6671 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6672 | * @hide |
| 6673 | */ |
| 6674 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6675 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6676 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6678 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6679 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6680 | if (phone != null) { |
| 6681 | return phone.hasMatchedTetherApnSetting(); |
| 6682 | } else { |
| 6683 | return false; |
| 6684 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | } finally { |
| 6686 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6687 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6691 | * Get the user enabled state of Mobile Data. |
| 6692 | * |
| 6693 | * TODO: remove and use isUserDataEnabled. |
| 6694 | * This can't be removed now because some vendor codes |
| 6695 | * calls through ITelephony directly while they should |
| 6696 | * use TelephonyManager. |
| 6697 | * |
| 6698 | * @return true on enabled |
| 6699 | */ |
| 6700 | @Override |
| 6701 | public boolean getDataEnabled(int subId) { |
| 6702 | return isUserDataEnabled(subId); |
| 6703 | } |
| 6704 | |
| 6705 | /** |
| 6706 | * Get whether mobile data is enabled per user setting. |
| 6707 | * |
| 6708 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6709 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6710 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6711 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6712 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6713 | * |
| 6714 | * @return {@code true} if data is enabled else {@code false} |
| 6715 | */ |
| 6716 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6717 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6718 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6719 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6720 | try { |
| 6721 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6722 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6723 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6724 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6725 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6726 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6728 | mApp, subId, functionName); |
| 6729 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6730 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | |
| 6732 | final long identity = Binder.clearCallingIdentity(); |
| 6733 | try { |
| 6734 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6735 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6736 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6737 | if (phone != null) { |
| 6738 | boolean retVal = phone.isUserDataEnabled(); |
| 6739 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6740 | return retVal; |
| 6741 | } else { |
| 6742 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6743 | return false; |
| 6744 | } |
| 6745 | } finally { |
| 6746 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6747 | } |
| 6748 | } |
| 6749 | |
| 6750 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6751 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6752 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6753 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6754 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6755 | * @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] | 6756 | */ |
| 6757 | @Override |
| 6758 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6759 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6760 | try { |
| 6761 | try { |
| 6762 | mApp.enforceCallingOrSelfPermission( |
| 6763 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6764 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6765 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6766 | try { |
| 6767 | mApp.enforceCallingOrSelfPermission( |
| 6768 | android.Manifest.permission.READ_PHONE_STATE, |
| 6769 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6770 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6771 | mApp.enforceCallingOrSelfPermission( |
| 6772 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6773 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6774 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6775 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6776 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6777 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6778 | |
| 6779 | final long identity = Binder.clearCallingIdentity(); |
| 6780 | try { |
| 6781 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6782 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6783 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6784 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6785 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6786 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | return retVal; |
| 6788 | } else { |
| 6789 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6790 | return false; |
| 6791 | } |
| 6792 | } finally { |
| 6793 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6794 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6795 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6796 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6797 | /** |
| 6798 | * Check if data is enabled for a specific reason |
| 6799 | * @param subId Subscription index |
| 6800 | * @param reason the reason the data enable change is taking place |
| 6801 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6802 | */ |
| 6803 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6804 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6805 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6806 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6807 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6808 | try { |
| 6809 | mApp.enforceCallingOrSelfPermission( |
| 6810 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6811 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6812 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6813 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6814 | functionName); |
| 6815 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6816 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6817 | try { |
| 6818 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6819 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6820 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6822 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6823 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6824 | } |
| 6825 | |
| 6826 | |
| 6827 | final long identity = Binder.clearCallingIdentity(); |
| 6828 | try { |
| 6829 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6830 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6831 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6832 | + " reason=" + reason); |
| 6833 | } |
| 6834 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6835 | if (phone != null) { |
| 6836 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6837 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6838 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6839 | return retVal; |
| 6840 | } else { |
| 6841 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6842 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6843 | + subId + " retVal=false"); |
| 6844 | } |
| 6845 | return false; |
| 6846 | } |
| 6847 | } finally { |
| 6848 | Binder.restoreCallingIdentity(identity); |
| 6849 | } |
| 6850 | } |
| 6851 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6852 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6853 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6854 | // No permission needed; this only lets the caller inspect their own status. |
| 6855 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6856 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6857 | |
| 6858 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6859 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6860 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6861 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6862 | } |
| 6863 | |
| 6864 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6865 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6866 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6867 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6868 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6869 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6870 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6871 | if (cpt == null) { |
| 6872 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6873 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6874 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6875 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6876 | } |
| 6877 | |
| 6878 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6879 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6880 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6881 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6882 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6883 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6884 | Phone phone = getPhone(subId); |
| 6885 | if (phone == null) { |
| 6886 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6887 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6888 | } |
| 6889 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6890 | if (cpt == null) { |
| 6891 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6892 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6893 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6894 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | @Override |
| 6898 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6899 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6900 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6901 | } |
| 6902 | |
| 6903 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6904 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6905 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6906 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6907 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6908 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6909 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6910 | if (phone == null) { |
| 6911 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6912 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6913 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6914 | if (cpt == null) { |
| 6915 | continue; |
| 6916 | } |
| 6917 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6918 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6919 | break; |
| 6920 | } |
| 6921 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6922 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6923 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6924 | |
| 6925 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6926 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6927 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6928 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6929 | if (phone == null) { |
| 6930 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6931 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6932 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6933 | if (cpt == null) { |
| 6934 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6935 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6936 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6937 | } |
| 6938 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6939 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6940 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6941 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6942 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6943 | if (phone == null) { |
| 6944 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6945 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6946 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6947 | if (cpt == null) { |
| 6948 | return Collections.emptyList(); |
| 6949 | } |
| 6950 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6951 | } |
| 6952 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6953 | @Override |
| 6954 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6955 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6956 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6957 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6958 | try { |
| 6959 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6960 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6961 | } |
| 6962 | } finally { |
| 6963 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6964 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6965 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6966 | } |
| 6967 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6968 | @Override |
| 6969 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6970 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6971 | |
| 6972 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6973 | if (phone == null) { |
| 6974 | return null; |
| 6975 | } |
| 6976 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6977 | if (cpt == null) { |
| 6978 | return null; |
| 6979 | } |
| 6980 | return cpt.getCarrierServicePackageName(); |
| 6981 | } |
| 6982 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6983 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6984 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6985 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6986 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6987 | return null; |
| 6988 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6989 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6990 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6991 | return null; |
| 6992 | } |
| 6993 | return iccId; |
| 6994 | } |
| 6995 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6996 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6997 | public void setCallComposerStatus(int subId, int status) { |
| 6998 | enforceModifyPermission(); |
| 6999 | |
| 7000 | final long identity = Binder.clearCallingIdentity(); |
| 7001 | try { |
| 7002 | Phone phone = getPhone(subId); |
| 7003 | if (phone != null) { |
| 7004 | Phone defaultPhone = phone.getImsPhone(); |
| 7005 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7006 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7007 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7008 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 7009 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7010 | } |
| 7011 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 7012 | } catch (ImsException e) { |
| 7013 | throw new ServiceSpecificException(e.getCode()); |
| 7014 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
| 7017 | } |
| 7018 | |
| 7019 | @Override |
| 7020 | public int getCallComposerStatus(int subId) { |
| 7021 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 7022 | |
| 7023 | final long identity = Binder.clearCallingIdentity(); |
| 7024 | try { |
| 7025 | Phone phone = getPhone(subId); |
| 7026 | if (phone != null) { |
| 7027 | Phone defaultPhone = phone.getImsPhone(); |
| 7028 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7029 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7030 | return imsPhone.getCallComposerStatus(); |
| 7031 | } |
| 7032 | } |
| 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
| 7035 | } |
| 7036 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7037 | } |
| 7038 | |
| 7039 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7040 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7041 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7042 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7043 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7044 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
| 7047 | final String iccId = getIccId(subId); |
| 7048 | final Phone phone = getPhone(subId); |
| 7049 | if (phone == null) { |
| 7050 | return false; |
| 7051 | } |
| 7052 | final String subscriberId = phone.getSubscriberId(); |
| 7053 | |
| 7054 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7055 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7056 | + subscriberId + " to " + number); |
| 7057 | } |
| 7058 | |
| 7059 | if (TextUtils.isEmpty(iccId)) { |
| 7060 | return false; |
| 7061 | } |
| 7062 | |
| 7063 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7064 | |
| 7065 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7066 | if (alphaTag == null) { |
| 7067 | editor.remove(alphaTagPrefKey); |
| 7068 | } else { |
| 7069 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7070 | } |
| 7071 | |
| 7072 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7073 | // track all merged IMSIs based on line number |
| 7074 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7075 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7076 | if (number == null) { |
| 7077 | editor.remove(numberPrefKey); |
| 7078 | editor.remove(subscriberPrefKey); |
| 7079 | } else { |
| 7080 | editor.putString(numberPrefKey, number); |
| 7081 | editor.putString(subscriberPrefKey, subscriberId); |
| 7082 | } |
| 7083 | |
| 7084 | editor.commit(); |
| 7085 | return true; |
| 7086 | } finally { |
| 7087 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7088 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7089 | } |
| 7090 | |
| 7091 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7092 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7093 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7094 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7095 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7096 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7097 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7098 | return null; |
| 7099 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7100 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7101 | final long identity = Binder.clearCallingIdentity(); |
| 7102 | try { |
| 7103 | String iccId = getIccId(subId); |
| 7104 | if (iccId != null) { |
| 7105 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7106 | if (DBG_MERGE) { |
| 7107 | log("getLine1NumberForDisplay returning " |
| 7108 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7109 | } |
| 7110 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7111 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7112 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7113 | return null; |
| 7114 | } finally { |
| 7115 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -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 getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7121 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7123 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7124 | return null; |
| 7125 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7126 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7127 | final long identity = Binder.clearCallingIdentity(); |
| 7128 | try { |
| 7129 | String iccId = getIccId(subId); |
| 7130 | if (iccId != null) { |
| 7131 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7132 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7133 | } |
| 7134 | return null; |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7137 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7138 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7139 | |
| 7140 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7141 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7142 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7143 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7144 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7146 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7147 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7148 | return null; |
| 7149 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7150 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7151 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7152 | // the process, where TelephonyManager was instantiated. |
| 7153 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7154 | final long identity = Binder.clearCallingIdentity(); |
| 7155 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7156 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7158 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7159 | |
| 7160 | // Figure out what subscribers are currently active |
| 7161 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7163 | // Only consider subs which match the current subId |
| 7164 | // This logic can be simplified. See b/131189269 for progress. |
| 7165 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7166 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | |
| 7169 | // First pass, find a number override for an active subscriber |
| 7170 | String mergeNumber = null; |
| 7171 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7172 | for (String key : prefs.keySet()) { |
| 7173 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7174 | final String subscriberId = (String) prefs.get(key); |
| 7175 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7176 | final String iccId = key.substring( |
| 7177 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7178 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7179 | mergeNumber = (String) prefs.get(numberKey); |
| 7180 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7181 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7182 | + " for active subscriber " + subscriberId); |
| 7183 | } |
| 7184 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7185 | break; |
| 7186 | } |
| 7187 | } |
| 7188 | } |
| 7189 | } |
| 7190 | |
| 7191 | // Shortcut when no active merged subscribers |
| 7192 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7193 | return null; |
| 7194 | } |
| 7195 | |
| 7196 | // Second pass, find all subscribers under that line override |
| 7197 | final ArraySet<String> result = new ArraySet<>(); |
| 7198 | for (String key : prefs.keySet()) { |
| 7199 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7200 | final String number = (String) prefs.get(key); |
| 7201 | if (mergeNumber.equals(number)) { |
| 7202 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7203 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7204 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7205 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7206 | result.add(subscriberId); |
| 7207 | } |
| 7208 | } |
| 7209 | } |
| 7210 | } |
| 7211 | |
| 7212 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7213 | Arrays.sort(resultArray); |
| 7214 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7215 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7216 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7217 | } |
| 7218 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7219 | } finally { |
| 7220 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7221 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7225 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7226 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7227 | |
| 7228 | final long identity = Binder.clearCallingIdentity(); |
| 7229 | try { |
| 7230 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7231 | TelephonyManager.class); |
| 7232 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7233 | if (subscriberId == null) { |
| 7234 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7235 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7236 | + subId); |
| 7237 | } |
| 7238 | return null; |
| 7239 | } |
| 7240 | |
| 7241 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7242 | .getSubscriptionInfo(subId); |
| 7243 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7244 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7245 | if (groupUuid == null) { |
| 7246 | return new String[]{subscriberId}; |
| 7247 | } |
| 7248 | |
| 7249 | // Get all subscriberIds from the group. |
| 7250 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7251 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7252 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7253 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7254 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7255 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7256 | if (subscriberId != null) { |
| 7257 | mergedSubscriberIds.add(subscriberId); |
| 7258 | } |
| 7259 | } |
| 7260 | |
| 7261 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7262 | } finally { |
| 7263 | Binder.restoreCallingIdentity(identity); |
| 7264 | |
| 7265 | } |
| 7266 | } |
| 7267 | |
| 7268 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7269 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7270 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7271 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | |
| 7273 | final long identity = Binder.clearCallingIdentity(); |
| 7274 | try { |
| 7275 | final Phone phone = getPhone(subId); |
| 7276 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
| 7279 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7280 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7281 | |
| 7282 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7283 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7284 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7285 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7286 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7287 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7288 | |
| 7289 | final long identity = Binder.clearCallingIdentity(); |
| 7290 | try { |
| 7291 | final Phone phone = getPhone(subId); |
| 7292 | if (phone == null) { |
| 7293 | return false; |
| 7294 | } |
| 7295 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7296 | cdmaNonRoamingList); |
| 7297 | } finally { |
| 7298 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7299 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7300 | } |
| 7301 | |
| 7302 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7303 | @Deprecated |
| 7304 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7305 | enforceModifyPermission(); |
| 7306 | |
| 7307 | int returnValue = 0; |
| 7308 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7309 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7310 | if(result.exception == null) { |
| 7311 | if (result.result != null) { |
| 7312 | byte[] responseData = (byte[])(result.result); |
| 7313 | if(responseData.length > oemResp.length) { |
| 7314 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7315 | responseData.length + "bytes. Buffer Size is " + |
| 7316 | oemResp.length + "bytes."); |
| 7317 | } |
| 7318 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7319 | returnValue = responseData.length; |
| 7320 | } |
| 7321 | } else { |
| 7322 | CommandException ex = (CommandException) result.exception; |
| 7323 | returnValue = ex.getCommandError().ordinal(); |
| 7324 | if(returnValue > 0) returnValue *= -1; |
| 7325 | } |
| 7326 | } catch (RuntimeException e) { |
| 7327 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7328 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7329 | if(returnValue > 0) returnValue *= -1; |
| 7330 | } |
| 7331 | |
| 7332 | return returnValue; |
| 7333 | } |
| 7334 | |
| 7335 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7336 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7337 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7338 | try { |
| 7339 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7340 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7341 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7342 | } catch (SecurityException e) { |
| 7343 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7344 | throw e; |
| 7345 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7346 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7347 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7348 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7349 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | final long identity = Binder.clearCallingIdentity(); |
| 7351 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7352 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7353 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7354 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7355 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | } finally { |
| 7357 | Binder.restoreCallingIdentity(identity); |
| 7358 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7359 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7360 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7361 | |
| 7362 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7363 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7364 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7365 | try { |
| 7366 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7367 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7368 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7369 | } |
| 7370 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7371 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7372 | } |
| 7373 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7374 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7375 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7376 | throw new SecurityException("App must be the dialer role holder to" |
| 7377 | + " upload a call composer pic"); |
| 7378 | } |
| 7379 | |
| 7380 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7381 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7382 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7383 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7384 | boolean readUntilEnd = false; |
| 7385 | int totalBytesRead = 0; |
| 7386 | byte[] buffer = new byte[16 * 1024]; |
| 7387 | while (true) { |
| 7388 | int numRead; |
| 7389 | try { |
| 7390 | numRead = input.read(buffer); |
| 7391 | } catch (IOException e) { |
| 7392 | try { |
| 7393 | fd.checkError(); |
| 7394 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7395 | null); |
| 7396 | } catch (IOException e1) { |
| 7397 | // This means that the other side closed explicitly with an error. If this |
| 7398 | // happens, log and ignore. |
| 7399 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7400 | } |
| 7401 | break; |
| 7402 | } |
| 7403 | if (numRead == -1) { |
| 7404 | readUntilEnd = true; |
| 7405 | break; |
| 7406 | } |
| 7407 | totalBytesRead += numRead; |
| 7408 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7409 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7410 | try { |
| 7411 | input.close(); |
| 7412 | } catch (IOException e) { |
| 7413 | // ignore |
| 7414 | } |
| 7415 | break; |
| 7416 | } |
| 7417 | output.write(buffer, 0, numRead); |
| 7418 | } |
| 7419 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7420 | // close is above, where the picture size is too big. |
| 7421 | |
| 7422 | try { |
| 7423 | fd.checkError(); |
| 7424 | } catch (IOException e) { |
| 7425 | loge("Remote end for call composer closed with an error: " + e); |
| 7426 | return; |
| 7427 | } |
| 7428 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7429 | if (!readUntilEnd) { |
| 7430 | loge("Did not finish reading entire image; aborting"); |
| 7431 | return; |
| 7432 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7433 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7434 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7435 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7436 | new CallComposerPictureTransfer.Factory() {}, |
| 7437 | imageData, |
| 7438 | (result) -> { |
| 7439 | if (result.first != null) { |
| 7440 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7441 | Bundle outputResult = new Bundle(); |
| 7442 | outputResult.putParcelable( |
| 7443 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7444 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7445 | outputResult); |
| 7446 | } else { |
| 7447 | callback.send(result.second, null); |
| 7448 | } |
| 7449 | } |
| 7450 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7451 | }); |
| 7452 | } |
| 7453 | |
| 7454 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7455 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7456 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7457 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | |
| 7459 | final long identity = Binder.clearCallingIdentity(); |
| 7460 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7461 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7462 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7463 | } finally { |
| 7464 | Binder.restoreCallingIdentity(identity); |
| 7465 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7466 | } |
| 7467 | |
| 7468 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7469 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7470 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7471 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7472 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7473 | return false; |
| 7474 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | final long identity = Binder.clearCallingIdentity(); |
| 7477 | try { |
| 7478 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7479 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7480 | // In the long run, we may instead need to check if there exists a connection service |
| 7481 | // which can support video calling. |
| 7482 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7483 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | return imsManager.isVtEnabledByPlatform() |
| 7485 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7486 | && imsManager.isVtEnabledByUser(); |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7490 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7491 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7492 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7493 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7494 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7496 | mApp, subId, callingPackage, callingFeatureId, |
| 7497 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7498 | return false; |
| 7499 | } |
| 7500 | |
| 7501 | final long identity = Binder.clearCallingIdentity(); |
| 7502 | try { |
| 7503 | CarrierConfigManager configManager = |
| 7504 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7505 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7507 | } finally { |
| 7508 | Binder.restoreCallingIdentity(identity); |
| 7509 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7513 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7514 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7515 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | return false; |
| 7517 | } |
| 7518 | |
| 7519 | final long identity = Binder.clearCallingIdentity(); |
| 7520 | try { |
| 7521 | CarrierConfigManager configManager = |
| 7522 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7523 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7525 | } finally { |
| 7526 | Binder.restoreCallingIdentity(identity); |
| 7527 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7528 | } |
| 7529 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7530 | @Override |
| 7531 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7532 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7533 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7534 | } |
| 7535 | |
| 7536 | @Override |
| 7537 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7540 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7544 | } |
| 7545 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7546 | /** |
| 7547 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7548 | * support for the feature and device firmware support. |
| 7549 | * |
| 7550 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7551 | */ |
| 7552 | @Override |
| 7553 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7554 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7555 | final Phone phone = getPhone(subscriptionId); |
| 7556 | if (phone == null) { |
| 7557 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7558 | return false; |
| 7559 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7560 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7561 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7563 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7564 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7565 | return isCarrierSupported && isDeviceSupported; |
| 7566 | } finally { |
| 7567 | Binder.restoreCallingIdentity(identity); |
| 7568 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7569 | } |
| 7570 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7571 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7572 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7573 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7574 | * 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] | 7575 | */ |
| 7576 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | final long identity = Binder.clearCallingIdentity(); |
| 7578 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7579 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7580 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7581 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7582 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7583 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7584 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7585 | } finally { |
| 7586 | Binder.restoreCallingIdentity(identity); |
| 7587 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7588 | } |
| 7589 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7590 | @Deprecated |
| 7591 | @Override |
| 7592 | public String getDeviceId(String callingPackage) { |
| 7593 | return getDeviceIdWithFeature(callingPackage, null); |
| 7594 | } |
| 7595 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7596 | /** |
| 7597 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7598 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7599 | * |
| 7600 | * <p>Requires Permission: |
| 7601 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7602 | */ |
| 7603 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7604 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7605 | try { |
| 7606 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7607 | } catch (SecurityException se) { |
| 7608 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7609 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7610 | + Binder.getCallingUid()); |
| 7611 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7612 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7613 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7614 | return null; |
| 7615 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7616 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7617 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7618 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7619 | return null; |
| 7620 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7621 | |
| 7622 | final long identity = Binder.clearCallingIdentity(); |
| 7623 | try { |
| 7624 | return phone.getDeviceId(); |
| 7625 | } finally { |
| 7626 | Binder.restoreCallingIdentity(identity); |
| 7627 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7628 | } |
| 7629 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7630 | /** |
| 7631 | * {@hide} |
| 7632 | * Returns the IMS Registration Status on a particular subid |
| 7633 | * |
| 7634 | * @param subId |
| 7635 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7636 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7637 | Phone phone = getPhone(subId); |
| 7638 | if (phone != null) { |
| 7639 | return phone.isImsRegistered(); |
| 7640 | } else { |
| 7641 | return false; |
| 7642 | } |
| 7643 | } |
| 7644 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7645 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7646 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7647 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7649 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7650 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7651 | } |
| 7652 | final long identity = Binder.clearCallingIdentity(); |
| 7653 | try { |
| 7654 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
| 7657 | } |
| 7658 | } |
| 7659 | |
| 7660 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7661 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7662 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7663 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7664 | mApp, |
| 7665 | subscriptionId, |
| 7666 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7667 | final long identity = Binder.clearCallingIdentity(); |
| 7668 | try { |
| 7669 | Phone phone = getPhone(subscriptionId); |
| 7670 | if (phone == null) { |
| 7671 | return null; |
| 7672 | } |
| 7673 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7674 | } finally { |
| 7675 | Binder.restoreCallingIdentity(identity); |
| 7676 | } |
| 7677 | } |
| 7678 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7679 | /** |
| 7680 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7681 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7682 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7683 | final long identity = Binder.clearCallingIdentity(); |
| 7684 | try { |
| 7685 | Phone phone = getPhone(subId); |
| 7686 | if (phone != null) { |
| 7687 | return phone.isWifiCallingEnabled(); |
| 7688 | } else { |
| 7689 | return false; |
| 7690 | } |
| 7691 | } finally { |
| 7692 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7693 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7694 | } |
| 7695 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7696 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7697 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7698 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7699 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | final long identity = Binder.clearCallingIdentity(); |
| 7701 | try { |
| 7702 | Phone phone = getPhone(subId); |
| 7703 | if (phone != null) { |
| 7704 | return phone.isVideoEnabled(); |
| 7705 | } else { |
| 7706 | return false; |
| 7707 | } |
| 7708 | } finally { |
| 7709 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7710 | } |
| 7711 | } |
| 7712 | |
| 7713 | /** |
| 7714 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7715 | * defined in {@link ImsRegistrationImplBase}. |
| 7716 | */ |
| 7717 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7718 | final long identity = Binder.clearCallingIdentity(); |
| 7719 | try { |
| 7720 | Phone phone = getPhone(subId); |
| 7721 | if (phone != null) { |
| 7722 | return phone.getImsRegistrationTech(); |
| 7723 | } else { |
| 7724 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7725 | } |
| 7726 | } finally { |
| 7727 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7728 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7729 | } |
| 7730 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7731 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7732 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7733 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7734 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7735 | return; |
| 7736 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7737 | Phone defaultPhone = getDefaultPhone(); |
| 7738 | if (defaultPhone != null) { |
| 7739 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7740 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7741 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7742 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7743 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7744 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7745 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7746 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7747 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7748 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7749 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7750 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7751 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7752 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7753 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7754 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7755 | // There has been issues when Sms raw table somehow stores orphan |
| 7756 | // fragments. They lead to garbled message when new fragments come |
| 7757 | // in and combined with those stale ones. In case this happens again, |
| 7758 | // user can reset all network settings which will clean up this table. |
| 7759 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7760 | // Clean up IMS settings as well here. |
| 7761 | int slotId = getSlotIndex(subId); |
| 7762 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7763 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7764 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7765 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7766 | if (defaultPhone == null) { |
| 7767 | return; |
| 7768 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7769 | // Erase modem config if erase modem on network setting is enabled. |
| 7770 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7771 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7772 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7773 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7774 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7775 | |
| 7776 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7777 | } finally { |
| 7778 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7779 | } |
| 7780 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7781 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7782 | @VisibleForTesting |
| 7783 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7784 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7785 | return; |
| 7786 | } |
| 7787 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7788 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7789 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7790 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7791 | "user=" + defaultNetworkType); |
| 7792 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7793 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7794 | defaultNetworkType, null); |
| 7795 | } |
| 7796 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7797 | private void cleanUpSmsRawTable(Context context) { |
| 7798 | ContentResolver resolver = context.getContentResolver(); |
| 7799 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7800 | resolver.delete(uri, null, null); |
| 7801 | } |
| 7802 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7803 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7804 | public String getSimLocaleForSubscriber(int subId) { |
| 7805 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7806 | final Phone phone = getPhone(subId); |
| 7807 | if (phone == null) { |
| 7808 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7809 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7810 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7811 | final long identity = Binder.clearCallingIdentity(); |
| 7812 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7813 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7814 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7815 | if (info == null) { |
| 7816 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7817 | return null; |
| 7818 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7820 | // preferences (EF-PL and EF-LI)... |
| 7821 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7823 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7824 | if (localeFromDefaultSim != null) { |
| 7825 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7826 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7827 | + localeFromDefaultSim); |
| 7828 | return localeFromDefaultSim.toLanguageTag(); |
| 7829 | } else { |
| 7830 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7831 | } |
| 7832 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7834 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7835 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7836 | // the SIM and carrier preferences does not include a country we add the country |
| 7837 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7838 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7839 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7840 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7841 | return mccLocale.toLanguageTag(); |
| 7842 | } |
| 7843 | |
| 7844 | if (DBG) log("No locale found - returning null"); |
| 7845 | return null; |
| 7846 | } finally { |
| 7847 | Binder.restoreCallingIdentity(identity); |
| 7848 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7849 | } |
| 7850 | |
| 7851 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7852 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7853 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7854 | } |
| 7855 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7856 | /** |
| 7857 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7858 | */ |
| 7859 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7860 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7861 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7862 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7863 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7864 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7865 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7866 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7867 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7868 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7869 | * representing the state of the modem. |
| 7870 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7871 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7872 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7873 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7874 | */ |
| 7875 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7876 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7877 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7878 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7879 | |
| 7880 | final long identity = Binder.clearCallingIdentity(); |
| 7881 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7882 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7885 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7886 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7887 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7888 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7889 | // less than total activity duration. |
| 7890 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7891 | if (info == null) { |
| 7892 | return false; |
| 7893 | } |
| 7894 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7895 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7896 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7897 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7898 | return (info.isValid() |
| 7899 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7900 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7901 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7902 | && (totalTxTimeMs <= activityDurationMs)); |
| 7903 | } |
| 7904 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7905 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7906 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7907 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7908 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7909 | |
| 7910 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7911 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7912 | } |
| 7913 | |
| 7914 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7915 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7916 | rat, |
| 7917 | freq, |
| 7918 | info.getReceiveTimeMillis(rat, freq) |
| 7919 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7920 | } |
| 7921 | |
| 7922 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7923 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7924 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7925 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7926 | |
| 7927 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7928 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7929 | } |
| 7930 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7931 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7932 | rat, |
| 7933 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7934 | } |
| 7935 | |
| 7936 | /** |
| 7937 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7938 | * @param info recent ModemActivityInfo |
| 7939 | */ |
| 7940 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7941 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7942 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7943 | boolean matched; |
| 7944 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7945 | matched = false; |
| 7946 | int rat = info.getSpecificInfoRat(i); |
| 7947 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7948 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7949 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7950 | //if it already exists |
| 7951 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7952 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7953 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7954 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7955 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7956 | updateLastModemActivityInfo(info, rat, freq); |
| 7957 | matched = true; |
| 7958 | } |
| 7959 | } else { |
| 7960 | updateLastModemActivityInfo(info, rat); |
| 7961 | matched = true; |
| 7962 | } |
| 7963 | } |
| 7964 | } |
| 7965 | |
| 7966 | if (!matched) { |
| 7967 | mDeltaSpecificInfo = |
| 7968 | new ActivityStatsTechSpecificInfo( |
| 7969 | rat, |
| 7970 | freq, |
| 7971 | info.getTransmitTimeMillis(rat, freq), |
| 7972 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7973 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7974 | } |
| 7975 | } |
| 7976 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7977 | mLastModemActivitySpecificInfo = |
| 7978 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7979 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7980 | |
| 7981 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7982 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7983 | info.getSleepTimeMillis() |
| 7984 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7985 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7986 | info.getIdleTimeMillis() |
| 7987 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7988 | } |
| 7989 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7990 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7991 | * Returns the service state information on specified subscription. |
| 7992 | */ |
| 7993 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7994 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7995 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7996 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7997 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7998 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7999 | return null; |
| 8000 | } |
| 8001 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8002 | boolean hasFinePermission = false; |
| 8003 | boolean hasCoarsePermission = false; |
| 8004 | if (!renounceFineLocationAccess) { |
| 8005 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 8006 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8007 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8008 | .setCallingPackage(callingPackage) |
| 8009 | .setCallingFeatureId(callingFeatureId) |
| 8010 | .setCallingPid(Binder.getCallingPid()) |
| 8011 | .setCallingUid(Binder.getCallingUid()) |
| 8012 | .setMethod("getServiceStateForSubscriber") |
| 8013 | .setLogAsInfo(true) |
| 8014 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 8015 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8016 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8017 | .build()); |
| 8018 | hasFinePermission = |
| 8019 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8020 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8021 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 8022 | if (!renounceCoarseLocationAccess) { |
| 8023 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 8024 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 8025 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 8026 | .setCallingPackage(callingPackage) |
| 8027 | .setCallingFeatureId(callingFeatureId) |
| 8028 | .setCallingPid(Binder.getCallingPid()) |
| 8029 | .setCallingUid(Binder.getCallingUid()) |
| 8030 | .setMethod("getServiceStateForSubscriber") |
| 8031 | .setLogAsInfo(true) |
| 8032 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 8033 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 8034 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 8035 | .build()); |
| 8036 | hasCoarsePermission = |
| 8037 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8038 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8039 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8040 | final Phone phone = getPhone(subId); |
| 8041 | if (phone == null) { |
| 8042 | return null; |
| 8043 | } |
| 8044 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8045 | final long identity = Binder.clearCallingIdentity(); |
| 8046 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8047 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8048 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8050 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8051 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8052 | Rlog.d(LOG_TAG, |
| 8053 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8054 | return null; |
| 8055 | } |
| 8056 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8057 | ServiceState ss = phone.getServiceState(); |
| 8058 | |
| 8059 | // Scrub out the location info in ServiceState depending on what level of access |
| 8060 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8061 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8062 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8063 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8064 | } finally { |
| 8065 | Binder.restoreCallingIdentity(identity); |
| 8066 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8067 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8068 | |
| 8069 | /** |
| 8070 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8071 | * |
| 8072 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8073 | * voicemail ringtone. |
| 8074 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8075 | * PhoneAccount. |
| 8076 | */ |
| 8077 | @Override |
| 8078 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8079 | final long identity = Binder.clearCallingIdentity(); |
| 8080 | try { |
| 8081 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8082 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8083 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8085 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8086 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8087 | } finally { |
| 8088 | Binder.restoreCallingIdentity(identity); |
| 8089 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8090 | } |
| 8091 | |
| 8092 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8093 | * Sets the per-account voicemail ringtone. |
| 8094 | * |
| 8095 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8096 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8097 | * |
| 8098 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8099 | * voicemail ringtone. |
| 8100 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8101 | * PhoneAccount. |
| 8102 | */ |
| 8103 | @Override |
| 8104 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8105 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8106 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8107 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8108 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8109 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8111 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8112 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8113 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8114 | |
| 8115 | final long identity = Binder.clearCallingIdentity(); |
| 8116 | try { |
| 8117 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8118 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8119 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8120 | } |
| 8121 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8124 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8128 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8129 | * |
| 8130 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8131 | * voicemail vibration setting. |
| 8132 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8133 | */ |
| 8134 | @Override |
| 8135 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8136 | final long identity = Binder.clearCallingIdentity(); |
| 8137 | try { |
| 8138 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8139 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8140 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8143 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8147 | } |
| 8148 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8149 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8150 | * Sets the per-account voicemail vibration. |
| 8151 | * |
| 8152 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8153 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8154 | * |
| 8155 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8156 | * voicemail vibration setting. |
| 8157 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8158 | * specific PhoneAccount. |
| 8159 | */ |
| 8160 | @Override |
| 8161 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8162 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8163 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8164 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8165 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8166 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8167 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8168 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8169 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8170 | } |
| 8171 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8172 | final long identity = Binder.clearCallingIdentity(); |
| 8173 | try { |
| 8174 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8175 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8176 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8177 | } |
| 8178 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8179 | } finally { |
| 8180 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8181 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8182 | } |
| 8183 | |
| 8184 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8185 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8186 | * |
| 8187 | * @throws SecurityException if the caller does not have the required permission |
| 8188 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8189 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8190 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8191 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8192 | } |
| 8193 | |
| 8194 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8195 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8196 | * permission. |
| 8197 | * |
| 8198 | * @throws SecurityException if the caller does not have the required permission |
| 8199 | */ |
| 8200 | private void enforceSendSmsPermission() { |
| 8201 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8202 | } |
| 8203 | |
| 8204 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8205 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8206 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8207 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8208 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8209 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8213 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | if (componentName == null) { |
| 8215 | throw new SecurityException( |
| 8216 | "Caller not current active visual voicemail package[null]"); |
| 8217 | } |
| 8218 | String vvmPackage = componentName.getPackageName(); |
| 8219 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8220 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8221 | } |
| 8222 | } finally { |
| 8223 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8224 | } |
| 8225 | } |
| 8226 | |
| 8227 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8228 | * Return the application ID for the app type. |
| 8229 | * |
| 8230 | * @param subId the subscription ID that this request applies to. |
| 8231 | * @param appType the uicc app type. |
| 8232 | * @return Application ID for specificied app type, or null if no uicc. |
| 8233 | */ |
| 8234 | @Override |
| 8235 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8236 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8237 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8238 | |
| 8239 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8240 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8241 | if (phone == null) { |
| 8242 | return null; |
| 8243 | } |
| 8244 | String aid = null; |
| 8245 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8246 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8247 | .getApplicationByType(appType).getAid(); |
| 8248 | } catch (Exception e) { |
| 8249 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8250 | } |
| 8251 | return aid; |
| 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8254 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8255 | } |
| 8256 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8257 | /** |
| 8258 | * Return the Electronic Serial Number. |
| 8259 | * |
| 8260 | * @param subId the subscription ID that this request applies to. |
| 8261 | * @return ESN or null if error. |
| 8262 | */ |
| 8263 | @Override |
| 8264 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8265 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8266 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8267 | |
| 8268 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8269 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8270 | if (phone == null) { |
| 8271 | return null; |
| 8272 | } |
| 8273 | String esn = null; |
| 8274 | try { |
| 8275 | esn = phone.getEsn(); |
| 8276 | } catch (Exception e) { |
| 8277 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8278 | } |
| 8279 | return esn; |
| 8280 | } finally { |
| 8281 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8282 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8283 | } |
| 8284 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8285 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8286 | * Return the Preferred Roaming List Version. |
| 8287 | * |
| 8288 | * @param subId the subscription ID that this request applies to. |
| 8289 | * @return PRLVersion or null if error. |
| 8290 | */ |
| 8291 | @Override |
| 8292 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8293 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8294 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8295 | |
| 8296 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8297 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8298 | if (phone == null) { |
| 8299 | return null; |
| 8300 | } |
| 8301 | String cdmaPrlVersion = null; |
| 8302 | try { |
| 8303 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8304 | } catch (Exception e) { |
| 8305 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8306 | } |
| 8307 | return cdmaPrlVersion; |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8310 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8311 | } |
| 8312 | |
| 8313 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8314 | * Get snapshot of Telephony histograms |
| 8315 | * @return List of Telephony histograms |
| 8316 | * @hide |
| 8317 | */ |
| 8318 | @Override |
| 8319 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8321 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8322 | |
| 8323 | final long identity = Binder.clearCallingIdentity(); |
| 8324 | try { |
| 8325 | return RIL.getTelephonyRILTimingHistograms(); |
| 8326 | } finally { |
| 8327 | Binder.restoreCallingIdentity(identity); |
| 8328 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8329 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8330 | |
| 8331 | /** |
| 8332 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8333 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8334 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8335 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8336 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8337 | * @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] | 8338 | */ |
| 8339 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8340 | @TelephonyManager.SetCarrierRestrictionResult |
| 8341 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8342 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8344 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8345 | if (carrierRestrictionRules == null) { |
| 8346 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8347 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8348 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8349 | final long identity = Binder.clearCallingIdentity(); |
| 8350 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8351 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8352 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8353 | } finally { |
| 8354 | Binder.restoreCallingIdentity(identity); |
| 8355 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8356 | } |
| 8357 | |
| 8358 | /** |
| 8359 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8360 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8361 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8362 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8363 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8364 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8365 | */ |
| 8366 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8367 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8368 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8369 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8370 | |
| 8371 | final long identity = Binder.clearCallingIdentity(); |
| 8372 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8373 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8374 | if (response instanceof CarrierRestrictionRules) { |
| 8375 | return (CarrierRestrictionRules) response; |
| 8376 | } |
| 8377 | // Response is an Exception of some kind, |
| 8378 | // which is signalled to the user as a NULL retval |
| 8379 | return null; |
| 8380 | } catch (Exception e) { |
| 8381 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8382 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | } finally { |
| 8384 | Binder.restoreCallingIdentity(identity); |
| 8385 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8386 | } |
| 8387 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8388 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8389 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8390 | * @param subId the subscription ID that this action applies to. |
| 8391 | * @param enabled control enable or disable radio. |
| 8392 | * {@hide} |
| 8393 | */ |
| 8394 | @Override |
| 8395 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8396 | enforceModifyPermission(); |
| 8397 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8398 | |
| 8399 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8400 | if (phone == null) { |
| 8401 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8402 | return; |
| 8403 | } |
| 8404 | try { |
| 8405 | phone.carrierActionSetRadioEnabled(enabled); |
| 8406 | } catch (Exception e) { |
| 8407 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8408 | } finally { |
| 8409 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8410 | } |
| 8411 | } |
| 8412 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8413 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8414 | * Enable or disable Voice over NR (VoNR) |
| 8415 | * @param subId the subscription ID that this action applies to. |
| 8416 | * @param enabled enable or disable VoNR. |
| 8417 | * @return operation result. |
| 8418 | */ |
| 8419 | @Override |
| 8420 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8421 | enforceModifyPermission(); |
| 8422 | final Phone phone = getPhone(subId); |
| 8423 | |
| 8424 | final long identity = Binder.clearCallingIdentity(); |
| 8425 | if (phone == null) { |
| 8426 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8427 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8428 | } |
| 8429 | |
| 8430 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8431 | try { |
| 8432 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8433 | workSource); |
| 8434 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8435 | |
| 8436 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8437 | if (DBG) { |
| 8438 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8439 | } |
| 8440 | SubscriptionManager.setSubscriptionProperty( |
| 8441 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8442 | (enabled ? "1" : "0")); |
| 8443 | } |
| 8444 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8445 | return result; |
| 8446 | } finally { |
| 8447 | Binder.restoreCallingIdentity(identity); |
| 8448 | } |
| 8449 | } |
| 8450 | |
| 8451 | /** |
| 8452 | * Is voice over NR enabled |
| 8453 | * @return true if VoNR is enabled else false |
| 8454 | */ |
| 8455 | @Override |
| 8456 | public boolean isVoNrEnabled(int subId) { |
| 8457 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8458 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8459 | final long identity = Binder.clearCallingIdentity(); |
| 8460 | try { |
| 8461 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8462 | null, subId, workSource); |
| 8463 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8464 | return isEnabled; |
| 8465 | } finally { |
| 8466 | Binder.restoreCallingIdentity(identity); |
| 8467 | } |
| 8468 | } |
| 8469 | |
| 8470 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8471 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8472 | * network status based on which carrier apps could apply actions accordingly, |
| 8473 | * enable/disable default url handler for example. |
| 8474 | * |
| 8475 | * @param subId the subscription ID that this action applies to. |
| 8476 | * @param report control start/stop reporting the default network status. |
| 8477 | * {@hide} |
| 8478 | */ |
| 8479 | @Override |
| 8480 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8481 | enforceModifyPermission(); |
| 8482 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8483 | |
| 8484 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8485 | if (phone == null) { |
| 8486 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8487 | return; |
| 8488 | } |
| 8489 | try { |
| 8490 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8491 | } catch (Exception e) { |
| 8492 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8493 | } finally { |
| 8494 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8495 | } |
| 8496 | } |
| 8497 | |
| 8498 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8499 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8500 | * @param subId the subscription ID that this action applies to. |
| 8501 | * {@hide} |
| 8502 | */ |
| 8503 | @Override |
| 8504 | public void carrierActionResetAll(int subId) { |
| 8505 | enforceModifyPermission(); |
| 8506 | final Phone phone = getPhone(subId); |
| 8507 | if (phone == null) { |
| 8508 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8509 | return; |
| 8510 | } |
| 8511 | try { |
| 8512 | phone.carrierActionResetAll(); |
| 8513 | } catch (Exception e) { |
| 8514 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8519 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8520 | * bug report is being generated. |
| 8521 | */ |
| 8522 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8523 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8524 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8525 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8526 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8527 | + Binder.getCallingPid() |
| 8528 | + ", uid=" + Binder.getCallingUid() |
| 8529 | + "without permission " |
| 8530 | + android.Manifest.permission.DUMP); |
| 8531 | return; |
| 8532 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8533 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8534 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8535 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8536 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8537 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8538 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8539 | @NonNull String[] args) { |
| 8540 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8541 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8542 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8543 | } |
| 8544 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8545 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8546 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8547 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8548 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8549 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8550 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8551 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8552 | */ |
| 8553 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8554 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8555 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8556 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8557 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8558 | try { |
| 8559 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8560 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8561 | } catch (SecurityException se) { |
| 8562 | enforceModifyPermission(); |
| 8563 | } |
| 8564 | } else { |
| 8565 | enforceModifyPermission(); |
| 8566 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8567 | |
| 8568 | final long identity = Binder.clearCallingIdentity(); |
| 8569 | try { |
| 8570 | Phone phone = getPhone(subId); |
| 8571 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8572 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8573 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8574 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8575 | phone.getDataSettingsManager().setDataEnabled( |
| 8576 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8578 | } |
| 8579 | } finally { |
| 8580 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8581 | } |
| 8582 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8583 | |
| 8584 | /** |
| 8585 | * Get Client request stats |
| 8586 | * @return List of Client Request Stats |
| 8587 | * @hide |
| 8588 | */ |
| 8589 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8590 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8591 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8592 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8593 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8594 | return null; |
| 8595 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8596 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | if (phone != null) { |
| 8601 | return phone.getClientRequestStats(); |
| 8602 | } |
| 8603 | |
| 8604 | return null; |
| 8605 | } finally { |
| 8606 | Binder.restoreCallingIdentity(identity); |
| 8607 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8608 | } |
| 8609 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8610 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8611 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8612 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8613 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8614 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8615 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8616 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8617 | // commands that plumb through the RIL as root, like so: |
| 8618 | // $ adb root |
| 8619 | // $ adb shell cmd phone ... |
| 8620 | packageName = "root"; |
| 8621 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8622 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8623 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8624 | |
| 8625 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8626 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8627 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8628 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8629 | * @param state State of SIM (power down, power up, pass through) |
| 8630 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8631 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8632 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8633 | * |
| 8634 | **/ |
| 8635 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8636 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8637 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8638 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8639 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8640 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8641 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8645 | phone.setSimPowerState(state, null, workSource); |
| 8646 | } |
| 8647 | } finally { |
| 8648 | Binder.restoreCallingIdentity(identity); |
| 8649 | } |
| 8650 | } |
| 8651 | |
| 8652 | /** |
| 8653 | * Set SIM card power state. |
| 8654 | * |
| 8655 | * @param slotIndex SIM slot id. |
| 8656 | * @param state State of SIM (power down, power up, pass through) |
| 8657 | * @param callback callback to trigger after success or failure |
| 8658 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8659 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8660 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8661 | * |
| 8662 | **/ |
| 8663 | @Override |
| 8664 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8665 | IIntegerConsumer callback) { |
| 8666 | enforceModifyPermission(); |
| 8667 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8668 | |
| 8669 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8670 | |
| 8671 | final long identity = Binder.clearCallingIdentity(); |
| 8672 | try { |
| 8673 | if (phone != null) { |
| 8674 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8675 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8676 | } |
| 8677 | } finally { |
| 8678 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8679 | } |
| 8680 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8681 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8682 | private boolean isUssdApiAllowed(int subId) { |
| 8683 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8684 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8685 | if (configManager == null) { |
| 8686 | return false; |
| 8687 | } |
| 8688 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8689 | if (pb == null) { |
| 8690 | return false; |
| 8691 | } |
| 8692 | return pb.getBoolean( |
| 8693 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8694 | } |
| 8695 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8696 | /** |
| 8697 | * Check if phone is in emergency callback mode |
| 8698 | * @return true if phone is in emergency callback mode |
| 8699 | * @param subId sub id |
| 8700 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8701 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8702 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8703 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8704 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8705 | |
| 8706 | final long identity = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | if (phone != null) { |
| 8709 | return phone.isInEcm(); |
| 8710 | } else { |
| 8711 | return false; |
| 8712 | } |
| 8713 | } finally { |
| 8714 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8715 | } |
| 8716 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8717 | |
| 8718 | /** |
| 8719 | * Get the current signal strength information for the given subscription. |
| 8720 | * Because this information is not updated when the device is in a low power state |
| 8721 | * it should not be relied-upon to be current. |
| 8722 | * @param subId Subscription index |
| 8723 | * @return the most recent cached signal strength info from the modem |
| 8724 | */ |
| 8725 | @Override |
| 8726 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8727 | final long identity = Binder.clearCallingIdentity(); |
| 8728 | try { |
| 8729 | Phone p = getPhone(subId); |
| 8730 | if (p == null) { |
| 8731 | return null; |
| 8732 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8734 | return p.getSignalStrength(); |
| 8735 | } finally { |
| 8736 | Binder.restoreCallingIdentity(identity); |
| 8737 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8738 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8739 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8740 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8741 | * Get the current modem radio state for the given slot. |
| 8742 | * @param slotIndex slot index. |
| 8743 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8744 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8745 | * @return the current radio power state from the modem |
| 8746 | */ |
| 8747 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8748 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8749 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8750 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8751 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8752 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8753 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8754 | } |
| 8755 | |
| 8756 | final long identity = Binder.clearCallingIdentity(); |
| 8757 | try { |
| 8758 | return phone.getRadioPowerState(); |
| 8759 | } finally { |
| 8760 | Binder.restoreCallingIdentity(identity); |
| 8761 | } |
| 8762 | } |
| 8763 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8764 | } |
| 8765 | |
| 8766 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8767 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8768 | * |
| 8769 | * <p>Requires one of the following permissions: |
| 8770 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8771 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8772 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8773 | * privileges. |
| 8774 | * |
| 8775 | * @param subId subscription id |
| 8776 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8777 | * {@code false}. |
| 8778 | */ |
| 8779 | @Override |
| 8780 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8781 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8782 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8783 | try { |
| 8784 | mApp.enforceCallingOrSelfPermission( |
| 8785 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8786 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8787 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8788 | mApp.enforceCallingOrSelfPermission( |
| 8789 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8790 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8791 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8792 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8793 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8794 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8795 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8796 | boolean isEnabled = false; |
| 8797 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8798 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8799 | Phone phone = getPhone(subId); |
| 8800 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8801 | } finally { |
| 8802 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8803 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8804 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8805 | } |
| 8806 | |
| 8807 | |
| 8808 | /** |
| 8809 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8810 | * |
| 8811 | * <p> Requires permission: |
| 8812 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8813 | * privileges. |
| 8814 | * |
| 8815 | * @param subId subscription id |
| 8816 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8817 | */ |
| 8818 | @Override |
| 8819 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8821 | mApp, subId, "setDataRoamingEnabled"); |
| 8822 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8823 | final long identity = Binder.clearCallingIdentity(); |
| 8824 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8825 | Phone phone = getPhone(subId); |
| 8826 | if (phone != null) { |
| 8827 | phone.setDataRoamingEnabled(isEnabled); |
| 8828 | } |
| 8829 | } finally { |
| 8830 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8831 | } |
| 8832 | } |
| 8833 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8834 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8835 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8836 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8837 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8838 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8839 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8840 | boolean isAllowed = true; |
| 8841 | final long identity = Binder.clearCallingIdentity(); |
| 8842 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8843 | Phone phone = getPhone(subId); |
| 8844 | if (phone != null) { |
| 8845 | isAllowed = phone.isCspPlmnEnabled(); |
| 8846 | } |
| 8847 | } finally { |
| 8848 | Binder.restoreCallingIdentity(identity); |
| 8849 | } |
| 8850 | return isAllowed; |
| 8851 | } |
| 8852 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8853 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8854 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8855 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8856 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8857 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8858 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8859 | if (phone == null) { |
| 8860 | return false; |
| 8861 | } |
| 8862 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8863 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8864 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8865 | } |
| 8866 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8867 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8868 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8869 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8870 | mApp.getSystemService(AppOpsManager.class) |
| 8871 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8872 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8873 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8874 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8875 | try { |
| 8876 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8877 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8878 | } catch (SecurityException e) { |
| 8879 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8880 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8881 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8882 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8883 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8884 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8885 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8886 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8887 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8888 | Binder.getCallingUid())) { |
| 8889 | isIccIdAccessRestricted = true; |
| 8890 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8891 | final long identity = Binder.clearCallingIdentity(); |
| 8892 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8893 | UiccController uiccController = UiccController.getInstance(); |
| 8894 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8895 | if (hasReadPermission) { |
| 8896 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8897 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8898 | |
| 8899 | // Remove private info if the caller doesn't have access |
| 8900 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8901 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8902 | //setting the value after compatibility check |
| 8903 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8904 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8905 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8906 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8907 | if (card == null) { |
| 8908 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8909 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8910 | continue; |
| 8911 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8912 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8913 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8914 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8915 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8916 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8917 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8918 | for (UiccPortInfo portInfo : portInfos) { |
| 8919 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8920 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8921 | if (port == null) { |
| 8922 | // assume no access if port is null |
| 8923 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8924 | continue; |
| 8925 | } |
| 8926 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8927 | uiccPortInfos.add(portInfo); |
| 8928 | } else { |
| 8929 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8930 | } |
| 8931 | } |
| 8932 | filteredInfos.add(new UiccCardInfo( |
| 8933 | cardInfo.isEuicc(), |
| 8934 | cardInfo.getCardId(), |
| 8935 | null, |
| 8936 | cardInfo.getPhysicalSlotIndex(), |
| 8937 | cardInfo.isRemovable(), |
| 8938 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8939 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8940 | } |
| 8941 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8942 | } finally { |
| 8943 | Binder.restoreCallingIdentity(identity); |
| 8944 | } |
| 8945 | } |
| 8946 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8947 | /** |
| 8948 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8949 | * generally private and require carrier privileges to view. |
| 8950 | * |
| 8951 | * @hide |
| 8952 | */ |
| 8953 | @NonNull |
| 8954 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8955 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8956 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8957 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8958 | } |
| 8959 | return new UiccCardInfo( |
| 8960 | cardInfo.isEuicc(), |
| 8961 | cardInfo.getCardId(), |
| 8962 | null, |
| 8963 | cardInfo.getPhysicalSlotIndex(), |
| 8964 | cardInfo.isRemovable(), |
| 8965 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8966 | portinfo |
| 8967 | ); |
| 8968 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8969 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8970 | /** |
| 8971 | * @hide |
| 8972 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8973 | * These values are generally private and require carrier privileges to view. |
| 8974 | */ |
| 8975 | @NonNull |
| 8976 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8977 | return new UiccPortInfo( |
| 8978 | UiccPortInfo.ICCID_REDACTED, |
| 8979 | portInfo.getPortIndex(), |
| 8980 | portInfo.getLogicalSlotIndex(), |
| 8981 | portInfo.isActive() |
| 8982 | ); |
| 8983 | } |
| 8984 | @Override |
| 8985 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8986 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8987 | mApp.getSystemService(AppOpsManager.class) |
| 8988 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8989 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8990 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8991 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8992 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8993 | // we are reading iccId which is PII data. |
| 8994 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8995 | |
| 8996 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8997 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8998 | Binder.getCallingUid())) { |
| 8999 | isLogicalSlotAccessRestricted = true; |
| 9000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9001 | final long identity = Binder.clearCallingIdentity(); |
| 9002 | try { |
| 9003 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 9004 | if (slots == null || slots.length == 0) { |
| 9005 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9006 | return null; |
| 9007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9008 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 9009 | for (int i = 0; i < slots.length; i++) { |
| 9010 | UiccSlot slot = slots[i]; |
| 9011 | if (slot == null) { |
| 9012 | continue; |
| 9013 | } |
| 9014 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9015 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9016 | UiccCard card = slot.getUiccCard(); |
| 9017 | if (card != null) { |
| 9018 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 9019 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9020 | cardId = slot.getEid(); |
| 9021 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9022 | // If cardId is null, use iccId of default port as cardId. |
| 9023 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 9024 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9025 | } |
| 9026 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 9027 | if (cardId != null) { |
| 9028 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 9029 | // if cardId is an EID, it's all digits so this is fine |
| 9030 | cardId = IccUtils.stripTrailingFs(cardId); |
| 9031 | } |
| 9032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9033 | int cardState = 0; |
| 9034 | switch (slot.getCardState()) { |
| 9035 | case CARDSTATE_ABSENT: |
| 9036 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9037 | break; |
| 9038 | case CARDSTATE_PRESENT: |
| 9039 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9040 | break; |
| 9041 | case CARDSTATE_ERROR: |
| 9042 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9043 | break; |
| 9044 | case CARDSTATE_RESTRICTED: |
| 9045 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9046 | break; |
| 9047 | default: |
| 9048 | break; |
| 9049 | |
| 9050 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9051 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9052 | int[] portIndexes = slot.getPortList(); |
| 9053 | for (int portIdx : portIndexes) { |
| 9054 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9055 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9056 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9057 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9058 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9059 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9060 | slot.isEuicc(), |
| 9061 | cardId, |
| 9062 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9063 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9064 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9065 | //setting the value after compatibility check |
| 9066 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9067 | } |
| 9068 | return infos; |
| 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9071 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9072 | } |
| 9073 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9074 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9075 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9076 | boolean hasReadPermission) { |
| 9077 | String iccId = slot.getIccId(portIndex); |
| 9078 | if (hasReadPermission) { // if has read permission |
| 9079 | return iccId; |
| 9080 | } else { |
| 9081 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9082 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9083 | // if no read permission, checking carrier privilege access |
| 9084 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9085 | return iccId; |
| 9086 | } |
| 9087 | } |
| 9088 | } |
| 9089 | // No read permission or carrier privilege access. |
| 9090 | return UiccPortInfo.ICCID_REDACTED; |
| 9091 | } |
| 9092 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9093 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9094 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9095 | public boolean switchSlots(int[] physicalSlots) { |
| 9096 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9097 | |
| 9098 | final long identity = Binder.clearCallingIdentity(); |
| 9099 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9100 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9101 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9102 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9103 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9104 | physicalSlots[i], i)); |
| 9105 | } |
| 9106 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9107 | } finally { |
| 9108 | Binder.restoreCallingIdentity(identity); |
| 9109 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9110 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9111 | |
| 9112 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9113 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9114 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9115 | enforceModifyPermission(); |
| 9116 | |
| 9117 | final long identity = Binder.clearCallingIdentity(); |
| 9118 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9119 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9120 | } finally { |
| 9121 | Binder.restoreCallingIdentity(identity); |
| 9122 | } |
| 9123 | } |
| 9124 | |
| 9125 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9126 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9127 | final long identity = Binder.clearCallingIdentity(); |
| 9128 | try { |
| 9129 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9130 | } finally { |
| 9131 | Binder.restoreCallingIdentity(identity); |
| 9132 | } |
| 9133 | } |
| 9134 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9135 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9136 | * A test API to reload the UICC profile. |
| 9137 | * |
| 9138 | * <p>Requires that the calling app has permission |
| 9139 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9140 | * @hide |
| 9141 | */ |
| 9142 | @Override |
| 9143 | public void refreshUiccProfile(int subId) { |
| 9144 | enforceModifyPermission(); |
| 9145 | |
| 9146 | final long identity = Binder.clearCallingIdentity(); |
| 9147 | try { |
| 9148 | Phone phone = getPhone(subId); |
| 9149 | if (phone == null) { |
| 9150 | return; |
| 9151 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9152 | UiccPort uiccPort = phone.getUiccPort(); |
| 9153 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9154 | return; |
| 9155 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9156 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9157 | if (uiccProfile == null) { |
| 9158 | return; |
| 9159 | } |
| 9160 | uiccProfile.refresh(); |
| 9161 | } finally { |
| 9162 | Binder.restoreCallingIdentity(identity); |
| 9163 | } |
| 9164 | } |
| 9165 | |
| 9166 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9167 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9168 | */ |
| 9169 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9170 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9171 | } |
| 9172 | |
| 9173 | /** |
| 9174 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9175 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9176 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9177 | */ |
| 9178 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9179 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9180 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9181 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9182 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9183 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9184 | return isDataRoamingEnabled; |
| 9185 | } |
| 9186 | |
| 9187 | /** |
| 9188 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9189 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9190 | */ |
| 9191 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9192 | List<Integer> list = TelephonyProperties.default_network(); |
| 9193 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9194 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9195 | return list.get(phoneId); |
| 9196 | } |
| 9197 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9198 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9199 | |
| 9200 | @Override |
| 9201 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9202 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9204 | |
| 9205 | final long identity = Binder.clearCallingIdentity(); |
| 9206 | try { |
| 9207 | final Phone phone = getPhone(subId); |
| 9208 | if (phone == null) { |
| 9209 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9210 | return; |
| 9211 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9212 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9213 | if (cpt != null) { |
| 9214 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9215 | } |
| 9216 | // 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] | 9217 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9218 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9219 | if (carrierPrivilegeRules == null) { |
| 9220 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9221 | } else { |
| 9222 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9223 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9224 | } finally { |
| 9225 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9226 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9227 | } |
| 9228 | |
| 9229 | @Override |
| 9230 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9231 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9232 | |
| 9233 | final long identity = Binder.clearCallingIdentity(); |
| 9234 | try { |
| 9235 | final Phone phone = getPhone(subId); |
| 9236 | if (phone == null) { |
| 9237 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9238 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9239 | } |
| 9240 | return phone.getCarrierIdListVersion(); |
| 9241 | } finally { |
| 9242 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9243 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9244 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9245 | |
| 9246 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9247 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9248 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9249 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9250 | mApp, subId, callingPackage, callingFeatureId, |
| 9251 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9252 | return -1; |
| 9253 | } |
| 9254 | |
| 9255 | final long identity = Binder.clearCallingIdentity(); |
| 9256 | try { |
| 9257 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
| 9260 | } |
| 9261 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9262 | |
| 9263 | @Override |
| 9264 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9265 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9266 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9267 | mApp, subId, "getCdmaRoamingMode"); |
| 9268 | |
| 9269 | final long identity = Binder.clearCallingIdentity(); |
| 9270 | try { |
| 9271 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9272 | } finally { |
| 9273 | Binder.restoreCallingIdentity(identity); |
| 9274 | } |
| 9275 | } |
| 9276 | |
| 9277 | @Override |
| 9278 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9279 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9280 | mApp, subId, "setCdmaRoamingMode"); |
| 9281 | |
| 9282 | final long identity = Binder.clearCallingIdentity(); |
| 9283 | try { |
| 9284 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9285 | } finally { |
| 9286 | Binder.restoreCallingIdentity(identity); |
| 9287 | } |
| 9288 | } |
| 9289 | |
| 9290 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9291 | public int getCdmaSubscriptionMode(int subId) { |
| 9292 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9293 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9294 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9295 | |
| 9296 | final long identity = Binder.clearCallingIdentity(); |
| 9297 | try { |
| 9298 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9299 | } finally { |
| 9300 | Binder.restoreCallingIdentity(identity); |
| 9301 | } |
| 9302 | } |
| 9303 | |
| 9304 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9305 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9307 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9308 | |
| 9309 | final long identity = Binder.clearCallingIdentity(); |
| 9310 | try { |
| 9311 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9312 | } finally { |
| 9313 | Binder.restoreCallingIdentity(identity); |
| 9314 | } |
| 9315 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9316 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9317 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9318 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9319 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9320 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9321 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9322 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9323 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9324 | } |
| 9325 | final long identity = Binder.clearCallingIdentity(); |
| 9326 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9327 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9328 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9329 | if (phone.getEmergencyNumberTracker() != null |
| 9330 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9331 | emergencyNumberListInternal.put( |
| 9332 | phone.getSubId(), |
| 9333 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9334 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9335 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9336 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9337 | } finally { |
| 9338 | Binder.restoreCallingIdentity(identity); |
| 9339 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9340 | } |
| 9341 | |
| 9342 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9343 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9344 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9345 | if (!exactMatch) { |
| 9346 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9347 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9348 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9349 | } |
| 9350 | final long identity = Binder.clearCallingIdentity(); |
| 9351 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9352 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9353 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9354 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9355 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9356 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9357 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9358 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9359 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9360 | } |
| 9361 | return false; |
| 9362 | } finally { |
| 9363 | Binder.restoreCallingIdentity(identity); |
| 9364 | } |
| 9365 | } |
| 9366 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9367 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9368 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9369 | */ |
| 9370 | @Override |
| 9371 | public void startEmergencyCallbackMode() { |
| 9372 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9373 | "startEmergencyCallbackMode"); |
| 9374 | enforceModifyPermission(); |
| 9375 | final long identity = Binder.clearCallingIdentity(); |
| 9376 | try { |
| 9377 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9378 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9379 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9380 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9381 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9382 | gsmCdmaPhone.obtainMessage( |
| 9383 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9384 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9385 | } |
| 9386 | } |
| 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
| 9389 | } |
| 9390 | } |
| 9391 | |
| 9392 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9393 | * Update emergency number list for test mode. |
| 9394 | */ |
| 9395 | @Override |
| 9396 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9397 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9398 | "updateEmergencyNumberListTestMode"); |
| 9399 | |
| 9400 | final long identity = Binder.clearCallingIdentity(); |
| 9401 | try { |
| 9402 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9403 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9404 | if (tracker != null) { |
| 9405 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9406 | } |
| 9407 | } |
| 9408 | } finally { |
| 9409 | Binder.restoreCallingIdentity(identity); |
| 9410 | } |
| 9411 | } |
| 9412 | |
| 9413 | /** |
| 9414 | * Get the full emergency number list for test mode. |
| 9415 | */ |
| 9416 | @Override |
| 9417 | public List<String> getEmergencyNumberListTestMode() { |
| 9418 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9419 | "getEmergencyNumberListTestMode"); |
| 9420 | |
| 9421 | final long identity = Binder.clearCallingIdentity(); |
| 9422 | try { |
| 9423 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9424 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9425 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9426 | if (tracker != null) { |
| 9427 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9428 | emergencyNumbers.add(num.getNumber()); |
| 9429 | } |
| 9430 | } |
| 9431 | } |
| 9432 | return new ArrayList<>(emergencyNumbers); |
| 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
| 9437 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9438 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9439 | public int getEmergencyNumberDbVersion(int subId) { |
| 9440 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9441 | |
| 9442 | final long identity = Binder.clearCallingIdentity(); |
| 9443 | try { |
| 9444 | final Phone phone = getPhone(subId); |
| 9445 | if (phone == null) { |
| 9446 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9447 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9448 | } |
| 9449 | return phone.getEmergencyNumberDbVersion(); |
| 9450 | } finally { |
| 9451 | Binder.restoreCallingIdentity(identity); |
| 9452 | } |
| 9453 | } |
| 9454 | |
| 9455 | @Override |
| 9456 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9457 | enforceModifyPermission(); |
| 9458 | |
| 9459 | final long identity = Binder.clearCallingIdentity(); |
| 9460 | try { |
| 9461 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9462 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9463 | if (tracker != null) { |
| 9464 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9465 | } |
| 9466 | } |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
| 9472 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9473 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9474 | enforceActiveEmergencySessionPermission(); |
| 9475 | |
| 9476 | final long identity = Binder.clearCallingIdentity(); |
| 9477 | try { |
| 9478 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9479 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9480 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9481 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9482 | } |
| 9483 | } |
| 9484 | } finally { |
| 9485 | Binder.restoreCallingIdentity(identity); |
| 9486 | } |
| 9487 | } |
| 9488 | |
| 9489 | @Override |
| 9490 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9491 | enforceActiveEmergencySessionPermission(); |
| 9492 | |
| 9493 | final long identity = Binder.clearCallingIdentity(); |
| 9494 | try { |
| 9495 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9496 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9497 | if (tracker != null) { |
| 9498 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9499 | } |
| 9500 | } |
| 9501 | } finally { |
| 9502 | Binder.restoreCallingIdentity(identity); |
| 9503 | } |
| 9504 | } |
| 9505 | |
| 9506 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9507 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9508 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9509 | Phone phone = getPhone(subId); |
| 9510 | if (phone == null) { |
| 9511 | return null; |
| 9512 | } |
| 9513 | final long identity = Binder.clearCallingIdentity(); |
| 9514 | try { |
| 9515 | UiccProfile profile = UiccController.getInstance() |
| 9516 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9517 | if (profile != null) { |
| 9518 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9519 | } |
| 9520 | } finally { |
| 9521 | Binder.restoreCallingIdentity(identity); |
| 9522 | } |
| 9523 | return null; |
| 9524 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9525 | |
| 9526 | /** |
| 9527 | * Enable or disable a modem stack. |
| 9528 | */ |
| 9529 | @Override |
| 9530 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9531 | enforceModifyPermission(); |
| 9532 | |
| 9533 | final long identity = Binder.clearCallingIdentity(); |
| 9534 | try { |
| 9535 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9536 | if (phone == null) { |
| 9537 | return false; |
| 9538 | } else { |
| 9539 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9540 | } |
| 9541 | } finally { |
| 9542 | Binder.restoreCallingIdentity(identity); |
| 9543 | } |
| 9544 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9545 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9546 | /** |
| 9547 | * Whether a modem stack is enabled or not. |
| 9548 | */ |
| 9549 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9550 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9551 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9552 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9553 | if (phone == null) return false; |
| 9554 | |
| 9555 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9556 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9557 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9558 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9559 | } |
| 9560 | |
| 9561 | final long identity = Binder.clearCallingIdentity(); |
| 9562 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9563 | try { |
| 9564 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9565 | } catch (NoSuchElementException ex) { |
| 9566 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9567 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9568 | } finally { |
| 9569 | Binder.restoreCallingIdentity(identity); |
| 9570 | } |
| 9571 | } |
| 9572 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9573 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9574 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9575 | enforceModifyPermission(); |
| 9576 | |
| 9577 | final long identity = Binder.clearCallingIdentity(); |
| 9578 | try { |
| 9579 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9580 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9581 | .commit(); |
| 9582 | } finally { |
| 9583 | Binder.restoreCallingIdentity(identity); |
| 9584 | } |
| 9585 | } |
| 9586 | |
| 9587 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9588 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9589 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9590 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9591 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9592 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9593 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9594 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9595 | |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9598 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9599 | } finally { |
| 9600 | Binder.restoreCallingIdentity(identity); |
| 9601 | } |
| 9602 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9603 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9604 | @TelephonyManager.IsMultiSimSupportedResult |
| 9605 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9606 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9607 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9608 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9609 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9610 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9611 | } |
| 9612 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9613 | // supported by the modem, indicate that it is restricted. |
| 9614 | PhoneCapability staticCapability = |
| 9615 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9616 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9617 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9618 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9619 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9620 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9621 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9622 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9623 | } |
| 9624 | // Check if support of multiple SIMs is restricted by carrier |
| 9625 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9626 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9627 | } |
| 9628 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9629 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9630 | } |
| 9631 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9632 | /** |
| 9633 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9634 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9635 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9636 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9637 | * @param numOfSims number of active sims we want to switch to |
| 9638 | */ |
| 9639 | @Override |
| 9640 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9641 | if (numOfSims == 1) { |
| 9642 | enforceModifyPermission(); |
| 9643 | } else { |
| 9644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9645 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9646 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9647 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9648 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9649 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9650 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9651 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9652 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9653 | return; |
| 9654 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9655 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9656 | } finally { |
| 9657 | Binder.restoreCallingIdentity(identity); |
| 9658 | } |
| 9659 | } |
| 9660 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9661 | @Override |
| 9662 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9663 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9664 | Phone phone = getPhone(subId); |
| 9665 | if (phone == null) { |
| 9666 | return false; |
| 9667 | } |
| 9668 | final long identity = Binder.clearCallingIdentity(); |
| 9669 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9670 | UiccPort uiccPort = phone.getUiccPort(); |
| 9671 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9672 | return false; |
| 9673 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9674 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9675 | if (uiccProfile == null) { |
| 9676 | return false; |
| 9677 | } |
| 9678 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9679 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9680 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9681 | } |
| 9682 | return false; |
| 9683 | } finally { |
| 9684 | Binder.restoreCallingIdentity(identity); |
| 9685 | } |
| 9686 | } |
| 9687 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9688 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9689 | * Get whether making changes to modem configurations will trigger reboot. |
| 9690 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9691 | */ |
| 9692 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9693 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9694 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9695 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9696 | mApp, subId, callingPackage, callingFeatureId, |
| 9697 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9698 | return false; |
| 9699 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9700 | final long identity = Binder.clearCallingIdentity(); |
| 9701 | try { |
| 9702 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9703 | } finally { |
| 9704 | Binder.restoreCallingIdentity(identity); |
| 9705 | } |
| 9706 | } |
| 9707 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9708 | private void updateModemStateMetrics() { |
| 9709 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9710 | // TODO: check the state for each modem if the api is ready. |
| 9711 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9712 | } |
| 9713 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9714 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9715 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9716 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9717 | // Verify that the callingPackage belongs to the calling UID |
| 9718 | mApp.getSystemService(AppOpsManager.class) |
| 9719 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9720 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9721 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9722 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9723 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9724 | if (slotInfos != null) { |
| 9725 | for (int i = 0; i < slotInfos.length; i++) { |
| 9726 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9727 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9728 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9729 | portInfo.getLogicalSlotIndex())); |
| 9730 | } |
| 9731 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9732 | } |
| 9733 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9734 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9735 | } finally { |
| 9736 | Binder.restoreCallingIdentity(identity); |
| 9737 | } |
| 9738 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9739 | |
| 9740 | /** |
| 9741 | * Get the IRadio HAL Version |
| 9742 | */ |
| 9743 | @Override |
| 9744 | public int getRadioHalVersion() { |
| 9745 | Phone phone = getDefaultPhone(); |
| 9746 | if (phone == null) return -1; |
| 9747 | HalVersion hv = phone.getHalVersion(); |
| 9748 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9749 | return hv.major * 100 + hv.minor; |
| 9750 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9751 | |
| 9752 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9753 | * Get the current calling package name. |
| 9754 | * @return the current calling package name |
| 9755 | */ |
| 9756 | @Override |
| 9757 | public String getCurrentPackageName() { |
| 9758 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9759 | } |
| 9760 | |
| 9761 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9762 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9763 | * corresponding network requests on a subId. |
| 9764 | * |
| 9765 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9766 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9767 | * 2) APN is un-metered for this subscription, or |
| 9768 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9769 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9770 | * |
| 9771 | * @return whether data is allowed for a apn type. |
| 9772 | * |
| 9773 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9774 | */ |
| 9775 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9776 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9777 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9778 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9779 | |
| 9780 | // Now that all security checks passes, perform the operation as ourselves. |
| 9781 | final long identity = Binder.clearCallingIdentity(); |
| 9782 | try { |
| 9783 | Phone phone = getPhone(subId); |
| 9784 | if (phone == null) return false; |
| 9785 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9786 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9787 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9788 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9789 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9790 | phone.getServiceState().getDataRoaming()); |
| 9791 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9792 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9793 | } finally { |
| 9794 | Binder.restoreCallingIdentity(identity); |
| 9795 | } |
| 9796 | } |
| 9797 | |
| 9798 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9799 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9800 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9801 | |
| 9802 | // Now that all security checks passes, perform the operation as ourselves. |
| 9803 | final long identity = Binder.clearCallingIdentity(); |
| 9804 | try { |
| 9805 | Phone phone = getPhone(subId); |
| 9806 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9807 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9808 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9809 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9810 | } finally { |
| 9811 | Binder.restoreCallingIdentity(identity); |
| 9812 | } |
| 9813 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9814 | |
| 9815 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9816 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9817 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9818 | enforceModifyPermission(); |
| 9819 | long token = Binder.clearCallingIdentity(); |
| 9820 | try { |
| 9821 | Phone phone = getPhone(subscriptionId); |
| 9822 | if (phone == null) { |
| 9823 | try { |
| 9824 | if (resultCallback != null) { |
| 9825 | resultCallback.accept(false); |
| 9826 | } |
| 9827 | } catch (RemoteException e) { |
| 9828 | // ignore |
| 9829 | } |
| 9830 | return; |
| 9831 | } |
| 9832 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9833 | Pair.create(specifiers, (x) -> { |
| 9834 | try { |
| 9835 | if (resultCallback != null) { |
| 9836 | resultCallback.accept(x); |
| 9837 | } |
| 9838 | } catch (RemoteException e) { |
| 9839 | // ignore |
| 9840 | } |
| 9841 | }); |
| 9842 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9843 | } finally { |
| 9844 | Binder.restoreCallingIdentity(token); |
| 9845 | } |
| 9846 | } |
| 9847 | |
| 9848 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9849 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9850 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9851 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9852 | mApp, subId, "getSystemSelectionChannels"); |
| 9853 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9856 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9857 | if (result instanceof IllegalStateException) { |
| 9858 | throw (IllegalStateException) result; |
| 9859 | } |
| 9860 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9861 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9862 | return specifiers; |
| 9863 | } finally { |
| 9864 | Binder.restoreCallingIdentity(identity); |
| 9865 | } |
| 9866 | } |
| 9867 | |
| 9868 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9869 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9870 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9871 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9872 | } |
| 9873 | |
| 9874 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9875 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9876 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9877 | if (callingPackage == null) { |
| 9878 | callingPackage = getCurrentPackageName(); |
| 9879 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9880 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9881 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9882 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9883 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9884 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9885 | } |
| 9886 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9887 | Intent intent = new Intent(); |
| 9888 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9889 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9890 | // Bring up choose default SMS subscription dialog right now |
| 9891 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9892 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9893 | mApp.startActivity(intent); |
| 9894 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9895 | |
| 9896 | @Override |
| 9897 | public String getMmsUAProfUrl(int subId) { |
| 9898 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9899 | final long identity = Binder.clearCallingIdentity(); |
| 9900 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9901 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9902 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9903 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9904 | return carrierUAProfUrl; |
| 9905 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9906 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9907 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9908 | } finally { |
| 9909 | Binder.restoreCallingIdentity(identity); |
| 9910 | } |
| 9911 | } |
| 9912 | |
| 9913 | @Override |
| 9914 | public String getMmsUserAgent(int subId) { |
| 9915 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9916 | final long identity = Binder.clearCallingIdentity(); |
| 9917 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9918 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9919 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9920 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9921 | return carrierUserAgent; |
| 9922 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9923 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9924 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9925 | } finally { |
| 9926 | Binder.restoreCallingIdentity(identity); |
| 9927 | } |
| 9928 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9929 | |
| 9930 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9931 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9932 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9933 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9934 | final long identity = Binder.clearCallingIdentity(); |
| 9935 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9936 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9937 | if (phone == null) return false; |
| 9938 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9939 | switch (policy) { |
| 9940 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9941 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9942 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9943 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9944 | default: |
| 9945 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9946 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9947 | } finally { |
| 9948 | Binder.restoreCallingIdentity(identity); |
| 9949 | } |
| 9950 | } |
| 9951 | |
| 9952 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9953 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9954 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9955 | enforceModifyPermission(); |
| 9956 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9957 | final long identity = Binder.clearCallingIdentity(); |
| 9958 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9959 | Phone phone = getPhone(subscriptionId); |
| 9960 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9961 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9962 | switch (policy) { |
| 9963 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9964 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9965 | break; |
| 9966 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9967 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9968 | break; |
| 9969 | default: |
| 9970 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9971 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9972 | } finally { |
| 9973 | Binder.restoreCallingIdentity(identity); |
| 9974 | } |
| 9975 | } |
| 9976 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9977 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9978 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9979 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9980 | * otherwise. |
| 9981 | */ |
| 9982 | @Override |
| 9983 | public void setCepEnabled(boolean isCepEnabled) { |
| 9984 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9985 | |
| 9986 | final long identity = Binder.clearCallingIdentity(); |
| 9987 | try { |
| 9988 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9989 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9990 | Phone defaultPhone = phone.getImsPhone(); |
| 9991 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9992 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9993 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9994 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9995 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9996 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9997 | + imsPhone.getMsisdn()); |
| 9998 | } |
| 9999 | } |
| 10000 | } finally { |
| 10001 | Binder.restoreCallingIdentity(identity); |
| 10002 | } |
| 10003 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10004 | |
| 10005 | /** |
| 10006 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 10007 | * |
| 10008 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 10009 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 10010 | * before being read. |
| 10011 | */ |
| 10012 | @Override |
| 10013 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10014 | isCompressed) { |
| 10015 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10016 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10017 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10018 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10019 | } |
| 10020 | if (!isImsAvailableOnDevice()) { |
| 10021 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10022 | "IMS not available on device."); |
| 10023 | } |
| 10024 | |
| 10025 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10026 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10027 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10028 | } finally { |
| 10029 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10030 | } |
| 10031 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10032 | |
| 10033 | @Override |
| 10034 | public boolean isIccLockEnabled(int subId) { |
| 10035 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10036 | |
| 10037 | // Now that all security checks passes, perform the operation as ourselves. |
| 10038 | final long identity = Binder.clearCallingIdentity(); |
| 10039 | try { |
| 10040 | Phone phone = getPhone(subId); |
| 10041 | if (phone != null && phone.getIccCard() != null) { |
| 10042 | return phone.getIccCard().getIccLockEnabled(); |
| 10043 | } else { |
| 10044 | return false; |
| 10045 | } |
| 10046 | } finally { |
| 10047 | Binder.restoreCallingIdentity(identity); |
| 10048 | } |
| 10049 | } |
| 10050 | |
| 10051 | /** |
| 10052 | * Set the ICC pin lock enabled or disabled. |
| 10053 | * |
| 10054 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10055 | * three cases: |
| 10056 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10057 | * successfully. |
| 10058 | * - Positive number and zero for remaining password attempts. |
| 10059 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10060 | * |
| 10061 | */ |
| 10062 | @Override |
| 10063 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10064 | enforceModifyPermission(); |
| 10065 | |
| 10066 | Phone phone = getPhone(subId); |
| 10067 | if (phone == null) { |
| 10068 | return 0; |
| 10069 | } |
| 10070 | // Now that all security checks passes, perform the operation as ourselves. |
| 10071 | final long identity = Binder.clearCallingIdentity(); |
| 10072 | try { |
| 10073 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10074 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10075 | return attemptsRemaining; |
| 10076 | |
| 10077 | } catch (Exception e) { |
| 10078 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10079 | } finally { |
| 10080 | Binder.restoreCallingIdentity(identity); |
| 10081 | } |
| 10082 | return 0; |
| 10083 | } |
| 10084 | |
| 10085 | /** |
| 10086 | * Change the ICC password used in ICC pin lock. |
| 10087 | * |
| 10088 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10089 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10090 | * - Positive number and zero for remaining password attempts. |
| 10091 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10092 | * |
| 10093 | */ |
| 10094 | @Override |
| 10095 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10096 | enforceModifyPermission(); |
| 10097 | |
| 10098 | Phone phone = getPhone(subId); |
| 10099 | if (phone == null) { |
| 10100 | return 0; |
| 10101 | } |
| 10102 | // Now that all security checks passes, perform the operation as ourselves. |
| 10103 | final long identity = Binder.clearCallingIdentity(); |
| 10104 | try { |
| 10105 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10106 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10107 | return attemptsRemaining; |
| 10108 | |
| 10109 | } catch (Exception e) { |
| 10110 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10111 | } finally { |
| 10112 | Binder.restoreCallingIdentity(identity); |
| 10113 | } |
| 10114 | return 0; |
| 10115 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10116 | |
| 10117 | /** |
| 10118 | * Request for receiving user activity notification |
| 10119 | */ |
| 10120 | @Override |
| 10121 | public void requestUserActivityNotification() { |
| 10122 | if (!mNotifyUserActivity.get() |
| 10123 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10124 | mNotifyUserActivity.set(true); |
| 10125 | } |
| 10126 | } |
| 10127 | |
| 10128 | /** |
| 10129 | * Called when userActivity is signalled in the power manager. |
| 10130 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10131 | */ |
| 10132 | @Override |
| 10133 | public void userActivity() { |
| 10134 | // *************************************** |
| 10135 | // * Inherited from PhoneWindowManager * |
| 10136 | // *************************************** |
| 10137 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10138 | // WITH ITS LOCKS HELD. |
| 10139 | // |
| 10140 | // This code must be VERY careful about the locks |
| 10141 | // it acquires. |
| 10142 | // In fact, the current code acquires way too many, |
| 10143 | // and probably has lurking deadlocks. |
| 10144 | |
| 10145 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10146 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10147 | } |
| 10148 | |
| 10149 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10150 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10151 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10152 | } |
| 10153 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10154 | |
| 10155 | @Override |
| 10156 | public boolean canConnectTo5GInDsdsMode() { |
| 10157 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10158 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10159 | |
| 10160 | @Override |
| 10161 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10162 | String callingFeatureId) { |
| 10163 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10164 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10165 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10166 | } |
| 10167 | |
| 10168 | Phone phone = getPhone(subId); |
| 10169 | if (phone == null) { |
| 10170 | throw new RuntimeException("phone is not available"); |
| 10171 | } |
| 10172 | // Now that all security checks passes, perform the operation as ourselves. |
| 10173 | final long identity = Binder.clearCallingIdentity(); |
| 10174 | try { |
| 10175 | return phone.getEquivalentHomePlmns(); |
| 10176 | } finally { |
| 10177 | Binder.restoreCallingIdentity(identity); |
| 10178 | } |
| 10179 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10180 | |
| 10181 | @Override |
| 10182 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10183 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10184 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10185 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10186 | if (radioInterfaceCapabilities == null) { |
| 10187 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10188 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10189 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10190 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10191 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10192 | @Override |
| 10193 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10194 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10195 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10196 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10197 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10198 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10199 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10200 | if (DBG) { |
| 10201 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10202 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10203 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10204 | } |
| 10205 | |
| 10206 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10207 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10208 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10209 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10210 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10211 | if (callback != null) { |
| 10212 | try { |
| 10213 | callback.onAuthenticationFailure( |
| 10214 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10215 | } catch (RemoteException exception) { |
| 10216 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10217 | } |
| 10218 | return; |
| 10219 | } |
| 10220 | } |
| 10221 | |
| 10222 | final long token = Binder.clearCallingIdentity(); |
| 10223 | try { |
| 10224 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10225 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10226 | forceBootStrapping, callback)); |
| 10227 | } finally { |
| 10228 | Binder.restoreCallingIdentity(token); |
| 10229 | } |
| 10230 | } |
| 10231 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10232 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10233 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10234 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10235 | * requested radio power state will actually be set. See {@link |
| 10236 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10237 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10238 | * @param enable {@code true} if trying to turn radio on. |
| 10239 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10240 | * false}. |
| 10241 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10242 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10243 | boolean isPhoneAvailable = false; |
| 10244 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10245 | Phone phone = PhoneFactory.getPhone(i); |
| 10246 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10247 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10248 | isPhoneAvailable = true; |
| 10249 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10250 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10251 | |
| 10252 | // return true if successfully informed the phone object about the thermal radio power |
| 10253 | // request. |
| 10254 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10255 | } |
| 10256 | |
| 10257 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10258 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10259 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10260 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10261 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10262 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10263 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10264 | } |
| 10265 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10266 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10267 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10268 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10269 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10270 | } |
| 10271 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10272 | setDataEnabledForReason( |
| 10273 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10274 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10275 | if (isDataThrottlingSupported) { |
| 10276 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10277 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10278 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10279 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10280 | } else if (thermalMitigationResult |
| 10281 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10282 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10283 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10284 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10285 | } |
| 10286 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10287 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10288 | |
| 10289 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10290 | } |
| 10291 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10292 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10293 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10294 | for (String pckg : context.getResources() |
| 10295 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10296 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10297 | } |
| 10298 | } |
| 10299 | |
| 10300 | return sThermalMitigationAllowlistedPackages; |
| 10301 | } |
| 10302 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10303 | private boolean isAnyPhoneInEmergencyState() { |
| 10304 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10305 | if (tm.isInEmergencyCall()) { |
| 10306 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10307 | return true; |
| 10308 | } |
| 10309 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10310 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10311 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10312 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10313 | + phone.isInEcm()); |
| 10314 | return true; |
| 10315 | } |
| 10316 | } |
| 10317 | |
| 10318 | return false; |
| 10319 | } |
| 10320 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10321 | /** |
| 10322 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10323 | * @param packageName name of package to be allowlisted |
| 10324 | * @param context |
| 10325 | */ |
| 10326 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10327 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10328 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10329 | } |
| 10330 | |
| 10331 | /** |
| 10332 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10333 | * @param packageName name of package to remove from allowlist |
| 10334 | * @param context |
| 10335 | */ |
| 10336 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10337 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10338 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10339 | } |
| 10340 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10341 | /** |
| 10342 | * Thermal mitigation request to control functionalities at modem. |
| 10343 | * |
| 10344 | * @param subId the id of the subscription. |
| 10345 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10346 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10347 | * |
| 10348 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10349 | */ |
| 10350 | @Override |
| 10351 | @ThermalMitigationResult |
| 10352 | public int sendThermalMitigationRequest( |
| 10353 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10354 | ThermalMitigationRequest thermalMitigationRequest, |
| 10355 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10356 | enforceModifyPermission(); |
| 10357 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10358 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10359 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10360 | .contains(callingPackage)) { |
| 10361 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10362 | + "calling package: " + callingPackage); |
| 10363 | } |
| 10364 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10365 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10366 | final long identity = Binder.clearCallingIdentity(); |
| 10367 | |
| 10368 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10369 | try { |
| 10370 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10371 | switch (thermalMitigationAction) { |
| 10372 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10373 | thermalMitigationResult = |
| 10374 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10375 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10376 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10377 | break; |
| 10378 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10379 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10380 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10381 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10382 | } |
| 10383 | |
| 10384 | // Ensure that radio is on. If not able to power on due to phone being |
| 10385 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10386 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10387 | thermalMitigationResult = |
| 10388 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10389 | break; |
| 10390 | } |
| 10391 | |
| 10392 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10393 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10394 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10395 | break; |
| 10396 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10397 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10398 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10399 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10400 | } |
| 10401 | |
| 10402 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10403 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10404 | Phone phone = getPhone(subId); |
| 10405 | if (phone == null) { |
| 10406 | thermalMitigationResult = |
| 10407 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10408 | break; |
| 10409 | } |
| 10410 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10411 | TelephonyConnectionService service = |
| 10412 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10413 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10414 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10415 | thermalMitigationResult = |
| 10416 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10417 | break; |
| 10418 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10419 | thermalMitigationResult = |
| 10420 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10421 | break; |
| 10422 | } |
| 10423 | } else { |
| 10424 | thermalMitigationResult = |
| 10425 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10426 | break; |
| 10427 | } |
| 10428 | |
| 10429 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10430 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10431 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10432 | thermalMitigationResult = |
| 10433 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10434 | break; |
| 10435 | } |
| 10436 | thermalMitigationResult = |
| 10437 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10438 | break; |
| 10439 | default: |
| 10440 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10441 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10442 | } |
| 10443 | } catch (IllegalArgumentException e) { |
| 10444 | throw e; |
| 10445 | } catch (Exception e) { |
| 10446 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10447 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10448 | } finally { |
| 10449 | Binder.restoreCallingIdentity(identity); |
| 10450 | } |
| 10451 | |
| 10452 | if (DBG) { |
| 10453 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10454 | + thermalMitigationResult); |
| 10455 | } |
| 10456 | |
| 10457 | return thermalMitigationResult; |
| 10458 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10459 | |
| 10460 | /** |
| 10461 | * Set the GbaService Package Name that Telephony will bind to. |
| 10462 | * |
| 10463 | * @param subId The sim that the GbaService is associated with. |
| 10464 | * @param packageName The name of the package to be replaced with. |
| 10465 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10466 | */ |
| 10467 | @Override |
| 10468 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10469 | enforceModifyPermission(); |
| 10470 | |
| 10471 | final long identity = Binder.clearCallingIdentity(); |
| 10472 | try { |
| 10473 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10474 | } finally { |
| 10475 | Binder.restoreCallingIdentity(identity); |
| 10476 | } |
| 10477 | } |
| 10478 | |
| 10479 | /** |
| 10480 | * Return the package name of the currently bound GbaService. |
| 10481 | * |
| 10482 | * @param subId The sim that the GbaService is associated with. |
| 10483 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10484 | */ |
| 10485 | @Override |
| 10486 | public String getBoundGbaService(int subId) { |
| 10487 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10488 | |
| 10489 | final long identity = Binder.clearCallingIdentity(); |
| 10490 | try { |
| 10491 | return getGbaManager(subId).getServicePackage(); |
| 10492 | } finally { |
| 10493 | Binder.restoreCallingIdentity(identity); |
| 10494 | } |
| 10495 | } |
| 10496 | |
| 10497 | /** |
| 10498 | * Set the release time for telephony to unbind GbaService. |
| 10499 | * |
| 10500 | * @param subId The sim that the GbaService is associated with. |
| 10501 | * @param interval The release time to unbind GbaService by millisecond. |
| 10502 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10503 | */ |
| 10504 | @Override |
| 10505 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10506 | enforceModifyPermission(); |
| 10507 | |
| 10508 | final long identity = Binder.clearCallingIdentity(); |
| 10509 | try { |
| 10510 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10511 | } finally { |
| 10512 | Binder.restoreCallingIdentity(identity); |
| 10513 | } |
| 10514 | } |
| 10515 | |
| 10516 | /** |
| 10517 | * Return the release time for telephony to unbind GbaService. |
| 10518 | * |
| 10519 | * @param subId The sim that the GbaService is associated with. |
| 10520 | * @return The release time to unbind GbaService by millisecond. |
| 10521 | */ |
| 10522 | @Override |
| 10523 | public int getGbaReleaseTime(int subId) { |
| 10524 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10525 | |
| 10526 | final long identity = Binder.clearCallingIdentity(); |
| 10527 | try { |
| 10528 | return getGbaManager(subId).getReleaseTime(); |
| 10529 | } finally { |
| 10530 | Binder.restoreCallingIdentity(identity); |
| 10531 | } |
| 10532 | } |
| 10533 | |
| 10534 | private GbaManager getGbaManager(int subId) { |
| 10535 | GbaManager instance = GbaManager.getInstance(subId); |
| 10536 | if (instance == null) { |
| 10537 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10538 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10539 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10540 | } |
| 10541 | return instance; |
| 10542 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10543 | |
| 10544 | /** |
| 10545 | * indicate whether the device and the carrier can support |
| 10546 | * RCS VoLTE single registration. |
| 10547 | */ |
| 10548 | @Override |
| 10549 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10550 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10551 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10552 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10553 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10554 | |
| 10555 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10556 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10557 | } |
| 10558 | |
| 10559 | final long identity = Binder.clearCallingIdentity(); |
| 10560 | try { |
| 10561 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10562 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10563 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10564 | if (isCapable != null) { |
| 10565 | return isCapable; |
| 10566 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10567 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10568 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10569 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10570 | } finally { |
| 10571 | Binder.restoreCallingIdentity(identity); |
| 10572 | } |
| 10573 | } |
| 10574 | |
| 10575 | /** |
| 10576 | * Register RCS provisioning callback. |
| 10577 | */ |
| 10578 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10579 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10580 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10581 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10582 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10583 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10584 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10585 | |
| 10586 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10587 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10588 | } |
| 10589 | if (!isImsAvailableOnDevice()) { |
| 10590 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10591 | "IMS not available on device."); |
| 10592 | } |
| 10593 | |
| 10594 | final long identity = Binder.clearCallingIdentity(); |
| 10595 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10596 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10597 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10598 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10599 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10600 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10601 | } finally { |
| 10602 | Binder.restoreCallingIdentity(identity); |
| 10603 | } |
| 10604 | } |
| 10605 | |
| 10606 | /** |
| 10607 | * Unregister RCS provisioning callback. |
| 10608 | */ |
| 10609 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10610 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10611 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10612 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10613 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10614 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10615 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10616 | |
| 10617 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10618 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10619 | } |
| 10620 | if (!isImsAvailableOnDevice()) { |
| 10621 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10622 | "IMS not available on device."); |
| 10623 | } |
| 10624 | |
| 10625 | final long identity = Binder.clearCallingIdentity(); |
| 10626 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10627 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10628 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10629 | } finally { |
| 10630 | Binder.restoreCallingIdentity(identity); |
| 10631 | } |
| 10632 | } |
| 10633 | |
| 10634 | /** |
| 10635 | * trigger RCS reconfiguration. |
| 10636 | */ |
| 10637 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10638 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10639 | "triggerRcsReconfiguration", |
| 10640 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10641 | |
| 10642 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10643 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10644 | } |
| 10645 | if (!isImsAvailableOnDevice()) { |
| 10646 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10647 | "IMS not available on device."); |
| 10648 | } |
| 10649 | |
| 10650 | final long identity = Binder.clearCallingIdentity(); |
| 10651 | try { |
| 10652 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10653 | } finally { |
| 10654 | Binder.restoreCallingIdentity(identity); |
| 10655 | } |
| 10656 | } |
| 10657 | |
| 10658 | /** |
| 10659 | * Provide the client configuration parameters of the RCS application. |
| 10660 | */ |
| 10661 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10662 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10663 | "setRcsClientConfiguration", |
| 10664 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10665 | |
| 10666 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10667 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10668 | } |
| 10669 | if (!isImsAvailableOnDevice()) { |
| 10670 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10671 | "IMS not available on device."); |
| 10672 | } |
| 10673 | |
| 10674 | final long identity = Binder.clearCallingIdentity(); |
| 10675 | |
| 10676 | try { |
| 10677 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10678 | if (configBinder == null) { |
| 10679 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10681 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10682 | } else { |
| 10683 | configBinder.setRcsClientConfiguration(rcc); |
| 10684 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10685 | |
| 10686 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10687 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10688 | } catch (RemoteException e) { |
| 10689 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10690 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10691 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10692 | } finally { |
| 10693 | Binder.restoreCallingIdentity(identity); |
| 10694 | } |
| 10695 | } |
| 10696 | |
| 10697 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10698 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10699 | */ |
| 10700 | @Override |
| 10701 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10702 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10703 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10704 | |
| 10705 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10706 | } |
| 10707 | |
| 10708 | /** |
| 10709 | * Gets the test mode for RCS VoLTE single registration. |
| 10710 | */ |
| 10711 | @Override |
| 10712 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10713 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10714 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10715 | |
| 10716 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10717 | } |
| 10718 | |
| 10719 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10720 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10721 | */ |
| 10722 | @Override |
| 10723 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10724 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10725 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10726 | enforceModifyPermission(); |
| 10727 | |
| 10728 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10729 | : Boolean.parseBoolean(enabledStr); |
| 10730 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10731 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10732 | } |
| 10733 | |
| 10734 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10735 | * Sends a device to device communication message. Only usable via shell. |
| 10736 | * @param message message to send. |
| 10737 | * @param value message value. |
| 10738 | */ |
| 10739 | @Override |
| 10740 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10741 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10742 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10743 | enforceModifyPermission(); |
| 10744 | |
| 10745 | final long identity = Binder.clearCallingIdentity(); |
| 10746 | try { |
| 10747 | TelephonyConnectionService service = |
| 10748 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10749 | if (service == null) { |
| 10750 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10751 | return; |
| 10752 | } |
| 10753 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10754 | } finally { |
| 10755 | Binder.restoreCallingIdentity(identity); |
| 10756 | } |
| 10757 | } |
| 10758 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10759 | /** |
| 10760 | * Sets the specified device to device transport active. |
| 10761 | * @param transport The transport to set active. |
| 10762 | */ |
| 10763 | @Override |
| 10764 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10765 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10766 | "setActiveDeviceToDeviceTransport"); |
| 10767 | enforceModifyPermission(); |
| 10768 | |
| 10769 | final long identity = Binder.clearCallingIdentity(); |
| 10770 | try { |
| 10771 | TelephonyConnectionService service = |
| 10772 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10773 | if (service == null) { |
| 10774 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10775 | return; |
| 10776 | } |
| 10777 | service.setActiveDeviceToDeviceTransport(transport); |
| 10778 | } finally { |
| 10779 | Binder.restoreCallingIdentity(identity); |
| 10780 | } |
| 10781 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10782 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10783 | @Override |
| 10784 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10785 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10786 | "setDeviceToDeviceForceEnabled"); |
| 10787 | |
| 10788 | final long identity = Binder.clearCallingIdentity(); |
| 10789 | try { |
| 10790 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10791 | p -> { |
| 10792 | Phone thePhone = p.getImsPhone(); |
| 10793 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10794 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10795 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10796 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10797 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10798 | (ImsPhoneCallTracker) tracker; |
| 10799 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10800 | } |
| 10801 | } |
| 10802 | } |
| 10803 | ); |
| 10804 | } finally { |
| 10805 | Binder.restoreCallingIdentity(identity); |
| 10806 | } |
| 10807 | } |
| 10808 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10809 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10810 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10811 | */ |
| 10812 | @Override |
| 10813 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10814 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10815 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10816 | } |
| 10817 | |
| 10818 | /** |
| 10819 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10820 | */ |
| 10821 | @Override |
| 10822 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10824 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10825 | enforceModifyPermission(); |
| 10826 | |
| 10827 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10828 | : Boolean.parseBoolean(enabledStr); |
| 10829 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10830 | subId, enabled); |
| 10831 | } |
| 10832 | |
| 10833 | /** |
| 10834 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10835 | */ |
| 10836 | @Override |
| 10837 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10838 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10839 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10840 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10841 | |
| 10842 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10843 | * Overrides the ims feature validation result |
| 10844 | */ |
| 10845 | @Override |
| 10846 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10847 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10848 | "setImsFeatureValidationOverride"); |
| 10849 | |
| 10850 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10851 | : Boolean.parseBoolean(enabledStr); |
| 10852 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10853 | subId, enabled); |
| 10854 | } |
| 10855 | |
| 10856 | /** |
| 10857 | * Gets the ims feature validation override value |
| 10858 | */ |
| 10859 | @Override |
| 10860 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10862 | "getImsFeatureValidationOverride"); |
| 10863 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10864 | } |
| 10865 | |
| 10866 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10867 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10868 | * their mobile plan. |
| 10869 | */ |
| 10870 | @Override |
| 10871 | public String getMobileProvisioningUrl() { |
| 10872 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10873 | final long identity = Binder.clearCallingIdentity(); |
| 10874 | try { |
| 10875 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10876 | } finally { |
| 10877 | Binder.restoreCallingIdentity(identity); |
| 10878 | } |
| 10879 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10880 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10881 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10882 | * Get the EAB contact from the EAB database. |
| 10883 | */ |
| 10884 | @Override |
| 10885 | public String getContactFromEab(String contact) { |
| 10886 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10887 | enforceModifyPermission(); |
| 10888 | final long identity = Binder.clearCallingIdentity(); |
| 10889 | try { |
| 10890 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10891 | } finally { |
| 10892 | Binder.restoreCallingIdentity(identity); |
| 10893 | } |
| 10894 | } |
| 10895 | |
| 10896 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10897 | * Get the EAB capability from the EAB database. |
| 10898 | */ |
| 10899 | @Override |
| 10900 | public String getCapabilityFromEab(String contact) { |
| 10901 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10902 | enforceModifyPermission(); |
| 10903 | final long identity = Binder.clearCallingIdentity(); |
| 10904 | try { |
| 10905 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10906 | } finally { |
| 10907 | Binder.restoreCallingIdentity(identity); |
| 10908 | } |
| 10909 | } |
| 10910 | |
| 10911 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10912 | * Remove the EAB contacts from the EAB database. |
| 10913 | */ |
| 10914 | @Override |
| 10915 | public int removeContactFromEab(int subId, String contacts) { |
| 10916 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10917 | enforceModifyPermission(); |
| 10918 | final long identity = Binder.clearCallingIdentity(); |
| 10919 | try { |
| 10920 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10921 | } finally { |
| 10922 | Binder.restoreCallingIdentity(identity); |
| 10923 | } |
| 10924 | } |
| 10925 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10926 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10927 | public boolean getDeviceUceEnabled() { |
| 10928 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10929 | final long identity = Binder.clearCallingIdentity(); |
| 10930 | try { |
| 10931 | return mApp.getDeviceUceEnabled(); |
| 10932 | } finally { |
| 10933 | Binder.restoreCallingIdentity(identity); |
| 10934 | } |
| 10935 | } |
| 10936 | |
| 10937 | @Override |
| 10938 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10939 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10940 | final long identity = Binder.clearCallingIdentity(); |
| 10941 | try { |
| 10942 | mApp.setDeviceUceEnabled(isEnabled); |
| 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
| 10947 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10948 | /** |
| 10949 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10950 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10951 | */ |
| 10952 | // Used for SHELL command only right now. |
| 10953 | @Override |
| 10954 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10955 | List<String> featureTags) { |
| 10956 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10957 | "addUceRegistrationOverrideShell"); |
| 10958 | final long identity = Binder.clearCallingIdentity(); |
| 10959 | try { |
| 10960 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10961 | new ArraySet<>(featureTags)); |
| 10962 | } catch (ImsException e) { |
| 10963 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10964 | } finally { |
| 10965 | Binder.restoreCallingIdentity(identity); |
| 10966 | } |
| 10967 | } |
| 10968 | |
| 10969 | /** |
| 10970 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10971 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10972 | */ |
| 10973 | // Used for SHELL command only right now. |
| 10974 | @Override |
| 10975 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10976 | List<String> featureTags) { |
| 10977 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10978 | "removeUceRegistrationOverrideShell"); |
| 10979 | final long identity = Binder.clearCallingIdentity(); |
| 10980 | try { |
| 10981 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10982 | new ArraySet<>(featureTags)); |
| 10983 | } catch (ImsException e) { |
| 10984 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10985 | } finally { |
| 10986 | Binder.restoreCallingIdentity(identity); |
| 10987 | } |
| 10988 | } |
| 10989 | |
| 10990 | /** |
| 10991 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10992 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10993 | */ |
| 10994 | // Used for SHELL command only right now. |
| 10995 | @Override |
| 10996 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10997 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10998 | "clearUceRegistrationOverrideShell"); |
| 10999 | final long identity = Binder.clearCallingIdentity(); |
| 11000 | try { |
| 11001 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 11002 | } catch (ImsException e) { |
| 11003 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11004 | } finally { |
| 11005 | Binder.restoreCallingIdentity(identity); |
| 11006 | } |
| 11007 | } |
| 11008 | |
| 11009 | /** |
| 11010 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 11011 | */ |
| 11012 | // Used for SHELL command only right now. |
| 11013 | @Override |
| 11014 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11015 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11016 | "getLatestRcsContactUceCapabilityShell"); |
| 11017 | final long identity = Binder.clearCallingIdentity(); |
| 11018 | try { |
| 11019 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11020 | } catch (ImsException e) { |
| 11021 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11022 | } finally { |
| 11023 | Binder.restoreCallingIdentity(identity); |
| 11024 | } |
| 11025 | } |
| 11026 | |
| 11027 | /** |
| 11028 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11029 | * device does not have an active PUBLISH. |
| 11030 | */ |
| 11031 | // Used for SHELL command only right now. |
| 11032 | @Override |
| 11033 | public String getLastUcePidfXmlShell(int subId) { |
| 11034 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11035 | final long identity = Binder.clearCallingIdentity(); |
| 11036 | try { |
| 11037 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11038 | } catch (ImsException e) { |
| 11039 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(identity); |
| 11042 | } |
| 11043 | } |
| 11044 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11045 | /** |
| 11046 | * Remove UCE requests cannot be sent to the network status. |
| 11047 | */ |
| 11048 | // Used for SHELL command only right now. |
| 11049 | @Override |
| 11050 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11051 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11052 | final long identity = Binder.clearCallingIdentity(); |
| 11053 | try { |
| 11054 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11055 | } catch (ImsException e) { |
| 11056 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11057 | } finally { |
| 11058 | Binder.restoreCallingIdentity(identity); |
| 11059 | } |
| 11060 | } |
| 11061 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11062 | /** |
| 11063 | * Remove UCE requests cannot be sent to the network status. |
| 11064 | */ |
| 11065 | // Used for SHELL command only. |
| 11066 | @Override |
| 11067 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11068 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
| 11071 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11072 | } catch (ImsException e) { |
| 11073 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11074 | } finally { |
| 11075 | Binder.restoreCallingIdentity(identity); |
| 11076 | } |
| 11077 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11078 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11079 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11080 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11081 | String callingPackage) { |
| 11082 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11083 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11084 | |
| 11085 | final int callingUid = Binder.getCallingUid(); |
| 11086 | // Verify that tha callingPackage belongs to the calling UID |
| 11087 | mApp.getSystemService(AppOpsManager.class) |
| 11088 | .checkPackage(callingUid, callingPackage); |
| 11089 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11090 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11091 | |
| 11092 | final long identity = Binder.clearCallingIdentity(); |
| 11093 | try { |
| 11094 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11095 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11096 | |
| 11097 | if (result instanceof IllegalStateException) { |
| 11098 | throw (IllegalStateException) result; |
| 11099 | } |
| 11100 | } finally { |
| 11101 | Binder.restoreCallingIdentity(identity); |
| 11102 | } |
| 11103 | } |
| 11104 | |
| 11105 | @Override |
| 11106 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11107 | String callingPackage) { |
| 11108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11109 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11110 | |
| 11111 | final int callingUid = Binder.getCallingUid(); |
| 11112 | // Verify that tha callingPackage belongs to the calling UID |
| 11113 | mApp.getSystemService(AppOpsManager.class) |
| 11114 | .checkPackage(callingUid, callingPackage); |
| 11115 | |
| 11116 | final long identity = Binder.clearCallingIdentity(); |
| 11117 | try { |
| 11118 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11119 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11120 | |
| 11121 | if (result instanceof IllegalStateException) { |
| 11122 | throw (IllegalStateException) result; |
| 11123 | } |
| 11124 | } finally { |
| 11125 | Binder.restoreCallingIdentity(identity); |
| 11126 | } |
| 11127 | } |
| 11128 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11129 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11130 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11131 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11132 | // phone/system process do not have further restriction on request |
| 11133 | return; |
| 11134 | } |
| 11135 | |
| 11136 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11137 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11138 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11139 | context.enforceCallingOrSelfPermission( |
| 11140 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11141 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11142 | } |
| 11143 | |
| 11144 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11145 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11146 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11147 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11148 | || info.isEnabled()) { |
| 11149 | throw new IllegalArgumentException( |
| 11150 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11151 | } |
| 11152 | |
| 11153 | // Thresholds length for each RAN need in range. This has been validated in |
| 11154 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11155 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11156 | final int[] thresholds = info.getThresholds(); |
| 11157 | Objects.requireNonNull(thresholds); |
| 11158 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11159 | || thresholds.length |
| 11160 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11161 | throw new IllegalArgumentException( |
| 11162 | "thresholds length is out of range: " + thresholds.length); |
| 11163 | } |
| 11164 | } |
| 11165 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11166 | |
| 11167 | /** |
| 11168 | * Gets the current phone capability. |
| 11169 | * |
| 11170 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11171 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11172 | * It's used to evaluate possible phone config change, for example from single |
| 11173 | * SIM device to multi-SIM device. |
| 11174 | */ |
| 11175 | @Override |
| 11176 | public PhoneCapability getPhoneCapability() { |
| 11177 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11181 | } finally { |
| 11182 | Binder.restoreCallingIdentity(identity); |
| 11183 | } |
| 11184 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11185 | |
| 11186 | /** |
| 11187 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11188 | * required to be done shortly after the API is invoked. |
| 11189 | */ |
| 11190 | @Override |
| 11191 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11192 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11193 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11194 | enforceRebootPermission(); |
| 11195 | |
| 11196 | final long identity = Binder.clearCallingIdentity(); |
| 11197 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11198 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11199 | } finally { |
| 11200 | Binder.restoreCallingIdentity(identity); |
| 11201 | } |
| 11202 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11203 | |
| 11204 | /** |
| 11205 | * Request to get the current slicing configuration including URSP rules and |
| 11206 | * NSSAIs (configured, allowed and rejected). |
| 11207 | * |
| 11208 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11209 | */ |
| 11210 | @Override |
| 11211 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11212 | TelephonyPermissions |
| 11213 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11214 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11215 | |
| 11216 | final long identity = Binder.clearCallingIdentity(); |
| 11217 | try { |
| 11218 | Phone phone = getDefaultPhone(); |
| 11219 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11220 | } finally { |
| 11221 | Binder.restoreCallingIdentity(identity); |
| 11222 | } |
| 11223 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11224 | |
| 11225 | /** |
Sarah Chin | 2ec39f6 | 2022-08-31 17:03:26 -0700 | [diff] [blame] | 11226 | * Check whether the given premium capability is available for purchase from the carrier. |
| 11227 | * |
| 11228 | * @param capability The premium capability to check. |
| 11229 | * @param subId The subId to check the premium capability for. |
| 11230 | * |
| 11231 | * @return Whether the given premium capability is available to purchase. |
| 11232 | */ |
| 11233 | @Override |
| 11234 | public boolean isPremiumCapabilityAvailableForPurchase(int capability, int subId) { |
| 11235 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11236 | mApp, "isPremiumCapabilityAvailableForPurchase")) { |
| 11237 | log("Premium capability " |
| 11238 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11239 | + " is not available for purchase due to missing permissions."); |
| 11240 | throw new SecurityException("isPremiumCapabilityAvailableForPurchase requires " |
| 11241 | + "permission READ_BASIC_PHONE_STATE."); |
| 11242 | } |
| 11243 | |
| 11244 | Phone phone = getPhone(subId); |
| 11245 | final long identity = Binder.clearCallingIdentity(); |
| 11246 | try { |
| 11247 | return SliceStore.getInstance(phone) |
| 11248 | .isPremiumCapabilityAvailableForPurchase(capability); |
| 11249 | } finally { |
| 11250 | Binder.restoreCallingIdentity(identity); |
| 11251 | } |
| 11252 | } |
| 11253 | |
| 11254 | /** |
| 11255 | * Purchase the given premium capability from the carrier. |
| 11256 | * |
| 11257 | * @param capability The premium capability to purchase. |
| 11258 | * @param callback The result of the purchase request. |
| 11259 | * @param subId The subId to purchase the premium capability for. |
| 11260 | */ |
| 11261 | @Override |
| 11262 | public void purchasePremiumCapability(int capability, IIntegerConsumer callback, int subId) { |
| 11263 | log("purchasePremiumCapability: capability=" |
| 11264 | + TelephonyManager.convertPremiumCapabilityToString(capability) + ", caller=" |
| 11265 | + getCurrentPackageName()); |
| 11266 | |
| 11267 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 11268 | mApp, "purchasePremiumCapability")) { |
| 11269 | log("purchasePremiumCapability " |
| 11270 | + TelephonyManager.convertPremiumCapabilityToString(capability) |
| 11271 | + " failed due to missing permissions."); |
| 11272 | throw new SecurityException("purchasePremiumCapability requires permission " |
| 11273 | + "READ_BASIC_PHONE_STATE."); |
| 11274 | } |
| 11275 | |
| 11276 | Phone phone = getPhone(subId); |
| 11277 | Pair<Integer, IIntegerConsumer> argument = new Pair<>(capability, callback); |
| 11278 | sendRequestAsync(CMD_PURCHASE_PREMIUM_CAPABILITY, argument, phone, null); |
| 11279 | } |
| 11280 | |
| 11281 | /** |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11282 | * Register an IMS connection state callback |
| 11283 | */ |
| 11284 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11285 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11286 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11287 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11288 | // ImsMmTelManager |
| 11289 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11290 | TelephonyPermissions |
| 11291 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11292 | mApp, subId, "registerImsStateCallback"); |
| 11293 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11294 | // ImsRcsManager or SipDelegateManager |
| 11295 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11296 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11297 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11298 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11299 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11300 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11301 | } |
| 11302 | |
| 11303 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11304 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11305 | "IMS not available on device."); |
| 11306 | } |
| 11307 | |
| 11308 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11309 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11310 | } |
| 11311 | |
| 11312 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11313 | if (controller == null) { |
| 11314 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11315 | "IMS not available on device."); |
| 11316 | } |
| 11317 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11318 | if (callingPackage == null) { |
| 11319 | callingPackage = getCurrentPackageName(); |
| 11320 | } |
| 11321 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11322 | final long token = Binder.clearCallingIdentity(); |
| 11323 | try { |
| 11324 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11325 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11326 | } catch (ImsException e) { |
| 11327 | throw new ServiceSpecificException(e.getCode()); |
| 11328 | } finally { |
| 11329 | Binder.restoreCallingIdentity(token); |
| 11330 | } |
| 11331 | } |
| 11332 | |
| 11333 | /** |
| 11334 | * Unregister an IMS connection state callback |
| 11335 | */ |
| 11336 | @Override |
| 11337 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11338 | final long token = Binder.clearCallingIdentity(); |
| 11339 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11340 | if (controller == null) { |
| 11341 | return; |
| 11342 | } |
| 11343 | try { |
| 11344 | controller.unregisterImsStateCallback(cb); |
| 11345 | } finally { |
| 11346 | Binder.restoreCallingIdentity(token); |
| 11347 | } |
| 11348 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11349 | |
| 11350 | /** |
| 11351 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11352 | * |
| 11353 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11354 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11355 | * SecurityException. |
| 11356 | * If there is current registered network this value will be same as the registered cell |
| 11357 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11358 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11359 | * it will be cleared and null will be returned. |
| 11360 | * |
| 11361 | */ |
| 11362 | @Override |
| 11363 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11364 | String callingFeatureId) { |
| 11365 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11366 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11367 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11368 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11369 | .setCallingPackage(callingPackage) |
| 11370 | .setCallingFeatureId(callingFeatureId) |
| 11371 | .setCallingPid(Binder.getCallingPid()) |
| 11372 | .setCallingUid(Binder.getCallingUid()) |
| 11373 | .setMethod("getLastKnownCellIdentity") |
| 11374 | .setLogAsInfo(true) |
| 11375 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11376 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11377 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11378 | .build()); |
| 11379 | |
| 11380 | boolean hasFinePermission = |
| 11381 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11382 | if (!hasFinePermission |
| 11383 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11384 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11385 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11386 | } |
| 11387 | |
| 11388 | final long identity = Binder.clearCallingIdentity(); |
| 11389 | try { |
| 11390 | Phone phone = getPhone(subId); |
| 11391 | if (phone == null) return null; |
| 11392 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11393 | if (sst == null) return null; |
| 11394 | return sst.getLastKnownCellIdentity(); |
| 11395 | } finally { |
| 11396 | Binder.restoreCallingIdentity(identity); |
| 11397 | } |
| 11398 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11399 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11400 | /** |
| 11401 | * Sets the modem service class Name that Telephony will bind to. |
| 11402 | * |
| 11403 | * @param serviceName The class name of the modem service. |
| 11404 | * @return true if the operation is succeed, otherwise false. |
| 11405 | */ |
| 11406 | public boolean setModemService(String serviceName) { |
| 11407 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11408 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11409 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11410 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11411 | "setModemService"); |
| 11412 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11413 | } |
| 11414 | |
| 11415 | /** |
| 11416 | * Return the class name of the currently bounded modem service. |
| 11417 | * |
| 11418 | * @return the class name of the modem service. |
| 11419 | */ |
| 11420 | public String getModemService() { |
| 11421 | String result; |
| 11422 | Log.d(LOG_TAG, "getModemService"); |
| 11423 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11424 | TelephonyPermissions |
| 11425 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11426 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11427 | "getModemService"); |
| 11428 | result = mPhoneConfigurationManager.getModemService(); |
| 11429 | Log.d(LOG_TAG, "result = " + result); |
| 11430 | return result; |
| 11431 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11432 | |
| 11433 | @Override |
| 11434 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11435 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11436 | mApp.enforceCallingOrSelfPermission( |
| 11437 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11438 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11439 | |
| 11440 | final long identity = Binder.clearCallingIdentity(); |
| 11441 | try { |
| 11442 | Phone phone = getPhone(subId); |
| 11443 | if (phone == null) return; |
| 11444 | phone.setVoiceServiceStateOverride(hasService); |
| 11445 | } finally { |
| 11446 | Binder.restoreCallingIdentity(identity); |
| 11447 | } |
| 11448 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11449 | |
| 11450 | /** |
| 11451 | * set removable eSIM as default eUICC. |
| 11452 | * |
| 11453 | * @hide |
| 11454 | */ |
| 11455 | @Override |
| 11456 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11457 | enforceModifyPermission(); |
| 11458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11459 | |
| 11460 | final long identity = Binder.clearCallingIdentity(); |
| 11461 | try { |
| 11462 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11463 | } finally { |
| 11464 | Binder.restoreCallingIdentity(identity); |
| 11465 | } |
| 11466 | } |
| 11467 | |
| 11468 | /** |
| 11469 | * Returns whether the removable eSIM is default eUICC or not. |
| 11470 | * |
| 11471 | * @hide |
| 11472 | */ |
| 11473 | @Override |
| 11474 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11475 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11476 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11477 | |
| 11478 | final long identity = Binder.clearCallingIdentity(); |
| 11479 | try { |
| 11480 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11481 | } finally { |
| 11482 | Binder.restoreCallingIdentity(identity); |
| 11483 | } |
| 11484 | } |
| 11485 | |
| 11486 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11487 | } |