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; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 80 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 81 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 82 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 83 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 84 | import android.telephony.CellIdentityCdma; |
| 85 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 87 | import android.telephony.CellInfoGsm; |
| 88 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 89 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 90 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 91 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 92 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 93 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 94 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 95 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 96 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 97 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 98 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 99 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 100 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 101 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 102 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 103 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 104 | import android.telephony.SignalStrengthUpdateRequest; |
| 105 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 106 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 107 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 108 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 109 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 110 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 111 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 112 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 113 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 114 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 115 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 116 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 117 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 118 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 119 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 120 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 121 | import android.telephony.gba.GbaAuthRequest; |
| 122 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 123 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 125 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 126 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 127 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 135 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 139 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 140 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 143 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 144 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 145 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 146 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 147 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.CommandsInterface; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 162 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 178 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyPermissions; |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 186 | import com.android.internal.telephony.data.DataUtils; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
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; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 213 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 214 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 217 | import com.android.services.telephony.TelecomAccountRegistry; |
| 218 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 219 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 220 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 221 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 222 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.IOException; |
| 224 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 225 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 226 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 227 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 228 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 229 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 230 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 231 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 232 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 233 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 234 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 235 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 236 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 237 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 238 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 239 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 240 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Implementation of the ITelephony interface. |
| 244 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 245 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 246 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 247 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 248 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 249 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 250 | |
| 251 | // Message codes used with mMainThreadHandler |
| 252 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 253 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 254 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 255 | private static final int CMD_OPEN_CHANNEL = 9; |
| 256 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 257 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 258 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 259 | private static final int CMD_NV_READ_ITEM = 13; |
| 260 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 261 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 262 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 263 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 264 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 266 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 267 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 268 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 269 | private static final int CMD_SEND_ENVELOPE = 25; |
| 270 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 271 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 272 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 273 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 274 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 275 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 276 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 277 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 278 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 279 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 280 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 282 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 283 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 284 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 285 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 286 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 287 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 288 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 289 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 290 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 291 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 292 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 293 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 294 | private static final int CMD_SWITCH_SLOTS = 50; |
| 295 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 296 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 297 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 298 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 299 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 300 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 301 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 302 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 303 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 304 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 305 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 306 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 307 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 308 | private static final int CMD_MODEM_REBOOT = 64; |
| 309 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 310 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 311 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 312 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 313 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 314 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 315 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 316 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 317 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 318 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 319 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 320 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 321 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 322 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 323 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 325 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 326 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 327 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 328 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 329 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 330 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 331 | private static final int CMD_GET_CALL_WAITING = 87; |
| 332 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 333 | private static final int CMD_SET_CALL_WAITING = 89; |
| 334 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 335 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 336 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 337 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 338 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 339 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 340 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 341 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 342 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 343 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 344 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_SIM_POWER = 101; |
| 346 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 347 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 348 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 349 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 350 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 351 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 352 | 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] | 353 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 354 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 355 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 356 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 357 | private static final int CMD_ENABLE_VONR = 113; |
| 358 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 359 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 360 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 361 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 362 | // Parameters of select command. |
| 363 | private static final int SELECT_COMMAND = 0xA4; |
| 364 | private static final int SELECT_P1 = 0x04; |
| 365 | private static final int SELECT_P2 = 0; |
| 366 | private static final int SELECT_P3 = 0x10; |
| 367 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 368 | /** The singleton instance. */ |
| 369 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 370 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 373 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 374 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 375 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 376 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 377 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 378 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 379 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 380 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 381 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 382 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 383 | private final Telephony2gUpdater mTelephony2gUpdater; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 385 | /** User Activity */ |
| 386 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 387 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 388 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 389 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 390 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 391 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 392 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 393 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 394 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 395 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 396 | // String to store multi SIM allowed |
| 397 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 398 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 399 | // The AID of ISD-R. |
| 400 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 401 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 402 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 403 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 404 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 405 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 406 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 407 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 408 | 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] | 409 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 410 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 411 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 412 | */ |
| 413 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 414 | "reset_network_erase_modem_config_enabled"; |
| 415 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 416 | 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] | 417 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 418 | /** |
| 419 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 420 | * one ICCID active at the same time. |
| 421 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 422 | * |
| 423 | * @hide |
| 424 | */ |
| 425 | @ChangeId |
| 426 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 427 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 428 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 429 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 430 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 431 | * operation fails. |
| 432 | */ |
| 433 | @ChangeId |
| 434 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 435 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 436 | |
| 437 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 438 | * A request object to use for transmitting data to an ICC. |
| 439 | */ |
| 440 | private static final class IccAPDUArgument { |
| 441 | public int channel, cla, command, p1, p2, p3; |
| 442 | public String data; |
| 443 | |
| 444 | public IccAPDUArgument(int channel, int cla, int command, |
| 445 | int p1, int p2, int p3, String data) { |
| 446 | this.channel = channel; |
| 447 | this.cla = cla; |
| 448 | this.command = command; |
| 449 | this.p1 = p1; |
| 450 | this.p2 = p2; |
| 451 | this.p3 = p3; |
| 452 | this.data = data; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 457 | * A request object to use for transmitting data to an ICC. |
| 458 | */ |
| 459 | private static final class ManualNetworkSelectionArgument { |
| 460 | public OperatorInfo operatorInfo; |
| 461 | public boolean persistSelection; |
| 462 | |
| 463 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 464 | this.operatorInfo = operatorInfo; |
| 465 | this.persistSelection = persistSelection; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 471 | * request after sending. The main thread will notify the request when it is complete. |
| 472 | */ |
| 473 | private static final class MainThreadRequest { |
| 474 | /** The argument to use for the request */ |
| 475 | public Object argument; |
| 476 | /** The result of the request that is run on the main thread */ |
| 477 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 478 | // The subscriber id that this request applies to. Defaults to |
| 479 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 480 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 482 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 483 | public Phone phone; |
| 484 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 485 | public WorkSource workSource; |
| 486 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | public MainThreadRequest(Object argument) { |
| 488 | this.argument = argument; |
| 489 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 490 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 491 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 492 | this.argument = argument; |
| 493 | if (phone != null) { |
| 494 | this.phone = phone; |
| 495 | } |
| 496 | this.workSource = workSource; |
| 497 | } |
| 498 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 499 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 500 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 501 | if (subId != null) { |
| 502 | this.subId = subId; |
| 503 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 504 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 508 | private static final class IncomingThirdPartyCallArgs { |
| 509 | public final ComponentName component; |
| 510 | public final String callId; |
| 511 | public final String callerDisplayName; |
| 512 | |
| 513 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 514 | String callerDisplayName) { |
| 515 | this.component = component; |
| 516 | this.callId = callId; |
| 517 | this.callerDisplayName = callerDisplayName; |
| 518 | } |
| 519 | } |
| 520 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | /** |
| 522 | * A handler that processes messages on the main thread in the phone process. Since many |
| 523 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 524 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 525 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 526 | * on, which will be notified when the operation completes and will contain the result of the |
| 527 | * request. |
| 528 | * |
| 529 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 530 | * note that request.result must be set to something non-null for the calling thread to |
| 531 | * unblock. |
| 532 | */ |
| 533 | private final class MainThreadHandler extends Handler { |
| 534 | @Override |
| 535 | public void handleMessage(Message msg) { |
| 536 | MainThreadRequest request; |
| 537 | Message onCompleted; |
| 538 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 539 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 541 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | |
| 543 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | case CMD_HANDLE_USSD_REQUEST: { |
| 545 | request = (MainThreadRequest) msg.obj; |
| 546 | final Phone phone = getPhoneFromRequest(request); |
| 547 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 548 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 550 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | if (!isUssdApiAllowed(request.subId)) { |
| 552 | // Carrier does not support use of this API, return failure. |
| 553 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 554 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 555 | Bundle returnData = new Bundle(); |
| 556 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 557 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 558 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | request.result = true; |
| 560 | notifyRequester(request); |
| 561 | return; |
| 562 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 563 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | try { |
| 565 | request.result = phone != null |
| 566 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 567 | } catch (CallStateException cse) { |
| 568 | request.result = false; |
| 569 | } |
| 570 | // Wake up the requesting thread |
| 571 | notifyRequester(request); |
| 572 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 575 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 577 | final Phone phone = getPhoneFromRequest(request); |
| 578 | request.result = phone != null ? |
| 579 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 580 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 589 | uiccPort = getUiccPortFromRequest(request); |
| 590 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 592 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 596 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 597 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 598 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 599 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 600 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | break; |
| 603 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | ar = (AsyncResult) msg.obj; |
| 606 | request = (MainThreadRequest) ar.userObj; |
| 607 | if (ar.exception == null && ar.result != null) { |
| 608 | request.result = ar.result; |
| 609 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 610 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 611 | if (ar.result == null) { |
| 612 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 613 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 615 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } else { |
| 617 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 618 | } |
| 619 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 624 | request = (MainThreadRequest) msg.obj; |
| 625 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 626 | uiccPort = getUiccPortFromRequest(request); |
| 627 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 629 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | } else { |
| 632 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 634 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 635 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 636 | iccArgument.p2, |
| 637 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 | } |
| 639 | break; |
| 640 | |
| 641 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 642 | ar = (AsyncResult) msg.obj; |
| 643 | request = (MainThreadRequest) ar.userObj; |
| 644 | if (ar.exception == null && ar.result != null) { |
| 645 | request.result = ar.result; |
| 646 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 647 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 648 | if (ar.result == null) { |
| 649 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 650 | } else if (ar.exception instanceof CommandException) { |
| 651 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 652 | ar.exception); |
| 653 | } else { |
| 654 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 655 | } |
| 656 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | break; |
| 659 | |
| 660 | case CMD_EXCHANGE_SIM_IO: |
| 661 | request = (MainThreadRequest) msg.obj; |
| 662 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 663 | uiccPort = getUiccPortFromRequest(request); |
| 664 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 665 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 666 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 667 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 668 | } else { |
| 669 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 670 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 671 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 673 | iccArgument.data, onCompleted); |
| 674 | } |
| 675 | break; |
| 676 | |
| 677 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 678 | ar = (AsyncResult) msg.obj; |
| 679 | request = (MainThreadRequest) ar.userObj; |
| 680 | if (ar.exception == null && ar.result != null) { |
| 681 | request.result = ar.result; |
| 682 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 683 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 688 | case CMD_SEND_ENVELOPE: |
| 689 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 690 | uiccPort = getUiccPortFromRequest(request); |
| 691 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 692 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 693 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 694 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 695 | } else { |
| 696 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 697 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 698 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case EVENT_SEND_ENVELOPE_DONE: |
| 702 | ar = (AsyncResult) msg.obj; |
| 703 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 704 | if (ar.exception == null && ar.result != null) { |
| 705 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 706 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 707 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 708 | if (ar.result == null) { |
| 709 | loge("sendEnvelopeWithStatus: Empty response"); |
| 710 | } else if (ar.exception instanceof CommandException) { |
| 711 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 712 | ar.exception); |
| 713 | } else { |
| 714 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 715 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 716 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 718 | break; |
| 719 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | case CMD_OPEN_CHANNEL: |
| 721 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 722 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 723 | IccLogicalChannelRequest openChannelRequest = |
| 724 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 725 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 726 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 727 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 728 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 729 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 730 | } else { |
| 731 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 732 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 733 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 734 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_OPEN_CHANNEL_DONE: |
| 738 | ar = (AsyncResult) msg.obj; |
| 739 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 740 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 742 | int[] result = (int[]) ar.result; |
| 743 | int channelId = result[0]; |
| 744 | byte[] selectResponse = null; |
| 745 | if (result.length > 1) { |
| 746 | selectResponse = new byte[result.length - 1]; |
| 747 | for (int i = 1; i < result.length; ++i) { |
| 748 | selectResponse[i - 1] = (byte) result[i]; |
| 749 | } |
| 750 | } |
| 751 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 752 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 753 | |
| 754 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 755 | if (uiccPort == null) { |
| 756 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 757 | } else { |
| 758 | IccLogicalChannelRequest channelRequest = |
| 759 | (IccLogicalChannelRequest) request.argument; |
| 760 | channelRequest.channel = channelId; |
| 761 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 762 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | if (ar.result == null) { |
| 765 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 766 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 767 | if (ar.exception != null) { |
| 768 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 769 | } |
| 770 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 771 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 772 | if (ar.exception instanceof CommandException) { |
| 773 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 774 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 775 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 776 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 777 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 778 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 782 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 783 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 784 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 785 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case CMD_CLOSE_CHANNEL: |
| 789 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 790 | uiccPort = getUiccPortFromRequest(request); |
| 791 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 792 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 793 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 794 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 795 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 796 | } else { |
| 797 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 798 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 799 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | if (ar.exception == null) { |
| 806 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 807 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 808 | if (uiccPort == null) { |
| 809 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 810 | } else { |
| 811 | final int channelId = (Integer) request.argument; |
| 812 | uiccPort.onLogicalChannelClosed(channelId); |
| 813 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 814 | } else { |
| 815 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 816 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 817 | if (ar.exception instanceof CommandException) { |
| 818 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 819 | CommandException.Error error = |
| 820 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 821 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 822 | // should only throw exceptions from the binder threads. |
| 823 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 824 | "iccCloseLogicalChannel: invalid argument "); |
| 825 | } |
| 826 | } else { |
| 827 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 828 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 829 | request.result = (exception != null) ? exception : |
| 830 | new IllegalStateException( |
| 831 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 832 | } |
| 833 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case CMD_NV_READ_ITEM: |
| 837 | request = (MainThreadRequest) msg.obj; |
| 838 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 839 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 840 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 841 | break; |
| 842 | |
| 843 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 844 | ar = (AsyncResult) msg.obj; |
| 845 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 846 | if (ar.exception == null && ar.result != null) { |
| 847 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 849 | request.result = ""; |
| 850 | if (ar.result == null) { |
| 851 | loge("nvReadItem: Empty response"); |
| 852 | } else if (ar.exception instanceof CommandException) { |
| 853 | loge("nvReadItem: CommandException: " + |
| 854 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 855 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 856 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 857 | } |
| 858 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 859 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 860 | break; |
| 861 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 862 | case CMD_NV_WRITE_ITEM: |
| 863 | request = (MainThreadRequest) msg.obj; |
| 864 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 865 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 866 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 867 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case EVENT_NV_WRITE_ITEM_DONE: |
| 871 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 872 | break; |
| 873 | |
| 874 | case CMD_NV_WRITE_CDMA_PRL: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 877 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 881 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 882 | break; |
| 883 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 884 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 886 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 887 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 890 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 891 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 892 | break; |
| 893 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 894 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 895 | request = (MainThreadRequest) msg.obj; |
| 896 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 897 | request); |
| 898 | Phone phone = getPhoneFromRequest(request); |
| 899 | if (phone != null) { |
| 900 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 901 | } else { |
| 902 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 903 | request.result = false; |
| 904 | notifyRequester(request); |
| 905 | } |
| 906 | break; |
| 907 | } |
| 908 | |
| 909 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 910 | ar = (AsyncResult) msg.obj; |
| 911 | request = (MainThreadRequest) ar.userObj; |
| 912 | if (ar.exception == null && ar.result != null) { |
| 913 | request.result = ar.result; |
| 914 | } else { |
| 915 | // request.result must be set to something non-null |
| 916 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 917 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 918 | request.result = ar.result; |
| 919 | } else { |
| 920 | request.result = false; |
| 921 | } |
| 922 | if (ar.result == null) { |
| 923 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 924 | } else if (ar.exception instanceof CommandException) { |
| 925 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 926 | + ar.exception); |
| 927 | } else { |
| 928 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 929 | } |
| 930 | } |
| 931 | notifyRequester(request); |
| 932 | break; |
| 933 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 934 | case CMD_IS_VONR_ENABLED: { |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 937 | request); |
| 938 | Phone phone = getPhoneFromRequest(request); |
| 939 | if (phone != null) { |
| 940 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 941 | } else { |
| 942 | loge("isVoNrEnabled: No phone object"); |
| 943 | request.result = false; |
| 944 | notifyRequester(request); |
| 945 | } |
| 946 | break; |
| 947 | } |
| 948 | |
| 949 | case EVENT_IS_VONR_ENABLED_DONE: |
| 950 | ar = (AsyncResult) msg.obj; |
| 951 | request = (MainThreadRequest) ar.userObj; |
| 952 | if (ar.exception == null && ar.result != null) { |
| 953 | request.result = ar.result; |
| 954 | } else { |
| 955 | // request.result must be set to something non-null |
| 956 | // for the calling thread to unblock |
| 957 | if (ar.result != null) { |
| 958 | request.result = ar.result; |
| 959 | } else { |
| 960 | request.result = false; |
| 961 | } |
| 962 | if (ar.result == null) { |
| 963 | loge("isVoNrEnabled: Empty response"); |
| 964 | } else if (ar.exception instanceof CommandException) { |
| 965 | loge("isVoNrEnabled: CommandException: " |
| 966 | + ar.exception); |
| 967 | } else { |
| 968 | loge("isVoNrEnabled: Unknown exception"); |
| 969 | } |
| 970 | } |
| 971 | notifyRequester(request); |
| 972 | break; |
| 973 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 974 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 975 | request = (MainThreadRequest) msg.obj; |
| 976 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 977 | Phone phone = getPhoneFromRequest(request); |
| 978 | if (phone != null) { |
| 979 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 980 | request.workSource); |
| 981 | } else { |
| 982 | loge("enableNrDualConnectivity: No phone object"); |
| 983 | request.result = |
| 984 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 985 | notifyRequester(request); |
| 986 | } |
| 987 | break; |
| 988 | } |
| 989 | |
| 990 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 991 | ar = (AsyncResult) msg.obj; |
| 992 | request = (MainThreadRequest) ar.userObj; |
| 993 | if (ar.exception == null) { |
| 994 | request.result = |
| 995 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 996 | } else { |
| 997 | request.result = |
| 998 | TelephonyManager |
| 999 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 1000 | if (ar.exception instanceof CommandException) { |
| 1001 | CommandException.Error error = |
| 1002 | ((CommandException) (ar.exception)).getCommandError(); |
| 1003 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1004 | request.result = |
| 1005 | TelephonyManager |
| 1006 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1007 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1008 | request.result = |
| 1009 | TelephonyManager |
| 1010 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1011 | } |
| 1012 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1013 | + ar.exception); |
| 1014 | } else { |
| 1015 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1016 | } |
| 1017 | } |
| 1018 | notifyRequester(request); |
| 1019 | break; |
| 1020 | } |
| 1021 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1022 | case CMD_ENABLE_VONR: { |
| 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1025 | Phone phone = getPhoneFromRequest(request); |
| 1026 | if (phone != null) { |
| 1027 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1028 | request.workSource); |
| 1029 | } else { |
| 1030 | loge("setVoNrEnabled: No phone object"); |
| 1031 | request.result = |
| 1032 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1033 | notifyRequester(request); |
| 1034 | } |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | case EVENT_ENABLE_VONR_DONE: { |
| 1039 | ar = (AsyncResult) msg.obj; |
| 1040 | request = (MainThreadRequest) ar.userObj; |
| 1041 | if (ar.exception == null) { |
| 1042 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1043 | } else { |
| 1044 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1045 | if (ar.exception instanceof CommandException) { |
| 1046 | CommandException.Error error = |
| 1047 | ((CommandException) (ar.exception)).getCommandError(); |
| 1048 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1049 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1050 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1051 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1052 | } else { |
| 1053 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1054 | } |
| 1055 | loge("setVoNrEnabled" + ": CommandException: " |
| 1056 | + ar.exception); |
| 1057 | } else { |
| 1058 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1059 | } |
| 1060 | } |
| 1061 | notifyRequester(request); |
| 1062 | break; |
| 1063 | } |
| 1064 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1065 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1066 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1067 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1068 | request); |
| 1069 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1070 | break; |
| 1071 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1072 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1073 | ar = (AsyncResult) msg.obj; |
| 1074 | request = (MainThreadRequest) ar.userObj; |
| 1075 | if (ar.exception == null && ar.result != null) { |
| 1076 | request.result = ar.result; // Integer |
| 1077 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1078 | // request.result must be set to something non-null |
| 1079 | // for the calling thread to unblock |
| 1080 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1081 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1082 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1083 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1084 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1085 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1086 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1087 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1088 | } |
| 1089 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1090 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1091 | break; |
| 1092 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1093 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1094 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1095 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1096 | request); |
| 1097 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1098 | (Pair<Integer, Long>) request.argument; |
| 1099 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1100 | reasonWithNetworkTypes.first, |
| 1101 | reasonWithNetworkTypes.second, |
| 1102 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1103 | break; |
| 1104 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1105 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1106 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1107 | break; |
| 1108 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1109 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1110 | request = (MainThreadRequest)msg.obj; |
| 1111 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1112 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1113 | break; |
| 1114 | |
| 1115 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1116 | ar = (AsyncResult)msg.obj; |
| 1117 | request = (MainThreadRequest)ar.userObj; |
| 1118 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1119 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1120 | break; |
| 1121 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1122 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1123 | request = (MainThreadRequest) msg.obj; |
| 1124 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1125 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1126 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1127 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1128 | break; |
| 1129 | |
| 1130 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1131 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1132 | break; |
| 1133 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1134 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1135 | request = (MainThreadRequest) msg.obj; |
| 1136 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1137 | request); |
| 1138 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1139 | break; |
| 1140 | |
| 1141 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1142 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1143 | break; |
| 1144 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1145 | case CMD_PERFORM_NETWORK_SCAN: |
| 1146 | request = (MainThreadRequest) msg.obj; |
| 1147 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1148 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1149 | break; |
| 1150 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1151 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | request = (MainThreadRequest) msg.obj; |
| 1153 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1154 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1155 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1156 | request.argument; |
| 1157 | int callForwardingReason = args.first; |
| 1158 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1159 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1160 | } |
| 1161 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | ar = (AsyncResult) msg.obj; |
| 1163 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1164 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1165 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1166 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1167 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1168 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1169 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1170 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1171 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1172 | // any service for voice call. |
| 1173 | if ((callForwardInfo.serviceClass |
| 1174 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1175 | callForwardingInfo = new CallForwardingInfo( |
| 1176 | callForwardInfo.status |
| 1177 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1178 | callForwardInfo.reason, |
| 1179 | callForwardInfo.number, |
| 1180 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1181 | break; |
| 1182 | } |
| 1183 | } |
| 1184 | // Didn't find a call forward info for voice call. |
| 1185 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1186 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1187 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1188 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1189 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1190 | } else { |
| 1191 | if (ar.result == null) { |
| 1192 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1193 | } |
| 1194 | if (ar.exception != null) { |
| 1195 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1196 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1197 | int errorCode = TelephonyManager |
| 1198 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1199 | if (ar.exception instanceof CommandException) { |
| 1200 | CommandException.Error error = |
| 1201 | ((CommandException) (ar.exception)).getCommandError(); |
| 1202 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1203 | errorCode = TelephonyManager |
| 1204 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1206 | errorCode = TelephonyManager |
| 1207 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | } |
| 1209 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1210 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1215 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1216 | request = (MainThreadRequest) msg.obj; |
| 1217 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1220 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1221 | request.argument).first; |
| 1222 | request.phone.setCallForwardingOption( |
| 1223 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1224 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | callForwardingInfoToSet.getReason(), |
| 1227 | callForwardingInfoToSet.getNumber(), |
| 1228 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1229 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1232 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | ar = (AsyncResult) msg.obj; |
| 1234 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | Consumer<Integer> callback = |
| 1236 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1237 | request.argument).second; |
| 1238 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1239 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1240 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1241 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | if (ar.exception instanceof CommandException) { |
| 1243 | CommandException.Error error = |
| 1244 | ((CommandException) (ar.exception)).getCommandError(); |
| 1245 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1246 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1247 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1248 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1249 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1250 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | } |
| 1252 | } |
| 1253 | callback.accept(errorCode); |
| 1254 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1255 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | request = (MainThreadRequest) msg.obj; |
| 1262 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1263 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1264 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1267 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | ar = (AsyncResult) msg.obj; |
| 1269 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1270 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1271 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1273 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1274 | // Service Class is a bit mask per 3gpp 27.007. |
| 1275 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1276 | if (callForwardResults.length > 1 |
| 1277 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1279 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1280 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1281 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1283 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1284 | } |
| 1285 | } else { |
| 1286 | if (ar.result == null) { |
| 1287 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1288 | } |
| 1289 | if (ar.exception != null) { |
| 1290 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1291 | } |
| 1292 | if (ar.exception instanceof CommandException) { |
| 1293 | CommandException.Error error = |
| 1294 | ((CommandException) (ar.exception)).getCommandError(); |
| 1295 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1296 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1298 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1299 | callWaitingStatus = |
| 1300 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1304 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1308 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1309 | request = (MainThreadRequest) msg.obj; |
| 1310 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1311 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1312 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1316 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | ar = (AsyncResult) msg.obj; |
| 1318 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1319 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1320 | Consumer<Integer> callback = |
| 1321 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1322 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1323 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1324 | if (ar.exception instanceof CommandException) { |
| 1325 | CommandException.Error error = |
| 1326 | ((CommandException) (ar.exception)).getCommandError(); |
| 1327 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1328 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1329 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1330 | callback.accept( |
| 1331 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1332 | } else { |
| 1333 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1334 | } |
| 1335 | } else { |
| 1336 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1337 | } |
| 1338 | } else { |
| 1339 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1340 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1342 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1343 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1344 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1345 | ar = (AsyncResult) msg.obj; |
| 1346 | request = (MainThreadRequest) ar.userObj; |
| 1347 | CellNetworkScanResult cellScanResult; |
| 1348 | if (ar.exception == null && ar.result != null) { |
| 1349 | cellScanResult = new CellNetworkScanResult( |
| 1350 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1351 | (List<OperatorInfo>) ar.result); |
| 1352 | } else { |
| 1353 | if (ar.result == null) { |
| 1354 | loge("getCellNetworkScanResults: Empty response"); |
| 1355 | } |
| 1356 | if (ar.exception != null) { |
| 1357 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1358 | } |
| 1359 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1360 | if (ar.exception instanceof CommandException) { |
| 1361 | CommandException.Error error = |
| 1362 | ((CommandException) (ar.exception)).getCommandError(); |
| 1363 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1364 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1365 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1366 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1367 | } |
| 1368 | } |
| 1369 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1370 | } |
| 1371 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1372 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1373 | break; |
| 1374 | |
| 1375 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1376 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1377 | ManualNetworkSelectionArgument selArg = |
| 1378 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1379 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1380 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1381 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1382 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1383 | break; |
| 1384 | |
| 1385 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1386 | ar = (AsyncResult) msg.obj; |
| 1387 | request = (MainThreadRequest) ar.userObj; |
| 1388 | if (ar.exception == null) { |
| 1389 | request.result = true; |
| 1390 | } else { |
| 1391 | request.result = false; |
| 1392 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1393 | } |
| 1394 | notifyRequester(request); |
| 1395 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1396 | break; |
| 1397 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1398 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1399 | request = (MainThreadRequest) msg.obj; |
| 1400 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1401 | if (defaultPhone != null) { |
| 1402 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1403 | } else { |
| 1404 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1405 | Bundle bundle = new Bundle(); |
| 1406 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1407 | new ModemActivityInfo(0, 0, 0, |
| 1408 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1409 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1410 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1413 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1414 | ar = (AsyncResult) msg.obj; |
| 1415 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1416 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1417 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1418 | if (mLastModemActivityInfo == null) { |
| 1419 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1420 | mLastModemActivitySpecificInfo[0] = |
| 1421 | new ActivityStatsTechSpecificInfo( |
| 1422 | 0, |
| 1423 | 0, |
| 1424 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1425 | 0); |
| 1426 | mLastModemActivityInfo = |
| 1427 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1428 | } |
| 1429 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1430 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1431 | // Update the last modem activity info and the result of the request. |
| 1432 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1433 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1434 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1435 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1436 | mLastModemActivityInfo = |
| 1437 | new ModemActivityInfo( |
| 1438 | mLastModemActivityInfo.getTimestampMillis(), |
| 1439 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1440 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1441 | mLastModemActivitySpecificInfo); |
| 1442 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1443 | } else { |
| 1444 | if (ar.result == null) { |
| 1445 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1446 | error = TelephonyManager.ModemActivityInfoException |
| 1447 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1448 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1449 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | error = TelephonyManager.ModemActivityInfoException |
| 1451 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1452 | } else { |
| 1453 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1454 | error = TelephonyManager.ModemActivityInfoException |
| 1455 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1456 | } |
| 1457 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1458 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1459 | if (mLastModemActivityInfo != null) { |
| 1460 | bundle.putParcelable( |
| 1461 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1462 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1463 | } else { |
| 1464 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1465 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1466 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1467 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1468 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1469 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1470 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1471 | case CMD_SET_ALLOWED_CARRIERS: |
| 1472 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1473 | CarrierRestrictionRules argument = |
| 1474 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1475 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1476 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1477 | break; |
| 1478 | |
| 1479 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1480 | ar = (AsyncResult) msg.obj; |
| 1481 | request = (MainThreadRequest) ar.userObj; |
| 1482 | if (ar.exception == null && ar.result != null) { |
| 1483 | request.result = ar.result; |
| 1484 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1485 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1486 | if (ar.exception instanceof CommandException) { |
| 1487 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1488 | CommandException.Error error = |
| 1489 | ((CommandException) (ar.exception)).getCommandError(); |
| 1490 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1491 | request.result = |
| 1492 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1493 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1494 | } else { |
| 1495 | loge("setAllowedCarriers: Unknown exception"); |
| 1496 | } |
| 1497 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1498 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | |
| 1501 | case CMD_GET_ALLOWED_CARRIERS: |
| 1502 | request = (MainThreadRequest) msg.obj; |
| 1503 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1504 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1505 | break; |
| 1506 | |
| 1507 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1508 | ar = (AsyncResult) msg.obj; |
| 1509 | request = (MainThreadRequest) ar.userObj; |
| 1510 | if (ar.exception == null && ar.result != null) { |
| 1511 | request.result = ar.result; |
| 1512 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1513 | request.result = new IllegalStateException( |
| 1514 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1515 | if (ar.result == null) { |
| 1516 | loge("getAllowedCarriers: Empty response"); |
| 1517 | } else if (ar.exception instanceof CommandException) { |
| 1518 | loge("getAllowedCarriers: CommandException: " + |
| 1519 | ar.exception); |
| 1520 | } else { |
| 1521 | loge("getAllowedCarriers: Unknown exception"); |
| 1522 | } |
| 1523 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1524 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1525 | break; |
| 1526 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1527 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1528 | ar = (AsyncResult) msg.obj; |
| 1529 | request = (MainThreadRequest) ar.userObj; |
| 1530 | if (ar.exception == null && ar.result != null) { |
| 1531 | request.result = ar.result; |
| 1532 | } else { |
| 1533 | request.result = new IllegalArgumentException( |
| 1534 | "Failed to retrieve Forbidden Plmns"); |
| 1535 | if (ar.result == null) { |
| 1536 | loge("getForbiddenPlmns: Empty response"); |
| 1537 | } else { |
| 1538 | loge("getForbiddenPlmns: Unknown exception"); |
| 1539 | } |
| 1540 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1541 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1542 | break; |
| 1543 | |
| 1544 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1545 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1546 | uiccPort = getUiccPortFromRequest(request); |
| 1547 | if (uiccPort == null) { |
| 1548 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1549 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1550 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1551 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1552 | break; |
| 1553 | } |
| 1554 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1555 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1556 | if (uiccApp == null) { |
| 1557 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1558 | + appType); |
| 1559 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1560 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1561 | break; |
| 1562 | } else { |
| 1563 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1564 | + " specified type -- " + appType); |
| 1565 | } |
| 1566 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1567 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1568 | onCompleted); |
| 1569 | break; |
| 1570 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1571 | case CMD_SWITCH_SLOTS: |
| 1572 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1573 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1574 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1575 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1576 | break; |
| 1577 | |
| 1578 | case EVENT_SWITCH_SLOTS_DONE: |
| 1579 | ar = (AsyncResult) msg.obj; |
| 1580 | request = (MainThreadRequest) ar.userObj; |
| 1581 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1582 | notifyRequester(request); |
| 1583 | break; |
| 1584 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1585 | request = (MainThreadRequest) msg.obj; |
| 1586 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1587 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1588 | break; |
| 1589 | |
| 1590 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1591 | ar = (AsyncResult) msg.obj; |
| 1592 | request = (MainThreadRequest) ar.userObj; |
| 1593 | if (ar.exception != null) { |
| 1594 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1595 | } else { |
| 1596 | int mode = ((int[]) ar.result)[0]; |
| 1597 | if (mode == 0) { |
| 1598 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1599 | } else { |
| 1600 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1601 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1602 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1603 | notifyRequester(request); |
| 1604 | break; |
| 1605 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1606 | request = (MainThreadRequest) msg.obj; |
| 1607 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1608 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1609 | break; |
| 1610 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1611 | ar = (AsyncResult) msg.obj; |
| 1612 | request = (MainThreadRequest) ar.userObj; |
| 1613 | if (ar.exception != null) { |
| 1614 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1615 | } else { |
| 1616 | request.result = ((int[]) ar.result)[0]; |
| 1617 | } |
| 1618 | notifyRequester(request); |
| 1619 | break; |
| 1620 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1621 | request = (MainThreadRequest) msg.obj; |
| 1622 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1623 | int mode = (int) request.argument; |
| 1624 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1625 | break; |
| 1626 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | request.result = ar.exception == null; |
| 1630 | notifyRequester(request); |
| 1631 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1632 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1633 | request = (MainThreadRequest) msg.obj; |
| 1634 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1635 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1636 | break; |
| 1637 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1638 | ar = (AsyncResult) msg.obj; |
| 1639 | request = (MainThreadRequest) ar.userObj; |
| 1640 | if (ar.exception != null) { |
| 1641 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1642 | } else { |
| 1643 | request.result = ((int[]) ar.result)[0]; |
| 1644 | } |
| 1645 | notifyRequester(request); |
| 1646 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1647 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1648 | request = (MainThreadRequest) msg.obj; |
| 1649 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1650 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1651 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1652 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1653 | break; |
| 1654 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1655 | ar = (AsyncResult) msg.obj; |
| 1656 | request = (MainThreadRequest) ar.userObj; |
| 1657 | request.result = ar.exception == null; |
| 1658 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1659 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | case CMD_GET_ALL_CELL_INFO: |
| 1661 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1662 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1663 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1664 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1665 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1666 | ar = (AsyncResult) msg.obj; |
| 1667 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1668 | // If a timeout occurs, the response will be null |
| 1669 | request.result = (ar.exception == null && ar.result != null) |
| 1670 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1671 | synchronized (request) { |
| 1672 | request.notifyAll(); |
| 1673 | } |
| 1674 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1675 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1676 | request = (MainThreadRequest) msg.obj; |
| 1677 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1678 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1679 | break; |
| 1680 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1681 | ar = (AsyncResult) msg.obj; |
| 1682 | request = (MainThreadRequest) ar.userObj; |
| 1683 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1684 | try { |
| 1685 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1686 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1687 | cb.onError( |
| 1688 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1689 | ar.exception.getClass().getName(), |
| 1690 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1691 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1692 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1693 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1694 | } else { |
| 1695 | // use the result as returned |
| 1696 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1697 | } |
| 1698 | } catch (RemoteException re) { |
| 1699 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1700 | } |
| 1701 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1702 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1703 | request = (MainThreadRequest) msg.obj; |
| 1704 | WorkSource ws = (WorkSource) request.argument; |
| 1705 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1706 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1707 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1708 | } |
| 1709 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1710 | ar = (AsyncResult) msg.obj; |
| 1711 | request = (MainThreadRequest) ar.userObj; |
| 1712 | if (ar.exception == null) { |
| 1713 | request.result = ar.result; |
| 1714 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1715 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1716 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1717 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | synchronized (request) { |
| 1721 | request.notifyAll(); |
| 1722 | } |
| 1723 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1724 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1725 | case CMD_MODEM_REBOOT: |
| 1726 | request = (MainThreadRequest) msg.obj; |
| 1727 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1728 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1729 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1730 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1731 | handleNullReturnEvent(msg, "rebootModem"); |
| 1732 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1733 | case CMD_REQUEST_ENABLE_MODEM: |
| 1734 | request = (MainThreadRequest) msg.obj; |
| 1735 | boolean enable = (boolean) request.argument; |
| 1736 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1737 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1738 | PhoneConfigurationManager.getInstance() |
| 1739 | .enablePhone(request.phone, enable, onCompleted); |
| 1740 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1741 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1742 | ar = (AsyncResult) msg.obj; |
| 1743 | request = (MainThreadRequest) ar.userObj; |
| 1744 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1745 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1746 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1747 | if ((boolean) request.result) { |
| 1748 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1749 | updateModemStateMetrics(); |
| 1750 | } else { |
| 1751 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1752 | + ar.exception); |
| 1753 | } |
| 1754 | notifyRequester(request); |
| 1755 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1756 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1757 | case CMD_GET_MODEM_STATUS: |
| 1758 | request = (MainThreadRequest) msg.obj; |
| 1759 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1760 | PhoneConfigurationManager.getInstance() |
| 1761 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1762 | break; |
| 1763 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1764 | ar = (AsyncResult) msg.obj; |
| 1765 | request = (MainThreadRequest) ar.userObj; |
| 1766 | int id = request.phone.getPhoneId(); |
| 1767 | if (ar.exception == null && ar.result != null) { |
| 1768 | request.result = ar.result; |
| 1769 | //update the cache as modem status has changed |
| 1770 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1771 | (boolean) request.result); |
| 1772 | } else { |
| 1773 | // Return true if modem status cannot be retrieved. For most cases, |
| 1774 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1775 | // and disable modem are not supported. Modem is always on. |
| 1776 | // TODO: this should be fixed in R to support a third |
| 1777 | // status UNKNOWN b/131631629 |
| 1778 | request.result = true; |
| 1779 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1780 | + ar.exception); |
| 1781 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1782 | notifyRequester(request); |
| 1783 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1784 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1785 | request = (MainThreadRequest) msg.obj; |
| 1786 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1787 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1788 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1789 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1790 | break; |
| 1791 | } |
| 1792 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1793 | ar = (AsyncResult) msg.obj; |
| 1794 | request = (MainThreadRequest) ar.userObj; |
| 1795 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1796 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1797 | args.second.accept(ar.exception == null); |
| 1798 | notifyRequester(request); |
| 1799 | break; |
| 1800 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1801 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1804 | Phone phone = getPhoneFromRequest(request); |
| 1805 | if (phone != null) { |
| 1806 | phone.getSystemSelectionChannels(onCompleted); |
| 1807 | } else { |
| 1808 | loge("getSystemSelectionChannels: No phone object"); |
| 1809 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1810 | notifyRequester(request); |
| 1811 | } |
| 1812 | break; |
| 1813 | } |
| 1814 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1815 | ar = (AsyncResult) msg.obj; |
| 1816 | request = (MainThreadRequest) ar.userObj; |
| 1817 | if (ar.exception == null && ar.result != null) { |
| 1818 | request.result = ar.result; |
| 1819 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1820 | request.result = new IllegalStateException( |
| 1821 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1822 | if (ar.result == null) { |
| 1823 | loge("getSystemSelectionChannels: Empty response"); |
| 1824 | } else { |
| 1825 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1826 | } |
| 1827 | } |
| 1828 | notifyRequester(request); |
| 1829 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1830 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1831 | ar = (AsyncResult) msg.obj; |
| 1832 | request = (MainThreadRequest) ar.userObj; |
| 1833 | if (ar.exception == null && ar.result != null) { |
| 1834 | request.result = ar.result; |
| 1835 | } else { |
| 1836 | request.result = -1; |
| 1837 | loge("Failed to set Forbidden Plmns"); |
| 1838 | if (ar.result == null) { |
| 1839 | loge("setForbidenPlmns: Empty response"); |
| 1840 | } else if (ar.exception != null) { |
| 1841 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1842 | request.result = -1; |
| 1843 | } else { |
| 1844 | loge("setForbiddenPlmns: Unknown exception"); |
| 1845 | } |
| 1846 | } |
| 1847 | notifyRequester(request); |
| 1848 | break; |
| 1849 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1850 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1851 | uiccPort = getUiccPortFromRequest(request); |
| 1852 | if (uiccPort == null) { |
| 1853 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1854 | request.result = -1; |
| 1855 | notifyRequester(request); |
| 1856 | break; |
| 1857 | } |
| 1858 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1859 | (Pair<Integer, List<String>>) request.argument; |
| 1860 | appType = setFplmnsArgs.first; |
| 1861 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1862 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1863 | if (uiccApp == null) { |
| 1864 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1865 | request.result = -1; |
| 1866 | loge("Failed to get UICC App"); |
| 1867 | notifyRequester(request); |
| 1868 | } else { |
| 1869 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1870 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1871 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1872 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1873 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1874 | case CMD_ERASE_MODEM_CONFIG: |
| 1875 | request = (MainThreadRequest) msg.obj; |
| 1876 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1877 | defaultPhone.eraseModemConfig(onCompleted); |
| 1878 | break; |
| 1879 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1880 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1881 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1882 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1883 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1884 | request = (MainThreadRequest) msg.obj; |
| 1885 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1886 | notifyRequester(request); |
| 1887 | break; |
| 1888 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1889 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1890 | request = (MainThreadRequest) msg.obj; |
| 1891 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1892 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1893 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1894 | changed.first, changed.second, onCompleted); |
| 1895 | break; |
| 1896 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1897 | ar = (AsyncResult) msg.obj; |
| 1898 | request = (MainThreadRequest) ar.userObj; |
| 1899 | if (ar.exception == null) { |
| 1900 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1901 | // If the operation is successful, update the PIN storage |
| 1902 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1903 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1904 | UiccController.getInstance().getPinStorage() |
| 1905 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1906 | } else { |
| 1907 | request.result = msg.arg1; |
| 1908 | } |
| 1909 | notifyRequester(request); |
| 1910 | break; |
| 1911 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1912 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1913 | request = (MainThreadRequest) msg.obj; |
| 1914 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1915 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1916 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1917 | enabled.first, enabled.second, onCompleted); |
| 1918 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1919 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1920 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1921 | ar = (AsyncResult) msg.obj; |
| 1922 | request = (MainThreadRequest) ar.userObj; |
| 1923 | if (ar.exception == null) { |
| 1924 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1925 | // If the operation is successful, update the PIN storage |
| 1926 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1927 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1928 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1929 | UiccController.getInstance().getPinStorage() |
| 1930 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1931 | } else { |
| 1932 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1933 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1934 | } else { |
| 1935 | request.result = msg.arg1; |
| 1936 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1937 | |
| 1938 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1939 | notifyRequester(request); |
| 1940 | break; |
| 1941 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1942 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1943 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1944 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1945 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1946 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1947 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1948 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1949 | |
| 1950 | case CMD_SET_DATA_THROTTLING: { |
| 1951 | request = (MainThreadRequest) msg.obj; |
| 1952 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1953 | DataThrottlingRequest dataThrottlingRequest = |
| 1954 | (DataThrottlingRequest) request.argument; |
| 1955 | Phone phone = getPhoneFromRequest(request); |
| 1956 | if (phone != null) { |
| 1957 | phone.setDataThrottling(onCompleted, |
| 1958 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1959 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1960 | } else { |
| 1961 | loge("setDataThrottling: No phone object"); |
| 1962 | request.result = |
| 1963 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1964 | notifyRequester(request); |
| 1965 | } |
| 1966 | |
| 1967 | break; |
| 1968 | } |
| 1969 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1970 | ar = (AsyncResult) msg.obj; |
| 1971 | request = (MainThreadRequest) ar.userObj; |
| 1972 | |
| 1973 | if (ar.exception == null) { |
| 1974 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1975 | } else if (ar.exception instanceof CommandException) { |
| 1976 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1977 | CommandException.Error error = |
| 1978 | ((CommandException) (ar.exception)).getCommandError(); |
| 1979 | |
| 1980 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1981 | request.result = TelephonyManager |
| 1982 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1983 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1984 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1985 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1986 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1987 | } else { |
| 1988 | request.result = |
| 1989 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1990 | } |
| 1991 | } else { |
| 1992 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1993 | } |
| 1994 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1995 | notifyRequester(request); |
| 1996 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1997 | |
| 1998 | case CMD_SET_SIM_POWER: { |
| 1999 | request = (MainThreadRequest) msg.obj; |
| 2000 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2001 | request = (MainThreadRequest) msg.obj; |
| 2002 | int stateToSet = |
| 2003 | ((Pair<Integer, IIntegerConsumer>) |
| 2004 | request.argument).first; |
| 2005 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2006 | break; |
| 2007 | } |
| 2008 | case EVENT_SET_SIM_POWER_DONE: { |
| 2009 | ar = (AsyncResult) msg.obj; |
| 2010 | request = (MainThreadRequest) ar.userObj; |
| 2011 | IIntegerConsumer callback = |
| 2012 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2013 | if (ar.exception != null) { |
| 2014 | loge("setSimPower exception: " + ar.exception); |
| 2015 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2016 | .RESULT_ERROR_UNKNOWN; |
| 2017 | if (ar.exception instanceof CommandException) { |
| 2018 | CommandException.Error error = |
| 2019 | ((CommandException) (ar.exception)).getCommandError(); |
| 2020 | if (error == CommandException.Error.SIM_ERR) { |
| 2021 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2022 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2023 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2024 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2025 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2026 | } else { |
| 2027 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2028 | } |
| 2029 | } |
| 2030 | try { |
| 2031 | callback.accept(errorCode); |
| 2032 | } catch (RemoteException e) { |
| 2033 | // Ignore if the remote process is no longer available to call back. |
| 2034 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2035 | } |
| 2036 | } else { |
| 2037 | try { |
| 2038 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2039 | } catch (RemoteException e) { |
| 2040 | // Ignore if the remote process is no longer available to call back. |
| 2041 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2042 | } |
| 2043 | } |
| 2044 | break; |
| 2045 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2046 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2047 | request = (MainThreadRequest) msg.obj; |
| 2048 | |
| 2049 | final Phone phone = getPhoneFromRequest(request); |
| 2050 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2051 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2052 | notifyRequester(request); |
| 2053 | break; |
| 2054 | } |
| 2055 | |
| 2056 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2057 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2058 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2059 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2060 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2061 | request.subId, pair.first /*callingUid*/, |
| 2062 | pair.second /*request*/, onCompleted); |
| 2063 | break; |
| 2064 | } |
| 2065 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2066 | ar = (AsyncResult) msg.obj; |
| 2067 | request = (MainThreadRequest) ar.userObj; |
| 2068 | // request.result will be the exception of ar if present, true otherwise. |
| 2069 | // Be cautious not to leave result null which will wait() forever |
| 2070 | request.result = ar.exception != null ? ar.exception : true; |
| 2071 | notifyRequester(request); |
| 2072 | break; |
| 2073 | } |
| 2074 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2075 | request = (MainThreadRequest) msg.obj; |
| 2076 | |
| 2077 | Phone phone = getPhoneFromRequest(request); |
| 2078 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2079 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2080 | notifyRequester(request); |
| 2081 | break; |
| 2082 | } |
| 2083 | |
| 2084 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2085 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2086 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2087 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2088 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2089 | request.subId, pair.first /*callingUid*/, |
| 2090 | pair.second /*request*/, onCompleted); |
| 2091 | break; |
| 2092 | } |
| 2093 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2094 | ar = (AsyncResult) msg.obj; |
| 2095 | request = (MainThreadRequest) ar.userObj; |
| 2096 | request.result = ar.exception != null ? ar.exception : true; |
| 2097 | notifyRequester(request); |
| 2098 | break; |
| 2099 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2100 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2101 | case CMD_GET_SLICING_CONFIG: { |
| 2102 | request = (MainThreadRequest) msg.obj; |
| 2103 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2104 | request.phone.getSlicingConfig(onCompleted); |
| 2105 | break; |
| 2106 | } |
| 2107 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2108 | ar = (AsyncResult) msg.obj; |
| 2109 | request = (MainThreadRequest) ar.userObj; |
| 2110 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2111 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2112 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2113 | Bundle bundle = new Bundle(); |
| 2114 | int resultCode = 0; |
| 2115 | if (ar.exception != null) { |
| 2116 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2117 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2118 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2119 | } else if (ar.result == null) { |
| 2120 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2121 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2122 | } else { |
| 2123 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2124 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2125 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2129 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2130 | } |
| 2131 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2132 | result.send(resultCode, bundle); |
| 2133 | notifyRequester(request); |
| 2134 | break; |
| 2135 | } |
| 2136 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2137 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2138 | request = (MainThreadRequest) msg.obj; |
| 2139 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2140 | UiccController.getInstance().getPinStorage() |
| 2141 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2142 | notifyRequester(request); |
| 2143 | break; |
| 2144 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2145 | default: |
| 2146 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2147 | break; |
| 2148 | } |
| 2149 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2150 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2151 | private void notifyRequester(MainThreadRequest request) { |
| 2152 | synchronized (request) { |
| 2153 | request.notifyAll(); |
| 2154 | } |
| 2155 | } |
| 2156 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2157 | private void handleNullReturnEvent(Message msg, String command) { |
| 2158 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2159 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2160 | if (ar.exception == null) { |
| 2161 | request.result = true; |
| 2162 | } else { |
| 2163 | request.result = false; |
| 2164 | if (ar.exception instanceof CommandException) { |
| 2165 | loge(command + ": CommandException: " + ar.exception); |
| 2166 | } else { |
| 2167 | loge(command + ": Unknown exception"); |
| 2168 | } |
| 2169 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2170 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * Posts the specified command to be executed on the main thread, |
| 2176 | * waits for the request to complete, and returns the result. |
| 2177 | * @see #sendRequestAsync |
| 2178 | */ |
| 2179 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2180 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2181 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | /** |
| 2185 | * Posts the specified command to be executed on the main thread, |
| 2186 | * waits for the request to complete, and returns the result. |
| 2187 | * @see #sendRequestAsync |
| 2188 | */ |
| 2189 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2190 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2191 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
| 2194 | /** |
| 2195 | * Posts the specified command to be executed on the main thread, |
| 2196 | * waits for the request to complete, and returns the result. |
| 2197 | * @see #sendRequestAsync |
| 2198 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2199 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2200 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2201 | } |
| 2202 | |
| 2203 | /** |
| 2204 | * Posts the specified command to be executed on the main thread, |
| 2205 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2206 | * if not timeout or null otherwise. |
| 2207 | * @see #sendRequestAsync |
| 2208 | */ |
| 2209 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2210 | long timeoutInMs) { |
| 2211 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | /** |
| 2215 | * Posts the specified command to be executed on the main thread, |
| 2216 | * waits for the request to complete, and returns the result. |
| 2217 | * @see #sendRequestAsync |
| 2218 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2219 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2220 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /** |
| 2224 | * Posts the specified command to be executed on the main thread, |
| 2225 | * waits for the request to complete, and returns the result. |
| 2226 | * @see #sendRequestAsync |
| 2227 | */ |
| 2228 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2229 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2230 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2234 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2235 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2236 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2237 | * @see #sendRequestAsync |
| 2238 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2239 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2240 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2242 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2243 | } |
| 2244 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2245 | MainThreadRequest request = null; |
| 2246 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2247 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2248 | } else if (phone != null) { |
| 2249 | request = new MainThreadRequest(argument, phone, workSource); |
| 2250 | } else { |
| 2251 | request = new MainThreadRequest(argument, subId, workSource); |
| 2252 | } |
| 2253 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2255 | msg.sendToTarget(); |
| 2256 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2257 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2259 | if (timeoutInMs >= 0) { |
| 2260 | // Wait for at least timeoutInMs before returning null request result |
| 2261 | long now = SystemClock.elapsedRealtime(); |
| 2262 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2263 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2264 | try { |
| 2265 | request.wait(deadline - now); |
| 2266 | } catch (InterruptedException e) { |
| 2267 | // Do nothing, go back and check if request is completed or timeout |
| 2268 | } finally { |
| 2269 | now = SystemClock.elapsedRealtime(); |
| 2270 | } |
| 2271 | } |
| 2272 | } else { |
| 2273 | // Wait for the request to complete |
| 2274 | while (request.result == null) { |
| 2275 | try { |
| 2276 | request.wait(); |
| 2277 | } catch (InterruptedException e) { |
| 2278 | // Do nothing, go back and wait until the request is complete |
| 2279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2283 | if (request.result == null) { |
| 2284 | Log.wtf(LOG_TAG, |
| 2285 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2286 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2287 | return request.result; |
| 2288 | } |
| 2289 | |
| 2290 | /** |
| 2291 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2292 | * Posts the specified command to be executed on the main thread, and |
| 2293 | * returns immediately. |
| 2294 | * @see #sendRequest |
| 2295 | */ |
| 2296 | private void sendRequestAsync(int command) { |
| 2297 | mMainThreadHandler.sendEmptyMessage(command); |
| 2298 | } |
| 2299 | |
| 2300 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2301 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2302 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2303 | */ |
| 2304 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2305 | sendRequestAsync(command, argument, null, null); |
| 2306 | } |
| 2307 | |
| 2308 | /** |
| 2309 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2310 | * @see {@link #sendRequest(int,Object)} |
| 2311 | */ |
| 2312 | private void sendRequestAsync( |
| 2313 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2314 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2315 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2316 | msg.sendToTarget(); |
| 2317 | } |
| 2318 | |
| 2319 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2321 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2322 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2323 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2324 | synchronized (PhoneInterfaceManager.class) { |
| 2325 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2326 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | } else { |
| 2328 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2329 | } |
| 2330 | return sInstance; |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2335 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2337 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2338 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2339 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2341 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2342 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2343 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2344 | mTelephonySharedPreferences = |
| 2345 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2346 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2347 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2348 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2349 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2350 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Gil Cukierman | 6dac5eb | 2022-09-19 16:09:04 +0000 | [diff] [blame] | 2351 | mTelephony2gUpdater = new Telephony2gUpdater( |
| 2352 | Executors.newSingleThreadExecutor(), mApp); |
| 2353 | mTelephony2gUpdater.init(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | publish(); |
| 2355 | } |
| 2356 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2357 | private Phone getDefaultPhone() { |
| 2358 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2359 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2360 | } |
| 2361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2362 | private void publish() { |
| 2363 | if (DBG) log("publish: " + this); |
| 2364 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2365 | TelephonyFrameworkInitializer |
| 2366 | .getTelephonyServiceManager() |
| 2367 | .getTelephonyServiceRegisterer() |
| 2368 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2371 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2372 | if (request.phone != null) { |
| 2373 | return request.phone; |
| 2374 | } else { |
| 2375 | return getPhoneFromSubId(request.subId); |
| 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | private Phone getPhoneFromSubId(int subId) { |
| 2380 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2381 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2382 | } |
| 2383 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2384 | @Nullable |
| 2385 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2386 | Phone phone = getPhoneFromRequest(request); |
| 2387 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2388 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2389 | } |
| 2390 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2391 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2392 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2393 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2394 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2396 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2397 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2398 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2399 | } |
| 2400 | |
| 2401 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2402 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2403 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2406 | private boolean isImsAvailableOnDevice() { |
| 2407 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2408 | if (pm == null) { |
| 2409 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2410 | // so do not throw error and allow. |
| 2411 | return true; |
| 2412 | } |
| 2413 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2414 | } |
| 2415 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2417 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2420 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | if (DBG) log("dial: " + number); |
| 2422 | // No permission check needed here: This is just a wrapper around the |
| 2423 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2424 | // the UI before it does anything. |
| 2425 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | final long identity = Binder.clearCallingIdentity(); |
| 2427 | try { |
| 2428 | String url = createTelUrl(number); |
| 2429 | if (url == null) { |
| 2430 | return; |
| 2431 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2433 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2434 | PhoneConstants.State state = mCM.getState(subId); |
| 2435 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2436 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2437 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2438 | mApp.startActivity(intent); |
| 2439 | } |
| 2440 | } finally { |
| 2441 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2446 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2449 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2450 | if (DBG) log("call: " + number); |
| 2451 | |
| 2452 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2453 | // need to do a permission check since we're calling startActivity() |
| 2454 | // from the context of the phone app. |
| 2455 | enforceCallPermission(); |
| 2456 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2457 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | != AppOpsManager.MODE_ALLOWED) { |
| 2459 | return; |
| 2460 | } |
| 2461 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | final long identity = Binder.clearCallingIdentity(); |
| 2463 | try { |
| 2464 | String url = createTelUrl(number); |
| 2465 | if (url == null) { |
| 2466 | return; |
| 2467 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | boolean isValid = false; |
| 2470 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2471 | if (slist != null) { |
| 2472 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2473 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2474 | isValid = true; |
| 2475 | break; |
| 2476 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2477 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2478 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2479 | if (!isValid) { |
| 2480 | return; |
| 2481 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2482 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2483 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2484 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2485 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2486 | mApp.startActivity(intent); |
| 2487 | } finally { |
| 2488 | Binder.restoreCallingIdentity(identity); |
| 2489 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2492 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2493 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2494 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2495 | } |
| 2496 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2497 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2498 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2499 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2500 | } |
| 2501 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2502 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | |
| 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2507 | Phone phone = getPhone(subId); |
| 2508 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2509 | checkSimPin.start(); |
| 2510 | return checkSimPin.unlockSim(null, pin); |
| 2511 | } finally { |
| 2512 | Binder.restoreCallingIdentity(identity); |
| 2513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2516 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | |
| 2519 | final long identity = Binder.clearCallingIdentity(); |
| 2520 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2521 | Phone phone = getPhone(subId); |
| 2522 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | checkSimPuk.start(); |
| 2524 | return checkSimPuk.unlockSim(puk, pin); |
| 2525 | } finally { |
| 2526 | Binder.restoreCallingIdentity(identity); |
| 2527 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2531 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | * a synchronous one. |
| 2533 | */ |
| 2534 | private static class UnlockSim extends Thread { |
| 2535 | |
| 2536 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2537 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | |
| 2539 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2540 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2541 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2542 | |
| 2543 | // For replies from SimCard interface |
| 2544 | private Handler mHandler; |
| 2545 | |
| 2546 | // For async handler to identify request type |
| 2547 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2548 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2549 | UnlockSim(int phoneId, IccCard simCard) { |
| 2550 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | mSimCard = simCard; |
| 2552 | } |
| 2553 | |
| 2554 | @Override |
| 2555 | public void run() { |
| 2556 | Looper.prepare(); |
| 2557 | synchronized (UnlockSim.this) { |
| 2558 | mHandler = new Handler() { |
| 2559 | @Override |
| 2560 | public void handleMessage(Message msg) { |
| 2561 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2562 | switch (msg.what) { |
| 2563 | case SUPPLY_PIN_COMPLETE: |
| 2564 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2565 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2566 | mRetryCount = msg.arg1; |
| 2567 | if (ar.exception != null) { |
| 2568 | if (ar.exception instanceof CommandException && |
| 2569 | ((CommandException)(ar.exception)).getCommandError() |
| 2570 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2571 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2572 | } //When UiccCardApp dispose,handle message and return exception |
| 2573 | else if (ar.exception instanceof CommandException && |
| 2574 | ((CommandException) (ar.exception)).getCommandError() |
| 2575 | == CommandException.Error.ABORTED) { |
| 2576 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2577 | } else { |
| 2578 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2579 | } |
| 2580 | } else { |
| 2581 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | mDone = true; |
| 2584 | UnlockSim.this.notifyAll(); |
| 2585 | } |
| 2586 | break; |
| 2587 | } |
| 2588 | } |
| 2589 | }; |
| 2590 | UnlockSim.this.notifyAll(); |
| 2591 | } |
| 2592 | Looper.loop(); |
| 2593 | } |
| 2594 | |
| 2595 | /* |
| 2596 | * Use PIN or PUK to unlock SIM card |
| 2597 | * |
| 2598 | * If PUK is null, unlock SIM card with PIN |
| 2599 | * |
| 2600 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2601 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2602 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2603 | |
| 2604 | while (mHandler == null) { |
| 2605 | try { |
| 2606 | wait(); |
| 2607 | } catch (InterruptedException e) { |
| 2608 | Thread.currentThread().interrupt(); |
| 2609 | } |
| 2610 | } |
| 2611 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2612 | |
| 2613 | if (puk == null) { |
| 2614 | mSimCard.supplyPin(pin, callback); |
| 2615 | } else { |
| 2616 | mSimCard.supplyPuk(puk, pin, callback); |
| 2617 | } |
| 2618 | |
| 2619 | while (!mDone) { |
| 2620 | try { |
| 2621 | Log.d(LOG_TAG, "wait for done"); |
| 2622 | wait(); |
| 2623 | } catch (InterruptedException e) { |
| 2624 | // Restore the interrupted status |
| 2625 | Thread.currentThread().interrupt(); |
| 2626 | } |
| 2627 | } |
| 2628 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2629 | int[] resultArray = new int[2]; |
| 2630 | resultArray[0] = mResult; |
| 2631 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2632 | |
| 2633 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2634 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2637 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2638 | } |
| 2639 | } |
| 2640 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2641 | /** |
| 2642 | * This method has been removed due to privacy and stability concerns. |
| 2643 | */ |
| 2644 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2645 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2646 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2647 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2650 | @Override |
| 2651 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2652 | mApp.getSystemService(AppOpsManager.class) |
| 2653 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2654 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2655 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2656 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2657 | // Callers targeting S have no business invoking this method. |
| 2658 | return; |
| 2659 | } |
| 2660 | |
| 2661 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2662 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2663 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2664 | .setCallingPackage(callingPackage) |
| 2665 | .setCallingFeatureId(null) |
| 2666 | .setCallingPid(Binder.getCallingPid()) |
| 2667 | .setCallingUid(Binder.getCallingUid()) |
| 2668 | .setMethod("updateServiceLocation") |
| 2669 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2670 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2671 | .build()); |
| 2672 | // Apps that lack location permission have no business calling this method; |
| 2673 | // however, because no permission was declared in the public API, denials must |
| 2674 | // all be "soft". |
| 2675 | switch (locationResult) { |
| 2676 | case DENIED_HARD: /* fall through */ |
| 2677 | case DENIED_SOFT: |
| 2678 | return; |
| 2679 | } |
| 2680 | |
| 2681 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2684 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2685 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2686 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | } |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2693 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2694 | @Override |
| 2695 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2696 | return isRadioOnWithFeature(callingPackage, null); |
| 2697 | } |
| 2698 | |
| 2699 | |
| 2700 | @Override |
| 2701 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2702 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2703 | callingFeatureId); |
| 2704 | } |
| 2705 | |
| 2706 | @Deprecated |
| 2707 | @Override |
| 2708 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2709 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2712 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2713 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2714 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2715 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2716 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2717 | return false; |
| 2718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | |
| 2720 | final long identity = Binder.clearCallingIdentity(); |
| 2721 | try { |
| 2722 | return isRadioOnForSubscriber(subId); |
| 2723 | } finally { |
| 2724 | Binder.restoreCallingIdentity(identity); |
| 2725 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2729 | final long identity = Binder.clearCallingIdentity(); |
| 2730 | try { |
| 2731 | final Phone phone = getPhone(subId); |
| 2732 | if (phone != null) { |
| 2733 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2734 | } else { |
| 2735 | return false; |
| 2736 | } |
| 2737 | } finally { |
| 2738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2743 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2745 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2746 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2748 | |
| 2749 | final long identity = Binder.clearCallingIdentity(); |
| 2750 | try { |
| 2751 | final Phone phone = getPhone(subId); |
| 2752 | if (phone != null) { |
| 2753 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2754 | } |
| 2755 | } finally { |
| 2756 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2757 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2761 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2764 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2765 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2766 | |
| 2767 | final long identity = Binder.clearCallingIdentity(); |
| 2768 | try { |
| 2769 | final Phone phone = getPhone(subId); |
| 2770 | if (phone == null) { |
| 2771 | return false; |
| 2772 | } |
| 2773 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2774 | toggleRadioOnOffForSubscriber(subId); |
| 2775 | } |
| 2776 | return true; |
| 2777 | } finally { |
| 2778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2780 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2781 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2782 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2783 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2784 | /* |
| 2785 | * If any of the Radios are available, it will need to be |
| 2786 | * shutdown. So return true if any Radio is available. |
| 2787 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2791 | Phone phone = PhoneFactory.getPhone(i); |
| 2792 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2793 | } |
| 2794 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2795 | return false; |
| 2796 | } finally { |
| 2797 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2798 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2802 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2803 | enforceModifyPermission(); |
| 2804 | |
| 2805 | final long identity = Binder.clearCallingIdentity(); |
| 2806 | try { |
| 2807 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2808 | logv("Shutting down Phone " + i); |
| 2809 | shutdownRadioUsingPhoneId(i); |
| 2810 | } |
| 2811 | } finally { |
| 2812 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2817 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2818 | if (phone != null && phone.isRadioAvailable()) { |
| 2819 | phone.shutdownRadio(); |
| 2820 | } |
| 2821 | } |
| 2822 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2823 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2824 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | |
| 2826 | final long identity = Binder.clearCallingIdentity(); |
| 2827 | try { |
| 2828 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2829 | if (defaultPhone != null) { |
| 2830 | defaultPhone.setRadioPower(turnOn); |
| 2831 | return true; |
| 2832 | } else { |
| 2833 | loge("There's no default phone."); |
| 2834 | return false; |
| 2835 | } |
| 2836 | } finally { |
| 2837 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2838 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2841 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2842 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2843 | |
| 2844 | final long identity = Binder.clearCallingIdentity(); |
| 2845 | try { |
| 2846 | final Phone phone = getPhone(subId); |
| 2847 | if (phone != null) { |
| 2848 | phone.setRadioPower(turnOn); |
| 2849 | return true; |
| 2850 | } else { |
| 2851 | return false; |
| 2852 | } |
| 2853 | } finally { |
| 2854 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2855 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2856 | } |
| 2857 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2858 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2859 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2860 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2861 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | |
| 2863 | final long identity = Binder.clearCallingIdentity(); |
| 2864 | try { |
| 2865 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2866 | final Phone phone = getPhone(subId); |
| 2867 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2868 | if (phone.isUsingNewDataStack()) { |
| 2869 | phone.getDataSettingsManager().setDataEnabled( |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2870 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2871 | } else { |
| 2872 | phone.getDataEnabledSettings().setDataEnabled( |
| 2873 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2874 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2875 | return true; |
| 2876 | } else { |
| 2877 | return false; |
| 2878 | } |
| 2879 | } finally { |
| 2880 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2881 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2884 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2885 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2886 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2887 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2888 | |
| 2889 | final long identity = Binder.clearCallingIdentity(); |
| 2890 | try { |
| 2891 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2892 | final Phone phone = getPhone(subId); |
| 2893 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2894 | if (phone.isUsingNewDataStack()) { |
| 2895 | phone.getDataSettingsManager().setDataEnabled( |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2896 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2897 | } else { |
| 2898 | phone.getDataEnabledSettings().setDataEnabled( |
| 2899 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2900 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | return true; |
| 2902 | } else { |
| 2903 | return false; |
| 2904 | } |
| 2905 | } finally { |
| 2906 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2907 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2910 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2911 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2912 | final long identity = Binder.clearCallingIdentity(); |
| 2913 | try { |
| 2914 | final Phone phone = getPhone(subId); |
| 2915 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 2916 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | } else { |
| 2918 | return false; |
| 2919 | } |
| 2920 | } finally { |
| 2921 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2922 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2926 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2929 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | enforceCallPermission(); |
| 2931 | |
| 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
| 2934 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2935 | return; |
| 2936 | } |
| 2937 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2938 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2939 | } finally { |
| 2940 | Binder.restoreCallingIdentity(identity); |
| 2941 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2942 | }; |
| 2943 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2944 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | |
| 2947 | final long identity = Binder.clearCallingIdentity(); |
| 2948 | try { |
| 2949 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2950 | return false; |
| 2951 | } |
| 2952 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2953 | } finally { |
| 2954 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2955 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | } |
| 2957 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2958 | /** |
| 2959 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2960 | * tag on getCallState Binder call. |
| 2961 | */ |
| 2962 | @Deprecated |
| 2963 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2965 | if (CompatChanges.isChangeEnabled( |
| 2966 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2967 | Binder.getCallingUid())) { |
| 2968 | // Do not allow this API to be called on API version 31+, it should only be |
| 2969 | // called on old apps using this Binder call directly. |
| 2970 | throw new SecurityException("This method can only be used for applications " |
| 2971 | + "targeting API version 30 or less."); |
| 2972 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2973 | final long identity = Binder.clearCallingIdentity(); |
| 2974 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2975 | Phone phone = getPhone(getDefaultSubscription()); |
| 2976 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2977 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2978 | } finally { |
| 2979 | Binder.restoreCallingIdentity(identity); |
| 2980 | } |
| 2981 | } |
| 2982 | |
| 2983 | @Override |
| 2984 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2985 | if (CompatChanges.isChangeEnabled( |
| 2986 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2987 | Binder.getCallingUid())) { |
| 2988 | // Check READ_PHONE_STATE for API version 31+ |
| 2989 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2990 | featureId, "getCallStateForSubscription")) { |
| 2991 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2992 | + "targeting API level 31+."); |
| 2993 | } |
| 2994 | } |
| 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2999 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3000 | } finally { |
| 3001 | Binder.restoreCallingIdentity(identity); |
| 3002 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3005 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3006 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3007 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3008 | } |
| 3009 | |
| 3010 | @Override |
| 3011 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | final long identity = Binder.clearCallingIdentity(); |
| 3013 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3014 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3016 | if (phone.isUsingNewDataStack()) { |
| 3017 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3020 | } else { |
| 3021 | return PhoneConstantConversions.convertDataState( |
| 3022 | PhoneConstants.DataState.DISCONNECTED); |
| 3023 | } |
| 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3026 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3030 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3031 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3032 | } |
| 3033 | |
| 3034 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3035 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3036 | final long identity = Binder.clearCallingIdentity(); |
| 3037 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3038 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3039 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3040 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | } else { |
| 3042 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3043 | } |
| 3044 | } finally { |
| 3045 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3046 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3047 | } |
| 3048 | |
| 3049 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3050 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3051 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3052 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3053 | |
| 3054 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3055 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3056 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3057 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3058 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3059 | .setCallingPid(Binder.getCallingPid()) |
| 3060 | .setCallingUid(Binder.getCallingUid()) |
| 3061 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3062 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3063 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3064 | .build()); |
| 3065 | switch (locationResult) { |
| 3066 | case DENIED_HARD: |
| 3067 | throw new SecurityException("Not allowed to access cell location"); |
| 3068 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3069 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3070 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3073 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | final long identity = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3077 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3078 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
| 3081 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3084 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3085 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3086 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3087 | // registered cell info, so return a NULL country instead. |
| 3088 | final long identity = Binder.clearCallingIdentity(); |
| 3089 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3090 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3091 | // Get default phone in this case. |
| 3092 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3093 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3094 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3095 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3096 | if (phone == null) return ""; |
| 3097 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3098 | if (sst == null) return ""; |
| 3099 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3100 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3101 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3102 | } finally { |
| 3103 | Binder.restoreCallingIdentity(identity); |
| 3104 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3107 | /** |
| 3108 | * This method was removed due to potential issues caused by performing partial |
| 3109 | * updates of service state, and lack of a credible use case. |
| 3110 | * |
| 3111 | * This has the ability to break the telephony implementation by disabling notification of |
| 3112 | * changes in device connectivity. DO NOT USE THIS! |
| 3113 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3114 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3115 | public void enableLocationUpdates() { |
| 3116 | mApp.enforceCallingOrSelfPermission( |
| 3117 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3120 | /** |
| 3121 | * This method was removed due to potential issues caused by performing partial |
| 3122 | * updates of service state, and lack of a credible use case. |
| 3123 | * |
| 3124 | * This has the ability to break the telephony implementation by disabling notification of |
| 3125 | * changes in device connectivity. DO NOT USE THIS! |
| 3126 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3127 | @Override |
| 3128 | public void disableLocationUpdates() { |
| 3129 | mApp.enforceCallingOrSelfPermission( |
| 3130 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | @Override |
| 3134 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3135 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3136 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3137 | try { |
| 3138 | mApp.getSystemService(AppOpsManager.class) |
| 3139 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3140 | } catch (SecurityException e) { |
| 3141 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3142 | throw e; |
| 3143 | } |
| 3144 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3145 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3146 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3147 | throw new SecurityException( |
| 3148 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3149 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3150 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3151 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3152 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3153 | return null; |
| 3154 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3155 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3156 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3158 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3159 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3161 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3162 | for (CellInfo ci : info) { |
| 3163 | if (ci instanceof CellInfoGsm) { |
| 3164 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3165 | } else if (ci instanceof CellInfoWcdma) { |
| 3166 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3167 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3168 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3169 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3172 | private List<CellInfo> getCachedCellInfo() { |
| 3173 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3174 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3175 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3176 | if (info != null) cellInfos.addAll(info); |
| 3177 | } |
| 3178 | return cellInfos; |
| 3179 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3180 | |
| 3181 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3182 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3183 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3184 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3185 | |
| 3186 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3187 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3188 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3189 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3190 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3191 | .setCallingPid(Binder.getCallingPid()) |
| 3192 | .setCallingUid(Binder.getCallingUid()) |
| 3193 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3194 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3195 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3196 | .build()); |
| 3197 | switch (locationResult) { |
| 3198 | case DENIED_HARD: |
| 3199 | throw new SecurityException("Not allowed to access cell info"); |
| 3200 | case DENIED_SOFT: |
| 3201 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3204 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3205 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3206 | return getCachedCellInfo(); |
| 3207 | } |
| 3208 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3209 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3210 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | final long identity = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3214 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3215 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3216 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3217 | if (info != null) cellInfos.addAll(info); |
| 3218 | } |
| 3219 | return cellInfos; |
| 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3225 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3226 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3227 | String callingFeatureId) { |
| 3228 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3229 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3233 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3234 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3235 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3236 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3237 | } |
| 3238 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3239 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3240 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3241 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3242 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3243 | |
| 3244 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3245 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3246 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3247 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3248 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3249 | .setCallingPid(Binder.getCallingPid()) |
| 3250 | .setCallingUid(Binder.getCallingUid()) |
| 3251 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3252 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3253 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3254 | .build()); |
| 3255 | switch (locationResult) { |
| 3256 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3257 | if (TelephonyPermissions |
| 3258 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3259 | // Safetynet logging for b/154934934 |
| 3260 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3261 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3262 | throw new SecurityException("Not allowed to access cell info"); |
| 3263 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3264 | if (TelephonyPermissions |
| 3265 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3266 | // Safetynet logging for b/154934934 |
| 3267 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3268 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3269 | try { |
| 3270 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3271 | } catch (RemoteException re) { |
| 3272 | // Drop without consequences |
| 3273 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3274 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3277 | |
| 3278 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3279 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3280 | |
| 3281 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3282 | } |
| 3283 | |
| 3284 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3285 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3286 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3287 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | |
| 3289 | final long identity = Binder.clearCallingIdentity(); |
| 3290 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3291 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3292 | } finally { |
| 3293 | Binder.restoreCallingIdentity(identity); |
| 3294 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3295 | } |
| 3296 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3297 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3298 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3299 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3300 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3301 | return null; |
| 3302 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3303 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3304 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3305 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3306 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3307 | return null; |
| 3308 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | |
| 3310 | final long identity = Binder.clearCallingIdentity(); |
| 3311 | try { |
| 3312 | return phone.getImei(); |
| 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
| 3315 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3319 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3320 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3321 | String tac = null; |
| 3322 | if (phone != null) { |
| 3323 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3324 | try { |
| 3325 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3326 | } catch (IndexOutOfBoundsException e) { |
| 3327 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3328 | return null; |
| 3329 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3330 | } |
| 3331 | return tac; |
| 3332 | } |
| 3333 | |
| 3334 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3335 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3336 | try { |
| 3337 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3338 | } catch (SecurityException se) { |
| 3339 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3340 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3341 | + Binder.getCallingUid()); |
| 3342 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3343 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3344 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3345 | return null; |
| 3346 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3347 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3348 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3349 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3350 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3351 | return null; |
| 3352 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3353 | |
| 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
| 3356 | return phone.getMeid(); |
| 3357 | } finally { |
| 3358 | Binder.restoreCallingIdentity(identity); |
| 3359 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3363 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3364 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3365 | String manufacturerCode = null; |
| 3366 | if (phone != null) { |
| 3367 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3368 | try { |
| 3369 | manufacturerCode = |
| 3370 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3371 | } catch (IndexOutOfBoundsException e) { |
| 3372 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3373 | return null; |
| 3374 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3375 | } |
| 3376 | return manufacturerCode; |
| 3377 | } |
| 3378 | |
| 3379 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3380 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3381 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3382 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3383 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3384 | return null; |
| 3385 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3386 | int subId = phone.getSubId(); |
| 3387 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3388 | mApp, subId, callingPackage, callingFeatureId, |
| 3389 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3390 | return null; |
| 3391 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | |
| 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
| 3395 | return phone.getDeviceSvn(); |
| 3396 | } finally { |
| 3397 | Binder.restoreCallingIdentity(identity); |
| 3398 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3399 | } |
| 3400 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3401 | @Override |
| 3402 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3403 | final long identity = Binder.clearCallingIdentity(); |
| 3404 | try { |
| 3405 | final Phone phone = getPhone(subId); |
| 3406 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | @Override |
| 3413 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | final Phone phone = getPhone(subId); |
| 3417 | return phone == null ? null : phone.getCarrierName(); |
| 3418 | } finally { |
| 3419 | Binder.restoreCallingIdentity(identity); |
| 3420 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3421 | } |
| 3422 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3423 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3424 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3425 | final long identity = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | final Phone phone = getPhone(subId); |
| 3428 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3429 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3436 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3437 | final long identity = Binder.clearCallingIdentity(); |
| 3438 | try { |
| 3439 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3440 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3441 | } finally { |
| 3442 | Binder.restoreCallingIdentity(identity); |
| 3443 | } |
| 3444 | } |
| 3445 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3446 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3447 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3448 | if (!isSubscriptionMccMnc) { |
| 3449 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3450 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3451 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3452 | if (phone == null) { |
| 3453 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3454 | } |
| 3455 | final long identity = Binder.clearCallingIdentity(); |
| 3456 | try { |
| 3457 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3458 | } finally { |
| 3459 | Binder.restoreCallingIdentity(identity); |
| 3460 | } |
| 3461 | } |
| 3462 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3463 | // |
| 3464 | // Internal helper methods. |
| 3465 | // |
| 3466 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3467 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3468 | * Make sure the caller is the calling package itself |
| 3469 | * |
| 3470 | * @throws SecurityException if the caller is not the calling package |
| 3471 | */ |
| 3472 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3473 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3474 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3475 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3476 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3477 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3478 | } catch (PackageManager.NameNotFoundException e) { |
| 3479 | // packageUid is -1 |
| 3480 | } |
| 3481 | if (packageUid != callingUid) { |
| 3482 | throw new SecurityException(message + ": Package " + callingPackage |
| 3483 | + " does not belong to " + callingUid); |
| 3484 | } |
| 3485 | } |
| 3486 | |
| 3487 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3488 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3489 | * |
| 3490 | * @throws SecurityException if the caller does not have the required permission |
| 3491 | */ |
| 3492 | private void enforceModifyPermission() { |
| 3493 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3494 | } |
| 3495 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3496 | private void enforceActiveEmergencySessionPermission() { |
| 3497 | mApp.enforceCallingOrSelfPermission( |
| 3498 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3499 | } |
| 3500 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3501 | /** |
| 3502 | * Make sure the caller has the CALL_PHONE permission. |
| 3503 | * |
| 3504 | * @throws SecurityException if the caller does not have the required permission |
| 3505 | */ |
| 3506 | private void enforceCallPermission() { |
| 3507 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3508 | } |
| 3509 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3510 | private void enforceSettingsPermission() { |
| 3511 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3514 | private void enforceRebootPermission() { |
| 3515 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3516 | } |
| 3517 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3518 | private String createTelUrl(String number) { |
| 3519 | if (TextUtils.isEmpty(number)) { |
| 3520 | return null; |
| 3521 | } |
| 3522 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3523 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3526 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3527 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3528 | } |
| 3529 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3530 | private static void logv(String msg) { |
| 3531 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3532 | } |
| 3533 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3534 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3536 | } |
| 3537 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3538 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3540 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3541 | } |
| 3542 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3543 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3544 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | final long identity = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3548 | if (phone == null) { |
| 3549 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3550 | } else { |
| 3551 | return phone.getPhoneType(); |
| 3552 | } |
| 3553 | } finally { |
| 3554 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3555 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | /** |
| 3559 | * Returns the CDMA ERI icon index to display |
| 3560 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3561 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3562 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3563 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3564 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3567 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3568 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3569 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3570 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3571 | mApp, subId, callingPackage, callingFeatureId, |
| 3572 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3573 | return -1; |
| 3574 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3575 | |
| 3576 | final long identity = Binder.clearCallingIdentity(); |
| 3577 | try { |
| 3578 | final Phone phone = getPhone(subId); |
| 3579 | if (phone != null) { |
| 3580 | return phone.getCdmaEriIconIndex(); |
| 3581 | } else { |
| 3582 | return -1; |
| 3583 | } |
| 3584 | } finally { |
| 3585 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | /** |
| 3590 | * Returns the CDMA ERI icon mode, |
| 3591 | * 0 - ON |
| 3592 | * 1 - FLASHING |
| 3593 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3594 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3595 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3596 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3597 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3598 | } |
| 3599 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3600 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3601 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3602 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3603 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3604 | mApp, subId, callingPackage, callingFeatureId, |
| 3605 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3606 | return -1; |
| 3607 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3608 | |
| 3609 | final long identity = Binder.clearCallingIdentity(); |
| 3610 | try { |
| 3611 | final Phone phone = getPhone(subId); |
| 3612 | if (phone != null) { |
| 3613 | return phone.getCdmaEriIconMode(); |
| 3614 | } else { |
| 3615 | return -1; |
| 3616 | } |
| 3617 | } finally { |
| 3618 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3619 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | /** |
| 3623 | * Returns the CDMA ERI text, |
| 3624 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3625 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3626 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3627 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3628 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3631 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3632 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3633 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3634 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3635 | mApp, subId, callingPackage, callingFeatureId, |
| 3636 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3637 | return null; |
| 3638 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3639 | |
| 3640 | final long identity = Binder.clearCallingIdentity(); |
| 3641 | try { |
| 3642 | final Phone phone = getPhone(subId); |
| 3643 | if (phone != null) { |
| 3644 | return phone.getCdmaEriText(); |
| 3645 | } else { |
| 3646 | return null; |
| 3647 | } |
| 3648 | } finally { |
| 3649 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3650 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3654 | * Returns the CDMA MDN. |
| 3655 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3656 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3657 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3659 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3660 | |
| 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3665 | return phone.getLine1Number(); |
| 3666 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3667 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3668 | return null; |
| 3669 | } |
| 3670 | } finally { |
| 3671 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3672 | } |
| 3673 | } |
| 3674 | |
| 3675 | /** |
| 3676 | * Returns the CDMA MIN. |
| 3677 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3678 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3679 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3681 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3682 | |
| 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | final Phone phone = getPhone(subId); |
| 3686 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3687 | return phone.getCdmaMin(); |
| 3688 | } else { |
| 3689 | return null; |
| 3690 | } |
| 3691 | } finally { |
| 3692 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3693 | } |
| 3694 | } |
| 3695 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3696 | @Override |
| 3697 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3698 | INumberVerificationCallback callback, String callingPackage) { |
| 3699 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3700 | != PERMISSION_GRANTED) { |
| 3701 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3702 | } |
| 3703 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3704 | |
| 3705 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3706 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3707 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3708 | + "calling package: " + callingPackage |
| 3709 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | if (range == null) { |
| 3713 | throw new NullPointerException("Range must be non-null"); |
| 3714 | } |
| 3715 | |
| 3716 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3717 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3718 | |
| 3719 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3720 | } |
| 3721 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3722 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3723 | * Returns true if CDMA provisioning needs to run. |
| 3724 | */ |
| 3725 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3726 | final long identity = Binder.clearCallingIdentity(); |
| 3727 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3729 | } finally { |
| 3730 | Binder.restoreCallingIdentity(identity); |
| 3731 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3735 | * Sets the voice mail number of a given subId. |
| 3736 | */ |
| 3737 | @Override |
| 3738 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3739 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3740 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | |
| 3742 | final long identity = Binder.clearCallingIdentity(); |
| 3743 | try { |
| 3744 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3745 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3746 | return success; |
| 3747 | } finally { |
| 3748 | Binder.restoreCallingIdentity(identity); |
| 3749 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3750 | } |
| 3751 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3752 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3753 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3754 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3755 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3756 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3757 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3758 | throw new SecurityException("caller must be system dialer"); |
| 3759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3760 | |
| 3761 | final long identity = Binder.clearCallingIdentity(); |
| 3762 | try { |
| 3763 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3764 | if (phoneAccountHandle == null) { |
| 3765 | return null; |
| 3766 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3767 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3768 | } finally { |
| 3769 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3770 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3774 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3775 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3776 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3777 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3778 | mApp, subId, callingPackage, callingFeatureId, |
| 3779 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3780 | return null; |
| 3781 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3782 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3783 | final long identity = Binder.clearCallingIdentity(); |
| 3784 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3785 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3786 | } finally { |
| 3787 | Binder.restoreCallingIdentity(identity); |
| 3788 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3792 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3793 | VisualVoicemailSmsFilterSettings settings) { |
| 3794 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3795 | |
| 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3799 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | } finally { |
| 3801 | Binder.restoreCallingIdentity(identity); |
| 3802 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3806 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3807 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3808 | |
| 3809 | final long identity = Binder.clearCallingIdentity(); |
| 3810 | try { |
| 3811 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3812 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(identity); |
| 3815 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3819 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3820 | String callingPackage, int subId) { |
| 3821 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3822 | |
| 3823 | final long identity = Binder.clearCallingIdentity(); |
| 3824 | try { |
| 3825 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3826 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(identity); |
| 3829 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3830 | } |
| 3831 | |
| 3832 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3833 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3834 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3835 | |
| 3836 | final long identity = Binder.clearCallingIdentity(); |
| 3837 | try { |
| 3838 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3839 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3843 | } |
| 3844 | |
| 3845 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3846 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3847 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3848 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3849 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3850 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3851 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3852 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3853 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3854 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3855 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3856 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3857 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3858 | * Sets the voice activation state of a given subId. |
| 3859 | */ |
| 3860 | @Override |
| 3861 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3863 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3864 | |
| 3865 | final long identity = Binder.clearCallingIdentity(); |
| 3866 | try { |
| 3867 | final Phone phone = getPhone(subId); |
| 3868 | if (phone != null) { |
| 3869 | phone.setVoiceActivationState(activationState); |
| 3870 | } else { |
| 3871 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3872 | } |
| 3873 | } finally { |
| 3874 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3875 | } |
| 3876 | } |
| 3877 | |
| 3878 | /** |
| 3879 | * Sets the data activation state of a given subId. |
| 3880 | */ |
| 3881 | @Override |
| 3882 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3883 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3884 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3885 | |
| 3886 | final long identity = Binder.clearCallingIdentity(); |
| 3887 | try { |
| 3888 | final Phone phone = getPhone(subId); |
| 3889 | if (phone != null) { |
| 3890 | phone.setDataActivationState(activationState); |
| 3891 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3892 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3893 | } |
| 3894 | } finally { |
| 3895 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3896 | } |
| 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * Returns the voice activation state of a given subId. |
| 3901 | */ |
| 3902 | @Override |
| 3903 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3904 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3905 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3906 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
| 3909 | if (phone != null) { |
| 3910 | return phone.getVoiceActivationState(); |
| 3911 | } else { |
| 3912 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3913 | } |
| 3914 | } finally { |
| 3915 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | /** |
| 3920 | * Returns the data activation state of a given subId. |
| 3921 | */ |
| 3922 | @Override |
| 3923 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3924 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3925 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3926 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | if (phone != null) { |
| 3930 | return phone.getDataActivationState(); |
| 3931 | } else { |
| 3932 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3933 | } |
| 3934 | } finally { |
| 3935 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
| 3939 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3940 | * Returns the unread count of voicemails for a subId |
| 3941 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3942 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3943 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3944 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3946 | mApp, subId, callingPackage, callingFeatureId, |
| 3947 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3948 | return 0; |
| 3949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3950 | final long identity = Binder.clearCallingIdentity(); |
| 3951 | try { |
| 3952 | final Phone phone = getPhone(subId); |
| 3953 | if (phone != null) { |
| 3954 | return phone.getVoiceMessageCount(); |
| 3955 | } else { |
| 3956 | return 0; |
| 3957 | } |
| 3958 | } finally { |
| 3959 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3960 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
| 3963 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3964 | * returns true, if the device is in a state where both voice and data |
| 3965 | * are supported simultaneously. This can change based on location or network condition. |
| 3966 | */ |
| 3967 | @Override |
| 3968 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | final long identity = Binder.clearCallingIdentity(); |
| 3970 | try { |
| 3971 | final Phone phone = getPhone(subId); |
| 3972 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3973 | } finally { |
| 3974 | Binder.restoreCallingIdentity(identity); |
| 3975 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3979 | * Send the dialer code if called from the current default dialer or the caller has |
| 3980 | * carrier privilege. |
| 3981 | * @param inputCode The dialer code to send |
| 3982 | */ |
| 3983 | @Override |
| 3984 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3985 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3986 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3987 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3988 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3989 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3990 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3991 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3992 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | |
| 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3996 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
| 3999 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4000 | } |
| 4001 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4002 | @Override |
| 4003 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4004 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4005 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4006 | mApp, subId, "getNetworkSelectionMode"); |
| 4007 | final long identity = Binder.clearCallingIdentity(); |
| 4008 | try { |
| 4009 | if (!isActiveSubscription(subId)) { |
| 4010 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4011 | } |
| 4012 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4013 | } finally { |
| 4014 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4015 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4019 | public boolean isInEmergencySmsMode() { |
| 4020 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4024 | if (phone.isInEmergencySmsMode()) { |
| 4025 | return true; |
| 4026 | } |
| 4027 | } |
| 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
| 4030 | } |
| 4031 | return false; |
| 4032 | } |
| 4033 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4034 | /** |
| 4035 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4036 | * @param subId The subscription to use to check the configuration. |
| 4037 | * @param c The callback that will be used to send the result. |
| 4038 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4039 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4040 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4041 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4042 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4043 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4044 | |
| 4045 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4046 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4047 | "IMS not available on device."); |
| 4048 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | final long token = Binder.clearCallingIdentity(); |
| 4050 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4051 | int slotId = getSlotIndexOrException(subId); |
| 4052 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4053 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4054 | } catch (ImsException e) { |
| 4055 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4056 | } finally { |
| 4057 | Binder.restoreCallingIdentity(token); |
| 4058 | } |
| 4059 | } |
| 4060 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4061 | /** |
| 4062 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4063 | * @param subId The subscription to use to check the configuration. |
| 4064 | * @param c The callback that will be used to send the result. |
| 4065 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4066 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4067 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4068 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4069 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4070 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4071 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4072 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4073 | final long token = Binder.clearCallingIdentity(); |
| 4074 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4075 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4076 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4077 | } catch (ImsException e) { |
| 4078 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4079 | + "is inactive, ignoring unregister."); |
| 4080 | // If the subscription is no longer active, just return, since the callback |
| 4081 | // will already have been removed internally. |
| 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(token); |
| 4084 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4085 | } |
| 4086 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4087 | /** |
| 4088 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4089 | */ |
| 4090 | @Override |
| 4091 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4092 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4093 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4094 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4095 | "IMS not available on device."); |
| 4096 | } |
| 4097 | final long token = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | Phone phone = getPhone(subId); |
| 4100 | if (phone == null) { |
| 4101 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4102 | + subId + "'"); |
| 4103 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4104 | } |
| 4105 | phone.getImsRegistrationState(regState -> { |
| 4106 | try { |
| 4107 | consumer.accept((regState == null) |
| 4108 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4109 | } catch (RemoteException e) { |
| 4110 | // Ignore if the remote process is no longer available to call back. |
| 4111 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4112 | } |
| 4113 | }); |
| 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(token); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Get the transport type for the IMS service registration state. |
| 4121 | */ |
| 4122 | @Override |
| 4123 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4124 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4125 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4126 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4127 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4128 | "IMS not available on device."); |
| 4129 | } |
| 4130 | final long token = Binder.clearCallingIdentity(); |
| 4131 | try { |
| 4132 | Phone phone = getPhone(subId); |
| 4133 | if (phone == null) { |
| 4134 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4135 | + subId + "'"); |
| 4136 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4137 | } |
| 4138 | phone.getImsRegistrationTech(regTech -> { |
| 4139 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4140 | int regTechConverted = (regTech == null) |
| 4141 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4142 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4143 | regTechConverted); |
| 4144 | try { |
| 4145 | consumer.accept(regTechConverted); |
| 4146 | } catch (RemoteException e) { |
| 4147 | // Ignore if the remote process is no longer available to call back. |
| 4148 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4149 | } |
| 4150 | }); |
| 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(token); |
| 4153 | } |
| 4154 | } |
| 4155 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4156 | /** |
| 4157 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4158 | * @param subId The subscription to use to check the configuration. |
| 4159 | * @param c The callback that will be used to send the result. |
| 4160 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4162 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4163 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4164 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4165 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4166 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4167 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4168 | "IMS not available on device."); |
| 4169 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4170 | final long token = Binder.clearCallingIdentity(); |
| 4171 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4172 | int slotId = getSlotIndexOrException(subId); |
| 4173 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4174 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4175 | } catch (ImsException e) { |
| 4176 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | } finally { |
| 4178 | Binder.restoreCallingIdentity(token); |
| 4179 | } |
| 4180 | } |
| 4181 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4182 | /** |
| 4183 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4184 | * @param subId The subscription to use to check the configuration. |
| 4185 | * @param c The callback that will be used to send the result. |
| 4186 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4187 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4188 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4189 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4190 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4191 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4192 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4193 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4194 | |
| 4195 | final long token = Binder.clearCallingIdentity(); |
| 4196 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4197 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4198 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4199 | } catch (ImsException e) { |
| 4200 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4201 | + "is inactive, ignoring unregister."); |
| 4202 | // If the subscription is no longer active, just return, since the callback |
| 4203 | // will already have been removed internally. |
| 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(token); |
| 4206 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4210 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4211 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | final long token = Binder.clearCallingIdentity(); |
| 4213 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4214 | int slotId = getSlotIndexOrException(subId); |
| 4215 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4216 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4217 | } catch (com.android.ims.ImsException e) { |
| 4218 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4219 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4220 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4221 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4222 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4223 | } finally { |
| 4224 | Binder.restoreCallingIdentity(token); |
| 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4229 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4230 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4231 | final long token = Binder.clearCallingIdentity(); |
| 4232 | try { |
| 4233 | Phone phone = getPhone(subId); |
| 4234 | if (phone == null) return false; |
| 4235 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4236 | } catch (com.android.ims.ImsException e) { |
| 4237 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4238 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4239 | } finally { |
| 4240 | Binder.restoreCallingIdentity(token); |
| 4241 | } |
| 4242 | } |
| 4243 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4244 | /** |
| 4245 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4246 | * subscription. |
| 4247 | * @param subId The subscription to use to check the configuration. |
| 4248 | * @param callback The callback that will be used to send the result. |
| 4249 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4250 | * @param transportType The transport type of the MmTelFeature capability. |
| 4251 | */ |
| 4252 | @Override |
| 4253 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4254 | int transportType) { |
| 4255 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4256 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4257 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4258 | "IMS not available on device."); |
| 4259 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4260 | final long token = Binder.clearCallingIdentity(); |
| 4261 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4262 | int slotId = getSlotIndex(subId); |
| 4263 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4264 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4265 | + subId + "'"); |
| 4266 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4267 | } |
| 4268 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4269 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4270 | transportType, aBoolean -> { |
| 4271 | try { |
| 4272 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4273 | } catch (RemoteException e) { |
| 4274 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4275 | + "running. Ignore"); |
| 4276 | } |
| 4277 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4278 | } catch (ImsException e) { |
| 4279 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4280 | } finally { |
| 4281 | Binder.restoreCallingIdentity(token); |
| 4282 | } |
| 4283 | } |
| 4284 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4285 | /** |
| 4286 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4287 | * @param subId The subscription to use to check the configuration. |
| 4288 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | @Override |
| 4290 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4291 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4292 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4293 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | final long token = Binder.clearCallingIdentity(); |
| 4295 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4296 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4297 | // 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] | 4298 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4299 | } catch (ImsException e) { |
| 4300 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4301 | } finally { |
| 4302 | Binder.restoreCallingIdentity(token); |
| 4303 | } |
| 4304 | } |
| 4305 | |
| 4306 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4307 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4309 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4310 | final long identity = Binder.clearCallingIdentity(); |
| 4311 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4312 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4313 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4314 | // 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] | 4315 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4316 | } catch (ImsException e) { |
| 4317 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4318 | } finally { |
| 4319 | Binder.restoreCallingIdentity(identity); |
| 4320 | } |
| 4321 | } |
| 4322 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4323 | /** |
| 4324 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4325 | * @param subId The subscription to use to check the configuration. |
| 4326 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4327 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4328 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4329 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4330 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4331 | final long identity = Binder.clearCallingIdentity(); |
| 4332 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4333 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4334 | // 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] | 4335 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4336 | } catch (ImsException e) { |
| 4337 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4338 | } finally { |
| 4339 | Binder.restoreCallingIdentity(identity); |
| 4340 | } |
| 4341 | } |
| 4342 | |
| 4343 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4344 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4346 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4347 | final long identity = Binder.clearCallingIdentity(); |
| 4348 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4349 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4350 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4351 | // 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] | 4352 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4353 | } catch (ImsException e) { |
| 4354 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4355 | } finally { |
| 4356 | Binder.restoreCallingIdentity(identity); |
| 4357 | } |
| 4358 | } |
| 4359 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4360 | /** |
| 4361 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4362 | * @param subId The subscription to use to check the configuration. |
| 4363 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4364 | @Override |
| 4365 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4366 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4367 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4370 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4371 | // 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] | 4372 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4373 | } catch (ImsException e) { |
| 4374 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4375 | } finally { |
| 4376 | Binder.restoreCallingIdentity(identity); |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4381 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4382 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4383 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4384 | final long identity = Binder.clearCallingIdentity(); |
| 4385 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4386 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4387 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4388 | // 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] | 4389 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4390 | } catch (ImsException e) { |
| 4391 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4392 | } finally { |
| 4393 | Binder.restoreCallingIdentity(identity); |
| 4394 | } |
| 4395 | } |
| 4396 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4397 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4398 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4399 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4400 | * @param subId The subscription to use to check the configuration. |
| 4401 | */ |
| 4402 | @Override |
| 4403 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4404 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4405 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4406 | final long identity = Binder.clearCallingIdentity(); |
| 4407 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4408 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4409 | // 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] | 4410 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4411 | } catch (ImsException e) { |
| 4412 | throw new ServiceSpecificException(e.getCode()); |
| 4413 | } finally { |
| 4414 | Binder.restoreCallingIdentity(identity); |
| 4415 | } |
| 4416 | } |
| 4417 | |
| 4418 | /** |
| 4419 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4420 | * Requires MODIFY_PHONE_STATE permission. |
| 4421 | * @param subId The subscription to use to check the configuration. |
| 4422 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4423 | * false otherwise |
| 4424 | */ |
| 4425 | @Override |
| 4426 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4427 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4428 | "setCrossSimCallingEnabled"); |
| 4429 | final long identity = Binder.clearCallingIdentity(); |
| 4430 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4431 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4432 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4433 | // 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] | 4434 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4435 | } catch (ImsException e) { |
| 4436 | throw new ServiceSpecificException(e.getCode()); |
| 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4443 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4444 | * @param subId The subscription to use to check the configuration. |
| 4445 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4446 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4447 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4449 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4450 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4451 | final long identity = Binder.clearCallingIdentity(); |
| 4452 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4453 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4454 | // 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] | 4455 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4456 | } catch (ImsException e) { |
| 4457 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4458 | } finally { |
| 4459 | Binder.restoreCallingIdentity(identity); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4464 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4465 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4466 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4467 | final long identity = Binder.clearCallingIdentity(); |
| 4468 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4469 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4470 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4471 | // 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] | 4472 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4473 | } catch (ImsException e) { |
| 4474 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4475 | } finally { |
| 4476 | Binder.restoreCallingIdentity(identity); |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | @Override |
| 4481 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4482 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4483 | "setVoWiFiNonPersistent"); |
| 4484 | final long identity = Binder.clearCallingIdentity(); |
| 4485 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4486 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4487 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4488 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4489 | } catch (ImsException e) { |
| 4490 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4491 | } finally { |
| 4492 | Binder.restoreCallingIdentity(identity); |
| 4493 | } |
| 4494 | } |
| 4495 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4496 | /** |
| 4497 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4498 | * @param subId The subscription to use to check the configuration. |
| 4499 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | @Override |
| 4501 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4503 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4506 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4507 | // 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] | 4508 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4509 | } catch (ImsException e) { |
| 4510 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4511 | } finally { |
| 4512 | Binder.restoreCallingIdentity(identity); |
| 4513 | } |
| 4514 | } |
| 4515 | |
| 4516 | @Override |
| 4517 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4519 | "setVoWiFiModeSetting"); |
| 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4522 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4523 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4524 | // 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] | 4525 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4526 | } catch (ImsException e) { |
| 4527 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
| 4530 | } |
| 4531 | } |
| 4532 | |
| 4533 | @Override |
| 4534 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4535 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4538 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4539 | // 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] | 4540 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4541 | } catch (ImsException e) { |
| 4542 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4543 | } finally { |
| 4544 | Binder.restoreCallingIdentity(identity); |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | @Override |
| 4549 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4551 | "setVoWiFiRoamingModeSetting"); |
| 4552 | final long identity = Binder.clearCallingIdentity(); |
| 4553 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4554 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4555 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4556 | // 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] | 4557 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4558 | } catch (ImsException e) { |
| 4559 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(identity); |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | @Override |
| 4566 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4568 | "setRttCapabilityEnabled"); |
| 4569 | final long identity = Binder.clearCallingIdentity(); |
| 4570 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4571 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4572 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4573 | // 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] | 4574 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4575 | } catch (ImsException e) { |
| 4576 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4577 | } finally { |
| 4578 | Binder.restoreCallingIdentity(identity); |
| 4579 | } |
| 4580 | } |
| 4581 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4582 | /** |
| 4583 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4584 | * @param subId The subscription to use to check the configuration. |
| 4585 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | @Override |
| 4587 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4588 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4589 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4590 | final long identity = Binder.clearCallingIdentity(); |
| 4591 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4592 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4593 | // 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] | 4594 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4595 | } catch (ImsException e) { |
| 4596 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4597 | } finally { |
| 4598 | Binder.restoreCallingIdentity(identity); |
| 4599 | } |
| 4600 | } |
| 4601 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4602 | @Override |
| 4603 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4604 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4605 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4608 | if (!isImsAvailableOnDevice()) { |
| 4609 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4610 | "IMS not available on device."); |
| 4611 | } |
| 4612 | int slotId = getSlotIndexOrException(subId); |
| 4613 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4614 | ImsManager.getInstance(mApp, slotId) |
| 4615 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4616 | } catch (ImsException e) { |
| 4617 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4618 | } finally { |
| 4619 | Binder.restoreCallingIdentity(identity); |
| 4620 | } |
| 4621 | } |
| 4622 | |
| 4623 | @Override |
| 4624 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4625 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4626 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4627 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4628 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4629 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4630 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4631 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4632 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4633 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4634 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4635 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4636 | + "is inactive, ignoring unregister."); |
| 4637 | // If the subscription is no longer active, just return, since the callback will already |
| 4638 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
| 4641 | } |
| 4642 | } |
| 4643 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4644 | @Override |
| 4645 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4646 | IFeatureProvisioningCallback callback) { |
| 4647 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4648 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4649 | |
| 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4652 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4653 | } |
| 4654 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4655 | try { |
| 4656 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4657 | if (controller == null) { |
| 4658 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4659 | "Device does not support IMS"); |
| 4660 | } |
| 4661 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4662 | } finally { |
| 4663 | Binder.restoreCallingIdentity(identity); |
| 4664 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | @Override |
| 4668 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4669 | IFeatureProvisioningCallback callback) { |
| 4670 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4671 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4672 | |
| 4673 | final long identity = Binder.clearCallingIdentity(); |
| 4674 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4675 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4676 | } |
| 4677 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4678 | try { |
| 4679 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4680 | if (controller == null) { |
| 4681 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4682 | return; |
| 4683 | } |
| 4684 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4685 | } finally { |
| 4686 | Binder.restoreCallingIdentity(identity); |
| 4687 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4688 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4689 | |
| 4690 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4692 | message); |
| 4693 | } |
| 4694 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4695 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4696 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4697 | boolean isProvisioned) { |
| 4698 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4699 | |
| 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4702 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4703 | if (controller == null) { |
| 4704 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4705 | return; |
| 4706 | } |
| 4707 | controller.setRcsProvisioningStatusForCapability( |
| 4708 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4709 | } finally { |
| 4710 | Binder.restoreCallingIdentity(identity); |
| 4711 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | |
| 4715 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4716 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4717 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4718 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4719 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4720 | final long identity = Binder.clearCallingIdentity(); |
| 4721 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4722 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4723 | if (controller == null) { |
| 4724 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4725 | |
| 4726 | // device does not support IMS, this method will return true always. |
| 4727 | return true; |
| 4728 | } |
| 4729 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
| 4733 | } |
| 4734 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4735 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4736 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4737 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4738 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4739 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4742 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4743 | if (controller == null) { |
| 4744 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4745 | return; |
| 4746 | } |
| 4747 | controller.setImsProvisioningStatusForCapability( |
| 4748 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4749 | } finally { |
| 4750 | Binder.restoreCallingIdentity(identity); |
| 4751 | } |
| 4752 | } |
| 4753 | |
| 4754 | @Override |
| 4755 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4756 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4757 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4758 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4759 | final long identity = Binder.clearCallingIdentity(); |
| 4760 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4761 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4762 | if (controller == null) { |
| 4763 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4764 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4765 | // device does not support IMS, this method will return true always. |
| 4766 | return true; |
| 4767 | } |
| 4768 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(identity); |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4775 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4776 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4777 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4778 | |
| 4779 | final long identity = Binder.clearCallingIdentity(); |
| 4780 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4781 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4782 | if (controller == null) { |
| 4783 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4784 | |
| 4785 | // device does not support IMS, this method will return false |
| 4786 | return false; |
| 4787 | } |
| 4788 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4789 | } finally { |
| 4790 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4791 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4792 | } |
| 4793 | |
| 4794 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4795 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4796 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4797 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4798 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4799 | final long identity = Binder.clearCallingIdentity(); |
| 4800 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4801 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4802 | if (controller == null) { |
| 4803 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4804 | |
| 4805 | // device does not support IMS, this method will return false |
| 4806 | return false; |
| 4807 | } |
| 4808 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4809 | } finally { |
| 4810 | Binder.restoreCallingIdentity(identity); |
| 4811 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4812 | } |
| 4813 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4814 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4815 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4816 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4817 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4818 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4819 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4820 | mApp, subId, "getImsProvisioningInt"); |
| 4821 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4825 | int slotId = getSlotIndex(subId); |
| 4826 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4827 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4828 | + subId + "' for key:" + key); |
| 4829 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4830 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4831 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4832 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4833 | if (controller == null) { |
| 4834 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4835 | |
| 4836 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4837 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4838 | } |
| 4839 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4840 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4841 | return retVal; |
| 4842 | } |
| 4843 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4844 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4845 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4846 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4847 | + subId + "' for key:" + key); |
| 4848 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4849 | } finally { |
| 4850 | Binder.restoreCallingIdentity(identity); |
| 4851 | } |
| 4852 | } |
| 4853 | |
| 4854 | @Override |
| 4855 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4856 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4857 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4858 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4859 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4860 | mApp, subId, "getImsProvisioningString"); |
| 4861 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
| 4864 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4865 | int slotId = getSlotIndex(subId); |
| 4866 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4867 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4868 | + subId + "' for key:" + key); |
| 4869 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4870 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4871 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4872 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4873 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4874 | + subId + "' for key:" + key); |
| 4875 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
| 4879 | } |
| 4880 | |
| 4881 | @Override |
| 4882 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4883 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4884 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4885 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4887 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4888 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
| 4891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4892 | int slotId = getSlotIndex(subId); |
| 4893 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4894 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4895 | + subId + "' for key:" + key); |
| 4896 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4897 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4898 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4899 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4900 | if (controller == null) { |
| 4901 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 4902 | |
| 4903 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 4904 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4905 | } |
| 4906 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4907 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4908 | return retVal; |
| 4909 | } |
| 4910 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4911 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4912 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4913 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4914 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4915 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | @Override |
| 4922 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4923 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4924 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4925 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4927 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4928 | final long identity = Binder.clearCallingIdentity(); |
| 4929 | try { |
| 4930 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4931 | int slotId = getSlotIndex(subId); |
| 4932 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4933 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4934 | + subId + "' for key:" + key); |
| 4935 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4936 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4937 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4938 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4939 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4940 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4941 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
| 4944 | } |
| 4945 | } |
| 4946 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4947 | /** |
| 4948 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4949 | * for the given slot ID or no ImsResolver instance has been created. |
| 4950 | * @param slotId The slot ID that the IMS service is created for. |
| 4951 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4952 | */ |
| 4953 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4954 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4955 | ImsFeature.FEATURE_MMTEL)) { |
| 4956 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4957 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4958 | } |
| 4959 | } |
| 4960 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4961 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4962 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4963 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4964 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4965 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4966 | } |
| 4967 | return slotId; |
| 4968 | } |
| 4969 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4970 | private int getSlotIndex(int subId) { |
| 4971 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4972 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4973 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4974 | } |
| 4975 | return slotId; |
| 4976 | } |
| 4977 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4978 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4979 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4980 | */ |
| 4981 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4982 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4983 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4984 | try { |
| 4985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4986 | } catch (SecurityException se) { |
| 4987 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4988 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4989 | + Binder.getCallingUid()); |
| 4990 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4991 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4992 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4993 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4994 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4995 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4996 | mApp, subId, callingPackage, callingFeatureId, |
| 4997 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4998 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4999 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | final long identity = Binder.clearCallingIdentity(); |
| 5002 | try { |
| 5003 | final Phone phone = getPhone(subId); |
| 5004 | if (phone != null) { |
| 5005 | return phone.getServiceState().getDataNetworkType(); |
| 5006 | } else { |
| 5007 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5008 | } |
| 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5011 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5012 | } |
| 5013 | |
| 5014 | /** |
| 5015 | * Returns the data network type |
| 5016 | */ |
| 5017 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5018 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5019 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5020 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | /** |
| 5024 | * Returns the data network type for a subId |
| 5025 | */ |
| 5026 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5027 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5028 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5029 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5030 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5031 | mApp, functionName)) { |
| 5032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5033 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5034 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5035 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5036 | } |
| 5037 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | final long identity = Binder.clearCallingIdentity(); |
| 5039 | try { |
| 5040 | final Phone phone = getPhone(subId); |
| 5041 | if (phone != null) { |
| 5042 | return phone.getServiceState().getDataNetworkType(); |
| 5043 | } else { |
| 5044 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5045 | } |
| 5046 | } finally { |
| 5047 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5048 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5052 | * Returns the Voice network type for a subId |
| 5053 | */ |
| 5054 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5055 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5056 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5057 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5058 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5059 | mApp, functionName)) { |
| 5060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5061 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5062 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5063 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5064 | } |
| 5065 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | final long identity = Binder.clearCallingIdentity(); |
| 5067 | try { |
| 5068 | final Phone phone = getPhone(subId); |
| 5069 | if (phone != null) { |
| 5070 | return phone.getServiceState().getVoiceNetworkType(); |
| 5071 | } else { |
| 5072 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5073 | } |
| 5074 | } finally { |
| 5075 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5076 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | /** |
| 5080 | * @return true if a ICC card is present |
| 5081 | */ |
| 5082 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5083 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5084 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5085 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5089 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5090 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5091 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5092 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | final long identity = Binder.clearCallingIdentity(); |
| 5094 | try { |
| 5095 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5096 | if (phone != null) { |
| 5097 | return phone.getIccCard().hasIccCard(); |
| 5098 | } else { |
| 5099 | return false; |
| 5100 | } |
| 5101 | } finally { |
| 5102 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5103 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /** |
| 5107 | * Return if the current radio is LTE on CDMA. This |
| 5108 | * is a tri-state return value as for a period of time |
| 5109 | * the mode may be unknown. |
| 5110 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5111 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5112 | * @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] | 5113 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5114 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5115 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5116 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5117 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5118 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5119 | } |
| 5120 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5121 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5122 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5123 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5124 | try { |
| 5125 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5126 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5127 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5128 | } |
| 5129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
| 5132 | final Phone phone = getPhone(subId); |
| 5133 | if (phone == null) { |
| 5134 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5135 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5136 | return TelephonyProperties.lte_on_cdma_device() |
| 5137 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | } |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5141 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5144 | /** |
| 5145 | * {@hide} |
| 5146 | * Returns Default subId, 0 in the case of single standby. |
| 5147 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5148 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5149 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5150 | } |
| 5151 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5152 | private int getSlotForDefaultSubscription() { |
| 5153 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5154 | } |
| 5155 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5156 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5157 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5158 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5159 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5160 | private boolean isActiveSubscription(int subId) { |
| 5161 | return mSubscriptionController.isActiveSubId(subId); |
| 5162 | } |
| 5163 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5164 | /** |
| 5165 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5166 | */ |
| 5167 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5170 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5171 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5172 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5173 | } finally { |
| 5174 | Binder.restoreCallingIdentity(identity); |
| 5175 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /** |
| 5179 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5180 | */ |
| 5181 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5182 | final long identity = Binder.clearCallingIdentity(); |
| 5183 | try { |
| 5184 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5185 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5187 | } finally { |
| 5188 | Binder.restoreCallingIdentity(identity); |
| 5189 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5190 | } |
| 5191 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5192 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5193 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5194 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5195 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5196 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5197 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5198 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5199 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5200 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5201 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5202 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5203 | } |
| 5204 | return PhoneFactory.getPhone(phoneId); |
| 5205 | } |
| 5206 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5207 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5208 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5209 | @NonNull IccLogicalChannelRequest request) { |
| 5210 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5211 | /*message=*/ "iccOpenLogicalChannel"); |
| 5212 | |
| 5213 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5214 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5215 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5216 | |
| 5217 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5218 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5219 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5220 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5221 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5222 | Phone phone; |
| 5223 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5224 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5225 | mApp, request.subId, message); |
| 5226 | phone = getPhoneFromSubId(request.subId); |
| 5227 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5228 | enforceModifyPermission(); |
| 5229 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5230 | } else { |
| 5231 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5232 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5233 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5237 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | final long identity = Binder.clearCallingIdentity(); |
| 5239 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5240 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5241 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5242 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5243 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5244 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5245 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | loge("The calling package is not allowed to access ISD-R."); |
| 5247 | throw new SecurityException( |
| 5248 | "The calling package is not allowed to access ISD-R."); |
| 5249 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5250 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5251 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5253 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5254 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5255 | return response; |
| 5256 | } finally { |
| 5257 | Binder.restoreCallingIdentity(identity); |
| 5258 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5262 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5263 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5264 | /*message=*/"iccCloseLogicalChannel"); |
| 5265 | |
| 5266 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5267 | |
| 5268 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5269 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5270 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5271 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5272 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5273 | // before this feature is enabled, this API should only return false if |
| 5274 | // the operation fails instead of throwing runtime exception for |
| 5275 | // backward-compatibility. |
| 5276 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5277 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | final long identity = Binder.clearCallingIdentity(); |
| 5279 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5280 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5281 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5283 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5284 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5285 | Boolean success = false; |
| 5286 | if (result instanceof RuntimeException) { |
| 5287 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5288 | if (shouldThrowExceptionOnFailure) { |
| 5289 | throw (RuntimeException) result; |
| 5290 | } else { |
| 5291 | return false; |
| 5292 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5293 | } else if (result instanceof Boolean) { |
| 5294 | success = (Boolean) result; |
| 5295 | } else { |
| 5296 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5297 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5298 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | return success; |
| 5300 | } finally { |
| 5301 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5302 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5306 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5307 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5308 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5309 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5310 | if (DBG) { |
| 5311 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5312 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5313 | + p3 + " data=" + data); |
| 5314 | } |
| 5315 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5316 | command, p1, p2, p3, data); |
| 5317 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5318 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5319 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5320 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5321 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5322 | enforceModifyPermission(); |
| 5323 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5324 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5325 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5326 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5327 | } |
| 5328 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5329 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5330 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5334 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5335 | final long identity = Binder.clearCallingIdentity(); |
| 5336 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5337 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5338 | return ""; |
| 5339 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5340 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5342 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5343 | null /* workSource */); |
| 5344 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5346 | // Append the returned status code to the end of the response payload. |
| 5347 | String s = Integer.toHexString( |
| 5348 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5349 | if (response.payload != null) { |
| 5350 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5351 | } |
| 5352 | return s; |
| 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5355 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5356 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5357 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5358 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5359 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5360 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5362 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5364 | if (DBG) { |
| 5365 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5366 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5367 | } |
| 5368 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5369 | cla, command, p1, p2, p3, data); |
| 5370 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5371 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5372 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5373 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5374 | 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] | 5375 | enforceModifyPermission(); |
| 5376 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5377 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5378 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5379 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5380 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5381 | } |
| 5382 | |
| 5383 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5384 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5385 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5389 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5390 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | final long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
| 5393 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5394 | && TextUtils.equals(ISDR_AID, data)) { |
| 5395 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5396 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5397 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | if (bestComponent == null |
| 5399 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5400 | loge("The calling package is not allowed to select ISD-R."); |
| 5401 | throw new SecurityException( |
| 5402 | "The calling package is not allowed to select ISD-R."); |
| 5403 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5404 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5405 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5407 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5408 | null /* workSource */); |
| 5409 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5410 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | // Append the returned status code to the end of the response payload. |
| 5412 | String s = Integer.toHexString( |
| 5413 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5414 | if (response.payload != null) { |
| 5415 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5416 | } |
| 5417 | return s; |
| 5418 | } finally { |
| 5419 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5420 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5424 | 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] | 5425 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5426 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5427 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5429 | final long identity = Binder.clearCallingIdentity(); |
| 5430 | try { |
| 5431 | if (DBG) { |
| 5432 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5433 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5434 | } |
| 5435 | |
| 5436 | IccIoResult response = |
| 5437 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5438 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5439 | subId); |
| 5440 | |
| 5441 | if (DBG) { |
| 5442 | log("Exchange SIM_IO [R]" + response); |
| 5443 | } |
| 5444 | |
| 5445 | byte[] result = null; |
| 5446 | int length = 2; |
| 5447 | if (response.payload != null) { |
| 5448 | length = 2 + response.payload.length; |
| 5449 | result = new byte[length]; |
| 5450 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5451 | } else { |
| 5452 | result = new byte[length]; |
| 5453 | } |
| 5454 | |
| 5455 | result[length - 1] = (byte) response.sw2; |
| 5456 | result[length - 2] = (byte) response.sw1; |
| 5457 | return result; |
| 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5460 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5463 | /** |
| 5464 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5465 | * on a particular subscription |
| 5466 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5467 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5468 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5469 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5470 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5471 | return null; |
| 5472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5473 | |
| 5474 | final long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
| 5476 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5477 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5478 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5479 | return null; |
| 5480 | } |
| 5481 | Object response = sendRequest( |
| 5482 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5483 | if (response instanceof String[]) { |
| 5484 | return (String[]) response; |
| 5485 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5486 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5488 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5491 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5492 | } |
| 5493 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5494 | /** |
| 5495 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5496 | * subscription. |
| 5497 | * |
| 5498 | * @param subId the id of the subscription. |
| 5499 | * @param appType the uicc app type, must be USIM or SIM. |
| 5500 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5501 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5502 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5503 | * @return number of fplmns that is successfully written to the SIM. |
| 5504 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5505 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5506 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5508 | mApp, subId, "setForbiddenPlmns"); |
| 5509 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5510 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5511 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5512 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5513 | } |
| 5514 | if (fplmns == null) { |
| 5515 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5516 | } |
| 5517 | for (String fplmn : fplmns) { |
| 5518 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5519 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5520 | } |
| 5521 | } |
| 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | Object response = sendRequest( |
| 5525 | CMD_SET_FORBIDDEN_PLMNS, |
| 5526 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5527 | subId); |
| 5528 | return (int) response; |
| 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
| 5531 | } |
| 5532 | } |
| 5533 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5534 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5535 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5537 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | final long identity = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5542 | if (response.payload == null) { |
| 5543 | return ""; |
| 5544 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5546 | // Append the returned status code to the end of the response payload. |
| 5547 | String s = Integer.toHexString( |
| 5548 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5549 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5550 | return s; |
| 5551 | } finally { |
| 5552 | Binder.restoreCallingIdentity(identity); |
| 5553 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5556 | /** |
| 5557 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5558 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5559 | * |
| 5560 | * @param itemID the ID of the item to read |
| 5561 | * @return the NV item as a String, or null on error. |
| 5562 | */ |
| 5563 | @Override |
| 5564 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5565 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5567 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5568 | |
| 5569 | final long identity = Binder.clearCallingIdentity(); |
| 5570 | try { |
| 5571 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5572 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5574 | return value; |
| 5575 | } finally { |
| 5576 | Binder.restoreCallingIdentity(identity); |
| 5577 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | /** |
| 5581 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5582 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5583 | * |
| 5584 | * @param itemID the ID of the item to read |
| 5585 | * @param itemValue the value to write, as a String |
| 5586 | * @return true on success; false on any failure |
| 5587 | */ |
| 5588 | @Override |
| 5589 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5590 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5591 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5592 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5593 | |
| 5594 | final long identity = Binder.clearCallingIdentity(); |
| 5595 | try { |
| 5596 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5597 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5598 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5600 | return success; |
| 5601 | } finally { |
| 5602 | Binder.restoreCallingIdentity(identity); |
| 5603 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | /** |
| 5607 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5608 | * Used for device configuration by some CDMA operators. |
| 5609 | * |
| 5610 | * @param preferredRoamingList byte array containing the new PRL |
| 5611 | * @return true on success; false on any failure |
| 5612 | */ |
| 5613 | @Override |
| 5614 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5615 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5616 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | |
| 5618 | final long identity = Binder.clearCallingIdentity(); |
| 5619 | try { |
| 5620 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5621 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5622 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5623 | return success; |
| 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(identity); |
| 5626 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5630 | * 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] | 5631 | * Used for device configuration by some CDMA operators. |
| 5632 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5633 | * @param slotIndex - device slot. |
| 5634 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5635 | * @return true on success; false on any failure |
| 5636 | */ |
| 5637 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5638 | public boolean resetModemConfig(int slotIndex) { |
| 5639 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5640 | if (phone != null) { |
| 5641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5642 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5643 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5644 | final long identity = Binder.clearCallingIdentity(); |
| 5645 | try { |
| 5646 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5647 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5648 | return success; |
| 5649 | } finally { |
| 5650 | Binder.restoreCallingIdentity(identity); |
| 5651 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5652 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5653 | return false; |
| 5654 | } |
| 5655 | |
| 5656 | /** |
| 5657 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5658 | * |
| 5659 | * @param slotIndex - device slot. |
| 5660 | * |
| 5661 | * @return true on success; false on any failure |
| 5662 | */ |
| 5663 | @Override |
| 5664 | public boolean rebootModem(int slotIndex) { |
| 5665 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5666 | if (phone != null) { |
| 5667 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5668 | mApp, phone.getSubId(), "rebootModem"); |
| 5669 | |
| 5670 | final long identity = Binder.clearCallingIdentity(); |
| 5671 | try { |
| 5672 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5673 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5674 | return success; |
| 5675 | } finally { |
| 5676 | Binder.restoreCallingIdentity(identity); |
| 5677 | } |
| 5678 | } |
| 5679 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5680 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5681 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5682 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5683 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5684 | * {@link #disableIms(int)}. |
| 5685 | * @param slotIndex device slot. |
| 5686 | */ |
| 5687 | public void resetIms(int slotIndex) { |
| 5688 | enforceModifyPermission(); |
| 5689 | |
| 5690 | final long identity = Binder.clearCallingIdentity(); |
| 5691 | try { |
| 5692 | if (mImsResolver == null) { |
| 5693 | // may happen if the does not support IMS. |
| 5694 | return; |
| 5695 | } |
| 5696 | mImsResolver.disableIms(slotIndex); |
| 5697 | mImsResolver.enableIms(slotIndex); |
| 5698 | } finally { |
| 5699 | Binder.restoreCallingIdentity(identity); |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5704 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5705 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5706 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5707 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5708 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5709 | |
| 5710 | final long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5712 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5713 | // may happen if the device does not support IMS. |
| 5714 | return; |
| 5715 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5716 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5717 | } finally { |
| 5718 | Binder.restoreCallingIdentity(identity); |
| 5719 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5723 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5724 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5725 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5726 | public void disableIms(int slotId) { |
| 5727 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5728 | |
| 5729 | final long identity = Binder.clearCallingIdentity(); |
| 5730 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5731 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5732 | // may happen if the device does not support IMS. |
| 5733 | return; |
| 5734 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5735 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5739 | } |
| 5740 | |
| 5741 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5742 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5743 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5744 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5745 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5746 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5747 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | |
| 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5751 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5752 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5753 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5754 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5755 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5756 | } finally { |
| 5757 | Binder.restoreCallingIdentity(identity); |
| 5758 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5759 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5760 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5761 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5762 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5763 | @Override |
| 5764 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5765 | enforceModifyPermission(); |
| 5766 | |
| 5767 | final long identity = Binder.clearCallingIdentity(); |
| 5768 | try { |
| 5769 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5770 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5771 | } finally { |
| 5772 | Binder.restoreCallingIdentity(identity); |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5777 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5778 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5779 | */ |
| 5780 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5781 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5782 | |
| 5783 | final long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5785 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5786 | // may happen if the device does not support IMS. |
| 5787 | return null; |
| 5788 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5789 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
| 5792 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5793 | } |
| 5794 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5795 | /** |
| 5796 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5797 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5798 | */ |
| 5799 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | |
| 5802 | final long identity = Binder.clearCallingIdentity(); |
| 5803 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5804 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5805 | // may happen if the device does not support IMS. |
| 5806 | return null; |
| 5807 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5808 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5814 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5815 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5816 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5817 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5818 | * @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] | 5819 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5820 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5821 | * @param packageName The name of the package that the current configuration will be replaced |
| 5822 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5823 | * @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] | 5824 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5825 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5826 | int[] featureTypes, String packageName) { |
| 5827 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5828 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5830 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5831 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5833 | final long identity = Binder.clearCallingIdentity(); |
| 5834 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5835 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5836 | // may happen if the device does not support IMS. |
| 5837 | return false; |
| 5838 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5839 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5840 | for (int featureType : featureTypes) { |
| 5841 | featureConfig.put(featureType, packageName); |
| 5842 | } |
| 5843 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5844 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5845 | } finally { |
| 5846 | Binder.restoreCallingIdentity(identity); |
| 5847 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5848 | } |
| 5849 | |
| 5850 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5851 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5852 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5853 | * |
| 5854 | * This should only be used for testing. |
| 5855 | * |
| 5856 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5857 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5858 | */ |
| 5859 | @Override |
| 5860 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5861 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5862 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5863 | "clearCarrierImsServiceOverride"); |
| 5864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5865 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5866 | "clearCarrierImsServiceOverride"); |
| 5867 | |
| 5868 | final long identity = Binder.clearCallingIdentity(); |
| 5869 | try { |
| 5870 | if (mImsResolver == null) { |
| 5871 | // may happen if the device does not support IMS. |
| 5872 | return false; |
| 5873 | } |
| 5874 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5875 | } finally { |
| 5876 | Binder.restoreCallingIdentity(identity); |
| 5877 | } |
| 5878 | } |
| 5879 | |
| 5880 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5881 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5882 | * |
| 5883 | * @param slotId The slot that the ImsService is associated with. |
| 5884 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5885 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5886 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5887 | * @return the package name of the ImsService configuration. |
| 5888 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5889 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5890 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5891 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5892 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5893 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5894 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5895 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5897 | final long identity = Binder.clearCallingIdentity(); |
| 5898 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5899 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5900 | // may happen if the device does not support IMS. |
| 5901 | return ""; |
| 5902 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5903 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5904 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5905 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | } finally { |
| 5907 | Binder.restoreCallingIdentity(identity); |
| 5908 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5911 | /** |
| 5912 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5913 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5914 | * @param callback A callback with an integer containing the |
| 5915 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5916 | */ |
| 5917 | @Override |
| 5918 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5919 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5920 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5921 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5922 | "IMS not available on device."); |
| 5923 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5924 | final long token = Binder.clearCallingIdentity(); |
| 5925 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5926 | int slotId = getSlotIndex(subId); |
| 5927 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5928 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5929 | + subId + "'"); |
| 5930 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5931 | } |
| 5932 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5933 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5934 | try { |
| 5935 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5936 | } catch (RemoteException e) { |
| 5937 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5938 | + "Ignore"); |
| 5939 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5940 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5941 | } catch (ImsException e) { |
| 5942 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(token); |
| 5945 | } |
| 5946 | } |
| 5947 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5948 | /** |
| 5949 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5950 | */ |
| 5951 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5952 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5953 | |
| 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5956 | // NOTE: Before S, this method only set the default phone. |
| 5957 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5958 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5959 | phone.setImsRegistrationState(registered); |
| 5960 | } |
| 5961 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | } finally { |
| 5963 | Binder.restoreCallingIdentity(identity); |
| 5964 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
| 5967 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5968 | * Set the network selection mode to automatic. |
| 5969 | * |
| 5970 | */ |
| 5971 | @Override |
| 5972 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5974 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | |
| 5976 | final long identity = Binder.clearCallingIdentity(); |
| 5977 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5978 | if (!isActiveSubscription(subId)) { |
| 5979 | return; |
| 5980 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5981 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5982 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5983 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | } finally { |
| 5985 | Binder.restoreCallingIdentity(identity); |
| 5986 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5987 | } |
| 5988 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5989 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5990 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5991 | * |
| 5992 | * @param subId the id of the subscription. |
| 5993 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5994 | * the operator to attach to. |
| 5995 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5996 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5997 | * normal network selection next time. |
| 5998 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5999 | */ |
| 6000 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6001 | public boolean setNetworkSelectionModeManual( |
| 6002 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6004 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6005 | |
| 6006 | if (!isActiveSubscription(subId)) { |
| 6007 | return false; |
| 6008 | } |
| 6009 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6010 | final long identity = Binder.clearCallingIdentity(); |
| 6011 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6012 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6014 | if (DBG) { |
| 6015 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6016 | + " operator: " + operatorInfo); |
| 6017 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6018 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6019 | } finally { |
| 6020 | Binder.restoreCallingIdentity(identity); |
| 6021 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6022 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6023 | /** |
| 6024 | * Get the manual network selection |
| 6025 | * |
| 6026 | * @param subId the id of the subscription. |
| 6027 | * |
| 6028 | * @return the previously saved user selected PLMN |
| 6029 | */ |
| 6030 | @Override |
| 6031 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6032 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6033 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6034 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6035 | |
| 6036 | final long identity = Binder.clearCallingIdentity(); |
| 6037 | try { |
| 6038 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6039 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6040 | } |
| 6041 | |
| 6042 | final Phone phone = getPhone(subId); |
| 6043 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6044 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6045 | } |
| 6046 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6047 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6048 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6049 | } finally { |
| 6050 | Binder.restoreCallingIdentity(identity); |
| 6051 | } |
| 6052 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6053 | |
| 6054 | /** |
| 6055 | * Scans for available networks. |
| 6056 | */ |
| 6057 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6058 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6059 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6061 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6062 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6063 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6064 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6065 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6066 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6067 | .setCallingPid(Binder.getCallingPid()) |
| 6068 | .setCallingUid(Binder.getCallingUid()) |
| 6069 | .setMethod("getCellNetworkScanResults") |
| 6070 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6071 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6072 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6073 | .build()); |
| 6074 | switch (locationResult) { |
| 6075 | case DENIED_HARD: |
| 6076 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6077 | case DENIED_SOFT: |
| 6078 | return null; |
| 6079 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6081 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6082 | try { |
| 6083 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6084 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6086 | } finally { |
| 6087 | Binder.restoreCallingIdentity(identity); |
| 6088 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6092 | * Get the call forwarding info, given the call forwarding reason. |
| 6093 | */ |
| 6094 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6095 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6096 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6097 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6098 | long identity = Binder.clearCallingIdentity(); |
| 6099 | try { |
| 6100 | if (DBG) { |
| 6101 | log("getCallForwarding: subId " + subId |
| 6102 | + " callForwardingReason" + callForwardingReason); |
| 6103 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6104 | |
| 6105 | Phone phone = getPhone(subId); |
| 6106 | if (phone == null) { |
| 6107 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6108 | callback.onError( |
| 6109 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6110 | } catch (RemoteException e) { |
| 6111 | // ignore |
| 6112 | } |
| 6113 | return; |
| 6114 | } |
| 6115 | |
| 6116 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6117 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6118 | @Override |
| 6119 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6120 | try { |
| 6121 | callback.onCallForwardingInfoAvailable(info); |
| 6122 | } catch (RemoteException e) { |
| 6123 | // ignore |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | @Override |
| 6128 | public void onError(int error) { |
| 6129 | try { |
| 6130 | callback.onError(error); |
| 6131 | } catch (RemoteException e) { |
| 6132 | // ignore |
| 6133 | } |
| 6134 | } |
| 6135 | }); |
| 6136 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6137 | } finally { |
| 6138 | Binder.restoreCallingIdentity(identity); |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | /** |
| 6143 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6144 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6145 | */ |
| 6146 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6147 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6148 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6149 | enforceModifyPermission(); |
| 6150 | long identity = Binder.clearCallingIdentity(); |
| 6151 | try { |
| 6152 | if (DBG) { |
| 6153 | log("setCallForwarding: subId " + subId |
| 6154 | + " callForwardingInfo" + callForwardingInfo); |
| 6155 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6156 | |
| 6157 | Phone phone = getPhone(subId); |
| 6158 | if (phone == null) { |
| 6159 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6160 | callback.accept( |
| 6161 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6162 | } catch (RemoteException e) { |
| 6163 | // ignore |
| 6164 | } |
| 6165 | return; |
| 6166 | } |
| 6167 | |
| 6168 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6169 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6170 | |
| 6171 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6172 | } finally { |
| 6173 | Binder.restoreCallingIdentity(identity); |
| 6174 | } |
| 6175 | } |
| 6176 | |
| 6177 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6178 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6179 | */ |
| 6180 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6181 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6182 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6183 | long identity = Binder.clearCallingIdentity(); |
| 6184 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6185 | Phone phone = getPhone(subId); |
| 6186 | if (phone == null) { |
| 6187 | try { |
| 6188 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6189 | } catch (RemoteException e) { |
| 6190 | // ignore |
| 6191 | } |
| 6192 | return; |
| 6193 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6194 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6195 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6196 | boolean requireUssd = c.getBoolean( |
| 6197 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6198 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6199 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6200 | if (requireUssd) { |
| 6201 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6202 | getSubscriptionCarrierId(subId)); |
| 6203 | String newUssdCommand = ""; |
| 6204 | try { |
| 6205 | newUssdCommand = carrierXmlParser.getFeature( |
| 6206 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6207 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6208 | } catch (NullPointerException e) { |
| 6209 | loge("Failed to generate USSD number" + e); |
| 6210 | } |
| 6211 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6212 | mMainThreadHandler, callback, carrierXmlParser, |
| 6213 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6214 | final String ussdCommand = newUssdCommand; |
| 6215 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6216 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6217 | }); |
| 6218 | } else { |
| 6219 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6220 | callback::accept); |
| 6221 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6222 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6223 | } finally { |
| 6224 | Binder.restoreCallingIdentity(identity); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6229 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6230 | */ |
| 6231 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6232 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6233 | enforceModifyPermission(); |
| 6234 | long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6236 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6237 | |
| 6238 | Phone phone = getPhone(subId); |
| 6239 | if (phone == null) { |
| 6240 | try { |
| 6241 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6242 | } catch (RemoteException e) { |
| 6243 | // ignore |
| 6244 | } |
| 6245 | return; |
| 6246 | } |
| 6247 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6248 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6249 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6250 | boolean requireUssd = c.getBoolean( |
| 6251 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6252 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6253 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6254 | if (requireUssd) { |
| 6255 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6256 | getSubscriptionCarrierId(subId)); |
| 6257 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6258 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6259 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6260 | String newUssdCommand = ""; |
| 6261 | try { |
| 6262 | newUssdCommand = carrierXmlParser.getFeature( |
| 6263 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6264 | .makeCommand(ssAction, null); |
| 6265 | } catch (NullPointerException e) { |
| 6266 | loge("Failed to generate USSD number" + e); |
| 6267 | } |
| 6268 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6269 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6270 | final String ussdCommand = newUssdCommand; |
| 6271 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6272 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6273 | }); |
| 6274 | } else { |
| 6275 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6276 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6277 | |
| 6278 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6279 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6280 | } finally { |
| 6281 | Binder.restoreCallingIdentity(identity); |
| 6282 | } |
| 6283 | } |
| 6284 | |
| 6285 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6286 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6287 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6288 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6289 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6290 | * location related information which will be sent if the caller already possess |
| 6291 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6292 | * @param request contains the radio access networks with bands/channels to scan |
| 6293 | * @param messenger callback messenger for scan results or errors |
| 6294 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6295 | * @return the id of the requested scan which can be used to stop the scan. |
| 6296 | */ |
| 6297 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6298 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6299 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6300 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6301 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6302 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6303 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6304 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6305 | if (!renounceFineLocationAccess) { |
| 6306 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6307 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6308 | .setCallingPackage(callingPackage) |
| 6309 | .setCallingFeatureId(callingFeatureId) |
| 6310 | .setCallingPid(Binder.getCallingPid()) |
| 6311 | .setCallingUid(Binder.getCallingUid()) |
| 6312 | .setMethod("requestNetworkScan") |
| 6313 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6314 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6315 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6316 | .build()); |
| 6317 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6318 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6319 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6320 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6321 | if (e != null) { |
| 6322 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6323 | throw e; |
| 6324 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6325 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6326 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6327 | } |
| 6328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6330 | int callingUid = Binder.getCallingUid(); |
| 6331 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6332 | final long identity = Binder.clearCallingIdentity(); |
| 6333 | try { |
| 6334 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6335 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6336 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6337 | } finally { |
| 6338 | Binder.restoreCallingIdentity(identity); |
| 6339 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6340 | } |
| 6341 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6342 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6343 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6344 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6345 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6346 | boolean hasNetworkScanPermission = |
| 6347 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6348 | == PERMISSION_GRANTED; |
| 6349 | |
| 6350 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6351 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6352 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6353 | } |
| 6354 | |
| 6355 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6356 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6357 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6358 | return new SecurityException("Specific channels must not be" |
| 6359 | + " scanned without location access."); |
| 6360 | } |
| 6361 | } |
| 6362 | } |
| 6363 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6364 | return null; |
| 6365 | } |
| 6366 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6367 | /** |
| 6368 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6369 | * |
| 6370 | * @param subId id of the subscription |
| 6371 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6372 | */ |
| 6373 | @Override |
| 6374 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6376 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6377 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6378 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6379 | final long identity = Binder.clearCallingIdentity(); |
| 6380 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6381 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | } finally { |
| 6383 | Binder.restoreCallingIdentity(identity); |
| 6384 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
| 6387 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6388 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6389 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6390 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6391 | */ |
| 6392 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6393 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6394 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6395 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6396 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | |
| 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6400 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6401 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6402 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6403 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6404 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6405 | } finally { |
| 6406 | Binder.restoreCallingIdentity(identity); |
| 6407 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6411 | * Get the allowed network types for certain reason. |
| 6412 | * |
| 6413 | * @param subId the id of the subscription. |
| 6414 | * @param reason the reason the allowed network type change is taking place |
| 6415 | * @return the allowed network types. |
| 6416 | */ |
| 6417 | @Override |
| 6418 | public long getAllowedNetworkTypesForReason(int subId, |
| 6419 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6420 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6421 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6422 | final long identity = Binder.clearCallingIdentity(); |
| 6423 | try { |
| 6424 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6425 | } finally { |
| 6426 | Binder.restoreCallingIdentity(identity); |
| 6427 | } |
| 6428 | } |
| 6429 | |
| 6430 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6431 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6432 | * @param subId subscription id of the sim card |
| 6433 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6434 | * This can be passed following states |
| 6435 | * <ol> |
| 6436 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6437 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6438 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6439 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6440 | * </ol> |
| 6441 | * @return operation result. |
| 6442 | */ |
| 6443 | @Override |
| 6444 | public int setNrDualConnectivityState(int subId, |
| 6445 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6447 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6448 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6449 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6450 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6451 | } |
| 6452 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6453 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6454 | final long identity = Binder.clearCallingIdentity(); |
| 6455 | try { |
| 6456 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6457 | nrDualConnectivityState, subId, |
| 6458 | workSource); |
| 6459 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6460 | return result; |
| 6461 | } finally { |
| 6462 | Binder.restoreCallingIdentity(identity); |
| 6463 | } |
| 6464 | } |
| 6465 | |
| 6466 | /** |
| 6467 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6468 | * @return true if dual connectivity is enabled else false |
| 6469 | */ |
| 6470 | @Override |
| 6471 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6472 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6473 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6474 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6475 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6476 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6477 | return false; |
| 6478 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6479 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6480 | final long identity = Binder.clearCallingIdentity(); |
| 6481 | try { |
| 6482 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6483 | null, subId, workSource); |
| 6484 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6485 | return isEnabled; |
| 6486 | } finally { |
| 6487 | Binder.restoreCallingIdentity(identity); |
| 6488 | } |
| 6489 | } |
| 6490 | |
| 6491 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6492 | * Set the allowed network types of the device and |
| 6493 | * provide the reason triggering the allowed network change. |
| 6494 | * |
| 6495 | * @param subId the id of the subscription. |
| 6496 | * @param reason the reason the allowed network type change is taking place |
| 6497 | * @param allowedNetworkTypes the allowed network types. |
| 6498 | * @return true on success; false on any failure. |
| 6499 | */ |
| 6500 | @Override |
| 6501 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6502 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6503 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6504 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6505 | mApp, subId, "setAllowedNetworkTypesForReason"); |
Gil Cukierman | 1d3d375 | 2022-10-03 21:31:33 +0000 | [diff] [blame^] | 6506 | // If the caller only has carrier privileges, then they should not be able to override |
| 6507 | // any network types which were set for security reasons. |
| 6508 | if (mApp.checkCallingOrSelfPermission(Manifest.permission.MODIFY_PHONE_STATE) |
| 6509 | != PERMISSION_GRANTED |
| 6510 | && (reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G |
| 6511 | || reason == TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER_RESTRICTIONS)) { |
| 6512 | throw new SecurityException( |
| 6513 | "setAllowedNetworkTypesForReason cannot be called with carrier privileges for" |
| 6514 | + " reason " |
| 6515 | + reason); |
| 6516 | } |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6517 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6518 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6519 | return false; |
| 6520 | } |
| 6521 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6522 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6523 | return false; |
| 6524 | } |
| 6525 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6526 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6527 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6528 | |
| 6529 | |
| 6530 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6531 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6532 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6533 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6534 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6535 | final long identity = Binder.clearCallingIdentity(); |
| 6536 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6537 | Boolean success = (Boolean) sendRequest( |
| 6538 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6539 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6540 | |
| 6541 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6542 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6543 | } finally { |
| 6544 | Binder.restoreCallingIdentity(identity); |
| 6545 | } |
| 6546 | } |
| 6547 | |
| 6548 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6549 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6550 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6551 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6552 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6553 | * @hide |
| 6554 | */ |
| 6555 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6556 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6557 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6559 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6561 | if (phone != null) { |
| 6562 | return phone.hasMatchedTetherApnSetting(); |
| 6563 | } else { |
| 6564 | return false; |
| 6565 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6566 | } finally { |
| 6567 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6568 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6569 | } |
| 6570 | |
| 6571 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6572 | * Get the user enabled state of Mobile Data. |
| 6573 | * |
| 6574 | * TODO: remove and use isUserDataEnabled. |
| 6575 | * This can't be removed now because some vendor codes |
| 6576 | * calls through ITelephony directly while they should |
| 6577 | * use TelephonyManager. |
| 6578 | * |
| 6579 | * @return true on enabled |
| 6580 | */ |
| 6581 | @Override |
| 6582 | public boolean getDataEnabled(int subId) { |
| 6583 | return isUserDataEnabled(subId); |
| 6584 | } |
| 6585 | |
| 6586 | /** |
| 6587 | * Get whether mobile data is enabled per user setting. |
| 6588 | * |
| 6589 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6590 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6591 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6592 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6593 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6594 | * |
| 6595 | * @return {@code true} if data is enabled else {@code false} |
| 6596 | */ |
| 6597 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6598 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6599 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6600 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6601 | try { |
| 6602 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6603 | functionName); |
| 6604 | } catch (Exception e) { |
| 6605 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6606 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6607 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6609 | mApp, subId, functionName); |
| 6610 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6611 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | |
| 6613 | final long identity = Binder.clearCallingIdentity(); |
| 6614 | try { |
| 6615 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6616 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6617 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6618 | if (phone != null) { |
| 6619 | boolean retVal = phone.isUserDataEnabled(); |
| 6620 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6621 | return retVal; |
| 6622 | } else { |
| 6623 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6624 | return false; |
| 6625 | } |
| 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6632 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6633 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6634 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6635 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6636 | * @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] | 6637 | */ |
| 6638 | @Override |
| 6639 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6640 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6641 | try { |
| 6642 | try { |
| 6643 | mApp.enforceCallingOrSelfPermission( |
| 6644 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6645 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6646 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6647 | try { |
| 6648 | mApp.enforceCallingOrSelfPermission( |
| 6649 | android.Manifest.permission.READ_PHONE_STATE, |
| 6650 | functionName); |
| 6651 | } catch (Exception e2) { |
| 6652 | mApp.enforceCallingOrSelfPermission( |
| 6653 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6654 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6655 | } |
| 6656 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6657 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | |
| 6660 | final long identity = Binder.clearCallingIdentity(); |
| 6661 | try { |
| 6662 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6664 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6665 | boolean retVal; |
| 6666 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 2c094c5 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6667 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6668 | } else { |
| 6669 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6670 | } |
| 6671 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6672 | return retVal; |
| 6673 | } else { |
| 6674 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6675 | return false; |
| 6676 | } |
| 6677 | } finally { |
| 6678 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6679 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6680 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6681 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6682 | /** |
| 6683 | * Check if data is enabled for a specific reason |
| 6684 | * @param subId Subscription index |
| 6685 | * @param reason the reason the data enable change is taking place |
| 6686 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6687 | */ |
| 6688 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6689 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6690 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6691 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6692 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6693 | try { |
| 6694 | mApp.enforceCallingOrSelfPermission( |
| 6695 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6696 | functionName); |
| 6697 | } catch (Exception e) { |
| 6698 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6699 | functionName); |
| 6700 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6701 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6702 | try { |
| 6703 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6704 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6705 | } catch (Exception e2) { |
| 6706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6707 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6708 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6709 | } |
| 6710 | |
| 6711 | |
| 6712 | final long identity = Binder.clearCallingIdentity(); |
| 6713 | try { |
| 6714 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6715 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6716 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6717 | + " reason=" + reason); |
| 6718 | } |
| 6719 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6720 | if (phone != null) { |
| 6721 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6722 | if (phone.isUsingNewDataStack()) { |
| 6723 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6724 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6725 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6726 | retVal = phone.isUserDataEnabled(); |
| 6727 | } else { |
| 6728 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6729 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6730 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6731 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6732 | return retVal; |
| 6733 | } else { |
| 6734 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6735 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6736 | + subId + " retVal=false"); |
| 6737 | } |
| 6738 | return false; |
| 6739 | } |
| 6740 | } finally { |
| 6741 | Binder.restoreCallingIdentity(identity); |
| 6742 | } |
| 6743 | } |
| 6744 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6745 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6746 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6747 | // No permission needed; this only lets the caller inspect their own status. |
| 6748 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6749 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6750 | |
| 6751 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6752 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6753 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6754 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6755 | } |
| 6756 | |
| 6757 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6758 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6759 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6760 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6761 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6762 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6763 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6764 | if (cpt == null) { |
| 6765 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6766 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6767 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6768 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6772 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6773 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6774 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6775 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6776 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6777 | Phone phone = getPhone(subId); |
| 6778 | if (phone == null) { |
| 6779 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6780 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6781 | } |
| 6782 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6783 | if (cpt == null) { |
| 6784 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6785 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6786 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6787 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6788 | } |
| 6789 | |
| 6790 | @Override |
| 6791 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6792 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6793 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6794 | } |
| 6795 | |
| 6796 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6797 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6798 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6799 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6800 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6801 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6802 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6803 | if (phone == null) { |
| 6804 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6805 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6806 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6807 | if (cpt == null) { |
| 6808 | continue; |
| 6809 | } |
| 6810 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6811 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6812 | break; |
| 6813 | } |
| 6814 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6815 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6816 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6817 | |
| 6818 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6819 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6820 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6821 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6822 | if (phone == null) { |
| 6823 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6824 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6825 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6826 | if (cpt == null) { |
| 6827 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6828 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6829 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6830 | } |
| 6831 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6832 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6833 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6834 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6835 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6836 | if (phone == null) { |
| 6837 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6838 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6839 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6840 | if (cpt == null) { |
| 6841 | return Collections.emptyList(); |
| 6842 | } |
| 6843 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6844 | } |
| 6845 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6846 | @Override |
| 6847 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6848 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6849 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6850 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6851 | try { |
| 6852 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6853 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6854 | } |
| 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6857 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6858 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6859 | } |
| 6860 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6861 | @Override |
| 6862 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6863 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6864 | |
| 6865 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6866 | if (phone == null) { |
| 6867 | return null; |
| 6868 | } |
| 6869 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6870 | if (cpt == null) { |
| 6871 | return null; |
| 6872 | } |
| 6873 | return cpt.getCarrierServicePackageName(); |
| 6874 | } |
| 6875 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6876 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6877 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6878 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6879 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6880 | return null; |
| 6881 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6882 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6883 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6884 | return null; |
| 6885 | } |
| 6886 | return iccId; |
| 6887 | } |
| 6888 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6889 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6890 | public void setCallComposerStatus(int subId, int status) { |
| 6891 | enforceModifyPermission(); |
| 6892 | |
| 6893 | final long identity = Binder.clearCallingIdentity(); |
| 6894 | try { |
| 6895 | Phone phone = getPhone(subId); |
| 6896 | if (phone != null) { |
| 6897 | Phone defaultPhone = phone.getImsPhone(); |
| 6898 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6899 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6900 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6901 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6902 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6903 | } |
| 6904 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6905 | } catch (ImsException e) { |
| 6906 | throw new ServiceSpecificException(e.getCode()); |
| 6907 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6908 | Binder.restoreCallingIdentity(identity); |
| 6909 | } |
| 6910 | } |
| 6911 | |
| 6912 | @Override |
| 6913 | public int getCallComposerStatus(int subId) { |
| 6914 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6915 | |
| 6916 | final long identity = Binder.clearCallingIdentity(); |
| 6917 | try { |
| 6918 | Phone phone = getPhone(subId); |
| 6919 | if (phone != null) { |
| 6920 | Phone defaultPhone = phone.getImsPhone(); |
| 6921 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6922 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6923 | return imsPhone.getCallComposerStatus(); |
| 6924 | } |
| 6925 | } |
| 6926 | } finally { |
| 6927 | Binder.restoreCallingIdentity(identity); |
| 6928 | } |
| 6929 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6930 | } |
| 6931 | |
| 6932 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6933 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6934 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6935 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6936 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6937 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | final long identity = Binder.clearCallingIdentity(); |
| 6939 | try { |
| 6940 | final String iccId = getIccId(subId); |
| 6941 | final Phone phone = getPhone(subId); |
| 6942 | if (phone == null) { |
| 6943 | return false; |
| 6944 | } |
| 6945 | final String subscriberId = phone.getSubscriberId(); |
| 6946 | |
| 6947 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6948 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6949 | + subscriberId + " to " + number); |
| 6950 | } |
| 6951 | |
| 6952 | if (TextUtils.isEmpty(iccId)) { |
| 6953 | return false; |
| 6954 | } |
| 6955 | |
| 6956 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6957 | |
| 6958 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6959 | if (alphaTag == null) { |
| 6960 | editor.remove(alphaTagPrefKey); |
| 6961 | } else { |
| 6962 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6963 | } |
| 6964 | |
| 6965 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6966 | // track all merged IMSIs based on line number |
| 6967 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6968 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6969 | if (number == null) { |
| 6970 | editor.remove(numberPrefKey); |
| 6971 | editor.remove(subscriberPrefKey); |
| 6972 | } else { |
| 6973 | editor.putString(numberPrefKey, number); |
| 6974 | editor.putString(subscriberPrefKey, subscriberId); |
| 6975 | } |
| 6976 | |
| 6977 | editor.commit(); |
| 6978 | return true; |
| 6979 | } finally { |
| 6980 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6981 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
| 6984 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6985 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6986 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6987 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6989 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6990 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6991 | return null; |
| 6992 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6993 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | final long identity = Binder.clearCallingIdentity(); |
| 6995 | try { |
| 6996 | String iccId = getIccId(subId); |
| 6997 | if (iccId != null) { |
| 6998 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6999 | if (DBG_MERGE) { |
| 7000 | log("getLine1NumberForDisplay returning " |
| 7001 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7002 | } |
| 7003 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7004 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7006 | return null; |
| 7007 | } finally { |
| 7008 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7009 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7010 | } |
| 7011 | |
| 7012 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7013 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7014 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7015 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7016 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7017 | return null; |
| 7018 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | String iccId = getIccId(subId); |
| 7023 | if (iccId != null) { |
| 7024 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7025 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7026 | } |
| 7027 | return null; |
| 7028 | } finally { |
| 7029 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7030 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7031 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7032 | |
| 7033 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7034 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7035 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7036 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7037 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7038 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7039 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7040 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7041 | return null; |
| 7042 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7043 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7044 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7045 | // the process, where TelephonyManager was instantiated. |
| 7046 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7047 | final long identity = Binder.clearCallingIdentity(); |
| 7048 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7049 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7051 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7052 | |
| 7053 | // Figure out what subscribers are currently active |
| 7054 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7056 | // Only consider subs which match the current subId |
| 7057 | // This logic can be simplified. See b/131189269 for progress. |
| 7058 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7059 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7060 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | |
| 7062 | // First pass, find a number override for an active subscriber |
| 7063 | String mergeNumber = null; |
| 7064 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7065 | for (String key : prefs.keySet()) { |
| 7066 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7067 | final String subscriberId = (String) prefs.get(key); |
| 7068 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7069 | final String iccId = key.substring( |
| 7070 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7071 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7072 | mergeNumber = (String) prefs.get(numberKey); |
| 7073 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7074 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | + " for active subscriber " + subscriberId); |
| 7076 | } |
| 7077 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7078 | break; |
| 7079 | } |
| 7080 | } |
| 7081 | } |
| 7082 | } |
| 7083 | |
| 7084 | // Shortcut when no active merged subscribers |
| 7085 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7086 | return null; |
| 7087 | } |
| 7088 | |
| 7089 | // Second pass, find all subscribers under that line override |
| 7090 | final ArraySet<String> result = new ArraySet<>(); |
| 7091 | for (String key : prefs.keySet()) { |
| 7092 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7093 | final String number = (String) prefs.get(key); |
| 7094 | if (mergeNumber.equals(number)) { |
| 7095 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7096 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7097 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7098 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7099 | result.add(subscriberId); |
| 7100 | } |
| 7101 | } |
| 7102 | } |
| 7103 | } |
| 7104 | |
| 7105 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7106 | Arrays.sort(resultArray); |
| 7107 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7108 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7110 | } |
| 7111 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7112 | } finally { |
| 7113 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7114 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7115 | } |
| 7116 | |
| 7117 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7118 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7119 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7120 | |
| 7121 | final long identity = Binder.clearCallingIdentity(); |
| 7122 | try { |
| 7123 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7124 | TelephonyManager.class); |
| 7125 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7126 | if (subscriberId == null) { |
| 7127 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7128 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7129 | + subId); |
| 7130 | } |
| 7131 | return null; |
| 7132 | } |
| 7133 | |
| 7134 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7135 | .getSubscriptionInfo(subId); |
| 7136 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7137 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7138 | if (groupUuid == null) { |
| 7139 | return new String[]{subscriberId}; |
| 7140 | } |
| 7141 | |
| 7142 | // Get all subscriberIds from the group. |
| 7143 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7144 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7145 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7146 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7147 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7148 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7149 | if (subscriberId != null) { |
| 7150 | mergedSubscriberIds.add(subscriberId); |
| 7151 | } |
| 7152 | } |
| 7153 | |
| 7154 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7155 | } finally { |
| 7156 | Binder.restoreCallingIdentity(identity); |
| 7157 | |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7162 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7163 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7164 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | |
| 7166 | final long identity = Binder.clearCallingIdentity(); |
| 7167 | try { |
| 7168 | final Phone phone = getPhone(subId); |
| 7169 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7170 | } finally { |
| 7171 | Binder.restoreCallingIdentity(identity); |
| 7172 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7173 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7174 | |
| 7175 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7176 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7177 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7178 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7179 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7180 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | |
| 7182 | final long identity = Binder.clearCallingIdentity(); |
| 7183 | try { |
| 7184 | final Phone phone = getPhone(subId); |
| 7185 | if (phone == null) { |
| 7186 | return false; |
| 7187 | } |
| 7188 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7189 | cdmaNonRoamingList); |
| 7190 | } finally { |
| 7191 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7192 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7193 | } |
| 7194 | |
| 7195 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7196 | @Deprecated |
| 7197 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7198 | enforceModifyPermission(); |
| 7199 | |
| 7200 | int returnValue = 0; |
| 7201 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7202 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7203 | if(result.exception == null) { |
| 7204 | if (result.result != null) { |
| 7205 | byte[] responseData = (byte[])(result.result); |
| 7206 | if(responseData.length > oemResp.length) { |
| 7207 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7208 | responseData.length + "bytes. Buffer Size is " + |
| 7209 | oemResp.length + "bytes."); |
| 7210 | } |
| 7211 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7212 | returnValue = responseData.length; |
| 7213 | } |
| 7214 | } else { |
| 7215 | CommandException ex = (CommandException) result.exception; |
| 7216 | returnValue = ex.getCommandError().ordinal(); |
| 7217 | if(returnValue > 0) returnValue *= -1; |
| 7218 | } |
| 7219 | } catch (RuntimeException e) { |
| 7220 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7221 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7222 | if(returnValue > 0) returnValue *= -1; |
| 7223 | } |
| 7224 | |
| 7225 | return returnValue; |
| 7226 | } |
| 7227 | |
| 7228 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7229 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7230 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7231 | try { |
| 7232 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7233 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7234 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7235 | } catch (SecurityException e) { |
| 7236 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7237 | throw e; |
| 7238 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7239 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7240 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7241 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7242 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | final long identity = Binder.clearCallingIdentity(); |
| 7244 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7245 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7246 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7247 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7248 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7249 | } finally { |
| 7250 | Binder.restoreCallingIdentity(identity); |
| 7251 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7252 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7253 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7254 | |
| 7255 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7256 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7257 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7258 | try { |
| 7259 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7260 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7261 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7262 | } |
| 7263 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7264 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7265 | } |
| 7266 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7267 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7268 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7269 | throw new SecurityException("App must be the dialer role holder to" |
| 7270 | + " upload a call composer pic"); |
| 7271 | } |
| 7272 | |
| 7273 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7274 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7275 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7276 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7277 | boolean readUntilEnd = false; |
| 7278 | int totalBytesRead = 0; |
| 7279 | byte[] buffer = new byte[16 * 1024]; |
| 7280 | while (true) { |
| 7281 | int numRead; |
| 7282 | try { |
| 7283 | numRead = input.read(buffer); |
| 7284 | } catch (IOException e) { |
| 7285 | try { |
| 7286 | fd.checkError(); |
| 7287 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7288 | null); |
| 7289 | } catch (IOException e1) { |
| 7290 | // This means that the other side closed explicitly with an error. If this |
| 7291 | // happens, log and ignore. |
| 7292 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7293 | } |
| 7294 | break; |
| 7295 | } |
| 7296 | if (numRead == -1) { |
| 7297 | readUntilEnd = true; |
| 7298 | break; |
| 7299 | } |
| 7300 | totalBytesRead += numRead; |
| 7301 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7302 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7303 | try { |
| 7304 | input.close(); |
| 7305 | } catch (IOException e) { |
| 7306 | // ignore |
| 7307 | } |
| 7308 | break; |
| 7309 | } |
| 7310 | output.write(buffer, 0, numRead); |
| 7311 | } |
| 7312 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7313 | // close is above, where the picture size is too big. |
| 7314 | |
| 7315 | try { |
| 7316 | fd.checkError(); |
| 7317 | } catch (IOException e) { |
| 7318 | loge("Remote end for call composer closed with an error: " + e); |
| 7319 | return; |
| 7320 | } |
| 7321 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7322 | if (!readUntilEnd) { |
| 7323 | loge("Did not finish reading entire image; aborting"); |
| 7324 | return; |
| 7325 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7326 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7327 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7328 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7329 | new CallComposerPictureTransfer.Factory() {}, |
| 7330 | imageData, |
| 7331 | (result) -> { |
| 7332 | if (result.first != null) { |
| 7333 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7334 | Bundle outputResult = new Bundle(); |
| 7335 | outputResult.putParcelable( |
| 7336 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7337 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7338 | outputResult); |
| 7339 | } else { |
| 7340 | callback.send(result.second, null); |
| 7341 | } |
| 7342 | } |
| 7343 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7344 | }); |
| 7345 | } |
| 7346 | |
| 7347 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7348 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7349 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7350 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7351 | |
| 7352 | final long identity = Binder.clearCallingIdentity(); |
| 7353 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7354 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7355 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | } finally { |
| 7357 | Binder.restoreCallingIdentity(identity); |
| 7358 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7359 | } |
| 7360 | |
| 7361 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7362 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7363 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7364 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7365 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7366 | return false; |
| 7367 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7368 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7369 | final long identity = Binder.clearCallingIdentity(); |
| 7370 | try { |
| 7371 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7372 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7373 | // In the long run, we may instead need to check if there exists a connection service |
| 7374 | // which can support video calling. |
| 7375 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7376 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7377 | return imsManager.isVtEnabledByPlatform() |
| 7378 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7379 | && imsManager.isVtEnabledByUser(); |
| 7380 | } finally { |
| 7381 | Binder.restoreCallingIdentity(identity); |
| 7382 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7383 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7384 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7385 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7386 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7387 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7389 | mApp, subId, callingPackage, callingFeatureId, |
| 7390 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7391 | return false; |
| 7392 | } |
| 7393 | |
| 7394 | final long identity = Binder.clearCallingIdentity(); |
| 7395 | try { |
| 7396 | CarrierConfigManager configManager = |
| 7397 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7398 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7399 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7400 | } finally { |
| 7401 | Binder.restoreCallingIdentity(identity); |
| 7402 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7403 | } |
| 7404 | |
| 7405 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7406 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7407 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7408 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | return false; |
| 7410 | } |
| 7411 | |
| 7412 | final long identity = Binder.clearCallingIdentity(); |
| 7413 | try { |
| 7414 | CarrierConfigManager configManager = |
| 7415 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7416 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7418 | } finally { |
| 7419 | Binder.restoreCallingIdentity(identity); |
| 7420 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7421 | } |
| 7422 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7423 | @Override |
| 7424 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7425 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7426 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7427 | } |
| 7428 | |
| 7429 | @Override |
| 7430 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7431 | final long identity = Binder.clearCallingIdentity(); |
| 7432 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7433 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7434 | } finally { |
| 7435 | Binder.restoreCallingIdentity(identity); |
| 7436 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7439 | /** |
| 7440 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7441 | * support for the feature and device firmware support. |
| 7442 | * |
| 7443 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7444 | */ |
| 7445 | @Override |
| 7446 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7448 | final Phone phone = getPhone(subscriptionId); |
| 7449 | if (phone == null) { |
| 7450 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7451 | return false; |
| 7452 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7454 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7456 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7457 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | return isCarrierSupported && isDeviceSupported; |
| 7459 | } finally { |
| 7460 | Binder.restoreCallingIdentity(identity); |
| 7461 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7462 | } |
| 7463 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7464 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7465 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7466 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7467 | * 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] | 7468 | */ |
| 7469 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | final long identity = Binder.clearCallingIdentity(); |
| 7471 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7472 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7473 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7474 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7475 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7476 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7477 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | } finally { |
| 7479 | Binder.restoreCallingIdentity(identity); |
| 7480 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7481 | } |
| 7482 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7483 | @Deprecated |
| 7484 | @Override |
| 7485 | public String getDeviceId(String callingPackage) { |
| 7486 | return getDeviceIdWithFeature(callingPackage, null); |
| 7487 | } |
| 7488 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7489 | /** |
| 7490 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7491 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7492 | * |
| 7493 | * <p>Requires Permission: |
| 7494 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7495 | */ |
| 7496 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7497 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7498 | try { |
| 7499 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7500 | } catch (SecurityException se) { |
| 7501 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7502 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7503 | + Binder.getCallingUid()); |
| 7504 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7505 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7506 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7507 | return null; |
| 7508 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7509 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7510 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7511 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7512 | return null; |
| 7513 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7514 | |
| 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
| 7517 | return phone.getDeviceId(); |
| 7518 | } finally { |
| 7519 | Binder.restoreCallingIdentity(identity); |
| 7520 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7521 | } |
| 7522 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7523 | /** |
| 7524 | * {@hide} |
| 7525 | * Returns the IMS Registration Status on a particular subid |
| 7526 | * |
| 7527 | * @param subId |
| 7528 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7529 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7530 | Phone phone = getPhone(subId); |
| 7531 | if (phone != null) { |
| 7532 | return phone.isImsRegistered(); |
| 7533 | } else { |
| 7534 | return false; |
| 7535 | } |
| 7536 | } |
| 7537 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7538 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7539 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7540 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7542 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7543 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7544 | } |
| 7545 | final long identity = Binder.clearCallingIdentity(); |
| 7546 | try { |
| 7547 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7548 | } finally { |
| 7549 | Binder.restoreCallingIdentity(identity); |
| 7550 | } |
| 7551 | } |
| 7552 | |
| 7553 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7554 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7555 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7556 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7557 | mApp, |
| 7558 | subscriptionId, |
| 7559 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | try { |
| 7562 | Phone phone = getPhone(subscriptionId); |
| 7563 | if (phone == null) { |
| 7564 | return null; |
| 7565 | } |
| 7566 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7567 | } finally { |
| 7568 | Binder.restoreCallingIdentity(identity); |
| 7569 | } |
| 7570 | } |
| 7571 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7572 | /** |
| 7573 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7574 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7575 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7576 | final long identity = Binder.clearCallingIdentity(); |
| 7577 | try { |
| 7578 | Phone phone = getPhone(subId); |
| 7579 | if (phone != null) { |
| 7580 | return phone.isWifiCallingEnabled(); |
| 7581 | } else { |
| 7582 | return false; |
| 7583 | } |
| 7584 | } finally { |
| 7585 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7586 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7587 | } |
| 7588 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7589 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7590 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7591 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7592 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7593 | final long identity = Binder.clearCallingIdentity(); |
| 7594 | try { |
| 7595 | Phone phone = getPhone(subId); |
| 7596 | if (phone != null) { |
| 7597 | return phone.isVideoEnabled(); |
| 7598 | } else { |
| 7599 | return false; |
| 7600 | } |
| 7601 | } finally { |
| 7602 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7603 | } |
| 7604 | } |
| 7605 | |
| 7606 | /** |
| 7607 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7608 | * defined in {@link ImsRegistrationImplBase}. |
| 7609 | */ |
| 7610 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | final long identity = Binder.clearCallingIdentity(); |
| 7612 | try { |
| 7613 | Phone phone = getPhone(subId); |
| 7614 | if (phone != null) { |
| 7615 | return phone.getImsRegistrationTech(); |
| 7616 | } else { |
| 7617 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7618 | } |
| 7619 | } finally { |
| 7620 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7621 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7622 | } |
| 7623 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7624 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7625 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7626 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7627 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7628 | return; |
| 7629 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7630 | Phone defaultPhone = getDefaultPhone(); |
| 7631 | if (defaultPhone != null) { |
| 7632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7633 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7634 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7635 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7636 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7637 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7638 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7639 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7640 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7641 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7642 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7643 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7644 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7645 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7646 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7647 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7648 | // There has been issues when Sms raw table somehow stores orphan |
| 7649 | // fragments. They lead to garbled message when new fragments come |
| 7650 | // in and combined with those stale ones. In case this happens again, |
| 7651 | // user can reset all network settings which will clean up this table. |
| 7652 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7653 | // Clean up IMS settings as well here. |
| 7654 | int slotId = getSlotIndex(subId); |
| 7655 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7656 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7657 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7658 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7659 | if (defaultPhone == null) { |
| 7660 | return; |
| 7661 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7662 | // Erase modem config if erase modem on network setting is enabled. |
| 7663 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7664 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7665 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7666 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7667 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7668 | |
| 7669 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7670 | } finally { |
| 7671 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7672 | } |
| 7673 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7674 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7675 | @VisibleForTesting |
| 7676 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7677 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7678 | return; |
| 7679 | } |
| 7680 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7681 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7682 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7683 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7684 | "user=" + defaultNetworkType); |
| 7685 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7686 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7687 | defaultNetworkType, null); |
| 7688 | } |
| 7689 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7690 | private void cleanUpSmsRawTable(Context context) { |
| 7691 | ContentResolver resolver = context.getContentResolver(); |
| 7692 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7693 | resolver.delete(uri, null, null); |
| 7694 | } |
| 7695 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7696 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7697 | public String getSimLocaleForSubscriber(int subId) { |
| 7698 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7699 | final Phone phone = getPhone(subId); |
| 7700 | if (phone == null) { |
| 7701 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7702 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7703 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7704 | final long identity = Binder.clearCallingIdentity(); |
| 7705 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7706 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7707 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7708 | if (info == null) { |
| 7709 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7710 | return null; |
| 7711 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7713 | // preferences (EF-PL and EF-LI)... |
| 7714 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7715 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7716 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7717 | if (localeFromDefaultSim != null) { |
| 7718 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7719 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7720 | + localeFromDefaultSim); |
| 7721 | return localeFromDefaultSim.toLanguageTag(); |
| 7722 | } else { |
| 7723 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | } |
| 7725 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7728 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7729 | // the SIM and carrier preferences does not include a country we add the country |
| 7730 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7731 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7733 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | return mccLocale.toLanguageTag(); |
| 7735 | } |
| 7736 | |
| 7737 | if (DBG) log("No locale found - returning null"); |
| 7738 | return null; |
| 7739 | } finally { |
| 7740 | Binder.restoreCallingIdentity(identity); |
| 7741 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7742 | } |
| 7743 | |
| 7744 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7745 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7746 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7747 | } |
| 7748 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | /** |
| 7750 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7751 | */ |
| 7752 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7753 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7754 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7755 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7756 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7757 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7758 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7759 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7760 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7761 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7762 | * representing the state of the modem. |
| 7763 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7764 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7765 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7766 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7767 | */ |
| 7768 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7769 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7770 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7771 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | |
| 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7775 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | } finally { |
| 7777 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7778 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7779 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7780 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7781 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7782 | // less than total activity duration. |
| 7783 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7784 | if (info == null) { |
| 7785 | return false; |
| 7786 | } |
| 7787 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7788 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7789 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7790 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7791 | return (info.isValid() |
| 7792 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7793 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7794 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7795 | && (totalTxTimeMs <= activityDurationMs)); |
| 7796 | } |
| 7797 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7798 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7799 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7800 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7801 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7802 | |
| 7803 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7804 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7805 | } |
| 7806 | |
| 7807 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7808 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7809 | rat, |
| 7810 | freq, |
| 7811 | info.getReceiveTimeMillis(rat, freq) |
| 7812 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7813 | } |
| 7814 | |
| 7815 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7816 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7817 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7818 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7819 | |
| 7820 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7821 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7822 | } |
| 7823 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7824 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7825 | rat, |
| 7826 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7827 | } |
| 7828 | |
| 7829 | /** |
| 7830 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7831 | * @param info recent ModemActivityInfo |
| 7832 | */ |
| 7833 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7834 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7835 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7836 | boolean matched; |
| 7837 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7838 | matched = false; |
| 7839 | int rat = info.getSpecificInfoRat(i); |
| 7840 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7841 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7842 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7843 | //if it already exists |
| 7844 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7845 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7846 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7847 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7848 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7849 | updateLastModemActivityInfo(info, rat, freq); |
| 7850 | matched = true; |
| 7851 | } |
| 7852 | } else { |
| 7853 | updateLastModemActivityInfo(info, rat); |
| 7854 | matched = true; |
| 7855 | } |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | if (!matched) { |
| 7860 | mDeltaSpecificInfo = |
| 7861 | new ActivityStatsTechSpecificInfo( |
| 7862 | rat, |
| 7863 | freq, |
| 7864 | info.getTransmitTimeMillis(rat, freq), |
| 7865 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7866 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7867 | } |
| 7868 | } |
| 7869 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7870 | mLastModemActivitySpecificInfo = |
| 7871 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7872 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7873 | |
| 7874 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7875 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7876 | info.getSleepTimeMillis() |
| 7877 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7878 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7879 | info.getIdleTimeMillis() |
| 7880 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7881 | } |
| 7882 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7883 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7884 | * Returns the service state information on specified subscription. |
| 7885 | */ |
| 7886 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7887 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7888 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7889 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7890 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7891 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7892 | return null; |
| 7893 | } |
| 7894 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7895 | boolean hasFinePermission = false; |
| 7896 | boolean hasCoarsePermission = false; |
| 7897 | if (!renounceFineLocationAccess) { |
| 7898 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7899 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7900 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7901 | .setCallingPackage(callingPackage) |
| 7902 | .setCallingFeatureId(callingFeatureId) |
| 7903 | .setCallingPid(Binder.getCallingPid()) |
| 7904 | .setCallingUid(Binder.getCallingUid()) |
| 7905 | .setMethod("getServiceStateForSubscriber") |
| 7906 | .setLogAsInfo(true) |
| 7907 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7908 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7909 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7910 | .build()); |
| 7911 | hasFinePermission = |
| 7912 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7913 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7914 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7915 | if (!renounceCoarseLocationAccess) { |
| 7916 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7917 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7918 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7919 | .setCallingPackage(callingPackage) |
| 7920 | .setCallingFeatureId(callingFeatureId) |
| 7921 | .setCallingPid(Binder.getCallingPid()) |
| 7922 | .setCallingUid(Binder.getCallingUid()) |
| 7923 | .setMethod("getServiceStateForSubscriber") |
| 7924 | .setLogAsInfo(true) |
| 7925 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7926 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7927 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7928 | .build()); |
| 7929 | hasCoarsePermission = |
| 7930 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7931 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7932 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7933 | final Phone phone = getPhone(subId); |
| 7934 | if (phone == null) { |
| 7935 | return null; |
| 7936 | } |
| 7937 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7940 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7941 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7943 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7944 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7945 | Rlog.d(LOG_TAG, |
| 7946 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7947 | return null; |
| 7948 | } |
| 7949 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7950 | ServiceState ss = phone.getServiceState(); |
| 7951 | |
| 7952 | // Scrub out the location info in ServiceState depending on what level of access |
| 7953 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7954 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7955 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7956 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | } finally { |
| 7958 | Binder.restoreCallingIdentity(identity); |
| 7959 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7960 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7961 | |
| 7962 | /** |
| 7963 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7964 | * |
| 7965 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7966 | * voicemail ringtone. |
| 7967 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7968 | * PhoneAccount. |
| 7969 | */ |
| 7970 | @Override |
| 7971 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7972 | final long identity = Binder.clearCallingIdentity(); |
| 7973 | try { |
| 7974 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7975 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7976 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7979 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7980 | } finally { |
| 7981 | Binder.restoreCallingIdentity(identity); |
| 7982 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7986 | * Sets the per-account voicemail ringtone. |
| 7987 | * |
| 7988 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7989 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7990 | * |
| 7991 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7992 | * voicemail ringtone. |
| 7993 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7994 | * PhoneAccount. |
| 7995 | */ |
| 7996 | @Override |
| 7997 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7998 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7999 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8000 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8001 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8002 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8004 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8005 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8006 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8007 | |
| 8008 | final long identity = Binder.clearCallingIdentity(); |
| 8009 | try { |
| 8010 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8011 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8012 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8013 | } |
| 8014 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8015 | } finally { |
| 8016 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8017 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8018 | } |
| 8019 | |
| 8020 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8021 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8022 | * |
| 8023 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8024 | * voicemail vibration setting. |
| 8025 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8026 | */ |
| 8027 | @Override |
| 8028 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | try { |
| 8031 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8032 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8033 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8034 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8035 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8037 | } finally { |
| 8038 | Binder.restoreCallingIdentity(identity); |
| 8039 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8040 | } |
| 8041 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8042 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8043 | * Sets the per-account voicemail vibration. |
| 8044 | * |
| 8045 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8046 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8047 | * |
| 8048 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8049 | * voicemail vibration setting. |
| 8050 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8051 | * specific PhoneAccount. |
| 8052 | */ |
| 8053 | @Override |
| 8054 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8055 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8056 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8057 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8058 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8059 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8061 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8062 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | final long identity = Binder.clearCallingIdentity(); |
| 8066 | try { |
| 8067 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8068 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8069 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8070 | } |
| 8071 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8072 | } finally { |
| 8073 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8074 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8075 | } |
| 8076 | |
| 8077 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8078 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8079 | * |
| 8080 | * @throws SecurityException if the caller does not have the required permission |
| 8081 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8082 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8083 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8084 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8085 | } |
| 8086 | |
| 8087 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8088 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8089 | * permission. |
| 8090 | * |
| 8091 | * @throws SecurityException if the caller does not have the required permission |
| 8092 | */ |
| 8093 | private void enforceSendSmsPermission() { |
| 8094 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8095 | } |
| 8096 | |
| 8097 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8098 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8099 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8100 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8101 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8102 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8103 | final long identity = Binder.clearCallingIdentity(); |
| 8104 | try { |
| 8105 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8106 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8107 | if (componentName == null) { |
| 8108 | throw new SecurityException( |
| 8109 | "Caller not current active visual voicemail package[null]"); |
| 8110 | } |
| 8111 | String vvmPackage = componentName.getPackageName(); |
| 8112 | if (!callingPackage.equals(vvmPackage)) { |
| 8113 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8114 | + vvmPackage + "]"); |
| 8115 | } |
| 8116 | } finally { |
| 8117 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8122 | * Return the application ID for the app type. |
| 8123 | * |
| 8124 | * @param subId the subscription ID that this request applies to. |
| 8125 | * @param appType the uicc app type. |
| 8126 | * @return Application ID for specificied app type, or null if no uicc. |
| 8127 | */ |
| 8128 | @Override |
| 8129 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8130 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8131 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8132 | |
| 8133 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8134 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | if (phone == null) { |
| 8136 | return null; |
| 8137 | } |
| 8138 | String aid = null; |
| 8139 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8140 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8141 | .getApplicationByType(appType).getAid(); |
| 8142 | } catch (Exception e) { |
| 8143 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8144 | } |
| 8145 | return aid; |
| 8146 | } finally { |
| 8147 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8148 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8149 | } |
| 8150 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8151 | /** |
| 8152 | * Return the Electronic Serial Number. |
| 8153 | * |
| 8154 | * @param subId the subscription ID that this request applies to. |
| 8155 | * @return ESN or null if error. |
| 8156 | */ |
| 8157 | @Override |
| 8158 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8159 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8160 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8161 | |
| 8162 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8163 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8164 | if (phone == null) { |
| 8165 | return null; |
| 8166 | } |
| 8167 | String esn = null; |
| 8168 | try { |
| 8169 | esn = phone.getEsn(); |
| 8170 | } catch (Exception e) { |
| 8171 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8172 | } |
| 8173 | return esn; |
| 8174 | } finally { |
| 8175 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8176 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8177 | } |
| 8178 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8179 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8180 | * Return the Preferred Roaming List Version. |
| 8181 | * |
| 8182 | * @param subId the subscription ID that this request applies to. |
| 8183 | * @return PRLVersion or null if error. |
| 8184 | */ |
| 8185 | @Override |
| 8186 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8187 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8188 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8191 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | if (phone == null) { |
| 8193 | return null; |
| 8194 | } |
| 8195 | String cdmaPrlVersion = null; |
| 8196 | try { |
| 8197 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8198 | } catch (Exception e) { |
| 8199 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8200 | } |
| 8201 | return cdmaPrlVersion; |
| 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8204 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8205 | } |
| 8206 | |
| 8207 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8208 | * Get snapshot of Telephony histograms |
| 8209 | * @return List of Telephony histograms |
| 8210 | * @hide |
| 8211 | */ |
| 8212 | @Override |
| 8213 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8215 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8216 | |
| 8217 | final long identity = Binder.clearCallingIdentity(); |
| 8218 | try { |
| 8219 | return RIL.getTelephonyRILTimingHistograms(); |
| 8220 | } finally { |
| 8221 | Binder.restoreCallingIdentity(identity); |
| 8222 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8223 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8224 | |
| 8225 | /** |
| 8226 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8227 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8228 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8229 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8230 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8231 | * @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] | 8232 | */ |
| 8233 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8234 | @TelephonyManager.SetCarrierRestrictionResult |
| 8235 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8236 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8237 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8238 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8239 | if (carrierRestrictionRules == null) { |
| 8240 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8241 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8243 | final long identity = Binder.clearCallingIdentity(); |
| 8244 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8245 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8246 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8247 | } finally { |
| 8248 | Binder.restoreCallingIdentity(identity); |
| 8249 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | /** |
| 8253 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8254 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8255 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8256 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8257 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8258 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8259 | */ |
| 8260 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8261 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8262 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | |
| 8265 | final long identity = Binder.clearCallingIdentity(); |
| 8266 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8267 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8268 | if (response instanceof CarrierRestrictionRules) { |
| 8269 | return (CarrierRestrictionRules) response; |
| 8270 | } |
| 8271 | // Response is an Exception of some kind, |
| 8272 | // which is signalled to the user as a NULL retval |
| 8273 | return null; |
| 8274 | } catch (Exception e) { |
| 8275 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8276 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8280 | } |
| 8281 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8282 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8283 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8284 | * @param subId the subscription ID that this action applies to. |
| 8285 | * @param enabled control enable or disable radio. |
| 8286 | * {@hide} |
| 8287 | */ |
| 8288 | @Override |
| 8289 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8290 | enforceModifyPermission(); |
| 8291 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8292 | |
| 8293 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8294 | if (phone == null) { |
| 8295 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8296 | return; |
| 8297 | } |
| 8298 | try { |
| 8299 | phone.carrierActionSetRadioEnabled(enabled); |
| 8300 | } catch (Exception e) { |
| 8301 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8302 | } finally { |
| 8303 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8304 | } |
| 8305 | } |
| 8306 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8307 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8308 | * Enable or disable Voice over NR (VoNR) |
| 8309 | * @param subId the subscription ID that this action applies to. |
| 8310 | * @param enabled enable or disable VoNR. |
| 8311 | * @return operation result. |
| 8312 | */ |
| 8313 | @Override |
| 8314 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8315 | enforceModifyPermission(); |
| 8316 | final Phone phone = getPhone(subId); |
| 8317 | |
| 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | if (phone == null) { |
| 8320 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8321 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8322 | } |
| 8323 | |
| 8324 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8325 | try { |
| 8326 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8327 | workSource); |
| 8328 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8329 | |
| 8330 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8331 | if (DBG) { |
| 8332 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8333 | } |
| 8334 | SubscriptionManager.setSubscriptionProperty( |
| 8335 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8336 | (enabled ? "1" : "0")); |
| 8337 | } |
| 8338 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8339 | return result; |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
| 8343 | } |
| 8344 | |
| 8345 | /** |
| 8346 | * Is voice over NR enabled |
| 8347 | * @return true if VoNR is enabled else false |
| 8348 | */ |
| 8349 | @Override |
| 8350 | public boolean isVoNrEnabled(int subId) { |
| 8351 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8352 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8353 | final long identity = Binder.clearCallingIdentity(); |
| 8354 | try { |
| 8355 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8356 | null, subId, workSource); |
| 8357 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8358 | return isEnabled; |
| 8359 | } finally { |
| 8360 | Binder.restoreCallingIdentity(identity); |
| 8361 | } |
| 8362 | } |
| 8363 | |
| 8364 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8365 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8366 | * network status based on which carrier apps could apply actions accordingly, |
| 8367 | * enable/disable default url handler for example. |
| 8368 | * |
| 8369 | * @param subId the subscription ID that this action applies to. |
| 8370 | * @param report control start/stop reporting the default network status. |
| 8371 | * {@hide} |
| 8372 | */ |
| 8373 | @Override |
| 8374 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8375 | enforceModifyPermission(); |
| 8376 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8377 | |
| 8378 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8379 | if (phone == null) { |
| 8380 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8381 | return; |
| 8382 | } |
| 8383 | try { |
| 8384 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8385 | } catch (Exception e) { |
| 8386 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8387 | } finally { |
| 8388 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8389 | } |
| 8390 | } |
| 8391 | |
| 8392 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8393 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8394 | * @param subId the subscription ID that this action applies to. |
| 8395 | * {@hide} |
| 8396 | */ |
| 8397 | @Override |
| 8398 | public void carrierActionResetAll(int subId) { |
| 8399 | enforceModifyPermission(); |
| 8400 | final Phone phone = getPhone(subId); |
| 8401 | if (phone == null) { |
| 8402 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8403 | return; |
| 8404 | } |
| 8405 | try { |
| 8406 | phone.carrierActionResetAll(); |
| 8407 | } catch (Exception e) { |
| 8408 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8409 | } |
| 8410 | } |
| 8411 | |
| 8412 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8413 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8414 | * bug report is being generated. |
| 8415 | */ |
| 8416 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8417 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8418 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8419 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8420 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8421 | + Binder.getCallingPid() |
| 8422 | + ", uid=" + Binder.getCallingUid() |
| 8423 | + "without permission " |
| 8424 | + android.Manifest.permission.DUMP); |
| 8425 | return; |
| 8426 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8427 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8428 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8429 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8430 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8431 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8432 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8433 | @NonNull String[] args) { |
| 8434 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8435 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8436 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8437 | } |
| 8438 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8439 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8440 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8441 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8442 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8443 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8444 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8445 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8446 | */ |
| 8447 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8448 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8449 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8450 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8451 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8452 | try { |
| 8453 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8454 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8455 | } catch (SecurityException se) { |
| 8456 | enforceModifyPermission(); |
| 8457 | } |
| 8458 | } else { |
| 8459 | enforceModifyPermission(); |
| 8460 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8461 | |
| 8462 | final long identity = Binder.clearCallingIdentity(); |
| 8463 | try { |
| 8464 | Phone phone = getPhone(subId); |
| 8465 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8466 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8467 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8468 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8469 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8470 | phone.getDataSettingsManager().setDataEnabled( |
| 8471 | reason, enabled, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8472 | } else { |
| 8473 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8474 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8476 | } |
| 8477 | } finally { |
| 8478 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8479 | } |
| 8480 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8481 | |
| 8482 | /** |
| 8483 | * Get Client request stats |
| 8484 | * @return List of Client Request Stats |
| 8485 | * @hide |
| 8486 | */ |
| 8487 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8488 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8489 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8490 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8491 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8492 | return null; |
| 8493 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8494 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8495 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8496 | final long identity = Binder.clearCallingIdentity(); |
| 8497 | try { |
| 8498 | if (phone != null) { |
| 8499 | return phone.getClientRequestStats(); |
| 8500 | } |
| 8501 | |
| 8502 | return null; |
| 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
| 8505 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8506 | } |
| 8507 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8508 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8509 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8510 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8511 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8512 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8513 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8514 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8515 | // commands that plumb through the RIL as root, like so: |
| 8516 | // $ adb root |
| 8517 | // $ adb shell cmd phone ... |
| 8518 | packageName = "root"; |
| 8519 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8520 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8521 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8522 | |
| 8523 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8524 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8525 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8526 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8527 | * @param state State of SIM (power down, power up, pass through) |
| 8528 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8529 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8530 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8531 | * |
| 8532 | **/ |
| 8533 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8534 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8535 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8536 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8537 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8538 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
| 8542 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8543 | phone.setSimPowerState(state, null, workSource); |
| 8544 | } |
| 8545 | } finally { |
| 8546 | Binder.restoreCallingIdentity(identity); |
| 8547 | } |
| 8548 | } |
| 8549 | |
| 8550 | /** |
| 8551 | * Set SIM card power state. |
| 8552 | * |
| 8553 | * @param slotIndex SIM slot id. |
| 8554 | * @param state State of SIM (power down, power up, pass through) |
| 8555 | * @param callback callback to trigger after success or failure |
| 8556 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8557 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8558 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8559 | * |
| 8560 | **/ |
| 8561 | @Override |
| 8562 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8563 | IIntegerConsumer callback) { |
| 8564 | enforceModifyPermission(); |
| 8565 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8566 | |
| 8567 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8568 | |
| 8569 | final long identity = Binder.clearCallingIdentity(); |
| 8570 | try { |
| 8571 | if (phone != null) { |
| 8572 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8573 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8574 | } |
| 8575 | } finally { |
| 8576 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8577 | } |
| 8578 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8579 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8580 | private boolean isUssdApiAllowed(int subId) { |
| 8581 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8582 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8583 | if (configManager == null) { |
| 8584 | return false; |
| 8585 | } |
| 8586 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8587 | if (pb == null) { |
| 8588 | return false; |
| 8589 | } |
| 8590 | return pb.getBoolean( |
| 8591 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8592 | } |
| 8593 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8594 | /** |
| 8595 | * Check if phone is in emergency callback mode |
| 8596 | * @return true if phone is in emergency callback mode |
| 8597 | * @param subId sub id |
| 8598 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8599 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8600 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8601 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8602 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8603 | |
| 8604 | final long identity = Binder.clearCallingIdentity(); |
| 8605 | try { |
| 8606 | if (phone != null) { |
| 8607 | return phone.isInEcm(); |
| 8608 | } else { |
| 8609 | return false; |
| 8610 | } |
| 8611 | } finally { |
| 8612 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8613 | } |
| 8614 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8615 | |
| 8616 | /** |
| 8617 | * Get the current signal strength information for the given subscription. |
| 8618 | * Because this information is not updated when the device is in a low power state |
| 8619 | * it should not be relied-upon to be current. |
| 8620 | * @param subId Subscription index |
| 8621 | * @return the most recent cached signal strength info from the modem |
| 8622 | */ |
| 8623 | @Override |
| 8624 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8625 | final long identity = Binder.clearCallingIdentity(); |
| 8626 | try { |
| 8627 | Phone p = getPhone(subId); |
| 8628 | if (p == null) { |
| 8629 | return null; |
| 8630 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8631 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8632 | return p.getSignalStrength(); |
| 8633 | } finally { |
| 8634 | Binder.restoreCallingIdentity(identity); |
| 8635 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8636 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8637 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8638 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8639 | * Get the current modem radio state for the given slot. |
| 8640 | * @param slotIndex slot index. |
| 8641 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8642 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8643 | * @return the current radio power state from the modem |
| 8644 | */ |
| 8645 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8646 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8647 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8648 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8649 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8650 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8651 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8652 | } |
| 8653 | |
| 8654 | final long identity = Binder.clearCallingIdentity(); |
| 8655 | try { |
| 8656 | return phone.getRadioPowerState(); |
| 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
| 8659 | } |
| 8660 | } |
| 8661 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8662 | } |
| 8663 | |
| 8664 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8665 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8666 | * |
| 8667 | * <p>Requires one of the following permissions: |
| 8668 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8669 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8670 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8671 | * privileges. |
| 8672 | * |
| 8673 | * @param subId subscription id |
| 8674 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8675 | * {@code false}. |
| 8676 | */ |
| 8677 | @Override |
| 8678 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8679 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8680 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8681 | try { |
| 8682 | mApp.enforceCallingOrSelfPermission( |
| 8683 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8684 | functionName); |
| 8685 | } catch (Exception e) { |
| 8686 | mApp.enforceCallingOrSelfPermission( |
| 8687 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8688 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8689 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8690 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8691 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8692 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8693 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8694 | boolean isEnabled = false; |
| 8695 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8696 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8697 | Phone phone = getPhone(subId); |
| 8698 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8699 | } finally { |
| 8700 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8701 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8702 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8703 | } |
| 8704 | |
| 8705 | |
| 8706 | /** |
| 8707 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8708 | * |
| 8709 | * <p> Requires permission: |
| 8710 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8711 | * privileges. |
| 8712 | * |
| 8713 | * @param subId subscription id |
| 8714 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8715 | */ |
| 8716 | @Override |
| 8717 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8719 | mApp, subId, "setDataRoamingEnabled"); |
| 8720 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8721 | final long identity = Binder.clearCallingIdentity(); |
| 8722 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8723 | Phone phone = getPhone(subId); |
| 8724 | if (phone != null) { |
| 8725 | phone.setDataRoamingEnabled(isEnabled); |
| 8726 | } |
| 8727 | } finally { |
| 8728 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8729 | } |
| 8730 | } |
| 8731 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8732 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8733 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8734 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8735 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8736 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8737 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8738 | boolean isAllowed = true; |
| 8739 | final long identity = Binder.clearCallingIdentity(); |
| 8740 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8741 | Phone phone = getPhone(subId); |
| 8742 | if (phone != null) { |
| 8743 | isAllowed = phone.isCspPlmnEnabled(); |
| 8744 | } |
| 8745 | } finally { |
| 8746 | Binder.restoreCallingIdentity(identity); |
| 8747 | } |
| 8748 | return isAllowed; |
| 8749 | } |
| 8750 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8751 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8752 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8753 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8754 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8755 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8756 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8757 | if (phone == null) { |
| 8758 | return false; |
| 8759 | } |
| 8760 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8761 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8762 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8763 | } |
| 8764 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8765 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8766 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8767 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8768 | mApp.getSystemService(AppOpsManager.class) |
| 8769 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8770 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8771 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8772 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8773 | try { |
| 8774 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8775 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8776 | } catch (SecurityException e) { |
| 8777 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8778 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8779 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8780 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8781 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8782 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8783 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8784 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8785 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8786 | Binder.getCallingUid())) { |
| 8787 | isIccIdAccessRestricted = true; |
| 8788 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8789 | final long identity = Binder.clearCallingIdentity(); |
| 8790 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8791 | UiccController uiccController = UiccController.getInstance(); |
| 8792 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8793 | if (hasReadPermission) { |
| 8794 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8795 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8796 | |
| 8797 | // Remove private info if the caller doesn't have access |
| 8798 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8799 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8800 | //setting the value after compatibility check |
| 8801 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8802 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8803 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8804 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8805 | if (card == null) { |
| 8806 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8807 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8808 | continue; |
| 8809 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8810 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8811 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8812 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8813 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8814 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8815 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8816 | for (UiccPortInfo portInfo : portInfos) { |
| 8817 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8818 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8819 | if (port == null) { |
| 8820 | // assume no access if port is null |
| 8821 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8822 | continue; |
| 8823 | } |
| 8824 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8825 | uiccPortInfos.add(portInfo); |
| 8826 | } else { |
| 8827 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8828 | } |
| 8829 | } |
| 8830 | filteredInfos.add(new UiccCardInfo( |
| 8831 | cardInfo.isEuicc(), |
| 8832 | cardInfo.getCardId(), |
| 8833 | null, |
| 8834 | cardInfo.getPhysicalSlotIndex(), |
| 8835 | cardInfo.isRemovable(), |
| 8836 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8837 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8838 | } |
| 8839 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8840 | } finally { |
| 8841 | Binder.restoreCallingIdentity(identity); |
| 8842 | } |
| 8843 | } |
| 8844 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8845 | /** |
| 8846 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8847 | * generally private and require carrier privileges to view. |
| 8848 | * |
| 8849 | * @hide |
| 8850 | */ |
| 8851 | @NonNull |
| 8852 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8853 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8854 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8855 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8856 | } |
| 8857 | return new UiccCardInfo( |
| 8858 | cardInfo.isEuicc(), |
| 8859 | cardInfo.getCardId(), |
| 8860 | null, |
| 8861 | cardInfo.getPhysicalSlotIndex(), |
| 8862 | cardInfo.isRemovable(), |
| 8863 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8864 | portinfo |
| 8865 | ); |
| 8866 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8867 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8868 | /** |
| 8869 | * @hide |
| 8870 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8871 | * These values are generally private and require carrier privileges to view. |
| 8872 | */ |
| 8873 | @NonNull |
| 8874 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8875 | return new UiccPortInfo( |
| 8876 | UiccPortInfo.ICCID_REDACTED, |
| 8877 | portInfo.getPortIndex(), |
| 8878 | portInfo.getLogicalSlotIndex(), |
| 8879 | portInfo.isActive() |
| 8880 | ); |
| 8881 | } |
| 8882 | @Override |
| 8883 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8884 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8885 | mApp.getSystemService(AppOpsManager.class) |
| 8886 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8887 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8888 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8889 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8890 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8891 | // we are reading iccId which is PII data. |
| 8892 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8893 | |
| 8894 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8895 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8896 | Binder.getCallingUid())) { |
| 8897 | isLogicalSlotAccessRestricted = true; |
| 8898 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8899 | final long identity = Binder.clearCallingIdentity(); |
| 8900 | try { |
| 8901 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8902 | if (slots == null || slots.length == 0) { |
| 8903 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8904 | return null; |
| 8905 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8906 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8907 | for (int i = 0; i < slots.length; i++) { |
| 8908 | UiccSlot slot = slots[i]; |
| 8909 | if (slot == null) { |
| 8910 | continue; |
| 8911 | } |
| 8912 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8913 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8914 | UiccCard card = slot.getUiccCard(); |
| 8915 | if (card != null) { |
| 8916 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8917 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8918 | cardId = slot.getEid(); |
| 8919 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8920 | // If cardId is null, use iccId of default port as cardId. |
| 8921 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8922 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8923 | } |
| 8924 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8925 | if (cardId != null) { |
| 8926 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8927 | // if cardId is an EID, it's all digits so this is fine |
| 8928 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8929 | } |
| 8930 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8931 | int cardState = 0; |
| 8932 | switch (slot.getCardState()) { |
| 8933 | case CARDSTATE_ABSENT: |
| 8934 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8935 | break; |
| 8936 | case CARDSTATE_PRESENT: |
| 8937 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8938 | break; |
| 8939 | case CARDSTATE_ERROR: |
| 8940 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8941 | break; |
| 8942 | case CARDSTATE_RESTRICTED: |
| 8943 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8944 | break; |
| 8945 | default: |
| 8946 | break; |
| 8947 | |
| 8948 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8949 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8950 | int[] portIndexes = slot.getPortList(); |
| 8951 | for (int portIdx : portIndexes) { |
| 8952 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8953 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 8954 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 8955 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8957 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8958 | slot.isEuicc(), |
| 8959 | cardId, |
| 8960 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8961 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8962 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8963 | //setting the value after compatibility check |
| 8964 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8965 | } |
| 8966 | return infos; |
| 8967 | } finally { |
| 8968 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8969 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8970 | } |
| 8971 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8972 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8973 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8974 | boolean hasReadPermission) { |
| 8975 | String iccId = slot.getIccId(portIndex); |
| 8976 | if (hasReadPermission) { // if has read permission |
| 8977 | return iccId; |
| 8978 | } else { |
| 8979 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8980 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8981 | // if no read permission, checking carrier privilege access |
| 8982 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8983 | return iccId; |
| 8984 | } |
| 8985 | } |
| 8986 | } |
| 8987 | // No read permission or carrier privilege access. |
| 8988 | return UiccPortInfo.ICCID_REDACTED; |
| 8989 | } |
| 8990 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8991 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8992 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8993 | public boolean switchSlots(int[] physicalSlots) { |
| 8994 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8995 | |
| 8996 | final long identity = Binder.clearCallingIdentity(); |
| 8997 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8998 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 8999 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9000 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9001 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9002 | physicalSlots[i], i)); |
| 9003 | } |
| 9004 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9005 | } finally { |
| 9006 | Binder.restoreCallingIdentity(identity); |
| 9007 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9008 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9009 | |
| 9010 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9011 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9012 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9013 | enforceModifyPermission(); |
| 9014 | |
| 9015 | final long identity = Binder.clearCallingIdentity(); |
| 9016 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9017 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9018 | } finally { |
| 9019 | Binder.restoreCallingIdentity(identity); |
| 9020 | } |
| 9021 | } |
| 9022 | |
| 9023 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9024 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9025 | final long identity = Binder.clearCallingIdentity(); |
| 9026 | try { |
| 9027 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9028 | } finally { |
| 9029 | Binder.restoreCallingIdentity(identity); |
| 9030 | } |
| 9031 | } |
| 9032 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9033 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9034 | * A test API to reload the UICC profile. |
| 9035 | * |
| 9036 | * <p>Requires that the calling app has permission |
| 9037 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9038 | * @hide |
| 9039 | */ |
| 9040 | @Override |
| 9041 | public void refreshUiccProfile(int subId) { |
| 9042 | enforceModifyPermission(); |
| 9043 | |
| 9044 | final long identity = Binder.clearCallingIdentity(); |
| 9045 | try { |
| 9046 | Phone phone = getPhone(subId); |
| 9047 | if (phone == null) { |
| 9048 | return; |
| 9049 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9050 | UiccPort uiccPort = phone.getUiccPort(); |
| 9051 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9052 | return; |
| 9053 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9054 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9055 | if (uiccProfile == null) { |
| 9056 | return; |
| 9057 | } |
| 9058 | uiccProfile.refresh(); |
| 9059 | } finally { |
| 9060 | Binder.restoreCallingIdentity(identity); |
| 9061 | } |
| 9062 | } |
| 9063 | |
| 9064 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9065 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9066 | */ |
| 9067 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9068 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9069 | } |
| 9070 | |
| 9071 | /** |
| 9072 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9073 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9074 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9075 | */ |
| 9076 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9077 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9078 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9079 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9080 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9081 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9082 | return isDataRoamingEnabled; |
| 9083 | } |
| 9084 | |
| 9085 | /** |
| 9086 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9087 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9088 | */ |
| 9089 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9090 | List<Integer> list = TelephonyProperties.default_network(); |
| 9091 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9092 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9093 | return list.get(phoneId); |
| 9094 | } |
| 9095 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9096 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9097 | |
| 9098 | @Override |
| 9099 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9100 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9101 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9102 | |
| 9103 | final long identity = Binder.clearCallingIdentity(); |
| 9104 | try { |
| 9105 | final Phone phone = getPhone(subId); |
| 9106 | if (phone == null) { |
| 9107 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9108 | return; |
| 9109 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9110 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9111 | if (cpt != null) { |
| 9112 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9113 | } |
| 9114 | // 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] | 9115 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9116 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9117 | if (carrierPrivilegeRules == null) { |
| 9118 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9119 | } else { |
| 9120 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9121 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9122 | } finally { |
| 9123 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9124 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9125 | } |
| 9126 | |
| 9127 | @Override |
| 9128 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9129 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9130 | |
| 9131 | final long identity = Binder.clearCallingIdentity(); |
| 9132 | try { |
| 9133 | final Phone phone = getPhone(subId); |
| 9134 | if (phone == null) { |
| 9135 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9136 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9137 | } |
| 9138 | return phone.getCarrierIdListVersion(); |
| 9139 | } finally { |
| 9140 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9141 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9142 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9143 | |
| 9144 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9145 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9146 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9147 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9148 | mApp, subId, callingPackage, callingFeatureId, |
| 9149 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9150 | return -1; |
| 9151 | } |
| 9152 | |
| 9153 | final long identity = Binder.clearCallingIdentity(); |
| 9154 | try { |
| 9155 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9156 | } finally { |
| 9157 | Binder.restoreCallingIdentity(identity); |
| 9158 | } |
| 9159 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9160 | |
| 9161 | @Override |
| 9162 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9163 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9164 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9165 | mApp, subId, "getCdmaRoamingMode"); |
| 9166 | |
| 9167 | final long identity = Binder.clearCallingIdentity(); |
| 9168 | try { |
| 9169 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
| 9172 | } |
| 9173 | } |
| 9174 | |
| 9175 | @Override |
| 9176 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9177 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9178 | mApp, subId, "setCdmaRoamingMode"); |
| 9179 | |
| 9180 | final long identity = Binder.clearCallingIdentity(); |
| 9181 | try { |
| 9182 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9183 | } finally { |
| 9184 | Binder.restoreCallingIdentity(identity); |
| 9185 | } |
| 9186 | } |
| 9187 | |
| 9188 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9189 | public int getCdmaSubscriptionMode(int subId) { |
| 9190 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9191 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9192 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9193 | |
| 9194 | final long identity = Binder.clearCallingIdentity(); |
| 9195 | try { |
| 9196 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9197 | } finally { |
| 9198 | Binder.restoreCallingIdentity(identity); |
| 9199 | } |
| 9200 | } |
| 9201 | |
| 9202 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9203 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9205 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9206 | |
| 9207 | final long identity = Binder.clearCallingIdentity(); |
| 9208 | try { |
| 9209 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9210 | } finally { |
| 9211 | Binder.restoreCallingIdentity(identity); |
| 9212 | } |
| 9213 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9214 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9215 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9216 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9217 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9218 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9219 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9220 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9221 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9222 | } |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9225 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9226 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9227 | if (phone.getEmergencyNumberTracker() != null |
| 9228 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9229 | emergencyNumberListInternal.put( |
| 9230 | phone.getSubId(), |
| 9231 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9232 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9233 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9234 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9235 | } finally { |
| 9236 | Binder.restoreCallingIdentity(identity); |
| 9237 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9238 | } |
| 9239 | |
| 9240 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9241 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9242 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9243 | if (!exactMatch) { |
| 9244 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9245 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9246 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9247 | } |
| 9248 | final long identity = Binder.clearCallingIdentity(); |
| 9249 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9250 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9251 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9252 | && phone.getEmergencyNumberTracker() |
| 9253 | .isEmergencyNumber(number, exactMatch)) { |
| 9254 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9255 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9256 | } |
| 9257 | return false; |
| 9258 | } finally { |
| 9259 | Binder.restoreCallingIdentity(identity); |
| 9260 | } |
| 9261 | } |
| 9262 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9263 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9264 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9265 | */ |
| 9266 | @Override |
| 9267 | public void startEmergencyCallbackMode() { |
| 9268 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9269 | "startEmergencyCallbackMode"); |
| 9270 | enforceModifyPermission(); |
| 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
| 9273 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9274 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9275 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9276 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9277 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9278 | gsmCdmaPhone.obtainMessage( |
| 9279 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9280 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9281 | } |
| 9282 | } |
| 9283 | } finally { |
| 9284 | Binder.restoreCallingIdentity(identity); |
| 9285 | } |
| 9286 | } |
| 9287 | |
| 9288 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9289 | * Update emergency number list for test mode. |
| 9290 | */ |
| 9291 | @Override |
| 9292 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9293 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9294 | "updateEmergencyNumberListTestMode"); |
| 9295 | |
| 9296 | final long identity = Binder.clearCallingIdentity(); |
| 9297 | try { |
| 9298 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9299 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9300 | if (tracker != null) { |
| 9301 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9302 | } |
| 9303 | } |
| 9304 | } finally { |
| 9305 | Binder.restoreCallingIdentity(identity); |
| 9306 | } |
| 9307 | } |
| 9308 | |
| 9309 | /** |
| 9310 | * Get the full emergency number list for test mode. |
| 9311 | */ |
| 9312 | @Override |
| 9313 | public List<String> getEmergencyNumberListTestMode() { |
| 9314 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9315 | "getEmergencyNumberListTestMode"); |
| 9316 | |
| 9317 | final long identity = Binder.clearCallingIdentity(); |
| 9318 | try { |
| 9319 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9320 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9321 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9322 | if (tracker != null) { |
| 9323 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9324 | emergencyNumbers.add(num.getNumber()); |
| 9325 | } |
| 9326 | } |
| 9327 | } |
| 9328 | return new ArrayList<>(emergencyNumbers); |
| 9329 | } finally { |
| 9330 | Binder.restoreCallingIdentity(identity); |
| 9331 | } |
| 9332 | } |
| 9333 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9334 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9335 | public int getEmergencyNumberDbVersion(int subId) { |
| 9336 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9337 | |
| 9338 | final long identity = Binder.clearCallingIdentity(); |
| 9339 | try { |
| 9340 | final Phone phone = getPhone(subId); |
| 9341 | if (phone == null) { |
| 9342 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9343 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9344 | } |
| 9345 | return phone.getEmergencyNumberDbVersion(); |
| 9346 | } finally { |
| 9347 | Binder.restoreCallingIdentity(identity); |
| 9348 | } |
| 9349 | } |
| 9350 | |
| 9351 | @Override |
| 9352 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9353 | enforceModifyPermission(); |
| 9354 | |
| 9355 | final long identity = Binder.clearCallingIdentity(); |
| 9356 | try { |
| 9357 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9358 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9359 | if (tracker != null) { |
| 9360 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9361 | } |
| 9362 | } |
| 9363 | } finally { |
| 9364 | Binder.restoreCallingIdentity(identity); |
| 9365 | } |
| 9366 | } |
| 9367 | |
| 9368 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9369 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9370 | enforceActiveEmergencySessionPermission(); |
| 9371 | |
| 9372 | final long identity = Binder.clearCallingIdentity(); |
| 9373 | try { |
| 9374 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9375 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9376 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9377 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9378 | } |
| 9379 | } |
| 9380 | } finally { |
| 9381 | Binder.restoreCallingIdentity(identity); |
| 9382 | } |
| 9383 | } |
| 9384 | |
| 9385 | @Override |
| 9386 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9387 | enforceActiveEmergencySessionPermission(); |
| 9388 | |
| 9389 | final long identity = Binder.clearCallingIdentity(); |
| 9390 | try { |
| 9391 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9392 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9393 | if (tracker != null) { |
| 9394 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9395 | } |
| 9396 | } |
| 9397 | } finally { |
| 9398 | Binder.restoreCallingIdentity(identity); |
| 9399 | } |
| 9400 | } |
| 9401 | |
| 9402 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9403 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9404 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9405 | Phone phone = getPhone(subId); |
| 9406 | if (phone == null) { |
| 9407 | return null; |
| 9408 | } |
| 9409 | final long identity = Binder.clearCallingIdentity(); |
| 9410 | try { |
| 9411 | UiccProfile profile = UiccController.getInstance() |
| 9412 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9413 | if (profile != null) { |
| 9414 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9415 | } |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
| 9418 | } |
| 9419 | return null; |
| 9420 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9421 | |
| 9422 | /** |
| 9423 | * Enable or disable a modem stack. |
| 9424 | */ |
| 9425 | @Override |
| 9426 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9427 | enforceModifyPermission(); |
| 9428 | |
| 9429 | final long identity = Binder.clearCallingIdentity(); |
| 9430 | try { |
| 9431 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9432 | if (phone == null) { |
| 9433 | return false; |
| 9434 | } else { |
| 9435 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9436 | } |
| 9437 | } finally { |
| 9438 | Binder.restoreCallingIdentity(identity); |
| 9439 | } |
| 9440 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9441 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9442 | /** |
| 9443 | * Whether a modem stack is enabled or not. |
| 9444 | */ |
| 9445 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9446 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9447 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9448 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9449 | if (phone == null) return false; |
| 9450 | |
| 9451 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9452 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9453 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9454 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9455 | } |
| 9456 | |
| 9457 | final long identity = Binder.clearCallingIdentity(); |
| 9458 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9459 | try { |
| 9460 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9461 | } catch (NoSuchElementException ex) { |
| 9462 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9463 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9464 | } finally { |
| 9465 | Binder.restoreCallingIdentity(identity); |
| 9466 | } |
| 9467 | } |
| 9468 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9469 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9470 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9471 | enforceModifyPermission(); |
| 9472 | |
| 9473 | final long identity = Binder.clearCallingIdentity(); |
| 9474 | try { |
| 9475 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9476 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9477 | .commit(); |
| 9478 | } finally { |
| 9479 | Binder.restoreCallingIdentity(identity); |
| 9480 | } |
| 9481 | } |
| 9482 | |
| 9483 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9484 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9485 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9487 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9488 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9489 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9490 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9491 | |
| 9492 | final long identity = Binder.clearCallingIdentity(); |
| 9493 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9494 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9495 | } finally { |
| 9496 | Binder.restoreCallingIdentity(identity); |
| 9497 | } |
| 9498 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9499 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9500 | @TelephonyManager.IsMultiSimSupportedResult |
| 9501 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9502 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9503 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9504 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9505 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9506 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9507 | } |
| 9508 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9509 | // supported by the modem, indicate that it is restricted. |
| 9510 | PhoneCapability staticCapability = |
| 9511 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9512 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9513 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9514 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9515 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9516 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9517 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9518 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9519 | } |
| 9520 | // Check if support of multiple SIMs is restricted by carrier |
| 9521 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9522 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9523 | } |
| 9524 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9525 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9526 | } |
| 9527 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9528 | /** |
| 9529 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9530 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9531 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9532 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9533 | * @param numOfSims number of active sims we want to switch to |
| 9534 | */ |
| 9535 | @Override |
| 9536 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9537 | if (numOfSims == 1) { |
| 9538 | enforceModifyPermission(); |
| 9539 | } else { |
| 9540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9541 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9542 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9543 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9544 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9545 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9546 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9547 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9548 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9549 | return; |
| 9550 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9551 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9552 | } finally { |
| 9553 | Binder.restoreCallingIdentity(identity); |
| 9554 | } |
| 9555 | } |
| 9556 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9557 | @Override |
| 9558 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9559 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9560 | Phone phone = getPhone(subId); |
| 9561 | if (phone == null) { |
| 9562 | return false; |
| 9563 | } |
| 9564 | final long identity = Binder.clearCallingIdentity(); |
| 9565 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9566 | UiccPort uiccPort = phone.getUiccPort(); |
| 9567 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9568 | return false; |
| 9569 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9570 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9571 | if (uiccProfile == null) { |
| 9572 | return false; |
| 9573 | } |
| 9574 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9575 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9576 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9577 | } |
| 9578 | return false; |
| 9579 | } finally { |
| 9580 | Binder.restoreCallingIdentity(identity); |
| 9581 | } |
| 9582 | } |
| 9583 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9584 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9585 | * Get whether making changes to modem configurations will trigger reboot. |
| 9586 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9587 | */ |
| 9588 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9589 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9590 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9591 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9592 | mApp, subId, callingPackage, callingFeatureId, |
| 9593 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9594 | return false; |
| 9595 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9599 | } finally { |
| 9600 | Binder.restoreCallingIdentity(identity); |
| 9601 | } |
| 9602 | } |
| 9603 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9604 | private void updateModemStateMetrics() { |
| 9605 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9606 | // TODO: check the state for each modem if the api is ready. |
| 9607 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9608 | } |
| 9609 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9610 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9611 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9612 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9613 | // Verify that the callingPackage belongs to the calling UID |
| 9614 | mApp.getSystemService(AppOpsManager.class) |
| 9615 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9616 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9617 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9618 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9619 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9620 | if (slotInfos != null) { |
| 9621 | for (int i = 0; i < slotInfos.length; i++) { |
| 9622 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9623 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9624 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9625 | portInfo.getLogicalSlotIndex())); |
| 9626 | } |
| 9627 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9628 | } |
| 9629 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9630 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9631 | } finally { |
| 9632 | Binder.restoreCallingIdentity(identity); |
| 9633 | } |
| 9634 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9635 | |
| 9636 | /** |
| 9637 | * Get the IRadio HAL Version |
| 9638 | */ |
| 9639 | @Override |
| 9640 | public int getRadioHalVersion() { |
| 9641 | Phone phone = getDefaultPhone(); |
| 9642 | if (phone == null) return -1; |
| 9643 | HalVersion hv = phone.getHalVersion(); |
| 9644 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9645 | return hv.major * 100 + hv.minor; |
| 9646 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9647 | |
| 9648 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9649 | * Get the current calling package name. |
| 9650 | * @return the current calling package name |
| 9651 | */ |
| 9652 | @Override |
| 9653 | public String getCurrentPackageName() { |
| 9654 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9655 | } |
| 9656 | |
| 9657 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9658 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9659 | * corresponding network requests on a subId. |
| 9660 | * |
| 9661 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9662 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9663 | * 2) APN is un-metered for this subscription, or |
| 9664 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9665 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9666 | * |
| 9667 | * @return whether data is allowed for a apn type. |
| 9668 | * |
| 9669 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9670 | */ |
| 9671 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9672 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9673 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9674 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9675 | |
| 9676 | // Now that all security checks passes, perform the operation as ourselves. |
| 9677 | final long identity = Binder.clearCallingIdentity(); |
| 9678 | try { |
| 9679 | Phone phone = getPhone(subId); |
| 9680 | if (phone == null) return false; |
| 9681 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9682 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9683 | boolean isDataEnabled; |
| 9684 | if (phone.isUsingNewDataStack()) { |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9685 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9686 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9687 | phone.getServiceState().getDataRoaming()); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9688 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9689 | } else { |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9690 | isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9691 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9692 | } |
| 9693 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9694 | } finally { |
| 9695 | Binder.restoreCallingIdentity(identity); |
| 9696 | } |
| 9697 | } |
| 9698 | |
| 9699 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9700 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9701 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9702 | |
| 9703 | // Now that all security checks passes, perform the operation as ourselves. |
| 9704 | final long identity = Binder.clearCallingIdentity(); |
| 9705 | try { |
| 9706 | Phone phone = getPhone(subId); |
| 9707 | if (phone == null) return true; // By default return true. |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9708 | if (phone.isUsingNewDataStack()) { |
| 9709 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9710 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9711 | phone.getServiceState().getDataRoaming()); |
| 9712 | } |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9713 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9714 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9715 | } finally { |
| 9716 | Binder.restoreCallingIdentity(identity); |
| 9717 | } |
| 9718 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9719 | |
| 9720 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9721 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9722 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9723 | enforceModifyPermission(); |
| 9724 | long token = Binder.clearCallingIdentity(); |
| 9725 | try { |
| 9726 | Phone phone = getPhone(subscriptionId); |
| 9727 | if (phone == null) { |
| 9728 | try { |
| 9729 | if (resultCallback != null) { |
| 9730 | resultCallback.accept(false); |
| 9731 | } |
| 9732 | } catch (RemoteException e) { |
| 9733 | // ignore |
| 9734 | } |
| 9735 | return; |
| 9736 | } |
| 9737 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9738 | Pair.create(specifiers, (x) -> { |
| 9739 | try { |
| 9740 | if (resultCallback != null) { |
| 9741 | resultCallback.accept(x); |
| 9742 | } |
| 9743 | } catch (RemoteException e) { |
| 9744 | // ignore |
| 9745 | } |
| 9746 | }); |
| 9747 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(token); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9754 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9755 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9756 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9757 | mApp, subId, "getSystemSelectionChannels"); |
| 9758 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9759 | final long identity = Binder.clearCallingIdentity(); |
| 9760 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9761 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9762 | if (result instanceof IllegalStateException) { |
| 9763 | throw (IllegalStateException) result; |
| 9764 | } |
| 9765 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9766 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9767 | return specifiers; |
| 9768 | } finally { |
| 9769 | Binder.restoreCallingIdentity(identity); |
| 9770 | } |
| 9771 | } |
| 9772 | |
| 9773 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9774 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9775 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9776 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9777 | } |
| 9778 | |
| 9779 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9780 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9781 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9782 | if (callingPackage == null) { |
| 9783 | callingPackage = getCurrentPackageName(); |
| 9784 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9785 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9786 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9787 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9788 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9789 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9790 | } |
| 9791 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9792 | Intent intent = new Intent(); |
| 9793 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9794 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9795 | // Bring up choose default SMS subscription dialog right now |
| 9796 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9797 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9798 | mApp.startActivity(intent); |
| 9799 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9800 | |
| 9801 | @Override |
| 9802 | public String getMmsUAProfUrl(int subId) { |
| 9803 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9804 | final long identity = Binder.clearCallingIdentity(); |
| 9805 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9806 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9807 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9808 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9809 | return carrierUAProfUrl; |
| 9810 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9811 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9812 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9813 | } finally { |
| 9814 | Binder.restoreCallingIdentity(identity); |
| 9815 | } |
| 9816 | } |
| 9817 | |
| 9818 | @Override |
| 9819 | public String getMmsUserAgent(int subId) { |
| 9820 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9821 | final long identity = Binder.clearCallingIdentity(); |
| 9822 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9823 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9824 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9825 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9826 | return carrierUserAgent; |
| 9827 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9828 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9829 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9830 | } finally { |
| 9831 | Binder.restoreCallingIdentity(identity); |
| 9832 | } |
| 9833 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9834 | |
| 9835 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9836 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9837 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9838 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9839 | final long identity = Binder.clearCallingIdentity(); |
| 9840 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9841 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9842 | if (phone == null) return false; |
| 9843 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9844 | switch (policy) { |
| 9845 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9846 | if (phone.isUsingNewDataStack()) { |
| 9847 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9848 | } else { |
| 9849 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9850 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9851 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9852 | if (phone.isUsingNewDataStack()) { |
| 9853 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9854 | } else { |
| 9855 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9856 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9857 | default: |
| 9858 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9859 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9860 | } finally { |
| 9861 | Binder.restoreCallingIdentity(identity); |
| 9862 | } |
| 9863 | } |
| 9864 | |
| 9865 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9866 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9867 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9868 | enforceModifyPermission(); |
| 9869 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9870 | final long identity = Binder.clearCallingIdentity(); |
| 9871 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9872 | Phone phone = getPhone(subscriptionId); |
| 9873 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9874 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9875 | switch (policy) { |
| 9876 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9877 | if (phone.isUsingNewDataStack()) { |
| 9878 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9879 | } else { |
| 9880 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9881 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9882 | break; |
| 9883 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9884 | if (phone.isUsingNewDataStack()) { |
| 9885 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9886 | } else { |
| 9887 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9888 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9889 | break; |
| 9890 | default: |
| 9891 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9892 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9893 | } finally { |
| 9894 | Binder.restoreCallingIdentity(identity); |
| 9895 | } |
| 9896 | } |
| 9897 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9898 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9899 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9900 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9901 | * otherwise. |
| 9902 | */ |
| 9903 | @Override |
| 9904 | public void setCepEnabled(boolean isCepEnabled) { |
| 9905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9906 | |
| 9907 | final long identity = Binder.clearCallingIdentity(); |
| 9908 | try { |
| 9909 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9910 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9911 | Phone defaultPhone = phone.getImsPhone(); |
| 9912 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9913 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9914 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9915 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9916 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9917 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9918 | + imsPhone.getMsisdn()); |
| 9919 | } |
| 9920 | } |
| 9921 | } finally { |
| 9922 | Binder.restoreCallingIdentity(identity); |
| 9923 | } |
| 9924 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9925 | |
| 9926 | /** |
| 9927 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9928 | * |
| 9929 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9930 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9931 | * before being read. |
| 9932 | */ |
| 9933 | @Override |
| 9934 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9935 | isCompressed) { |
| 9936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9937 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9938 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9939 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9940 | } |
| 9941 | if (!isImsAvailableOnDevice()) { |
| 9942 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9943 | "IMS not available on device."); |
| 9944 | } |
| 9945 | |
| 9946 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9947 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9948 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9949 | } finally { |
| 9950 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9951 | } |
| 9952 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9953 | |
| 9954 | @Override |
| 9955 | public boolean isIccLockEnabled(int subId) { |
| 9956 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9957 | |
| 9958 | // Now that all security checks passes, perform the operation as ourselves. |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
| 9961 | Phone phone = getPhone(subId); |
| 9962 | if (phone != null && phone.getIccCard() != null) { |
| 9963 | return phone.getIccCard().getIccLockEnabled(); |
| 9964 | } else { |
| 9965 | return false; |
| 9966 | } |
| 9967 | } finally { |
| 9968 | Binder.restoreCallingIdentity(identity); |
| 9969 | } |
| 9970 | } |
| 9971 | |
| 9972 | /** |
| 9973 | * Set the ICC pin lock enabled or disabled. |
| 9974 | * |
| 9975 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9976 | * three cases: |
| 9977 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9978 | * successfully. |
| 9979 | * - Positive number and zero for remaining password attempts. |
| 9980 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9981 | * |
| 9982 | */ |
| 9983 | @Override |
| 9984 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9985 | enforceModifyPermission(); |
| 9986 | |
| 9987 | Phone phone = getPhone(subId); |
| 9988 | if (phone == null) { |
| 9989 | return 0; |
| 9990 | } |
| 9991 | // Now that all security checks passes, perform the operation as ourselves. |
| 9992 | final long identity = Binder.clearCallingIdentity(); |
| 9993 | try { |
| 9994 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9995 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9996 | return attemptsRemaining; |
| 9997 | |
| 9998 | } catch (Exception e) { |
| 9999 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10000 | } finally { |
| 10001 | Binder.restoreCallingIdentity(identity); |
| 10002 | } |
| 10003 | return 0; |
| 10004 | } |
| 10005 | |
| 10006 | /** |
| 10007 | * Change the ICC password used in ICC pin lock. |
| 10008 | * |
| 10009 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10010 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10011 | * - Positive number and zero for remaining password attempts. |
| 10012 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10013 | * |
| 10014 | */ |
| 10015 | @Override |
| 10016 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10017 | enforceModifyPermission(); |
| 10018 | |
| 10019 | Phone phone = getPhone(subId); |
| 10020 | if (phone == null) { |
| 10021 | return 0; |
| 10022 | } |
| 10023 | // Now that all security checks passes, perform the operation as ourselves. |
| 10024 | final long identity = Binder.clearCallingIdentity(); |
| 10025 | try { |
| 10026 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10027 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10028 | return attemptsRemaining; |
| 10029 | |
| 10030 | } catch (Exception e) { |
| 10031 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10032 | } finally { |
| 10033 | Binder.restoreCallingIdentity(identity); |
| 10034 | } |
| 10035 | return 0; |
| 10036 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10037 | |
| 10038 | /** |
| 10039 | * Request for receiving user activity notification |
| 10040 | */ |
| 10041 | @Override |
| 10042 | public void requestUserActivityNotification() { |
| 10043 | if (!mNotifyUserActivity.get() |
| 10044 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10045 | mNotifyUserActivity.set(true); |
| 10046 | } |
| 10047 | } |
| 10048 | |
| 10049 | /** |
| 10050 | * Called when userActivity is signalled in the power manager. |
| 10051 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10052 | */ |
| 10053 | @Override |
| 10054 | public void userActivity() { |
| 10055 | // *************************************** |
| 10056 | // * Inherited from PhoneWindowManager * |
| 10057 | // *************************************** |
| 10058 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10059 | // WITH ITS LOCKS HELD. |
| 10060 | // |
| 10061 | // This code must be VERY careful about the locks |
| 10062 | // it acquires. |
| 10063 | // In fact, the current code acquires way too many, |
| 10064 | // and probably has lurking deadlocks. |
| 10065 | |
| 10066 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10067 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10068 | } |
| 10069 | |
| 10070 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10071 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10072 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10073 | } |
| 10074 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10075 | |
| 10076 | @Override |
| 10077 | public boolean canConnectTo5GInDsdsMode() { |
| 10078 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10079 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10080 | |
| 10081 | @Override |
| 10082 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10083 | String callingFeatureId) { |
| 10084 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10085 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10086 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10087 | } |
| 10088 | |
| 10089 | Phone phone = getPhone(subId); |
| 10090 | if (phone == null) { |
| 10091 | throw new RuntimeException("phone is not available"); |
| 10092 | } |
| 10093 | // Now that all security checks passes, perform the operation as ourselves. |
| 10094 | final long identity = Binder.clearCallingIdentity(); |
| 10095 | try { |
| 10096 | return phone.getEquivalentHomePlmns(); |
| 10097 | } finally { |
| 10098 | Binder.restoreCallingIdentity(identity); |
| 10099 | } |
| 10100 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10101 | |
| 10102 | @Override |
| 10103 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10104 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10105 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10106 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10107 | if (radioInterfaceCapabilities == null) { |
| 10108 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10109 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10110 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10111 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10112 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10113 | @Override |
| 10114 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10115 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10116 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10117 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10118 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10119 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10120 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10121 | if (DBG) { |
| 10122 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10123 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10124 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10125 | } |
| 10126 | |
| 10127 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10128 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10129 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10130 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10131 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10132 | if (callback != null) { |
| 10133 | try { |
| 10134 | callback.onAuthenticationFailure( |
| 10135 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10136 | } catch (RemoteException exception) { |
| 10137 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10138 | } |
| 10139 | return; |
| 10140 | } |
| 10141 | } |
| 10142 | |
| 10143 | final long token = Binder.clearCallingIdentity(); |
| 10144 | try { |
| 10145 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10146 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10147 | forceBootStrapping, callback)); |
| 10148 | } finally { |
| 10149 | Binder.restoreCallingIdentity(token); |
| 10150 | } |
| 10151 | } |
| 10152 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10153 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10154 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10155 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10156 | * requested radio power state will actually be set. See {@link |
| 10157 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10158 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10159 | * @param enable {@code true} if trying to turn radio on. |
| 10160 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10161 | * false}. |
| 10162 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10163 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10164 | boolean isPhoneAvailable = false; |
| 10165 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10166 | Phone phone = PhoneFactory.getPhone(i); |
| 10167 | if (phone != null) { |
| 10168 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10169 | isPhoneAvailable = true; |
| 10170 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10171 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10172 | |
| 10173 | // return true if successfully informed the phone object about the thermal radio power |
| 10174 | // request. |
| 10175 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10176 | } |
| 10177 | |
| 10178 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10179 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10180 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10181 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10182 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10183 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10184 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10185 | } |
| 10186 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10187 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10188 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10189 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10190 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10191 | } |
| 10192 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10193 | setDataEnabledForReason( |
| 10194 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10195 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10196 | if (isDataThrottlingSupported) { |
| 10197 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10198 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10199 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10200 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10201 | } else if (thermalMitigationResult |
| 10202 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10203 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10204 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10205 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10206 | } |
| 10207 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10208 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10209 | |
| 10210 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10211 | } |
| 10212 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10213 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10214 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10215 | for (String pckg : context.getResources() |
| 10216 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10217 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10218 | } |
| 10219 | } |
| 10220 | |
| 10221 | return sThermalMitigationAllowlistedPackages; |
| 10222 | } |
| 10223 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10224 | private boolean isAnyPhoneInEmergencyState() { |
| 10225 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10226 | if (tm.isInEmergencyCall()) { |
| 10227 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10228 | return true; |
| 10229 | } |
| 10230 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10231 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10232 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10233 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10234 | + phone.isInEcm()); |
| 10235 | return true; |
| 10236 | } |
| 10237 | } |
| 10238 | |
| 10239 | return false; |
| 10240 | } |
| 10241 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10242 | /** |
| 10243 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10244 | * @param packageName name of package to be allowlisted |
| 10245 | * @param context |
| 10246 | */ |
| 10247 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10248 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10249 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10250 | } |
| 10251 | |
| 10252 | /** |
| 10253 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10254 | * @param packageName name of package to remove from allowlist |
| 10255 | * @param context |
| 10256 | */ |
| 10257 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10258 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10259 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10260 | } |
| 10261 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10262 | /** |
| 10263 | * Thermal mitigation request to control functionalities at modem. |
| 10264 | * |
| 10265 | * @param subId the id of the subscription. |
| 10266 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10267 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10268 | * |
| 10269 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10270 | */ |
| 10271 | @Override |
| 10272 | @ThermalMitigationResult |
| 10273 | public int sendThermalMitigationRequest( |
| 10274 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10275 | ThermalMitigationRequest thermalMitigationRequest, |
| 10276 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10277 | enforceModifyPermission(); |
| 10278 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10279 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10280 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10281 | .contains(callingPackage)) { |
| 10282 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10283 | + "calling package: " + callingPackage); |
| 10284 | } |
| 10285 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10286 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10287 | final long identity = Binder.clearCallingIdentity(); |
| 10288 | |
| 10289 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10290 | try { |
| 10291 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10292 | switch (thermalMitigationAction) { |
| 10293 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10294 | thermalMitigationResult = |
| 10295 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10296 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10297 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10298 | break; |
| 10299 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10300 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10301 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10302 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10303 | } |
| 10304 | |
| 10305 | // Ensure that radio is on. If not able to power on due to phone being |
| 10306 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10307 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10308 | thermalMitigationResult = |
| 10309 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10310 | break; |
| 10311 | } |
| 10312 | |
| 10313 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10314 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10315 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10316 | break; |
| 10317 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10318 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10319 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10320 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10321 | } |
| 10322 | |
| 10323 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10324 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10325 | Phone phone = getPhone(subId); |
| 10326 | if (phone == null) { |
| 10327 | thermalMitigationResult = |
| 10328 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10329 | break; |
| 10330 | } |
| 10331 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10332 | TelephonyConnectionService service = |
| 10333 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10334 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10335 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10336 | thermalMitigationResult = |
| 10337 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10338 | break; |
| 10339 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10340 | thermalMitigationResult = |
| 10341 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10342 | break; |
| 10343 | } |
| 10344 | } else { |
| 10345 | thermalMitigationResult = |
| 10346 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10347 | break; |
| 10348 | } |
| 10349 | |
| 10350 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10351 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10352 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10353 | thermalMitigationResult = |
| 10354 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10355 | break; |
| 10356 | } |
| 10357 | thermalMitigationResult = |
| 10358 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10359 | break; |
| 10360 | default: |
| 10361 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10362 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10363 | } |
| 10364 | } catch (IllegalArgumentException e) { |
| 10365 | throw e; |
| 10366 | } catch (Exception e) { |
| 10367 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10368 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10369 | } finally { |
| 10370 | Binder.restoreCallingIdentity(identity); |
| 10371 | } |
| 10372 | |
| 10373 | if (DBG) { |
| 10374 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10375 | + thermalMitigationResult); |
| 10376 | } |
| 10377 | |
| 10378 | return thermalMitigationResult; |
| 10379 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10380 | |
| 10381 | /** |
| 10382 | * Set the GbaService Package Name that Telephony will bind to. |
| 10383 | * |
| 10384 | * @param subId The sim that the GbaService is associated with. |
| 10385 | * @param packageName The name of the package to be replaced with. |
| 10386 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10387 | */ |
| 10388 | @Override |
| 10389 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10390 | enforceModifyPermission(); |
| 10391 | |
| 10392 | final long identity = Binder.clearCallingIdentity(); |
| 10393 | try { |
| 10394 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10395 | } finally { |
| 10396 | Binder.restoreCallingIdentity(identity); |
| 10397 | } |
| 10398 | } |
| 10399 | |
| 10400 | /** |
| 10401 | * Return the package name of the currently bound GbaService. |
| 10402 | * |
| 10403 | * @param subId The sim that the GbaService is associated with. |
| 10404 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10405 | */ |
| 10406 | @Override |
| 10407 | public String getBoundGbaService(int subId) { |
| 10408 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10409 | |
| 10410 | final long identity = Binder.clearCallingIdentity(); |
| 10411 | try { |
| 10412 | return getGbaManager(subId).getServicePackage(); |
| 10413 | } finally { |
| 10414 | Binder.restoreCallingIdentity(identity); |
| 10415 | } |
| 10416 | } |
| 10417 | |
| 10418 | /** |
| 10419 | * Set the release time for telephony to unbind GbaService. |
| 10420 | * |
| 10421 | * @param subId The sim that the GbaService is associated with. |
| 10422 | * @param interval The release time to unbind GbaService by millisecond. |
| 10423 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10424 | */ |
| 10425 | @Override |
| 10426 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10427 | enforceModifyPermission(); |
| 10428 | |
| 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10432 | } finally { |
| 10433 | Binder.restoreCallingIdentity(identity); |
| 10434 | } |
| 10435 | } |
| 10436 | |
| 10437 | /** |
| 10438 | * Return the release time for telephony to unbind GbaService. |
| 10439 | * |
| 10440 | * @param subId The sim that the GbaService is associated with. |
| 10441 | * @return The release time to unbind GbaService by millisecond. |
| 10442 | */ |
| 10443 | @Override |
| 10444 | public int getGbaReleaseTime(int subId) { |
| 10445 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10446 | |
| 10447 | final long identity = Binder.clearCallingIdentity(); |
| 10448 | try { |
| 10449 | return getGbaManager(subId).getReleaseTime(); |
| 10450 | } finally { |
| 10451 | Binder.restoreCallingIdentity(identity); |
| 10452 | } |
| 10453 | } |
| 10454 | |
| 10455 | private GbaManager getGbaManager(int subId) { |
| 10456 | GbaManager instance = GbaManager.getInstance(subId); |
| 10457 | if (instance == null) { |
| 10458 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10459 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10460 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10461 | } |
| 10462 | return instance; |
| 10463 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10464 | |
| 10465 | /** |
| 10466 | * indicate whether the device and the carrier can support |
| 10467 | * RCS VoLTE single registration. |
| 10468 | */ |
| 10469 | @Override |
| 10470 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10471 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10472 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10473 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10474 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10475 | |
| 10476 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10477 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10478 | } |
| 10479 | |
| 10480 | final long identity = Binder.clearCallingIdentity(); |
| 10481 | try { |
| 10482 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10483 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10484 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10485 | if (isCapable != null) { |
| 10486 | return isCapable; |
| 10487 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10488 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10489 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10490 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10491 | } finally { |
| 10492 | Binder.restoreCallingIdentity(identity); |
| 10493 | } |
| 10494 | } |
| 10495 | |
| 10496 | /** |
| 10497 | * Register RCS provisioning callback. |
| 10498 | */ |
| 10499 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10500 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10501 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10502 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10503 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10504 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10505 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10506 | |
| 10507 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10508 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10509 | } |
| 10510 | if (!isImsAvailableOnDevice()) { |
| 10511 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10512 | "IMS not available on device."); |
| 10513 | } |
| 10514 | |
| 10515 | final long identity = Binder.clearCallingIdentity(); |
| 10516 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10517 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10518 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10519 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10520 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10521 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10522 | } finally { |
| 10523 | Binder.restoreCallingIdentity(identity); |
| 10524 | } |
| 10525 | } |
| 10526 | |
| 10527 | /** |
| 10528 | * Unregister RCS provisioning callback. |
| 10529 | */ |
| 10530 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10531 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10532 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10533 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10534 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10535 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10536 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10537 | |
| 10538 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10539 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10540 | } |
| 10541 | if (!isImsAvailableOnDevice()) { |
| 10542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10543 | "IMS not available on device."); |
| 10544 | } |
| 10545 | |
| 10546 | final long identity = Binder.clearCallingIdentity(); |
| 10547 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10548 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10549 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10550 | } finally { |
| 10551 | Binder.restoreCallingIdentity(identity); |
| 10552 | } |
| 10553 | } |
| 10554 | |
| 10555 | /** |
| 10556 | * trigger RCS reconfiguration. |
| 10557 | */ |
| 10558 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10559 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10560 | "triggerRcsReconfiguration", |
| 10561 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10562 | |
| 10563 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10564 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10565 | } |
| 10566 | if (!isImsAvailableOnDevice()) { |
| 10567 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10568 | "IMS not available on device."); |
| 10569 | } |
| 10570 | |
| 10571 | final long identity = Binder.clearCallingIdentity(); |
| 10572 | try { |
| 10573 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10574 | } finally { |
| 10575 | Binder.restoreCallingIdentity(identity); |
| 10576 | } |
| 10577 | } |
| 10578 | |
| 10579 | /** |
| 10580 | * Provide the client configuration parameters of the RCS application. |
| 10581 | */ |
| 10582 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10583 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10584 | "setRcsClientConfiguration", |
| 10585 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10586 | |
| 10587 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10588 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10589 | } |
| 10590 | if (!isImsAvailableOnDevice()) { |
| 10591 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10592 | "IMS not available on device."); |
| 10593 | } |
| 10594 | |
| 10595 | final long identity = Binder.clearCallingIdentity(); |
| 10596 | |
| 10597 | try { |
| 10598 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10599 | if (configBinder == null) { |
| 10600 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10601 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10602 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10603 | } else { |
| 10604 | configBinder.setRcsClientConfiguration(rcc); |
| 10605 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10606 | |
| 10607 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10608 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10609 | } catch (RemoteException e) { |
| 10610 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10611 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10612 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10613 | } finally { |
| 10614 | Binder.restoreCallingIdentity(identity); |
| 10615 | } |
| 10616 | } |
| 10617 | |
| 10618 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10619 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10620 | */ |
| 10621 | @Override |
| 10622 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10623 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10624 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10625 | |
| 10626 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10627 | } |
| 10628 | |
| 10629 | /** |
| 10630 | * Gets the test mode for RCS VoLTE single registration. |
| 10631 | */ |
| 10632 | @Override |
| 10633 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10634 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10635 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10636 | |
| 10637 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10638 | } |
| 10639 | |
| 10640 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10641 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10642 | */ |
| 10643 | @Override |
| 10644 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10645 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10646 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10647 | enforceModifyPermission(); |
| 10648 | |
| 10649 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10650 | : Boolean.parseBoolean(enabledStr); |
| 10651 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10652 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10653 | } |
| 10654 | |
| 10655 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10656 | * Sends a device to device communication message. Only usable via shell. |
| 10657 | * @param message message to send. |
| 10658 | * @param value message value. |
| 10659 | */ |
| 10660 | @Override |
| 10661 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10662 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10663 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10664 | enforceModifyPermission(); |
| 10665 | |
| 10666 | final long identity = Binder.clearCallingIdentity(); |
| 10667 | try { |
| 10668 | TelephonyConnectionService service = |
| 10669 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10670 | if (service == null) { |
| 10671 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10672 | return; |
| 10673 | } |
| 10674 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10675 | } finally { |
| 10676 | Binder.restoreCallingIdentity(identity); |
| 10677 | } |
| 10678 | } |
| 10679 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10680 | /** |
| 10681 | * Sets the specified device to device transport active. |
| 10682 | * @param transport The transport to set active. |
| 10683 | */ |
| 10684 | @Override |
| 10685 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10686 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10687 | "setActiveDeviceToDeviceTransport"); |
| 10688 | enforceModifyPermission(); |
| 10689 | |
| 10690 | final long identity = Binder.clearCallingIdentity(); |
| 10691 | try { |
| 10692 | TelephonyConnectionService service = |
| 10693 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10694 | if (service == null) { |
| 10695 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10696 | return; |
| 10697 | } |
| 10698 | service.setActiveDeviceToDeviceTransport(transport); |
| 10699 | } finally { |
| 10700 | Binder.restoreCallingIdentity(identity); |
| 10701 | } |
| 10702 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10703 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10704 | @Override |
| 10705 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10706 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10707 | "setDeviceToDeviceForceEnabled"); |
| 10708 | |
| 10709 | final long identity = Binder.clearCallingIdentity(); |
| 10710 | try { |
| 10711 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10712 | p -> { |
| 10713 | Phone thePhone = p.getImsPhone(); |
| 10714 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10715 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10716 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10717 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10718 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10719 | (ImsPhoneCallTracker) tracker; |
| 10720 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10721 | } |
| 10722 | } |
| 10723 | } |
| 10724 | ); |
| 10725 | } finally { |
| 10726 | Binder.restoreCallingIdentity(identity); |
| 10727 | } |
| 10728 | } |
| 10729 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10730 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10731 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10732 | */ |
| 10733 | @Override |
| 10734 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10735 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10736 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10737 | } |
| 10738 | |
| 10739 | /** |
| 10740 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10741 | */ |
| 10742 | @Override |
| 10743 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10744 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10745 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10746 | enforceModifyPermission(); |
| 10747 | |
| 10748 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10749 | : Boolean.parseBoolean(enabledStr); |
| 10750 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10751 | subId, enabled); |
| 10752 | } |
| 10753 | |
| 10754 | /** |
| 10755 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10756 | */ |
| 10757 | @Override |
| 10758 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10759 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10760 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10761 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10762 | |
| 10763 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10764 | * Overrides the ims feature validation result |
| 10765 | */ |
| 10766 | @Override |
| 10767 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10768 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10769 | "setImsFeatureValidationOverride"); |
| 10770 | |
| 10771 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10772 | : Boolean.parseBoolean(enabledStr); |
| 10773 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10774 | subId, enabled); |
| 10775 | } |
| 10776 | |
| 10777 | /** |
| 10778 | * Gets the ims feature validation override value |
| 10779 | */ |
| 10780 | @Override |
| 10781 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10782 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10783 | "getImsFeatureValidationOverride"); |
| 10784 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10785 | } |
| 10786 | |
| 10787 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10788 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10789 | * their mobile plan. |
| 10790 | */ |
| 10791 | @Override |
| 10792 | public String getMobileProvisioningUrl() { |
| 10793 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10794 | final long identity = Binder.clearCallingIdentity(); |
| 10795 | try { |
| 10796 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10797 | } finally { |
| 10798 | Binder.restoreCallingIdentity(identity); |
| 10799 | } |
| 10800 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10801 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10802 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10803 | * Get the EAB contact from the EAB database. |
| 10804 | */ |
| 10805 | @Override |
| 10806 | public String getContactFromEab(String contact) { |
| 10807 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10808 | enforceModifyPermission(); |
| 10809 | final long identity = Binder.clearCallingIdentity(); |
| 10810 | try { |
| 10811 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10812 | } finally { |
| 10813 | Binder.restoreCallingIdentity(identity); |
| 10814 | } |
| 10815 | } |
| 10816 | |
| 10817 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10818 | * Get the EAB capability from the EAB database. |
| 10819 | */ |
| 10820 | @Override |
| 10821 | public String getCapabilityFromEab(String contact) { |
| 10822 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10823 | enforceModifyPermission(); |
| 10824 | final long identity = Binder.clearCallingIdentity(); |
| 10825 | try { |
| 10826 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10827 | } finally { |
| 10828 | Binder.restoreCallingIdentity(identity); |
| 10829 | } |
| 10830 | } |
| 10831 | |
| 10832 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10833 | * Remove the EAB contacts from the EAB database. |
| 10834 | */ |
| 10835 | @Override |
| 10836 | public int removeContactFromEab(int subId, String contacts) { |
| 10837 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10838 | enforceModifyPermission(); |
| 10839 | final long identity = Binder.clearCallingIdentity(); |
| 10840 | try { |
| 10841 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10842 | } finally { |
| 10843 | Binder.restoreCallingIdentity(identity); |
| 10844 | } |
| 10845 | } |
| 10846 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10847 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10848 | public boolean getDeviceUceEnabled() { |
| 10849 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10850 | final long identity = Binder.clearCallingIdentity(); |
| 10851 | try { |
| 10852 | return mApp.getDeviceUceEnabled(); |
| 10853 | } finally { |
| 10854 | Binder.restoreCallingIdentity(identity); |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | @Override |
| 10859 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10860 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10861 | final long identity = Binder.clearCallingIdentity(); |
| 10862 | try { |
| 10863 | mApp.setDeviceUceEnabled(isEnabled); |
| 10864 | } finally { |
| 10865 | Binder.restoreCallingIdentity(identity); |
| 10866 | } |
| 10867 | } |
| 10868 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10869 | /** |
| 10870 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10871 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10872 | */ |
| 10873 | // Used for SHELL command only right now. |
| 10874 | @Override |
| 10875 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10876 | List<String> featureTags) { |
| 10877 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10878 | "addUceRegistrationOverrideShell"); |
| 10879 | final long identity = Binder.clearCallingIdentity(); |
| 10880 | try { |
| 10881 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10882 | new ArraySet<>(featureTags)); |
| 10883 | } catch (ImsException e) { |
| 10884 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10885 | } finally { |
| 10886 | Binder.restoreCallingIdentity(identity); |
| 10887 | } |
| 10888 | } |
| 10889 | |
| 10890 | /** |
| 10891 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10892 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10893 | */ |
| 10894 | // Used for SHELL command only right now. |
| 10895 | @Override |
| 10896 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10897 | List<String> featureTags) { |
| 10898 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10899 | "removeUceRegistrationOverrideShell"); |
| 10900 | final long identity = Binder.clearCallingIdentity(); |
| 10901 | try { |
| 10902 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10903 | new ArraySet<>(featureTags)); |
| 10904 | } catch (ImsException e) { |
| 10905 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10906 | } finally { |
| 10907 | Binder.restoreCallingIdentity(identity); |
| 10908 | } |
| 10909 | } |
| 10910 | |
| 10911 | /** |
| 10912 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10913 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10914 | */ |
| 10915 | // Used for SHELL command only right now. |
| 10916 | @Override |
| 10917 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10918 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10919 | "clearUceRegistrationOverrideShell"); |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
| 10922 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10923 | } catch (ImsException e) { |
| 10924 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10925 | } finally { |
| 10926 | Binder.restoreCallingIdentity(identity); |
| 10927 | } |
| 10928 | } |
| 10929 | |
| 10930 | /** |
| 10931 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10932 | */ |
| 10933 | // Used for SHELL command only right now. |
| 10934 | @Override |
| 10935 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10936 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10937 | "getLatestRcsContactUceCapabilityShell"); |
| 10938 | final long identity = Binder.clearCallingIdentity(); |
| 10939 | try { |
| 10940 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10941 | } catch (ImsException e) { |
| 10942 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10943 | } finally { |
| 10944 | Binder.restoreCallingIdentity(identity); |
| 10945 | } |
| 10946 | } |
| 10947 | |
| 10948 | /** |
| 10949 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10950 | * device does not have an active PUBLISH. |
| 10951 | */ |
| 10952 | // Used for SHELL command only right now. |
| 10953 | @Override |
| 10954 | public String getLastUcePidfXmlShell(int subId) { |
| 10955 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10956 | final long identity = Binder.clearCallingIdentity(); |
| 10957 | try { |
| 10958 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10959 | } catch (ImsException e) { |
| 10960 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10961 | } finally { |
| 10962 | Binder.restoreCallingIdentity(identity); |
| 10963 | } |
| 10964 | } |
| 10965 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10966 | /** |
| 10967 | * Remove UCE requests cannot be sent to the network status. |
| 10968 | */ |
| 10969 | // Used for SHELL command only right now. |
| 10970 | @Override |
| 10971 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10972 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10973 | final long identity = Binder.clearCallingIdentity(); |
| 10974 | try { |
| 10975 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10976 | } catch (ImsException e) { |
| 10977 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10978 | } finally { |
| 10979 | Binder.restoreCallingIdentity(identity); |
| 10980 | } |
| 10981 | } |
| 10982 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10983 | /** |
| 10984 | * Remove UCE requests cannot be sent to the network status. |
| 10985 | */ |
| 10986 | // Used for SHELL command only. |
| 10987 | @Override |
| 10988 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10989 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10990 | final long identity = Binder.clearCallingIdentity(); |
| 10991 | try { |
| 10992 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10993 | } catch (ImsException e) { |
| 10994 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10995 | } finally { |
| 10996 | Binder.restoreCallingIdentity(identity); |
| 10997 | } |
| 10998 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10999 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11000 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11001 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11002 | String callingPackage) { |
| 11003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11004 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11005 | |
| 11006 | final int callingUid = Binder.getCallingUid(); |
| 11007 | // Verify that tha callingPackage belongs to the calling UID |
| 11008 | mApp.getSystemService(AppOpsManager.class) |
| 11009 | .checkPackage(callingUid, callingPackage); |
| 11010 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11011 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11012 | |
| 11013 | final long identity = Binder.clearCallingIdentity(); |
| 11014 | try { |
| 11015 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11016 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11017 | |
| 11018 | if (result instanceof IllegalStateException) { |
| 11019 | throw (IllegalStateException) result; |
| 11020 | } |
| 11021 | } finally { |
| 11022 | Binder.restoreCallingIdentity(identity); |
| 11023 | } |
| 11024 | } |
| 11025 | |
| 11026 | @Override |
| 11027 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11028 | String callingPackage) { |
| 11029 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11030 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11031 | |
| 11032 | final int callingUid = Binder.getCallingUid(); |
| 11033 | // Verify that tha callingPackage belongs to the calling UID |
| 11034 | mApp.getSystemService(AppOpsManager.class) |
| 11035 | .checkPackage(callingUid, callingPackage); |
| 11036 | |
| 11037 | final long identity = Binder.clearCallingIdentity(); |
| 11038 | try { |
| 11039 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11040 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11041 | |
| 11042 | if (result instanceof IllegalStateException) { |
| 11043 | throw (IllegalStateException) result; |
| 11044 | } |
| 11045 | } finally { |
| 11046 | Binder.restoreCallingIdentity(identity); |
| 11047 | } |
| 11048 | } |
| 11049 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11050 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11051 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11052 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11053 | // phone/system process do not have further restriction on request |
| 11054 | return; |
| 11055 | } |
| 11056 | |
| 11057 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11058 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11059 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11060 | context.enforceCallingOrSelfPermission( |
| 11061 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11062 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11063 | } |
| 11064 | |
| 11065 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11066 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11067 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11068 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11069 | || info.isEnabled()) { |
| 11070 | throw new IllegalArgumentException( |
| 11071 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11072 | } |
| 11073 | |
| 11074 | // Thresholds length for each RAN need in range. This has been validated in |
| 11075 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11076 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11077 | final int[] thresholds = info.getThresholds(); |
| 11078 | Objects.requireNonNull(thresholds); |
| 11079 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11080 | || thresholds.length |
| 11081 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11082 | throw new IllegalArgumentException( |
| 11083 | "thresholds length is out of range: " + thresholds.length); |
| 11084 | } |
| 11085 | } |
| 11086 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11087 | |
| 11088 | /** |
| 11089 | * Gets the current phone capability. |
| 11090 | * |
| 11091 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11092 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11093 | * It's used to evaluate possible phone config change, for example from single |
| 11094 | * SIM device to multi-SIM device. |
| 11095 | */ |
| 11096 | @Override |
| 11097 | public PhoneCapability getPhoneCapability() { |
| 11098 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11099 | final long identity = Binder.clearCallingIdentity(); |
| 11100 | try { |
| 11101 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11102 | } finally { |
| 11103 | Binder.restoreCallingIdentity(identity); |
| 11104 | } |
| 11105 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11106 | |
| 11107 | /** |
| 11108 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11109 | * required to be done shortly after the API is invoked. |
| 11110 | */ |
| 11111 | @Override |
| 11112 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11113 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11114 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11115 | enforceRebootPermission(); |
| 11116 | |
| 11117 | final long identity = Binder.clearCallingIdentity(); |
| 11118 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11119 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11120 | } finally { |
| 11121 | Binder.restoreCallingIdentity(identity); |
| 11122 | } |
| 11123 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11124 | |
| 11125 | /** |
| 11126 | * Request to get the current slicing configuration including URSP rules and |
| 11127 | * NSSAIs (configured, allowed and rejected). |
| 11128 | * |
| 11129 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11130 | */ |
| 11131 | @Override |
| 11132 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11133 | TelephonyPermissions |
| 11134 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11135 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11136 | |
| 11137 | final long identity = Binder.clearCallingIdentity(); |
| 11138 | try { |
| 11139 | Phone phone = getDefaultPhone(); |
| 11140 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11141 | } finally { |
| 11142 | Binder.restoreCallingIdentity(identity); |
| 11143 | } |
| 11144 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11145 | |
| 11146 | /** |
| 11147 | * Register an IMS connection state callback |
| 11148 | */ |
| 11149 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11150 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11151 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11152 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11153 | // ImsMmTelManager |
| 11154 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11155 | TelephonyPermissions |
| 11156 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11157 | mApp, subId, "registerImsStateCallback"); |
| 11158 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11159 | // ImsRcsManager or SipDelegateManager |
| 11160 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11161 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11162 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11163 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11164 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11165 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11166 | } |
| 11167 | |
| 11168 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11169 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11170 | "IMS not available on device."); |
| 11171 | } |
| 11172 | |
| 11173 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11174 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11175 | } |
| 11176 | |
| 11177 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11178 | if (controller == null) { |
| 11179 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11180 | "IMS not available on device."); |
| 11181 | } |
| 11182 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11183 | if (callingPackage == null) { |
| 11184 | callingPackage = getCurrentPackageName(); |
| 11185 | } |
| 11186 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11187 | final long token = Binder.clearCallingIdentity(); |
| 11188 | try { |
| 11189 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11190 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11191 | } catch (ImsException e) { |
| 11192 | throw new ServiceSpecificException(e.getCode()); |
| 11193 | } finally { |
| 11194 | Binder.restoreCallingIdentity(token); |
| 11195 | } |
| 11196 | } |
| 11197 | |
| 11198 | /** |
| 11199 | * Unregister an IMS connection state callback |
| 11200 | */ |
| 11201 | @Override |
| 11202 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11203 | final long token = Binder.clearCallingIdentity(); |
| 11204 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11205 | if (controller == null) { |
| 11206 | return; |
| 11207 | } |
| 11208 | try { |
| 11209 | controller.unregisterImsStateCallback(cb); |
| 11210 | } finally { |
| 11211 | Binder.restoreCallingIdentity(token); |
| 11212 | } |
| 11213 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11214 | |
| 11215 | /** |
| 11216 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11217 | * |
| 11218 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11219 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11220 | * SecurityException. |
| 11221 | * If there is current registered network this value will be same as the registered cell |
| 11222 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11223 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11224 | * it will be cleared and null will be returned. |
| 11225 | * |
| 11226 | */ |
| 11227 | @Override |
| 11228 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11229 | String callingFeatureId) { |
| 11230 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11231 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11232 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11233 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11234 | .setCallingPackage(callingPackage) |
| 11235 | .setCallingFeatureId(callingFeatureId) |
| 11236 | .setCallingPid(Binder.getCallingPid()) |
| 11237 | .setCallingUid(Binder.getCallingUid()) |
| 11238 | .setMethod("getLastKnownCellIdentity") |
| 11239 | .setLogAsInfo(true) |
| 11240 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11241 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11242 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11243 | .build()); |
| 11244 | |
| 11245 | boolean hasFinePermission = |
| 11246 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11247 | if (!hasFinePermission |
| 11248 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11249 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11250 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11251 | } |
| 11252 | |
| 11253 | final long identity = Binder.clearCallingIdentity(); |
| 11254 | try { |
| 11255 | Phone phone = getPhone(subId); |
| 11256 | if (phone == null) return null; |
| 11257 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11258 | if (sst == null) return null; |
| 11259 | return sst.getLastKnownCellIdentity(); |
| 11260 | } finally { |
| 11261 | Binder.restoreCallingIdentity(identity); |
| 11262 | } |
| 11263 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11264 | |
| 11265 | @Override |
| 11266 | public boolean isUsingNewDataStack() { |
| 11267 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11268 | return getDefaultPhone().isUsingNewDataStack(); |
| 11269 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11270 | |
| 11271 | /** |
| 11272 | * Sets the modem service class Name that Telephony will bind to. |
| 11273 | * |
| 11274 | * @param serviceName The class name of the modem service. |
| 11275 | * @return true if the operation is succeed, otherwise false. |
| 11276 | */ |
| 11277 | public boolean setModemService(String serviceName) { |
| 11278 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11279 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11280 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11281 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11282 | "setModemService"); |
| 11283 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11284 | } |
| 11285 | |
| 11286 | /** |
| 11287 | * Return the class name of the currently bounded modem service. |
| 11288 | * |
| 11289 | * @return the class name of the modem service. |
| 11290 | */ |
| 11291 | public String getModemService() { |
| 11292 | String result; |
| 11293 | Log.d(LOG_TAG, "getModemService"); |
| 11294 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11295 | TelephonyPermissions |
| 11296 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11297 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11298 | "getModemService"); |
| 11299 | result = mPhoneConfigurationManager.getModemService(); |
| 11300 | Log.d(LOG_TAG, "result = " + result); |
| 11301 | return result; |
| 11302 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11303 | |
| 11304 | @Override |
| 11305 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11306 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11307 | mApp.enforceCallingOrSelfPermission( |
| 11308 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11309 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11310 | |
| 11311 | final long identity = Binder.clearCallingIdentity(); |
| 11312 | try { |
| 11313 | Phone phone = getPhone(subId); |
| 11314 | if (phone == null) return; |
| 11315 | phone.setVoiceServiceStateOverride(hasService); |
| 11316 | } finally { |
| 11317 | Binder.restoreCallingIdentity(identity); |
| 11318 | } |
| 11319 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11320 | |
| 11321 | /** |
| 11322 | * set removable eSIM as default eUICC. |
| 11323 | * |
| 11324 | * @hide |
| 11325 | */ |
| 11326 | @Override |
| 11327 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11328 | enforceModifyPermission(); |
| 11329 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11330 | |
| 11331 | final long identity = Binder.clearCallingIdentity(); |
| 11332 | try { |
| 11333 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11334 | } finally { |
| 11335 | Binder.restoreCallingIdentity(identity); |
| 11336 | } |
| 11337 | } |
| 11338 | |
| 11339 | /** |
| 11340 | * Returns whether the removable eSIM is default eUICC or not. |
| 11341 | * |
| 11342 | * @hide |
| 11343 | */ |
| 11344 | @Override |
| 11345 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11346 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11347 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11348 | |
| 11349 | final long identity = Binder.clearCallingIdentity(); |
| 11350 | try { |
| 11351 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11352 | } finally { |
| 11353 | Binder.restoreCallingIdentity(identity); |
| 11354 | } |
| 11355 | } |
| 11356 | |
| 11357 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11358 | } |