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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 383 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 384 | /** User Activity */ |
| 385 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 386 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 387 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 388 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 389 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 390 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 391 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 392 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 393 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 394 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 395 | // String to store multi SIM allowed |
| 396 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 397 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 398 | // The AID of ISD-R. |
| 399 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 400 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 401 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 402 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 403 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 404 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 405 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 406 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 407 | 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] | 408 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 409 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 410 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 411 | */ |
| 412 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 413 | "reset_network_erase_modem_config_enabled"; |
| 414 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 415 | 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] | 416 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 417 | /** |
| 418 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 419 | * one ICCID active at the same time. |
| 420 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 421 | * |
| 422 | * @hide |
| 423 | */ |
| 424 | @ChangeId |
| 425 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 426 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 427 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 428 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 429 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 430 | * operation fails. |
| 431 | */ |
| 432 | @ChangeId |
| 433 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 434 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 435 | |
| 436 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 437 | * A request object to use for transmitting data to an ICC. |
| 438 | */ |
| 439 | private static final class IccAPDUArgument { |
| 440 | public int channel, cla, command, p1, p2, p3; |
| 441 | public String data; |
| 442 | |
| 443 | public IccAPDUArgument(int channel, int cla, int command, |
| 444 | int p1, int p2, int p3, String data) { |
| 445 | this.channel = channel; |
| 446 | this.cla = cla; |
| 447 | this.command = command; |
| 448 | this.p1 = p1; |
| 449 | this.p2 = p2; |
| 450 | this.p3 = p3; |
| 451 | this.data = data; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 456 | * A request object to use for transmitting data to an ICC. |
| 457 | */ |
| 458 | private static final class ManualNetworkSelectionArgument { |
| 459 | public OperatorInfo operatorInfo; |
| 460 | public boolean persistSelection; |
| 461 | |
| 462 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 463 | this.operatorInfo = operatorInfo; |
| 464 | this.persistSelection = persistSelection; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 470 | * request after sending. The main thread will notify the request when it is complete. |
| 471 | */ |
| 472 | private static final class MainThreadRequest { |
| 473 | /** The argument to use for the request */ |
| 474 | public Object argument; |
| 475 | /** The result of the request that is run on the main thread */ |
| 476 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 477 | // The subscriber id that this request applies to. Defaults to |
| 478 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 479 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 480 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 481 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 482 | public Phone phone; |
| 483 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 484 | public WorkSource workSource; |
| 485 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | public MainThreadRequest(Object argument) { |
| 487 | this.argument = argument; |
| 488 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 489 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 490 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 491 | this.argument = argument; |
| 492 | if (phone != null) { |
| 493 | this.phone = phone; |
| 494 | } |
| 495 | this.workSource = workSource; |
| 496 | } |
| 497 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 498 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 499 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 500 | if (subId != null) { |
| 501 | this.subId = subId; |
| 502 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 503 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 507 | private static final class IncomingThirdPartyCallArgs { |
| 508 | public final ComponentName component; |
| 509 | public final String callId; |
| 510 | public final String callerDisplayName; |
| 511 | |
| 512 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 513 | String callerDisplayName) { |
| 514 | this.component = component; |
| 515 | this.callId = callId; |
| 516 | this.callerDisplayName = callerDisplayName; |
| 517 | } |
| 518 | } |
| 519 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | /** |
| 521 | * A handler that processes messages on the main thread in the phone process. Since many |
| 522 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 523 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 524 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 525 | * on, which will be notified when the operation completes and will contain the result of the |
| 526 | * request. |
| 527 | * |
| 528 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 529 | * note that request.result must be set to something non-null for the calling thread to |
| 530 | * unblock. |
| 531 | */ |
| 532 | private final class MainThreadHandler extends Handler { |
| 533 | @Override |
| 534 | public void handleMessage(Message msg) { |
| 535 | MainThreadRequest request; |
| 536 | Message onCompleted; |
| 537 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 538 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 540 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 541 | |
| 542 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 543 | case CMD_HANDLE_USSD_REQUEST: { |
| 544 | request = (MainThreadRequest) msg.obj; |
| 545 | final Phone phone = getPhoneFromRequest(request); |
| 546 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 547 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 548 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 549 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | if (!isUssdApiAllowed(request.subId)) { |
| 551 | // Carrier does not support use of this API, return failure. |
| 552 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 553 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 554 | Bundle returnData = new Bundle(); |
| 555 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 556 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 557 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 558 | request.result = true; |
| 559 | notifyRequester(request); |
| 560 | return; |
| 561 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 562 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | try { |
| 564 | request.result = phone != null |
| 565 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 566 | } catch (CallStateException cse) { |
| 567 | request.result = false; |
| 568 | } |
| 569 | // Wake up the requesting thread |
| 570 | notifyRequester(request); |
| 571 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 574 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 575 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 576 | final Phone phone = getPhoneFromRequest(request); |
| 577 | request.result = phone != null ? |
| 578 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 579 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 580 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 581 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 583 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 584 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 586 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 588 | uiccPort = getUiccPortFromRequest(request); |
| 589 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 591 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 594 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 595 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 596 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 597 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 598 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 599 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 600 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
| 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
| 608 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 609 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 610 | if (ar.result == null) { |
| 611 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 612 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 614 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | } else { |
| 616 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 617 | } |
| 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 620 | break; |
| 621 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 623 | request = (MainThreadRequest) msg.obj; |
| 624 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 625 | uiccPort = getUiccPortFromRequest(request); |
| 626 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 627 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 628 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 632 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 633 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 634 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 635 | iccArgument.p2, |
| 636 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 637 | } |
| 638 | break; |
| 639 | |
| 640 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
| 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
| 645 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 646 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 647 | if (ar.result == null) { |
| 648 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 654 | } |
| 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case CMD_EXCHANGE_SIM_IO: |
| 660 | request = (MainThreadRequest) msg.obj; |
| 661 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 662 | uiccPort = getUiccPortFromRequest(request); |
| 663 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 665 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 669 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 670 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 672 | iccArgument.data, onCompleted); |
| 673 | } |
| 674 | break; |
| 675 | |
| 676 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
| 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; |
| 681 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 682 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 687 | case CMD_SEND_ENVELOPE: |
| 688 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 689 | uiccPort = getUiccPortFromRequest(request); |
| 690 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 692 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | } else { |
| 695 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 696 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 697 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_SEND_ENVELOPE_DONE: |
| 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 706 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 707 | if (ar.result == null) { |
| 708 | loge("sendEnvelopeWithStatus: Empty response"); |
| 709 | } else if (ar.exception instanceof CommandException) { |
| 710 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 711 | ar.exception); |
| 712 | } else { |
| 713 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 714 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 715 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | case CMD_OPEN_CHANNEL: |
| 720 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 721 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 722 | IccLogicalChannelRequest openChannelRequest = |
| 723 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 726 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 727 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | } else { |
| 730 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 731 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 732 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_OPEN_CHANNEL_DONE: |
| 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | int[] result = (int[]) ar.result; |
| 742 | int channelId = result[0]; |
| 743 | byte[] selectResponse = null; |
| 744 | if (result.length > 1) { |
| 745 | selectResponse = new byte[result.length - 1]; |
| 746 | for (int i = 1; i < result.length; ++i) { |
| 747 | selectResponse[i - 1] = (byte) result[i]; |
| 748 | } |
| 749 | } |
| 750 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 751 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 752 | |
| 753 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 754 | if (uiccPort == null) { |
| 755 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 756 | } else { |
| 757 | IccLogicalChannelRequest channelRequest = |
| 758 | (IccLogicalChannelRequest) request.argument; |
| 759 | channelRequest.channel = channelId; |
| 760 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 761 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | if (ar.result == null) { |
| 764 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 765 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 766 | if (ar.exception != null) { |
| 767 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 768 | } |
| 769 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 770 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 771 | if (ar.exception instanceof CommandException) { |
| 772 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 773 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 774 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 775 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 776 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 777 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 781 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 782 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 783 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 784 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case CMD_CLOSE_CHANNEL: |
| 788 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 789 | uiccPort = getUiccPortFromRequest(request); |
| 790 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 791 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 792 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 793 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 794 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 795 | } else { |
| 796 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 797 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 798 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 802 | ar = (AsyncResult) msg.obj; |
| 803 | request = (MainThreadRequest) ar.userObj; |
| 804 | if (ar.exception == null) { |
| 805 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 806 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 807 | if (uiccPort == null) { |
| 808 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 809 | } else { |
| 810 | final int channelId = (Integer) request.argument; |
| 811 | uiccPort.onLogicalChannelClosed(channelId); |
| 812 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 813 | } else { |
| 814 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 815 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 816 | if (ar.exception instanceof CommandException) { |
| 817 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 818 | CommandException.Error error = |
| 819 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 820 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 821 | // should only throw exceptions from the binder threads. |
| 822 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 823 | "iccCloseLogicalChannel: invalid argument "); |
| 824 | } |
| 825 | } else { |
| 826 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 827 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 828 | request.result = (exception != null) ? exception : |
| 829 | new IllegalStateException( |
| 830 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 831 | } |
| 832 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case CMD_NV_READ_ITEM: |
| 836 | request = (MainThreadRequest) msg.obj; |
| 837 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 838 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 839 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 843 | ar = (AsyncResult) msg.obj; |
| 844 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 845 | if (ar.exception == null && ar.result != null) { |
| 846 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 847 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 848 | request.result = ""; |
| 849 | if (ar.result == null) { |
| 850 | loge("nvReadItem: Empty response"); |
| 851 | } else if (ar.exception instanceof CommandException) { |
| 852 | loge("nvReadItem: CommandException: " + |
| 853 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 854 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 855 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 856 | } |
| 857 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 858 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 859 | break; |
| 860 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 861 | case CMD_NV_WRITE_ITEM: |
| 862 | request = (MainThreadRequest) msg.obj; |
| 863 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 864 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 865 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 866 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 867 | break; |
| 868 | |
| 869 | case EVENT_NV_WRITE_ITEM_DONE: |
| 870 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 871 | break; |
| 872 | |
| 873 | case CMD_NV_WRITE_CDMA_PRL: |
| 874 | request = (MainThreadRequest) msg.obj; |
| 875 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 876 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 880 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 881 | break; |
| 882 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 883 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 884 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 885 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 886 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 887 | break; |
| 888 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 889 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 890 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 893 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 894 | request = (MainThreadRequest) msg.obj; |
| 895 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 896 | request); |
| 897 | Phone phone = getPhoneFromRequest(request); |
| 898 | if (phone != null) { |
| 899 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 900 | } else { |
| 901 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 902 | request.result = false; |
| 903 | notifyRequester(request); |
| 904 | } |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 909 | ar = (AsyncResult) msg.obj; |
| 910 | request = (MainThreadRequest) ar.userObj; |
| 911 | if (ar.exception == null && ar.result != null) { |
| 912 | request.result = ar.result; |
| 913 | } else { |
| 914 | // request.result must be set to something non-null |
| 915 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 916 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 917 | request.result = ar.result; |
| 918 | } else { |
| 919 | request.result = false; |
| 920 | } |
| 921 | if (ar.result == null) { |
| 922 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 923 | } else if (ar.exception instanceof CommandException) { |
| 924 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 925 | + ar.exception); |
| 926 | } else { |
| 927 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 928 | } |
| 929 | } |
| 930 | notifyRequester(request); |
| 931 | break; |
| 932 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 933 | case CMD_IS_VONR_ENABLED: { |
| 934 | request = (MainThreadRequest) msg.obj; |
| 935 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 936 | request); |
| 937 | Phone phone = getPhoneFromRequest(request); |
| 938 | if (phone != null) { |
| 939 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 940 | } else { |
| 941 | loge("isVoNrEnabled: No phone object"); |
| 942 | request.result = false; |
| 943 | notifyRequester(request); |
| 944 | } |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | case EVENT_IS_VONR_ENABLED_DONE: |
| 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
| 951 | if (ar.exception == null && ar.result != null) { |
| 952 | request.result = ar.result; |
| 953 | } else { |
| 954 | // request.result must be set to something non-null |
| 955 | // for the calling thread to unblock |
| 956 | if (ar.result != null) { |
| 957 | request.result = ar.result; |
| 958 | } else { |
| 959 | request.result = false; |
| 960 | } |
| 961 | if (ar.result == null) { |
| 962 | loge("isVoNrEnabled: Empty response"); |
| 963 | } else if (ar.exception instanceof CommandException) { |
| 964 | loge("isVoNrEnabled: CommandException: " |
| 965 | + ar.exception); |
| 966 | } else { |
| 967 | loge("isVoNrEnabled: Unknown exception"); |
| 968 | } |
| 969 | } |
| 970 | notifyRequester(request); |
| 971 | break; |
| 972 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 973 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 974 | request = (MainThreadRequest) msg.obj; |
| 975 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 976 | Phone phone = getPhoneFromRequest(request); |
| 977 | if (phone != null) { |
| 978 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 979 | request.workSource); |
| 980 | } else { |
| 981 | loge("enableNrDualConnectivity: No phone object"); |
| 982 | request.result = |
| 983 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 984 | notifyRequester(request); |
| 985 | } |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 990 | ar = (AsyncResult) msg.obj; |
| 991 | request = (MainThreadRequest) ar.userObj; |
| 992 | if (ar.exception == null) { |
| 993 | request.result = |
| 994 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 995 | } else { |
| 996 | request.result = |
| 997 | TelephonyManager |
| 998 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 999 | if (ar.exception instanceof CommandException) { |
| 1000 | CommandException.Error error = |
| 1001 | ((CommandException) (ar.exception)).getCommandError(); |
| 1002 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1003 | request.result = |
| 1004 | TelephonyManager |
| 1005 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1006 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1007 | request.result = |
| 1008 | TelephonyManager |
| 1009 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1010 | } |
| 1011 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1012 | + ar.exception); |
| 1013 | } else { |
| 1014 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1015 | } |
| 1016 | } |
| 1017 | notifyRequester(request); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1021 | case CMD_ENABLE_VONR: { |
| 1022 | request = (MainThreadRequest) msg.obj; |
| 1023 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1024 | Phone phone = getPhoneFromRequest(request); |
| 1025 | if (phone != null) { |
| 1026 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1027 | request.workSource); |
| 1028 | } else { |
| 1029 | loge("setVoNrEnabled: No phone object"); |
| 1030 | request.result = |
| 1031 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1032 | notifyRequester(request); |
| 1033 | } |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | case EVENT_ENABLE_VONR_DONE: { |
| 1038 | ar = (AsyncResult) msg.obj; |
| 1039 | request = (MainThreadRequest) ar.userObj; |
| 1040 | if (ar.exception == null) { |
| 1041 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1042 | } else { |
| 1043 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1044 | if (ar.exception instanceof CommandException) { |
| 1045 | CommandException.Error error = |
| 1046 | ((CommandException) (ar.exception)).getCommandError(); |
| 1047 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1048 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1049 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1050 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1051 | } else { |
| 1052 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1053 | } |
| 1054 | loge("setVoNrEnabled" + ": CommandException: " |
| 1055 | + ar.exception); |
| 1056 | } else { |
| 1057 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1058 | } |
| 1059 | } |
| 1060 | notifyRequester(request); |
| 1061 | break; |
| 1062 | } |
| 1063 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1064 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1065 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1066 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1067 | request); |
| 1068 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1069 | break; |
| 1070 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1071 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1072 | ar = (AsyncResult) msg.obj; |
| 1073 | request = (MainThreadRequest) ar.userObj; |
| 1074 | if (ar.exception == null && ar.result != null) { |
| 1075 | request.result = ar.result; // Integer |
| 1076 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1077 | // request.result must be set to something non-null |
| 1078 | // for the calling thread to unblock |
| 1079 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1080 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1081 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1082 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1083 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1084 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1085 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1086 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1087 | } |
| 1088 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1089 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1090 | break; |
| 1091 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1092 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1093 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1094 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1095 | request); |
| 1096 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1097 | (Pair<Integer, Long>) request.argument; |
| 1098 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1099 | reasonWithNetworkTypes.first, |
| 1100 | reasonWithNetworkTypes.second, |
| 1101 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1102 | break; |
| 1103 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1104 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1105 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1106 | break; |
| 1107 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1108 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1109 | request = (MainThreadRequest)msg.obj; |
| 1110 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1111 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1112 | break; |
| 1113 | |
| 1114 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1115 | ar = (AsyncResult)msg.obj; |
| 1116 | request = (MainThreadRequest)ar.userObj; |
| 1117 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1118 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1121 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1122 | request = (MainThreadRequest) msg.obj; |
| 1123 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1124 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1125 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1126 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1127 | break; |
| 1128 | |
| 1129 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1130 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1131 | break; |
| 1132 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1133 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1134 | request = (MainThreadRequest) msg.obj; |
| 1135 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1136 | request); |
| 1137 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1138 | break; |
| 1139 | |
| 1140 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1141 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1142 | break; |
| 1143 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1144 | case CMD_PERFORM_NETWORK_SCAN: |
| 1145 | request = (MainThreadRequest) msg.obj; |
| 1146 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1147 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1148 | break; |
| 1149 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1150 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1151 | request = (MainThreadRequest) msg.obj; |
| 1152 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1154 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1155 | request.argument; |
| 1156 | int callForwardingReason = args.first; |
| 1157 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1158 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1159 | } |
| 1160 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1161 | ar = (AsyncResult) msg.obj; |
| 1162 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1163 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1164 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1165 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1166 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1167 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1168 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1169 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1170 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1171 | // any service for voice call. |
| 1172 | if ((callForwardInfo.serviceClass |
| 1173 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1174 | callForwardingInfo = new CallForwardingInfo( |
| 1175 | callForwardInfo.status |
| 1176 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1177 | callForwardInfo.reason, |
| 1178 | callForwardInfo.number, |
| 1179 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1180 | break; |
| 1181 | } |
| 1182 | } |
| 1183 | // Didn't find a call forward info for voice call. |
| 1184 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1185 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1186 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1187 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1188 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1189 | } else { |
| 1190 | if (ar.result == null) { |
| 1191 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1192 | } |
| 1193 | if (ar.exception != null) { |
| 1194 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1195 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1196 | int errorCode = TelephonyManager |
| 1197 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1198 | if (ar.exception instanceof CommandException) { |
| 1199 | CommandException.Error error = |
| 1200 | ((CommandException) (ar.exception)).getCommandError(); |
| 1201 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1202 | errorCode = TelephonyManager |
| 1203 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1205 | errorCode = TelephonyManager |
| 1206 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | } |
| 1208 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1211 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1215 | request = (MainThreadRequest) msg.obj; |
| 1216 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1217 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1218 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1220 | request.argument).first; |
| 1221 | request.phone.setCallForwardingOption( |
| 1222 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1223 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | callForwardingInfoToSet.getReason(), |
| 1226 | callForwardingInfoToSet.getNumber(), |
| 1227 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1228 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1230 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1231 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | ar = (AsyncResult) msg.obj; |
| 1233 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1234 | Consumer<Integer> callback = |
| 1235 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1236 | request.argument).second; |
| 1237 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1238 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1240 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | if (ar.exception instanceof CommandException) { |
| 1242 | CommandException.Error error = |
| 1243 | ((CommandException) (ar.exception)).getCommandError(); |
| 1244 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1245 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1246 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1247 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1249 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1250 | } |
| 1251 | } |
| 1252 | callback.accept(errorCode); |
| 1253 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1254 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1256 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1257 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1258 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | request = (MainThreadRequest) msg.obj; |
| 1261 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1262 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1263 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1266 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | ar = (AsyncResult) msg.obj; |
| 1268 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1269 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1270 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1271 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1272 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1273 | // Service Class is a bit mask per 3gpp 27.007. |
| 1274 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1275 | if (callForwardResults.length > 1 |
| 1276 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1277 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1278 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1279 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1280 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1281 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1282 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1283 | } |
| 1284 | } else { |
| 1285 | if (ar.result == null) { |
| 1286 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1287 | } |
| 1288 | if (ar.exception != null) { |
| 1289 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1290 | } |
| 1291 | if (ar.exception instanceof CommandException) { |
| 1292 | CommandException.Error error = |
| 1293 | ((CommandException) (ar.exception)).getCommandError(); |
| 1294 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1295 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1296 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1297 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1298 | callWaitingStatus = |
| 1299 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | } |
| 1301 | } |
| 1302 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1303 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1304 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | request = (MainThreadRequest) msg.obj; |
| 1309 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1311 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1312 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1314 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1315 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | ar = (AsyncResult) msg.obj; |
| 1317 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1319 | Consumer<Integer> callback = |
| 1320 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1321 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1322 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1323 | if (ar.exception instanceof CommandException) { |
| 1324 | CommandException.Error error = |
| 1325 | ((CommandException) (ar.exception)).getCommandError(); |
| 1326 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1327 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1328 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1329 | callback.accept( |
| 1330 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1331 | } else { |
| 1332 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1333 | } |
| 1334 | } else { |
| 1335 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1336 | } |
| 1337 | } else { |
| 1338 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1339 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1341 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1342 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1343 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1344 | ar = (AsyncResult) msg.obj; |
| 1345 | request = (MainThreadRequest) ar.userObj; |
| 1346 | CellNetworkScanResult cellScanResult; |
| 1347 | if (ar.exception == null && ar.result != null) { |
| 1348 | cellScanResult = new CellNetworkScanResult( |
| 1349 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1350 | (List<OperatorInfo>) ar.result); |
| 1351 | } else { |
| 1352 | if (ar.result == null) { |
| 1353 | loge("getCellNetworkScanResults: Empty response"); |
| 1354 | } |
| 1355 | if (ar.exception != null) { |
| 1356 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1357 | } |
| 1358 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1359 | if (ar.exception instanceof CommandException) { |
| 1360 | CommandException.Error error = |
| 1361 | ((CommandException) (ar.exception)).getCommandError(); |
| 1362 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1363 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1364 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1365 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1366 | } |
| 1367 | } |
| 1368 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1369 | } |
| 1370 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1371 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1372 | break; |
| 1373 | |
| 1374 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1375 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1376 | ManualNetworkSelectionArgument selArg = |
| 1377 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1378 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1379 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1380 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1381 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1382 | break; |
| 1383 | |
| 1384 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | if (ar.exception == null) { |
| 1388 | request.result = true; |
| 1389 | } else { |
| 1390 | request.result = false; |
| 1391 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1392 | } |
| 1393 | notifyRequester(request); |
| 1394 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1395 | break; |
| 1396 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1397 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1398 | request = (MainThreadRequest) msg.obj; |
| 1399 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1400 | if (defaultPhone != null) { |
| 1401 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1402 | } else { |
| 1403 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1404 | Bundle bundle = new Bundle(); |
| 1405 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1406 | new ModemActivityInfo(0, 0, 0, |
| 1407 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1408 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1409 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1410 | break; |
| 1411 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1412 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1413 | ar = (AsyncResult) msg.obj; |
| 1414 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1415 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1416 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1417 | if (mLastModemActivityInfo == null) { |
| 1418 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1419 | mLastModemActivitySpecificInfo[0] = |
| 1420 | new ActivityStatsTechSpecificInfo( |
| 1421 | 0, |
| 1422 | 0, |
| 1423 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1424 | 0); |
| 1425 | mLastModemActivityInfo = |
| 1426 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1427 | } |
| 1428 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1429 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1430 | // Update the last modem activity info and the result of the request. |
| 1431 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1432 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1433 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1434 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1435 | mLastModemActivityInfo = |
| 1436 | new ModemActivityInfo( |
| 1437 | mLastModemActivityInfo.getTimestampMillis(), |
| 1438 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1439 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1440 | mLastModemActivitySpecificInfo); |
| 1441 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1442 | } else { |
| 1443 | if (ar.result == null) { |
| 1444 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1445 | error = TelephonyManager.ModemActivityInfoException |
| 1446 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1448 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1449 | error = TelephonyManager.ModemActivityInfoException |
| 1450 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1451 | } else { |
| 1452 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1453 | error = TelephonyManager.ModemActivityInfoException |
| 1454 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1455 | } |
| 1456 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1457 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1458 | if (mLastModemActivityInfo != null) { |
| 1459 | bundle.putParcelable( |
| 1460 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1461 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1462 | } else { |
| 1463 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1464 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1465 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1466 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1467 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1468 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1469 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1470 | case CMD_SET_ALLOWED_CARRIERS: |
| 1471 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1472 | CarrierRestrictionRules argument = |
| 1473 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1474 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1475 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1476 | break; |
| 1477 | |
| 1478 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1479 | ar = (AsyncResult) msg.obj; |
| 1480 | request = (MainThreadRequest) ar.userObj; |
| 1481 | if (ar.exception == null && ar.result != null) { |
| 1482 | request.result = ar.result; |
| 1483 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1484 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1485 | if (ar.exception instanceof CommandException) { |
| 1486 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1487 | CommandException.Error error = |
| 1488 | ((CommandException) (ar.exception)).getCommandError(); |
| 1489 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1490 | request.result = |
| 1491 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1492 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1493 | } else { |
| 1494 | loge("setAllowedCarriers: Unknown exception"); |
| 1495 | } |
| 1496 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1497 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1498 | break; |
| 1499 | |
| 1500 | case CMD_GET_ALLOWED_CARRIERS: |
| 1501 | request = (MainThreadRequest) msg.obj; |
| 1502 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1503 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1504 | break; |
| 1505 | |
| 1506 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1507 | ar = (AsyncResult) msg.obj; |
| 1508 | request = (MainThreadRequest) ar.userObj; |
| 1509 | if (ar.exception == null && ar.result != null) { |
| 1510 | request.result = ar.result; |
| 1511 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1512 | request.result = new IllegalStateException( |
| 1513 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1514 | if (ar.result == null) { |
| 1515 | loge("getAllowedCarriers: Empty response"); |
| 1516 | } else if (ar.exception instanceof CommandException) { |
| 1517 | loge("getAllowedCarriers: CommandException: " + |
| 1518 | ar.exception); |
| 1519 | } else { |
| 1520 | loge("getAllowedCarriers: Unknown exception"); |
| 1521 | } |
| 1522 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1523 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1524 | break; |
| 1525 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1526 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1527 | ar = (AsyncResult) msg.obj; |
| 1528 | request = (MainThreadRequest) ar.userObj; |
| 1529 | if (ar.exception == null && ar.result != null) { |
| 1530 | request.result = ar.result; |
| 1531 | } else { |
| 1532 | request.result = new IllegalArgumentException( |
| 1533 | "Failed to retrieve Forbidden Plmns"); |
| 1534 | if (ar.result == null) { |
| 1535 | loge("getForbiddenPlmns: Empty response"); |
| 1536 | } else { |
| 1537 | loge("getForbiddenPlmns: Unknown exception"); |
| 1538 | } |
| 1539 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1540 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | |
| 1543 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1544 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1545 | uiccPort = getUiccPortFromRequest(request); |
| 1546 | if (uiccPort == null) { |
| 1547 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1548 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1549 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1550 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1551 | break; |
| 1552 | } |
| 1553 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1554 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1555 | if (uiccApp == null) { |
| 1556 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1557 | + appType); |
| 1558 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1559 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1560 | break; |
| 1561 | } else { |
| 1562 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1563 | + " specified type -- " + appType); |
| 1564 | } |
| 1565 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1566 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1567 | onCompleted); |
| 1568 | break; |
| 1569 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1570 | case CMD_SWITCH_SLOTS: |
| 1571 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1572 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1573 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1574 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1575 | break; |
| 1576 | |
| 1577 | case EVENT_SWITCH_SLOTS_DONE: |
| 1578 | ar = (AsyncResult) msg.obj; |
| 1579 | request = (MainThreadRequest) ar.userObj; |
| 1580 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1581 | notifyRequester(request); |
| 1582 | break; |
| 1583 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1584 | request = (MainThreadRequest) msg.obj; |
| 1585 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1586 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1587 | break; |
| 1588 | |
| 1589 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1590 | ar = (AsyncResult) msg.obj; |
| 1591 | request = (MainThreadRequest) ar.userObj; |
| 1592 | if (ar.exception != null) { |
| 1593 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1594 | } else { |
| 1595 | int mode = ((int[]) ar.result)[0]; |
| 1596 | if (mode == 0) { |
| 1597 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1598 | } else { |
| 1599 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1600 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1601 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1602 | notifyRequester(request); |
| 1603 | break; |
| 1604 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1605 | request = (MainThreadRequest) msg.obj; |
| 1606 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1607 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1608 | break; |
| 1609 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1610 | ar = (AsyncResult) msg.obj; |
| 1611 | request = (MainThreadRequest) ar.userObj; |
| 1612 | if (ar.exception != null) { |
| 1613 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1614 | } else { |
| 1615 | request.result = ((int[]) ar.result)[0]; |
| 1616 | } |
| 1617 | notifyRequester(request); |
| 1618 | break; |
| 1619 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1620 | request = (MainThreadRequest) msg.obj; |
| 1621 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1622 | int mode = (int) request.argument; |
| 1623 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1624 | break; |
| 1625 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1626 | ar = (AsyncResult) msg.obj; |
| 1627 | request = (MainThreadRequest) ar.userObj; |
| 1628 | request.result = ar.exception == null; |
| 1629 | notifyRequester(request); |
| 1630 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1631 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1632 | request = (MainThreadRequest) msg.obj; |
| 1633 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1634 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1635 | break; |
| 1636 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1637 | ar = (AsyncResult) msg.obj; |
| 1638 | request = (MainThreadRequest) ar.userObj; |
| 1639 | if (ar.exception != null) { |
| 1640 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1641 | } else { |
| 1642 | request.result = ((int[]) ar.result)[0]; |
| 1643 | } |
| 1644 | notifyRequester(request); |
| 1645 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1646 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1647 | request = (MainThreadRequest) msg.obj; |
| 1648 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1649 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1650 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1651 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1652 | break; |
| 1653 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1654 | ar = (AsyncResult) msg.obj; |
| 1655 | request = (MainThreadRequest) ar.userObj; |
| 1656 | request.result = ar.exception == null; |
| 1657 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1658 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1659 | case CMD_GET_ALL_CELL_INFO: |
| 1660 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1661 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1662 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1663 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1664 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1665 | ar = (AsyncResult) msg.obj; |
| 1666 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1667 | // If a timeout occurs, the response will be null |
| 1668 | request.result = (ar.exception == null && ar.result != null) |
| 1669 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1670 | synchronized (request) { |
| 1671 | request.notifyAll(); |
| 1672 | } |
| 1673 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1674 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1675 | request = (MainThreadRequest) msg.obj; |
| 1676 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1677 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1678 | break; |
| 1679 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1680 | ar = (AsyncResult) msg.obj; |
| 1681 | request = (MainThreadRequest) ar.userObj; |
| 1682 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1683 | try { |
| 1684 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1685 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1686 | cb.onError( |
| 1687 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1688 | ar.exception.getClass().getName(), |
| 1689 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1690 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1691 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1692 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1693 | } else { |
| 1694 | // use the result as returned |
| 1695 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1696 | } |
| 1697 | } catch (RemoteException re) { |
| 1698 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1699 | } |
| 1700 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1701 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1702 | request = (MainThreadRequest) msg.obj; |
| 1703 | WorkSource ws = (WorkSource) request.argument; |
| 1704 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1705 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1706 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1707 | } |
| 1708 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1709 | ar = (AsyncResult) msg.obj; |
| 1710 | request = (MainThreadRequest) ar.userObj; |
| 1711 | if (ar.exception == null) { |
| 1712 | request.result = ar.result; |
| 1713 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1714 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1715 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1716 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | synchronized (request) { |
| 1720 | request.notifyAll(); |
| 1721 | } |
| 1722 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1723 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1724 | case CMD_MODEM_REBOOT: |
| 1725 | request = (MainThreadRequest) msg.obj; |
| 1726 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1727 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1728 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1729 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1730 | handleNullReturnEvent(msg, "rebootModem"); |
| 1731 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1732 | case CMD_REQUEST_ENABLE_MODEM: |
| 1733 | request = (MainThreadRequest) msg.obj; |
| 1734 | boolean enable = (boolean) request.argument; |
| 1735 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1736 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1737 | PhoneConfigurationManager.getInstance() |
| 1738 | .enablePhone(request.phone, enable, onCompleted); |
| 1739 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1740 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1741 | ar = (AsyncResult) msg.obj; |
| 1742 | request = (MainThreadRequest) ar.userObj; |
| 1743 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1744 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1745 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1746 | if ((boolean) request.result) { |
| 1747 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1748 | updateModemStateMetrics(); |
| 1749 | } else { |
| 1750 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1751 | + ar.exception); |
| 1752 | } |
| 1753 | notifyRequester(request); |
| 1754 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1755 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1756 | case CMD_GET_MODEM_STATUS: |
| 1757 | request = (MainThreadRequest) msg.obj; |
| 1758 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1759 | PhoneConfigurationManager.getInstance() |
| 1760 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1761 | break; |
| 1762 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1763 | ar = (AsyncResult) msg.obj; |
| 1764 | request = (MainThreadRequest) ar.userObj; |
| 1765 | int id = request.phone.getPhoneId(); |
| 1766 | if (ar.exception == null && ar.result != null) { |
| 1767 | request.result = ar.result; |
| 1768 | //update the cache as modem status has changed |
| 1769 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1770 | (boolean) request.result); |
| 1771 | } else { |
| 1772 | // Return true if modem status cannot be retrieved. For most cases, |
| 1773 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1774 | // and disable modem are not supported. Modem is always on. |
| 1775 | // TODO: this should be fixed in R to support a third |
| 1776 | // status UNKNOWN b/131631629 |
| 1777 | request.result = true; |
| 1778 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1779 | + ar.exception); |
| 1780 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1781 | notifyRequester(request); |
| 1782 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1783 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1784 | request = (MainThreadRequest) msg.obj; |
| 1785 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1786 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1787 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1788 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1789 | break; |
| 1790 | } |
| 1791 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1792 | ar = (AsyncResult) msg.obj; |
| 1793 | request = (MainThreadRequest) ar.userObj; |
| 1794 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1795 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1796 | args.second.accept(ar.exception == null); |
| 1797 | notifyRequester(request); |
| 1798 | break; |
| 1799 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1800 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1801 | request = (MainThreadRequest) msg.obj; |
| 1802 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1803 | Phone phone = getPhoneFromRequest(request); |
| 1804 | if (phone != null) { |
| 1805 | phone.getSystemSelectionChannels(onCompleted); |
| 1806 | } else { |
| 1807 | loge("getSystemSelectionChannels: No phone object"); |
| 1808 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1809 | notifyRequester(request); |
| 1810 | } |
| 1811 | break; |
| 1812 | } |
| 1813 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1814 | ar = (AsyncResult) msg.obj; |
| 1815 | request = (MainThreadRequest) ar.userObj; |
| 1816 | if (ar.exception == null && ar.result != null) { |
| 1817 | request.result = ar.result; |
| 1818 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1819 | request.result = new IllegalStateException( |
| 1820 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1821 | if (ar.result == null) { |
| 1822 | loge("getSystemSelectionChannels: Empty response"); |
| 1823 | } else { |
| 1824 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1825 | } |
| 1826 | } |
| 1827 | notifyRequester(request); |
| 1828 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1829 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1830 | ar = (AsyncResult) msg.obj; |
| 1831 | request = (MainThreadRequest) ar.userObj; |
| 1832 | if (ar.exception == null && ar.result != null) { |
| 1833 | request.result = ar.result; |
| 1834 | } else { |
| 1835 | request.result = -1; |
| 1836 | loge("Failed to set Forbidden Plmns"); |
| 1837 | if (ar.result == null) { |
| 1838 | loge("setForbidenPlmns: Empty response"); |
| 1839 | } else if (ar.exception != null) { |
| 1840 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1841 | request.result = -1; |
| 1842 | } else { |
| 1843 | loge("setForbiddenPlmns: Unknown exception"); |
| 1844 | } |
| 1845 | } |
| 1846 | notifyRequester(request); |
| 1847 | break; |
| 1848 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1849 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1850 | uiccPort = getUiccPortFromRequest(request); |
| 1851 | if (uiccPort == null) { |
| 1852 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1853 | request.result = -1; |
| 1854 | notifyRequester(request); |
| 1855 | break; |
| 1856 | } |
| 1857 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1858 | (Pair<Integer, List<String>>) request.argument; |
| 1859 | appType = setFplmnsArgs.first; |
| 1860 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1861 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1862 | if (uiccApp == null) { |
| 1863 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1864 | request.result = -1; |
| 1865 | loge("Failed to get UICC App"); |
| 1866 | notifyRequester(request); |
| 1867 | } else { |
| 1868 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1869 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1870 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1871 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1872 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1873 | case CMD_ERASE_MODEM_CONFIG: |
| 1874 | request = (MainThreadRequest) msg.obj; |
| 1875 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1876 | defaultPhone.eraseModemConfig(onCompleted); |
| 1877 | break; |
| 1878 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1879 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1880 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1881 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1882 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1883 | request = (MainThreadRequest) msg.obj; |
| 1884 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1885 | notifyRequester(request); |
| 1886 | break; |
| 1887 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1888 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1889 | request = (MainThreadRequest) msg.obj; |
| 1890 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1891 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1892 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1893 | changed.first, changed.second, onCompleted); |
| 1894 | break; |
| 1895 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1896 | ar = (AsyncResult) msg.obj; |
| 1897 | request = (MainThreadRequest) ar.userObj; |
| 1898 | if (ar.exception == null) { |
| 1899 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1900 | // If the operation is successful, update the PIN storage |
| 1901 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1902 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1903 | UiccController.getInstance().getPinStorage() |
| 1904 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1905 | } else { |
| 1906 | request.result = msg.arg1; |
| 1907 | } |
| 1908 | notifyRequester(request); |
| 1909 | break; |
| 1910 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1911 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1912 | request = (MainThreadRequest) msg.obj; |
| 1913 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1914 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1915 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1916 | enabled.first, enabled.second, onCompleted); |
| 1917 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1918 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1919 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1920 | ar = (AsyncResult) msg.obj; |
| 1921 | request = (MainThreadRequest) ar.userObj; |
| 1922 | if (ar.exception == null) { |
| 1923 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1924 | // If the operation is successful, update the PIN storage |
| 1925 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1926 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1927 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1928 | UiccController.getInstance().getPinStorage() |
| 1929 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1930 | } else { |
| 1931 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1932 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1933 | } else { |
| 1934 | request.result = msg.arg1; |
| 1935 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1936 | |
| 1937 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1938 | notifyRequester(request); |
| 1939 | break; |
| 1940 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1941 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1942 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1943 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1944 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1945 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1946 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1947 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1948 | |
| 1949 | case CMD_SET_DATA_THROTTLING: { |
| 1950 | request = (MainThreadRequest) msg.obj; |
| 1951 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1952 | DataThrottlingRequest dataThrottlingRequest = |
| 1953 | (DataThrottlingRequest) request.argument; |
| 1954 | Phone phone = getPhoneFromRequest(request); |
| 1955 | if (phone != null) { |
| 1956 | phone.setDataThrottling(onCompleted, |
| 1957 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1958 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1959 | } else { |
| 1960 | loge("setDataThrottling: No phone object"); |
| 1961 | request.result = |
| 1962 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1963 | notifyRequester(request); |
| 1964 | } |
| 1965 | |
| 1966 | break; |
| 1967 | } |
| 1968 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1969 | ar = (AsyncResult) msg.obj; |
| 1970 | request = (MainThreadRequest) ar.userObj; |
| 1971 | |
| 1972 | if (ar.exception == null) { |
| 1973 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1974 | } else if (ar.exception instanceof CommandException) { |
| 1975 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1976 | CommandException.Error error = |
| 1977 | ((CommandException) (ar.exception)).getCommandError(); |
| 1978 | |
| 1979 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1980 | request.result = TelephonyManager |
| 1981 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1982 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1983 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1984 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1985 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1986 | } else { |
| 1987 | request.result = |
| 1988 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1989 | } |
| 1990 | } else { |
| 1991 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1992 | } |
| 1993 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1994 | notifyRequester(request); |
| 1995 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1996 | |
| 1997 | case CMD_SET_SIM_POWER: { |
| 1998 | request = (MainThreadRequest) msg.obj; |
| 1999 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 2000 | request = (MainThreadRequest) msg.obj; |
| 2001 | int stateToSet = |
| 2002 | ((Pair<Integer, IIntegerConsumer>) |
| 2003 | request.argument).first; |
| 2004 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2005 | break; |
| 2006 | } |
| 2007 | case EVENT_SET_SIM_POWER_DONE: { |
| 2008 | ar = (AsyncResult) msg.obj; |
| 2009 | request = (MainThreadRequest) ar.userObj; |
| 2010 | IIntegerConsumer callback = |
| 2011 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2012 | if (ar.exception != null) { |
| 2013 | loge("setSimPower exception: " + ar.exception); |
| 2014 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2015 | .RESULT_ERROR_UNKNOWN; |
| 2016 | if (ar.exception instanceof CommandException) { |
| 2017 | CommandException.Error error = |
| 2018 | ((CommandException) (ar.exception)).getCommandError(); |
| 2019 | if (error == CommandException.Error.SIM_ERR) { |
| 2020 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2021 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2022 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2023 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2024 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2025 | } else { |
| 2026 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2027 | } |
| 2028 | } |
| 2029 | try { |
| 2030 | callback.accept(errorCode); |
| 2031 | } catch (RemoteException e) { |
| 2032 | // Ignore if the remote process is no longer available to call back. |
| 2033 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2034 | } |
| 2035 | } else { |
| 2036 | try { |
| 2037 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2038 | } catch (RemoteException e) { |
| 2039 | // Ignore if the remote process is no longer available to call back. |
| 2040 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2041 | } |
| 2042 | } |
| 2043 | break; |
| 2044 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2045 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2046 | request = (MainThreadRequest) msg.obj; |
| 2047 | |
| 2048 | final Phone phone = getPhoneFromRequest(request); |
| 2049 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2050 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2051 | notifyRequester(request); |
| 2052 | break; |
| 2053 | } |
| 2054 | |
| 2055 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2056 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2057 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2058 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2059 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2060 | request.subId, pair.first /*callingUid*/, |
| 2061 | pair.second /*request*/, onCompleted); |
| 2062 | break; |
| 2063 | } |
| 2064 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2065 | ar = (AsyncResult) msg.obj; |
| 2066 | request = (MainThreadRequest) ar.userObj; |
| 2067 | // request.result will be the exception of ar if present, true otherwise. |
| 2068 | // Be cautious not to leave result null which will wait() forever |
| 2069 | request.result = ar.exception != null ? ar.exception : true; |
| 2070 | notifyRequester(request); |
| 2071 | break; |
| 2072 | } |
| 2073 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2074 | request = (MainThreadRequest) msg.obj; |
| 2075 | |
| 2076 | Phone phone = getPhoneFromRequest(request); |
| 2077 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2078 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2079 | notifyRequester(request); |
| 2080 | break; |
| 2081 | } |
| 2082 | |
| 2083 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2084 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2085 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2086 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2087 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2088 | request.subId, pair.first /*callingUid*/, |
| 2089 | pair.second /*request*/, onCompleted); |
| 2090 | break; |
| 2091 | } |
| 2092 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2093 | ar = (AsyncResult) msg.obj; |
| 2094 | request = (MainThreadRequest) ar.userObj; |
| 2095 | request.result = ar.exception != null ? ar.exception : true; |
| 2096 | notifyRequester(request); |
| 2097 | break; |
| 2098 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2099 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2100 | case CMD_GET_SLICING_CONFIG: { |
| 2101 | request = (MainThreadRequest) msg.obj; |
| 2102 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2103 | request.phone.getSlicingConfig(onCompleted); |
| 2104 | break; |
| 2105 | } |
| 2106 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2107 | ar = (AsyncResult) msg.obj; |
| 2108 | request = (MainThreadRequest) ar.userObj; |
| 2109 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2110 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2111 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2112 | Bundle bundle = new Bundle(); |
| 2113 | int resultCode = 0; |
| 2114 | if (ar.exception != null) { |
| 2115 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2116 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2117 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2118 | } else if (ar.result == null) { |
| 2119 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2120 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2121 | } else { |
| 2122 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2123 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2124 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2128 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2129 | } |
| 2130 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2131 | result.send(resultCode, bundle); |
| 2132 | notifyRequester(request); |
| 2133 | break; |
| 2134 | } |
| 2135 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2136 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2137 | request = (MainThreadRequest) msg.obj; |
| 2138 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2139 | UiccController.getInstance().getPinStorage() |
| 2140 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2141 | notifyRequester(request); |
| 2142 | break; |
| 2143 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2144 | default: |
| 2145 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2146 | break; |
| 2147 | } |
| 2148 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2149 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2150 | private void notifyRequester(MainThreadRequest request) { |
| 2151 | synchronized (request) { |
| 2152 | request.notifyAll(); |
| 2153 | } |
| 2154 | } |
| 2155 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2156 | private void handleNullReturnEvent(Message msg, String command) { |
| 2157 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2158 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2159 | if (ar.exception == null) { |
| 2160 | request.result = true; |
| 2161 | } else { |
| 2162 | request.result = false; |
| 2163 | if (ar.exception instanceof CommandException) { |
| 2164 | loge(command + ": CommandException: " + ar.exception); |
| 2165 | } else { |
| 2166 | loge(command + ": Unknown exception"); |
| 2167 | } |
| 2168 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2169 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2170 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | /** |
| 2174 | * Posts the specified command to be executed on the main thread, |
| 2175 | * waits for the request to complete, and returns the result. |
| 2176 | * @see #sendRequestAsync |
| 2177 | */ |
| 2178 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2179 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2180 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | /** |
| 2184 | * Posts the specified command to be executed on the main thread, |
| 2185 | * waits for the request to complete, and returns the result. |
| 2186 | * @see #sendRequestAsync |
| 2187 | */ |
| 2188 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2189 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2190 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * Posts the specified command to be executed on the main thread, |
| 2195 | * waits for the request to complete, and returns the result. |
| 2196 | * @see #sendRequestAsync |
| 2197 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2198 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2199 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2200 | } |
| 2201 | |
| 2202 | /** |
| 2203 | * Posts the specified command to be executed on the main thread, |
| 2204 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2205 | * if not timeout or null otherwise. |
| 2206 | * @see #sendRequestAsync |
| 2207 | */ |
| 2208 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2209 | long timeoutInMs) { |
| 2210 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /** |
| 2214 | * Posts the specified command to be executed on the main thread, |
| 2215 | * waits for the request to complete, and returns the result. |
| 2216 | * @see #sendRequestAsync |
| 2217 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2218 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2219 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
| 2222 | /** |
| 2223 | * Posts the specified command to be executed on the main thread, |
| 2224 | * waits for the request to complete, and returns the result. |
| 2225 | * @see #sendRequestAsync |
| 2226 | */ |
| 2227 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2228 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2229 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2233 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2234 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2235 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2236 | * @see #sendRequestAsync |
| 2237 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2238 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2239 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2240 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2241 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2242 | } |
| 2243 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2244 | MainThreadRequest request = null; |
| 2245 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2246 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2247 | } else if (phone != null) { |
| 2248 | request = new MainThreadRequest(argument, phone, workSource); |
| 2249 | } else { |
| 2250 | request = new MainThreadRequest(argument, subId, workSource); |
| 2251 | } |
| 2252 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2254 | msg.sendToTarget(); |
| 2255 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2256 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2257 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2258 | if (timeoutInMs >= 0) { |
| 2259 | // Wait for at least timeoutInMs before returning null request result |
| 2260 | long now = SystemClock.elapsedRealtime(); |
| 2261 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2262 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2263 | try { |
| 2264 | request.wait(deadline - now); |
| 2265 | } catch (InterruptedException e) { |
| 2266 | // Do nothing, go back and check if request is completed or timeout |
| 2267 | } finally { |
| 2268 | now = SystemClock.elapsedRealtime(); |
| 2269 | } |
| 2270 | } |
| 2271 | } else { |
| 2272 | // Wait for the request to complete |
| 2273 | while (request.result == null) { |
| 2274 | try { |
| 2275 | request.wait(); |
| 2276 | } catch (InterruptedException e) { |
| 2277 | // Do nothing, go back and wait until the request is complete |
| 2278 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2279 | } |
| 2280 | } |
| 2281 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2282 | if (request.result == null) { |
| 2283 | Log.wtf(LOG_TAG, |
| 2284 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | return request.result; |
| 2287 | } |
| 2288 | |
| 2289 | /** |
| 2290 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2291 | * Posts the specified command to be executed on the main thread, and |
| 2292 | * returns immediately. |
| 2293 | * @see #sendRequest |
| 2294 | */ |
| 2295 | private void sendRequestAsync(int command) { |
| 2296 | mMainThreadHandler.sendEmptyMessage(command); |
| 2297 | } |
| 2298 | |
| 2299 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2300 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2301 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2302 | */ |
| 2303 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2304 | sendRequestAsync(command, argument, null, null); |
| 2305 | } |
| 2306 | |
| 2307 | /** |
| 2308 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2309 | * @see {@link #sendRequest(int,Object)} |
| 2310 | */ |
| 2311 | private void sendRequestAsync( |
| 2312 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2313 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2314 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2315 | msg.sendToTarget(); |
| 2316 | } |
| 2317 | |
| 2318 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2320 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2321 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2322 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2323 | synchronized (PhoneInterfaceManager.class) { |
| 2324 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2325 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2326 | } else { |
| 2327 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2328 | } |
| 2329 | return sInstance; |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2334 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2337 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2338 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2340 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2341 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2342 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2343 | mTelephonySharedPreferences = |
| 2344 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2345 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2346 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2347 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2348 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2349 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | publish(); |
| 2351 | } |
| 2352 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2353 | private Phone getDefaultPhone() { |
| 2354 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2355 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2356 | } |
| 2357 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2358 | private void publish() { |
| 2359 | if (DBG) log("publish: " + this); |
| 2360 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2361 | TelephonyFrameworkInitializer |
| 2362 | .getTelephonyServiceManager() |
| 2363 | .getTelephonyServiceRegisterer() |
| 2364 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2367 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2368 | if (request.phone != null) { |
| 2369 | return request.phone; |
| 2370 | } else { |
| 2371 | return getPhoneFromSubId(request.subId); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | private Phone getPhoneFromSubId(int subId) { |
| 2376 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2377 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2380 | @Nullable |
| 2381 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2382 | Phone phone = getPhoneFromRequest(request); |
| 2383 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2384 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2385 | } |
| 2386 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2387 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2388 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2389 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2391 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2392 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2393 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2394 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2395 | } |
| 2396 | |
| 2397 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2398 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2399 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2402 | private boolean isImsAvailableOnDevice() { |
| 2403 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2404 | if (pm == null) { |
| 2405 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2406 | // so do not throw error and allow. |
| 2407 | return true; |
| 2408 | } |
| 2409 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2410 | } |
| 2411 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2412 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2413 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2416 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2417 | if (DBG) log("dial: " + number); |
| 2418 | // No permission check needed here: This is just a wrapper around the |
| 2419 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2420 | // the UI before it does anything. |
| 2421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | final long identity = Binder.clearCallingIdentity(); |
| 2423 | try { |
| 2424 | String url = createTelUrl(number); |
| 2425 | if (url == null) { |
| 2426 | return; |
| 2427 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2429 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2430 | PhoneConstants.State state = mCM.getState(subId); |
| 2431 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2432 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2433 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2434 | mApp.startActivity(intent); |
| 2435 | } |
| 2436 | } finally { |
| 2437 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2442 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2445 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2446 | if (DBG) log("call: " + number); |
| 2447 | |
| 2448 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2449 | // need to do a permission check since we're calling startActivity() |
| 2450 | // from the context of the phone app. |
| 2451 | enforceCallPermission(); |
| 2452 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2453 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2454 | != AppOpsManager.MODE_ALLOWED) { |
| 2455 | return; |
| 2456 | } |
| 2457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2458 | final long identity = Binder.clearCallingIdentity(); |
| 2459 | try { |
| 2460 | String url = createTelUrl(number); |
| 2461 | if (url == null) { |
| 2462 | return; |
| 2463 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | boolean isValid = false; |
| 2466 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2467 | if (slist != null) { |
| 2468 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2469 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2470 | isValid = true; |
| 2471 | break; |
| 2472 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2473 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2475 | if (!isValid) { |
| 2476 | return; |
| 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 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2480 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2481 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2482 | mApp.startActivity(intent); |
| 2483 | } finally { |
| 2484 | Binder.restoreCallingIdentity(identity); |
| 2485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2488 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2489 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2490 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2491 | } |
| 2492 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2493 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2494 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2495 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2496 | } |
| 2497 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2498 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2500 | |
| 2501 | final long identity = Binder.clearCallingIdentity(); |
| 2502 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2503 | Phone phone = getPhone(subId); |
| 2504 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | checkSimPin.start(); |
| 2506 | return checkSimPin.unlockSim(null, pin); |
| 2507 | } finally { |
| 2508 | Binder.restoreCallingIdentity(identity); |
| 2509 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | } |
| 2511 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2512 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2514 | |
| 2515 | final long identity = Binder.clearCallingIdentity(); |
| 2516 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2517 | Phone phone = getPhone(subId); |
| 2518 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | checkSimPuk.start(); |
| 2520 | return checkSimPuk.unlockSim(puk, pin); |
| 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(identity); |
| 2523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2527 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | * a synchronous one. |
| 2529 | */ |
| 2530 | private static class UnlockSim extends Thread { |
| 2531 | |
| 2532 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2533 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | |
| 2535 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2536 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2537 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | |
| 2539 | // For replies from SimCard interface |
| 2540 | private Handler mHandler; |
| 2541 | |
| 2542 | // For async handler to identify request type |
| 2543 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2544 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2545 | UnlockSim(int phoneId, IccCard simCard) { |
| 2546 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2547 | mSimCard = simCard; |
| 2548 | } |
| 2549 | |
| 2550 | @Override |
| 2551 | public void run() { |
| 2552 | Looper.prepare(); |
| 2553 | synchronized (UnlockSim.this) { |
| 2554 | mHandler = new Handler() { |
| 2555 | @Override |
| 2556 | public void handleMessage(Message msg) { |
| 2557 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2558 | switch (msg.what) { |
| 2559 | case SUPPLY_PIN_COMPLETE: |
| 2560 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2561 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2562 | mRetryCount = msg.arg1; |
| 2563 | if (ar.exception != null) { |
| 2564 | if (ar.exception instanceof CommandException && |
| 2565 | ((CommandException)(ar.exception)).getCommandError() |
| 2566 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2567 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2568 | } //When UiccCardApp dispose,handle message and return exception |
| 2569 | else if (ar.exception instanceof CommandException && |
| 2570 | ((CommandException) (ar.exception)).getCommandError() |
| 2571 | == CommandException.Error.ABORTED) { |
| 2572 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2573 | } else { |
| 2574 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2575 | } |
| 2576 | } else { |
| 2577 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2578 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2579 | mDone = true; |
| 2580 | UnlockSim.this.notifyAll(); |
| 2581 | } |
| 2582 | break; |
| 2583 | } |
| 2584 | } |
| 2585 | }; |
| 2586 | UnlockSim.this.notifyAll(); |
| 2587 | } |
| 2588 | Looper.loop(); |
| 2589 | } |
| 2590 | |
| 2591 | /* |
| 2592 | * Use PIN or PUK to unlock SIM card |
| 2593 | * |
| 2594 | * If PUK is null, unlock SIM card with PIN |
| 2595 | * |
| 2596 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2597 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2598 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | |
| 2600 | while (mHandler == null) { |
| 2601 | try { |
| 2602 | wait(); |
| 2603 | } catch (InterruptedException e) { |
| 2604 | Thread.currentThread().interrupt(); |
| 2605 | } |
| 2606 | } |
| 2607 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2608 | |
| 2609 | if (puk == null) { |
| 2610 | mSimCard.supplyPin(pin, callback); |
| 2611 | } else { |
| 2612 | mSimCard.supplyPuk(puk, pin, callback); |
| 2613 | } |
| 2614 | |
| 2615 | while (!mDone) { |
| 2616 | try { |
| 2617 | Log.d(LOG_TAG, "wait for done"); |
| 2618 | wait(); |
| 2619 | } catch (InterruptedException e) { |
| 2620 | // Restore the interrupted status |
| 2621 | Thread.currentThread().interrupt(); |
| 2622 | } |
| 2623 | } |
| 2624 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2625 | int[] resultArray = new int[2]; |
| 2626 | resultArray[0] = mResult; |
| 2627 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2628 | |
| 2629 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2630 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2631 | } |
| 2632 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2633 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2637 | /** |
| 2638 | * This method has been removed due to privacy and stability concerns. |
| 2639 | */ |
| 2640 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2641 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2642 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2643 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2646 | @Override |
| 2647 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2648 | mApp.getSystemService(AppOpsManager.class) |
| 2649 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2650 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2651 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2652 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2653 | // Callers targeting S have no business invoking this method. |
| 2654 | return; |
| 2655 | } |
| 2656 | |
| 2657 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2658 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2659 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2660 | .setCallingPackage(callingPackage) |
| 2661 | .setCallingFeatureId(null) |
| 2662 | .setCallingPid(Binder.getCallingPid()) |
| 2663 | .setCallingUid(Binder.getCallingUid()) |
| 2664 | .setMethod("updateServiceLocation") |
| 2665 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2666 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2667 | .build()); |
| 2668 | // Apps that lack location permission have no business calling this method; |
| 2669 | // however, because no permission was declared in the public API, denials must |
| 2670 | // all be "soft". |
| 2671 | switch (locationResult) { |
| 2672 | case DENIED_HARD: /* fall through */ |
| 2673 | case DENIED_SOFT: |
| 2674 | return; |
| 2675 | } |
| 2676 | |
| 2677 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2678 | final long identity = Binder.clearCallingIdentity(); |
| 2679 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2680 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2682 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | } |
| 2684 | } finally { |
| 2685 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2686 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2687 | } |
| 2688 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2689 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2690 | @Override |
| 2691 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2692 | return isRadioOnWithFeature(callingPackage, null); |
| 2693 | } |
| 2694 | |
| 2695 | |
| 2696 | @Override |
| 2697 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2698 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2699 | callingFeatureId); |
| 2700 | } |
| 2701 | |
| 2702 | @Deprecated |
| 2703 | @Override |
| 2704 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2705 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2708 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2709 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2710 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2711 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2712 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2713 | return false; |
| 2714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2715 | |
| 2716 | final long identity = Binder.clearCallingIdentity(); |
| 2717 | try { |
| 2718 | return isRadioOnForSubscriber(subId); |
| 2719 | } finally { |
| 2720 | Binder.restoreCallingIdentity(identity); |
| 2721 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2725 | final long identity = Binder.clearCallingIdentity(); |
| 2726 | try { |
| 2727 | final Phone phone = getPhone(subId); |
| 2728 | if (phone != null) { |
| 2729 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2730 | } else { |
| 2731 | return false; |
| 2732 | } |
| 2733 | } finally { |
| 2734 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2735 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2739 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2741 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2742 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2744 | |
| 2745 | final long identity = Binder.clearCallingIdentity(); |
| 2746 | try { |
| 2747 | final Phone phone = getPhone(subId); |
| 2748 | if (phone != null) { |
| 2749 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2750 | } |
| 2751 | } finally { |
| 2752 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2753 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2757 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2760 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2761 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2762 | |
| 2763 | final long identity = Binder.clearCallingIdentity(); |
| 2764 | try { |
| 2765 | final Phone phone = getPhone(subId); |
| 2766 | if (phone == null) { |
| 2767 | return false; |
| 2768 | } |
| 2769 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2770 | toggleRadioOnOffForSubscriber(subId); |
| 2771 | } |
| 2772 | return true; |
| 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2775 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2776 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2777 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2778 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2779 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2780 | /* |
| 2781 | * If any of the Radios are available, it will need to be |
| 2782 | * shutdown. So return true if any Radio is available. |
| 2783 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2784 | final long identity = Binder.clearCallingIdentity(); |
| 2785 | try { |
| 2786 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2787 | Phone phone = PhoneFactory.getPhone(i); |
| 2788 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2789 | } |
| 2790 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2791 | return false; |
| 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2794 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2798 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2799 | enforceModifyPermission(); |
| 2800 | |
| 2801 | final long identity = Binder.clearCallingIdentity(); |
| 2802 | try { |
| 2803 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2804 | logv("Shutting down Phone " + i); |
| 2805 | shutdownRadioUsingPhoneId(i); |
| 2806 | } |
| 2807 | } finally { |
| 2808 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2813 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2814 | if (phone != null && phone.isRadioAvailable()) { |
| 2815 | phone.shutdownRadio(); |
| 2816 | } |
| 2817 | } |
| 2818 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2820 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | |
| 2822 | final long identity = Binder.clearCallingIdentity(); |
| 2823 | try { |
| 2824 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2825 | if (defaultPhone != null) { |
| 2826 | defaultPhone.setRadioPower(turnOn); |
| 2827 | return true; |
| 2828 | } else { |
| 2829 | loge("There's no default phone."); |
| 2830 | return false; |
| 2831 | } |
| 2832 | } finally { |
| 2833 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2834 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2837 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2838 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2839 | |
| 2840 | final long identity = Binder.clearCallingIdentity(); |
| 2841 | try { |
| 2842 | final Phone phone = getPhone(subId); |
| 2843 | if (phone != null) { |
| 2844 | phone.setRadioPower(turnOn); |
| 2845 | return true; |
| 2846 | } else { |
| 2847 | return false; |
| 2848 | } |
| 2849 | } finally { |
| 2850 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2851 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2854 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2855 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2856 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2857 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2858 | |
| 2859 | final long identity = Binder.clearCallingIdentity(); |
| 2860 | try { |
| 2861 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2862 | final Phone phone = getPhone(subId); |
| 2863 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2864 | if (phone.isUsingNewDataStack()) { |
| 2865 | phone.getDataSettingsManager().setDataEnabled( |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2866 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2867 | } else { |
| 2868 | phone.getDataEnabledSettings().setDataEnabled( |
| 2869 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2870 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2871 | return true; |
| 2872 | } else { |
| 2873 | return false; |
| 2874 | } |
| 2875 | } finally { |
| 2876 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2877 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2880 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2881 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2882 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2883 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2884 | |
| 2885 | final long identity = Binder.clearCallingIdentity(); |
| 2886 | try { |
| 2887 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2888 | final Phone phone = getPhone(subId); |
| 2889 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2890 | if (phone.isUsingNewDataStack()) { |
| 2891 | phone.getDataSettingsManager().setDataEnabled( |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2892 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2893 | } else { |
| 2894 | phone.getDataEnabledSettings().setDataEnabled( |
| 2895 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2896 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | return true; |
| 2898 | } else { |
| 2899 | return false; |
| 2900 | } |
| 2901 | } finally { |
| 2902 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2903 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2904 | } |
| 2905 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2906 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2907 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2908 | final long identity = Binder.clearCallingIdentity(); |
| 2909 | try { |
| 2910 | final Phone phone = getPhone(subId); |
| 2911 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 2912 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2913 | } else { |
| 2914 | return false; |
| 2915 | } |
| 2916 | } finally { |
| 2917 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2922 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2925 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2926 | enforceCallPermission(); |
| 2927 | |
| 2928 | final long identity = Binder.clearCallingIdentity(); |
| 2929 | try { |
| 2930 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2931 | return; |
| 2932 | } |
| 2933 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2934 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2938 | }; |
| 2939 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2940 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2941 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | |
| 2943 | final long identity = Binder.clearCallingIdentity(); |
| 2944 | try { |
| 2945 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2946 | return false; |
| 2947 | } |
| 2948 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2949 | } finally { |
| 2950 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2951 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2954 | /** |
| 2955 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2956 | * tag on getCallState Binder call. |
| 2957 | */ |
| 2958 | @Deprecated |
| 2959 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2960 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2961 | if (CompatChanges.isChangeEnabled( |
| 2962 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2963 | Binder.getCallingUid())) { |
| 2964 | // Do not allow this API to be called on API version 31+, it should only be |
| 2965 | // called on old apps using this Binder call directly. |
| 2966 | throw new SecurityException("This method can only be used for applications " |
| 2967 | + "targeting API version 30 or less."); |
| 2968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2969 | final long identity = Binder.clearCallingIdentity(); |
| 2970 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2971 | Phone phone = getPhone(getDefaultSubscription()); |
| 2972 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2973 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | @Override |
| 2980 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2981 | if (CompatChanges.isChangeEnabled( |
| 2982 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2983 | Binder.getCallingUid())) { |
| 2984 | // Check READ_PHONE_STATE for API version 31+ |
| 2985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2986 | featureId, "getCallStateForSubscription")) { |
| 2987 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2988 | + "targeting API level 31+."); |
| 2989 | } |
| 2990 | } |
| 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2994 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2995 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3001 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3002 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3003 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3004 | } |
| 3005 | |
| 3006 | @Override |
| 3007 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3008 | final long identity = Binder.clearCallingIdentity(); |
| 3009 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3010 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3011 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3012 | if (phone.isUsingNewDataStack()) { |
| 3013 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3014 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3015 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3016 | } else { |
| 3017 | return PhoneConstantConversions.convertDataState( |
| 3018 | PhoneConstants.DataState.DISCONNECTED); |
| 3019 | } |
| 3020 | } finally { |
| 3021 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3022 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3025 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3026 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3027 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3028 | } |
| 3029 | |
| 3030 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3031 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3032 | final long identity = Binder.clearCallingIdentity(); |
| 3033 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3034 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3035 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3036 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | } else { |
| 3038 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3039 | } |
| 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3042 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3046 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3047 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3048 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3049 | |
| 3050 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3051 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3052 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3053 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3054 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3055 | .setCallingPid(Binder.getCallingPid()) |
| 3056 | .setCallingUid(Binder.getCallingUid()) |
| 3057 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3058 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3059 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3060 | .build()); |
| 3061 | switch (locationResult) { |
| 3062 | case DENIED_HARD: |
| 3063 | throw new SecurityException("Not allowed to access cell location"); |
| 3064 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3065 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3066 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3067 | } |
| 3068 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3069 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
| 3072 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3073 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3074 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3075 | } finally { |
| 3076 | Binder.restoreCallingIdentity(identity); |
| 3077 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3078 | } |
| 3079 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3081 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3082 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3083 | // registered cell info, so return a NULL country instead. |
| 3084 | final long identity = Binder.clearCallingIdentity(); |
| 3085 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3086 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3087 | // Get default phone in this case. |
| 3088 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3089 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3090 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3092 | if (phone == null) return ""; |
| 3093 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3094 | if (sst == null) return ""; |
| 3095 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3096 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3097 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
| 3100 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3103 | /** |
| 3104 | * This method was removed due to potential issues caused by performing partial |
| 3105 | * updates of service state, and lack of a credible use case. |
| 3106 | * |
| 3107 | * This has the ability to break the telephony implementation by disabling notification of |
| 3108 | * changes in device connectivity. DO NOT USE THIS! |
| 3109 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3110 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | public void enableLocationUpdates() { |
| 3112 | mApp.enforceCallingOrSelfPermission( |
| 3113 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3116 | /** |
| 3117 | * This method was removed due to potential issues caused by performing partial |
| 3118 | * updates of service state, and lack of a credible use case. |
| 3119 | * |
| 3120 | * This has the ability to break the telephony implementation by disabling notification of |
| 3121 | * changes in device connectivity. DO NOT USE THIS! |
| 3122 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3123 | @Override |
| 3124 | public void disableLocationUpdates() { |
| 3125 | mApp.enforceCallingOrSelfPermission( |
| 3126 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | @Override |
| 3130 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3131 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3132 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3133 | try { |
| 3134 | mApp.getSystemService(AppOpsManager.class) |
| 3135 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3136 | } catch (SecurityException e) { |
| 3137 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3138 | throw e; |
| 3139 | } |
| 3140 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3141 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3142 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3143 | throw new SecurityException( |
| 3144 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3145 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3146 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3147 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3149 | return null; |
| 3150 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3151 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3152 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3153 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3154 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3155 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3156 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3157 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3158 | for (CellInfo ci : info) { |
| 3159 | if (ci instanceof CellInfoGsm) { |
| 3160 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3161 | } else if (ci instanceof CellInfoWcdma) { |
| 3162 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3163 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3165 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3168 | private List<CellInfo> getCachedCellInfo() { |
| 3169 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3170 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3171 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3172 | if (info != null) cellInfos.addAll(info); |
| 3173 | } |
| 3174 | return cellInfos; |
| 3175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3176 | |
| 3177 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3178 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3179 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3180 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3181 | |
| 3182 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3183 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3184 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3185 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3186 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3187 | .setCallingPid(Binder.getCallingPid()) |
| 3188 | .setCallingUid(Binder.getCallingUid()) |
| 3189 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3190 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3191 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3192 | .build()); |
| 3193 | switch (locationResult) { |
| 3194 | case DENIED_HARD: |
| 3195 | throw new SecurityException("Not allowed to access cell info"); |
| 3196 | case DENIED_SOFT: |
| 3197 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3200 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3201 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3202 | return getCachedCellInfo(); |
| 3203 | } |
| 3204 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3205 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3206 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | final long identity = Binder.clearCallingIdentity(); |
| 3208 | try { |
| 3209 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3210 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3211 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3212 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | if (info != null) cellInfos.addAll(info); |
| 3214 | } |
| 3215 | return cellInfos; |
| 3216 | } finally { |
| 3217 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3218 | } |
| 3219 | } |
| 3220 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3221 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3222 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3223 | String callingFeatureId) { |
| 3224 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3225 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3229 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3230 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3231 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3232 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3235 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3236 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3237 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3238 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3239 | |
| 3240 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3241 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3242 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3243 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3244 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3245 | .setCallingPid(Binder.getCallingPid()) |
| 3246 | .setCallingUid(Binder.getCallingUid()) |
| 3247 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3248 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3249 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3250 | .build()); |
| 3251 | switch (locationResult) { |
| 3252 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3253 | if (TelephonyPermissions |
| 3254 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3255 | // Safetynet logging for b/154934934 |
| 3256 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3257 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3258 | throw new SecurityException("Not allowed to access cell info"); |
| 3259 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3260 | if (TelephonyPermissions |
| 3261 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3262 | // Safetynet logging for b/154934934 |
| 3263 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3264 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3265 | try { |
| 3266 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3267 | } catch (RemoteException re) { |
| 3268 | // Drop without consequences |
| 3269 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3270 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3273 | |
| 3274 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3275 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3276 | |
| 3277 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3278 | } |
| 3279 | |
| 3280 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3281 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3282 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3283 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | |
| 3285 | final long identity = Binder.clearCallingIdentity(); |
| 3286 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3287 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | } finally { |
| 3289 | Binder.restoreCallingIdentity(identity); |
| 3290 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3291 | } |
| 3292 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3293 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3294 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3295 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3296 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3297 | return null; |
| 3298 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3299 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3300 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3301 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3302 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3303 | return null; |
| 3304 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3305 | |
| 3306 | final long identity = Binder.clearCallingIdentity(); |
| 3307 | try { |
| 3308 | return phone.getImei(); |
| 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
| 3311 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3315 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3316 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3317 | String tac = null; |
| 3318 | if (phone != null) { |
| 3319 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3320 | try { |
| 3321 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3322 | } catch (IndexOutOfBoundsException e) { |
| 3323 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3324 | return null; |
| 3325 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3326 | } |
| 3327 | return tac; |
| 3328 | } |
| 3329 | |
| 3330 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3331 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3332 | try { |
| 3333 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3334 | } catch (SecurityException se) { |
| 3335 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3336 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3337 | + Binder.getCallingUid()); |
| 3338 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3339 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3340 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3341 | return null; |
| 3342 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3343 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3344 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3345 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3346 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3347 | return null; |
| 3348 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3349 | |
| 3350 | final long identity = Binder.clearCallingIdentity(); |
| 3351 | try { |
| 3352 | return phone.getMeid(); |
| 3353 | } finally { |
| 3354 | Binder.restoreCallingIdentity(identity); |
| 3355 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3359 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3360 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3361 | String manufacturerCode = null; |
| 3362 | if (phone != null) { |
| 3363 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3364 | try { |
| 3365 | manufacturerCode = |
| 3366 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3367 | } catch (IndexOutOfBoundsException e) { |
| 3368 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3369 | return null; |
| 3370 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3371 | } |
| 3372 | return manufacturerCode; |
| 3373 | } |
| 3374 | |
| 3375 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3376 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3377 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3378 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3379 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3380 | return null; |
| 3381 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3382 | int subId = phone.getSubId(); |
| 3383 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3384 | mApp, subId, callingPackage, callingFeatureId, |
| 3385 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3386 | return null; |
| 3387 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3388 | |
| 3389 | final long identity = Binder.clearCallingIdentity(); |
| 3390 | try { |
| 3391 | return phone.getDeviceSvn(); |
| 3392 | } finally { |
| 3393 | Binder.restoreCallingIdentity(identity); |
| 3394 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3397 | @Override |
| 3398 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3399 | final long identity = Binder.clearCallingIdentity(); |
| 3400 | try { |
| 3401 | final Phone phone = getPhone(subId); |
| 3402 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3403 | } finally { |
| 3404 | Binder.restoreCallingIdentity(identity); |
| 3405 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | @Override |
| 3409 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3410 | final long identity = Binder.clearCallingIdentity(); |
| 3411 | try { |
| 3412 | final Phone phone = getPhone(subId); |
| 3413 | return phone == null ? null : phone.getCarrierName(); |
| 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(identity); |
| 3416 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3417 | } |
| 3418 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3419 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3420 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | final Phone phone = getPhone(subId); |
| 3424 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3425 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3426 | } finally { |
| 3427 | Binder.restoreCallingIdentity(identity); |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3432 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3433 | final long identity = Binder.clearCallingIdentity(); |
| 3434 | try { |
| 3435 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3436 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
| 3439 | } |
| 3440 | } |
| 3441 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3442 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3443 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3444 | if (!isSubscriptionMccMnc) { |
| 3445 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3446 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3447 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3448 | if (phone == null) { |
| 3449 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3450 | } |
| 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3454 | } finally { |
| 3455 | Binder.restoreCallingIdentity(identity); |
| 3456 | } |
| 3457 | } |
| 3458 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3459 | // |
| 3460 | // Internal helper methods. |
| 3461 | // |
| 3462 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3463 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3464 | * Make sure the caller is the calling package itself |
| 3465 | * |
| 3466 | * @throws SecurityException if the caller is not the calling package |
| 3467 | */ |
| 3468 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3469 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3470 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3471 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3472 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3473 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3474 | } catch (PackageManager.NameNotFoundException e) { |
| 3475 | // packageUid is -1 |
| 3476 | } |
| 3477 | if (packageUid != callingUid) { |
| 3478 | throw new SecurityException(message + ": Package " + callingPackage |
| 3479 | + " does not belong to " + callingUid); |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3484 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3485 | * |
| 3486 | * @throws SecurityException if the caller does not have the required permission |
| 3487 | */ |
| 3488 | private void enforceModifyPermission() { |
| 3489 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3490 | } |
| 3491 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3492 | private void enforceActiveEmergencySessionPermission() { |
| 3493 | mApp.enforceCallingOrSelfPermission( |
| 3494 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3495 | } |
| 3496 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3497 | /** |
| 3498 | * Make sure the caller has the CALL_PHONE permission. |
| 3499 | * |
| 3500 | * @throws SecurityException if the caller does not have the required permission |
| 3501 | */ |
| 3502 | private void enforceCallPermission() { |
| 3503 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3504 | } |
| 3505 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3506 | private void enforceSettingsPermission() { |
| 3507 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3510 | private void enforceRebootPermission() { |
| 3511 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3512 | } |
| 3513 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | private String createTelUrl(String number) { |
| 3515 | if (TextUtils.isEmpty(number)) { |
| 3516 | return null; |
| 3517 | } |
| 3518 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3519 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3522 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3523 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3524 | } |
| 3525 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3526 | private static void logv(String msg) { |
| 3527 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3528 | } |
| 3529 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3530 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3531 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3532 | } |
| 3533 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3534 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3535 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3536 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3539 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3540 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3541 | final long identity = Binder.clearCallingIdentity(); |
| 3542 | try { |
| 3543 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3544 | if (phone == null) { |
| 3545 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3546 | } else { |
| 3547 | return phone.getPhoneType(); |
| 3548 | } |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | /** |
| 3555 | * Returns the CDMA ERI icon index to display |
| 3556 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3557 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3558 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3559 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3560 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3561 | } |
| 3562 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3563 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3564 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3565 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3566 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3567 | mApp, subId, callingPackage, callingFeatureId, |
| 3568 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3569 | return -1; |
| 3570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3571 | |
| 3572 | final long identity = Binder.clearCallingIdentity(); |
| 3573 | try { |
| 3574 | final Phone phone = getPhone(subId); |
| 3575 | if (phone != null) { |
| 3576 | return phone.getCdmaEriIconIndex(); |
| 3577 | } else { |
| 3578 | return -1; |
| 3579 | } |
| 3580 | } finally { |
| 3581 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * Returns the CDMA ERI icon mode, |
| 3587 | * 0 - ON |
| 3588 | * 1 - FLASHING |
| 3589 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3590 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3591 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3592 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3593 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3594 | } |
| 3595 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3596 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3597 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3598 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3599 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3600 | mApp, subId, callingPackage, callingFeatureId, |
| 3601 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3602 | return -1; |
| 3603 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3604 | |
| 3605 | final long identity = Binder.clearCallingIdentity(); |
| 3606 | try { |
| 3607 | final Phone phone = getPhone(subId); |
| 3608 | if (phone != null) { |
| 3609 | return phone.getCdmaEriIconMode(); |
| 3610 | } else { |
| 3611 | return -1; |
| 3612 | } |
| 3613 | } finally { |
| 3614 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | /** |
| 3619 | * Returns the CDMA ERI text, |
| 3620 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3621 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3622 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3623 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3624 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3625 | } |
| 3626 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3627 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3628 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3629 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3631 | mApp, subId, callingPackage, callingFeatureId, |
| 3632 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3633 | return null; |
| 3634 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3635 | |
| 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | final Phone phone = getPhone(subId); |
| 3639 | if (phone != null) { |
| 3640 | return phone.getCdmaEriText(); |
| 3641 | } else { |
| 3642 | return null; |
| 3643 | } |
| 3644 | } finally { |
| 3645 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3650 | * Returns the CDMA MDN. |
| 3651 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3652 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3653 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3655 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3656 | |
| 3657 | final long identity = Binder.clearCallingIdentity(); |
| 3658 | try { |
| 3659 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3660 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3661 | return phone.getLine1Number(); |
| 3662 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3663 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3664 | return null; |
| 3665 | } |
| 3666 | } finally { |
| 3667 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | /** |
| 3672 | * Returns the CDMA MIN. |
| 3673 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3674 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3675 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3676 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3677 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3678 | |
| 3679 | final long identity = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | final Phone phone = getPhone(subId); |
| 3682 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3683 | return phone.getCdmaMin(); |
| 3684 | } else { |
| 3685 | return null; |
| 3686 | } |
| 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3689 | } |
| 3690 | } |
| 3691 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3692 | @Override |
| 3693 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3694 | INumberVerificationCallback callback, String callingPackage) { |
| 3695 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3696 | != PERMISSION_GRANTED) { |
| 3697 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3698 | } |
| 3699 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3700 | |
| 3701 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3702 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3703 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3704 | + "calling package: " + callingPackage |
| 3705 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | if (range == null) { |
| 3709 | throw new NullPointerException("Range must be non-null"); |
| 3710 | } |
| 3711 | |
| 3712 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3713 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3714 | |
| 3715 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3716 | } |
| 3717 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3718 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3719 | * Returns true if CDMA provisioning needs to run. |
| 3720 | */ |
| 3721 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3724 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3731 | * Sets the voice mail number of a given subId. |
| 3732 | */ |
| 3733 | @Override |
| 3734 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3736 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3737 | |
| 3738 | final long identity = Binder.clearCallingIdentity(); |
| 3739 | try { |
| 3740 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3741 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3742 | return success; |
| 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
| 3745 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3746 | } |
| 3747 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3748 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3749 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3750 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3751 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3752 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3753 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3754 | throw new SecurityException("caller must be system dialer"); |
| 3755 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3756 | |
| 3757 | final long identity = Binder.clearCallingIdentity(); |
| 3758 | try { |
| 3759 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3760 | if (phoneAccountHandle == null) { |
| 3761 | return null; |
| 3762 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3763 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3764 | } finally { |
| 3765 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3766 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3767 | } |
| 3768 | |
| 3769 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3770 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3771 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3772 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3773 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3774 | mApp, subId, callingPackage, callingFeatureId, |
| 3775 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3776 | return null; |
| 3777 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3778 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3779 | final long identity = Binder.clearCallingIdentity(); |
| 3780 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3781 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3782 | } finally { |
| 3783 | Binder.restoreCallingIdentity(identity); |
| 3784 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3785 | } |
| 3786 | |
| 3787 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3788 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3789 | VisualVoicemailSmsFilterSettings settings) { |
| 3790 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3791 | |
| 3792 | final long identity = Binder.clearCallingIdentity(); |
| 3793 | try { |
| 3794 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3795 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3796 | } finally { |
| 3797 | Binder.restoreCallingIdentity(identity); |
| 3798 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3802 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3803 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3804 | |
| 3805 | final long identity = Binder.clearCallingIdentity(); |
| 3806 | try { |
| 3807 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3808 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3809 | } finally { |
| 3810 | Binder.restoreCallingIdentity(identity); |
| 3811 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3815 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3816 | String callingPackage, int subId) { |
| 3817 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3818 | |
| 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3822 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
| 3825 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3829 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3830 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | |
| 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3835 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | } finally { |
| 3837 | Binder.restoreCallingIdentity(identity); |
| 3838 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3842 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3843 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3844 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3845 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3846 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3847 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3848 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3849 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3850 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3851 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3852 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3853 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3854 | * Sets the voice activation state of a given subId. |
| 3855 | */ |
| 3856 | @Override |
| 3857 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3859 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3860 | |
| 3861 | final long identity = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | final Phone phone = getPhone(subId); |
| 3864 | if (phone != null) { |
| 3865 | phone.setVoiceActivationState(activationState); |
| 3866 | } else { |
| 3867 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3868 | } |
| 3869 | } finally { |
| 3870 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3871 | } |
| 3872 | } |
| 3873 | |
| 3874 | /** |
| 3875 | * Sets the data activation state of a given subId. |
| 3876 | */ |
| 3877 | @Override |
| 3878 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3880 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3881 | |
| 3882 | final long identity = Binder.clearCallingIdentity(); |
| 3883 | try { |
| 3884 | final Phone phone = getPhone(subId); |
| 3885 | if (phone != null) { |
| 3886 | phone.setDataActivationState(activationState); |
| 3887 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3888 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | } |
| 3890 | } finally { |
| 3891 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | /** |
| 3896 | * Returns the voice activation state of a given subId. |
| 3897 | */ |
| 3898 | @Override |
| 3899 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3901 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3902 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3903 | final long identity = Binder.clearCallingIdentity(); |
| 3904 | try { |
| 3905 | if (phone != null) { |
| 3906 | return phone.getVoiceActivationState(); |
| 3907 | } else { |
| 3908 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3909 | } |
| 3910 | } finally { |
| 3911 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | /** |
| 3916 | * Returns the data activation state of a given subId. |
| 3917 | */ |
| 3918 | @Override |
| 3919 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3921 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3922 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3923 | final long identity = Binder.clearCallingIdentity(); |
| 3924 | try { |
| 3925 | if (phone != null) { |
| 3926 | return phone.getDataActivationState(); |
| 3927 | } else { |
| 3928 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3929 | } |
| 3930 | } finally { |
| 3931 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3936 | * Returns the unread count of voicemails for a subId |
| 3937 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3938 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3939 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3940 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3941 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3942 | mApp, subId, callingPackage, callingFeatureId, |
| 3943 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3944 | return 0; |
| 3945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3946 | final long identity = Binder.clearCallingIdentity(); |
| 3947 | try { |
| 3948 | final Phone phone = getPhone(subId); |
| 3949 | if (phone != null) { |
| 3950 | return phone.getVoiceMessageCount(); |
| 3951 | } else { |
| 3952 | return 0; |
| 3953 | } |
| 3954 | } finally { |
| 3955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3960 | * returns true, if the device is in a state where both voice and data |
| 3961 | * are supported simultaneously. This can change based on location or network condition. |
| 3962 | */ |
| 3963 | @Override |
| 3964 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3965 | final long identity = Binder.clearCallingIdentity(); |
| 3966 | try { |
| 3967 | final Phone phone = getPhone(subId); |
| 3968 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(identity); |
| 3971 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3975 | * Send the dialer code if called from the current default dialer or the caller has |
| 3976 | * carrier privilege. |
| 3977 | * @param inputCode The dialer code to send |
| 3978 | */ |
| 3979 | @Override |
| 3980 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3981 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3983 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3984 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3985 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3986 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3987 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3988 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3989 | |
| 3990 | final long identity = Binder.clearCallingIdentity(); |
| 3991 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3992 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3993 | } finally { |
| 3994 | Binder.restoreCallingIdentity(identity); |
| 3995 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3996 | } |
| 3997 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3998 | @Override |
| 3999 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4000 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4001 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4002 | mApp, subId, "getNetworkSelectionMode"); |
| 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | if (!isActiveSubscription(subId)) { |
| 4006 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4007 | } |
| 4008 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4009 | } finally { |
| 4010 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4011 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4015 | public boolean isInEmergencySmsMode() { |
| 4016 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4017 | final long identity = Binder.clearCallingIdentity(); |
| 4018 | try { |
| 4019 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4020 | if (phone.isInEmergencySmsMode()) { |
| 4021 | return true; |
| 4022 | } |
| 4023 | } |
| 4024 | } finally { |
| 4025 | Binder.restoreCallingIdentity(identity); |
| 4026 | } |
| 4027 | return false; |
| 4028 | } |
| 4029 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4030 | /** |
| 4031 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4032 | * @param subId The subscription to use to check the configuration. |
| 4033 | * @param c The callback that will be used to send the result. |
| 4034 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4035 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4036 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4037 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4038 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4039 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4040 | |
| 4041 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4042 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4043 | "IMS not available on device."); |
| 4044 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4045 | final long token = Binder.clearCallingIdentity(); |
| 4046 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4047 | int slotId = getSlotIndexOrException(subId); |
| 4048 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4049 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4050 | } catch (ImsException e) { |
| 4051 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4052 | } finally { |
| 4053 | Binder.restoreCallingIdentity(token); |
| 4054 | } |
| 4055 | } |
| 4056 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4057 | /** |
| 4058 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4059 | * @param subId The subscription to use to check the configuration. |
| 4060 | * @param c The callback that will be used to send the result. |
| 4061 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4062 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4063 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4064 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4065 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4066 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4067 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4068 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4069 | final long token = Binder.clearCallingIdentity(); |
| 4070 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4071 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4072 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4073 | } catch (ImsException e) { |
| 4074 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4075 | + "is inactive, ignoring unregister."); |
| 4076 | // If the subscription is no longer active, just return, since the callback |
| 4077 | // will already have been removed internally. |
| 4078 | } finally { |
| 4079 | Binder.restoreCallingIdentity(token); |
| 4080 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4083 | /** |
| 4084 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4085 | */ |
| 4086 | @Override |
| 4087 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4088 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4089 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4090 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4091 | "IMS not available on device."); |
| 4092 | } |
| 4093 | final long token = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | Phone phone = getPhone(subId); |
| 4096 | if (phone == null) { |
| 4097 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4098 | + subId + "'"); |
| 4099 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4100 | } |
| 4101 | phone.getImsRegistrationState(regState -> { |
| 4102 | try { |
| 4103 | consumer.accept((regState == null) |
| 4104 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4105 | } catch (RemoteException e) { |
| 4106 | // Ignore if the remote process is no longer available to call back. |
| 4107 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4108 | } |
| 4109 | }); |
| 4110 | } finally { |
| 4111 | Binder.restoreCallingIdentity(token); |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | /** |
| 4116 | * Get the transport type for the IMS service registration state. |
| 4117 | */ |
| 4118 | @Override |
| 4119 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4120 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4121 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4122 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4123 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4124 | "IMS not available on device."); |
| 4125 | } |
| 4126 | final long token = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | Phone phone = getPhone(subId); |
| 4129 | if (phone == null) { |
| 4130 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4131 | + subId + "'"); |
| 4132 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4133 | } |
| 4134 | phone.getImsRegistrationTech(regTech -> { |
| 4135 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4136 | int regTechConverted = (regTech == null) |
| 4137 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4138 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4139 | regTechConverted); |
| 4140 | try { |
| 4141 | consumer.accept(regTechConverted); |
| 4142 | } catch (RemoteException e) { |
| 4143 | // Ignore if the remote process is no longer available to call back. |
| 4144 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4145 | } |
| 4146 | }); |
| 4147 | } finally { |
| 4148 | Binder.restoreCallingIdentity(token); |
| 4149 | } |
| 4150 | } |
| 4151 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4152 | /** |
| 4153 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4154 | * @param subId The subscription to use to check the configuration. |
| 4155 | * @param c The callback that will be used to send the result. |
| 4156 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4157 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4158 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4159 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4160 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4161 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4162 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4163 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4164 | "IMS not available on device."); |
| 4165 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4166 | final long token = Binder.clearCallingIdentity(); |
| 4167 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4168 | int slotId = getSlotIndexOrException(subId); |
| 4169 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4170 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4171 | } catch (ImsException e) { |
| 4172 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4173 | } finally { |
| 4174 | Binder.restoreCallingIdentity(token); |
| 4175 | } |
| 4176 | } |
| 4177 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4178 | /** |
| 4179 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4180 | * @param subId The subscription to use to check the configuration. |
| 4181 | * @param c The callback that will be used to send the result. |
| 4182 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4183 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4184 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4185 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4186 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4187 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4188 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4189 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4190 | |
| 4191 | final long token = Binder.clearCallingIdentity(); |
| 4192 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4193 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4194 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4195 | } catch (ImsException e) { |
| 4196 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4197 | + "is inactive, ignoring unregister."); |
| 4198 | // If the subscription is no longer active, just return, since the callback |
| 4199 | // will already have been removed internally. |
| 4200 | } finally { |
| 4201 | Binder.restoreCallingIdentity(token); |
| 4202 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4203 | } |
| 4204 | |
| 4205 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4206 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4207 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | final long token = Binder.clearCallingIdentity(); |
| 4209 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4210 | int slotId = getSlotIndexOrException(subId); |
| 4211 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4212 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4213 | } catch (com.android.ims.ImsException e) { |
| 4214 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4215 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4216 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4217 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4218 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4219 | } finally { |
| 4220 | Binder.restoreCallingIdentity(token); |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4225 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4226 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4227 | final long token = Binder.clearCallingIdentity(); |
| 4228 | try { |
| 4229 | Phone phone = getPhone(subId); |
| 4230 | if (phone == null) return false; |
| 4231 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4232 | } catch (com.android.ims.ImsException e) { |
| 4233 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4234 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4235 | } finally { |
| 4236 | Binder.restoreCallingIdentity(token); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4240 | /** |
| 4241 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4242 | * subscription. |
| 4243 | * @param subId The subscription to use to check the configuration. |
| 4244 | * @param callback The callback that will be used to send the result. |
| 4245 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4246 | * @param transportType The transport type of the MmTelFeature capability. |
| 4247 | */ |
| 4248 | @Override |
| 4249 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4250 | int transportType) { |
| 4251 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4252 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4253 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4254 | "IMS not available on device."); |
| 4255 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4256 | final long token = Binder.clearCallingIdentity(); |
| 4257 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4258 | int slotId = getSlotIndex(subId); |
| 4259 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4260 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4261 | + subId + "'"); |
| 4262 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4263 | } |
| 4264 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4265 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4266 | transportType, aBoolean -> { |
| 4267 | try { |
| 4268 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4269 | } catch (RemoteException e) { |
| 4270 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4271 | + "running. Ignore"); |
| 4272 | } |
| 4273 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4274 | } catch (ImsException e) { |
| 4275 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4276 | } finally { |
| 4277 | Binder.restoreCallingIdentity(token); |
| 4278 | } |
| 4279 | } |
| 4280 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4281 | /** |
| 4282 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4283 | * @param subId The subscription to use to check the configuration. |
| 4284 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4285 | @Override |
| 4286 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4287 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4288 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4289 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4290 | final long token = Binder.clearCallingIdentity(); |
| 4291 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4292 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4293 | // 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] | 4294 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4295 | } catch (ImsException e) { |
| 4296 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(token); |
| 4299 | } |
| 4300 | } |
| 4301 | |
| 4302 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4303 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4305 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4306 | final long identity = Binder.clearCallingIdentity(); |
| 4307 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4308 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4309 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4310 | // 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] | 4311 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4312 | } catch (ImsException e) { |
| 4313 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
| 4317 | } |
| 4318 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4319 | /** |
| 4320 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4321 | * @param subId The subscription to use to check the configuration. |
| 4322 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4323 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4324 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4325 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4326 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4327 | final long identity = Binder.clearCallingIdentity(); |
| 4328 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4329 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4330 | // 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] | 4331 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4332 | } catch (ImsException e) { |
| 4333 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(identity); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4340 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4342 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4343 | final long identity = Binder.clearCallingIdentity(); |
| 4344 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4345 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4346 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4347 | // 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] | 4348 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4349 | } catch (ImsException e) { |
| 4350 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(identity); |
| 4353 | } |
| 4354 | } |
| 4355 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4356 | /** |
| 4357 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4358 | * @param subId The subscription to use to check the configuration. |
| 4359 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | @Override |
| 4361 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4362 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4363 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4364 | final long identity = Binder.clearCallingIdentity(); |
| 4365 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4366 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4367 | // 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] | 4368 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4369 | } catch (ImsException e) { |
| 4370 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4377 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4379 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4382 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4383 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4384 | // 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] | 4385 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4386 | } catch (ImsException e) { |
| 4387 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
| 4390 | } |
| 4391 | } |
| 4392 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4393 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4394 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4395 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4396 | * @param subId The subscription to use to check the configuration. |
| 4397 | */ |
| 4398 | @Override |
| 4399 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4400 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4401 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4404 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4405 | // 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] | 4406 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4407 | } catch (ImsException e) { |
| 4408 | throw new ServiceSpecificException(e.getCode()); |
| 4409 | } finally { |
| 4410 | Binder.restoreCallingIdentity(identity); |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | /** |
| 4415 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4416 | * Requires MODIFY_PHONE_STATE permission. |
| 4417 | * @param subId The subscription to use to check the configuration. |
| 4418 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4419 | * false otherwise |
| 4420 | */ |
| 4421 | @Override |
| 4422 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4423 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4424 | "setCrossSimCallingEnabled"); |
| 4425 | final long identity = Binder.clearCallingIdentity(); |
| 4426 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4427 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4428 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4429 | // 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] | 4430 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4431 | } catch (ImsException e) { |
| 4432 | throw new ServiceSpecificException(e.getCode()); |
| 4433 | } finally { |
| 4434 | Binder.restoreCallingIdentity(identity); |
| 4435 | } |
| 4436 | } |
| 4437 | |
| 4438 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4439 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4440 | * @param subId The subscription to use to check the configuration. |
| 4441 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4443 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4444 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4445 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4446 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4447 | final long identity = Binder.clearCallingIdentity(); |
| 4448 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4449 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4450 | // 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] | 4451 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4452 | } catch (ImsException e) { |
| 4453 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(identity); |
| 4456 | } |
| 4457 | } |
| 4458 | |
| 4459 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4460 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4461 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4462 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4463 | final long identity = Binder.clearCallingIdentity(); |
| 4464 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4465 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4466 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4467 | // 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] | 4468 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4469 | } catch (ImsException e) { |
| 4470 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4471 | } finally { |
| 4472 | Binder.restoreCallingIdentity(identity); |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | @Override |
| 4477 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4479 | "setVoWiFiNonPersistent"); |
| 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4482 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4483 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4484 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4485 | } catch (ImsException e) { |
| 4486 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
| 4490 | } |
| 4491 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4492 | /** |
| 4493 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4494 | * @param subId The subscription to use to check the configuration. |
| 4495 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4496 | @Override |
| 4497 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4498 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4499 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | final long identity = Binder.clearCallingIdentity(); |
| 4501 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4502 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4503 | // 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] | 4504 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4505 | } catch (ImsException e) { |
| 4506 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4507 | } finally { |
| 4508 | Binder.restoreCallingIdentity(identity); |
| 4509 | } |
| 4510 | } |
| 4511 | |
| 4512 | @Override |
| 4513 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4514 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4515 | "setVoWiFiModeSetting"); |
| 4516 | final long identity = Binder.clearCallingIdentity(); |
| 4517 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4518 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4519 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4520 | // 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] | 4521 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4522 | } catch (ImsException e) { |
| 4523 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | @Override |
| 4530 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4531 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4532 | final long identity = Binder.clearCallingIdentity(); |
| 4533 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4534 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4535 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4536 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4537 | } catch (ImsException e) { |
| 4538 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4539 | } finally { |
| 4540 | Binder.restoreCallingIdentity(identity); |
| 4541 | } |
| 4542 | } |
| 4543 | |
| 4544 | @Override |
| 4545 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4547 | "setVoWiFiRoamingModeSetting"); |
| 4548 | final long identity = Binder.clearCallingIdentity(); |
| 4549 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4550 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4551 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4552 | // 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] | 4553 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4554 | } catch (ImsException e) { |
| 4555 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4556 | } finally { |
| 4557 | Binder.restoreCallingIdentity(identity); |
| 4558 | } |
| 4559 | } |
| 4560 | |
| 4561 | @Override |
| 4562 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4564 | "setRttCapabilityEnabled"); |
| 4565 | final long identity = Binder.clearCallingIdentity(); |
| 4566 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4567 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4568 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4569 | // 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] | 4570 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4571 | } catch (ImsException e) { |
| 4572 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
| 4575 | } |
| 4576 | } |
| 4577 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4578 | /** |
| 4579 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4580 | * @param subId The subscription to use to check the configuration. |
| 4581 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | @Override |
| 4583 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4584 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4585 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | final long identity = Binder.clearCallingIdentity(); |
| 4587 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4588 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4589 | // 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] | 4590 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4591 | } catch (ImsException e) { |
| 4592 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4593 | } finally { |
| 4594 | Binder.restoreCallingIdentity(identity); |
| 4595 | } |
| 4596 | } |
| 4597 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4598 | @Override |
| 4599 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4600 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4601 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4602 | final long identity = Binder.clearCallingIdentity(); |
| 4603 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4604 | if (!isImsAvailableOnDevice()) { |
| 4605 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4606 | "IMS not available on device."); |
| 4607 | } |
| 4608 | int slotId = getSlotIndexOrException(subId); |
| 4609 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4610 | ImsManager.getInstance(mApp, slotId) |
| 4611 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4612 | } catch (ImsException e) { |
| 4613 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
| 4620 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4621 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4622 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4623 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4624 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4625 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4626 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4627 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4628 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4629 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4630 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4631 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4632 | + "is inactive, ignoring unregister."); |
| 4633 | // If the subscription is no longer active, just return, since the callback will already |
| 4634 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
| 4637 | } |
| 4638 | } |
| 4639 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4640 | @Override |
| 4641 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4642 | IFeatureProvisioningCallback callback) { |
| 4643 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4644 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4645 | |
| 4646 | final long identity = Binder.clearCallingIdentity(); |
| 4647 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4648 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4649 | } |
| 4650 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4651 | try { |
| 4652 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4653 | if (controller == null) { |
| 4654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4655 | "Device does not support IMS"); |
| 4656 | } |
| 4657 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4658 | } finally { |
| 4659 | Binder.restoreCallingIdentity(identity); |
| 4660 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | @Override |
| 4664 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4665 | IFeatureProvisioningCallback callback) { |
| 4666 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4667 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4668 | |
| 4669 | final long identity = Binder.clearCallingIdentity(); |
| 4670 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4671 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4672 | } |
| 4673 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4674 | try { |
| 4675 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4676 | if (controller == null) { |
| 4677 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4678 | return; |
| 4679 | } |
| 4680 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4681 | } finally { |
| 4682 | Binder.restoreCallingIdentity(identity); |
| 4683 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4684 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4685 | |
| 4686 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4687 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4688 | message); |
| 4689 | } |
| 4690 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4691 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4692 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4693 | boolean isProvisioned) { |
| 4694 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4695 | |
| 4696 | final long identity = Binder.clearCallingIdentity(); |
| 4697 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4698 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4699 | if (controller == null) { |
| 4700 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4701 | return; |
| 4702 | } |
| 4703 | controller.setRcsProvisioningStatusForCapability( |
| 4704 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
| 4707 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | |
| 4711 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4712 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4713 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4714 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4715 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4716 | final long identity = Binder.clearCallingIdentity(); |
| 4717 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4718 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4719 | if (controller == null) { |
| 4720 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4721 | |
| 4722 | // device does not support IMS, this method will return true always. |
| 4723 | return true; |
| 4724 | } |
| 4725 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4726 | } finally { |
| 4727 | Binder.restoreCallingIdentity(identity); |
| 4728 | } |
| 4729 | } |
| 4730 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4731 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4732 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4733 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4734 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4735 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4736 | final long identity = Binder.clearCallingIdentity(); |
| 4737 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4738 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4739 | if (controller == null) { |
| 4740 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4741 | return; |
| 4742 | } |
| 4743 | controller.setImsProvisioningStatusForCapability( |
| 4744 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
| 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | @Override |
| 4751 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4752 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4753 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4754 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4755 | final long identity = Binder.clearCallingIdentity(); |
| 4756 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4757 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4758 | if (controller == null) { |
| 4759 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4760 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4761 | // device does not support IMS, this method will return true always. |
| 4762 | return true; |
| 4763 | } |
| 4764 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4765 | } finally { |
| 4766 | Binder.restoreCallingIdentity(identity); |
| 4767 | } |
| 4768 | } |
| 4769 | |
| 4770 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4771 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4772 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4773 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4774 | |
| 4775 | final long identity = Binder.clearCallingIdentity(); |
| 4776 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4777 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4778 | if (controller == null) { |
| 4779 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4780 | |
| 4781 | // device does not support IMS, this method will return false |
| 4782 | return false; |
| 4783 | } |
| 4784 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4785 | } finally { |
| 4786 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4787 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4788 | } |
| 4789 | |
| 4790 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4791 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4792 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4793 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4794 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4795 | final long identity = Binder.clearCallingIdentity(); |
| 4796 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4797 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4798 | if (controller == null) { |
| 4799 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4800 | |
| 4801 | // device does not support IMS, this method will return false |
| 4802 | return false; |
| 4803 | } |
| 4804 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4805 | } finally { |
| 4806 | Binder.restoreCallingIdentity(identity); |
| 4807 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4808 | } |
| 4809 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4810 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4811 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4812 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4813 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4814 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4815 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4816 | mApp, subId, "getImsProvisioningInt"); |
| 4817 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4818 | final long identity = Binder.clearCallingIdentity(); |
| 4819 | try { |
| 4820 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4821 | int slotId = getSlotIndex(subId); |
| 4822 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4823 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4824 | + subId + "' for key:" + key); |
| 4825 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4826 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4827 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4828 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4829 | if (controller == null) { |
| 4830 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4831 | |
| 4832 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4833 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4834 | } |
| 4835 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4836 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4837 | return retVal; |
| 4838 | } |
| 4839 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4840 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4841 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4842 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4843 | + subId + "' for key:" + key); |
| 4844 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4845 | } finally { |
| 4846 | Binder.restoreCallingIdentity(identity); |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | @Override |
| 4851 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4852 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4853 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4854 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4855 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4856 | mApp, subId, "getImsProvisioningString"); |
| 4857 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4858 | final long identity = Binder.clearCallingIdentity(); |
| 4859 | try { |
| 4860 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4861 | int slotId = getSlotIndex(subId); |
| 4862 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4863 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4864 | + subId + "' for key:" + key); |
| 4865 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4866 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4867 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4868 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4869 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4870 | + subId + "' for key:" + key); |
| 4871 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4872 | } finally { |
| 4873 | Binder.restoreCallingIdentity(identity); |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | @Override |
| 4878 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4879 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4880 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4881 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4883 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4884 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4885 | final long identity = Binder.clearCallingIdentity(); |
| 4886 | try { |
| 4887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4888 | int slotId = getSlotIndex(subId); |
| 4889 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4890 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4891 | + subId + "' for key:" + key); |
| 4892 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4893 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4894 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4895 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4896 | if (controller == null) { |
| 4897 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 4898 | |
| 4899 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 4900 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4901 | } |
| 4902 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4903 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4904 | return retVal; |
| 4905 | } |
| 4906 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4907 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4908 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4909 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4910 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4911 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4912 | } finally { |
| 4913 | Binder.restoreCallingIdentity(identity); |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | @Override |
| 4918 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4919 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4920 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4921 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4922 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4923 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
| 4926 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4927 | int slotId = getSlotIndex(subId); |
| 4928 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4929 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4930 | + subId + "' for key:" + key); |
| 4931 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4932 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4933 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4934 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4935 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4936 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4937 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4938 | } finally { |
| 4939 | Binder.restoreCallingIdentity(identity); |
| 4940 | } |
| 4941 | } |
| 4942 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4943 | /** |
| 4944 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4945 | * for the given slot ID or no ImsResolver instance has been created. |
| 4946 | * @param slotId The slot ID that the IMS service is created for. |
| 4947 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4948 | */ |
| 4949 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4950 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4951 | ImsFeature.FEATURE_MMTEL)) { |
| 4952 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4953 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4954 | } |
| 4955 | } |
| 4956 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4957 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4958 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4959 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4960 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4961 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4962 | } |
| 4963 | return slotId; |
| 4964 | } |
| 4965 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4966 | private int getSlotIndex(int subId) { |
| 4967 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4968 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4969 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4970 | } |
| 4971 | return slotId; |
| 4972 | } |
| 4973 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4974 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4975 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4976 | */ |
| 4977 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4978 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4979 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4980 | try { |
| 4981 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4982 | } catch (SecurityException se) { |
| 4983 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4984 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 4985 | + Binder.getCallingUid()); |
| 4986 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4987 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4988 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4989 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4990 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4991 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4992 | mApp, subId, callingPackage, callingFeatureId, |
| 4993 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4994 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4995 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4996 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | final long identity = Binder.clearCallingIdentity(); |
| 4998 | try { |
| 4999 | final Phone phone = getPhone(subId); |
| 5000 | if (phone != null) { |
| 5001 | return phone.getServiceState().getDataNetworkType(); |
| 5002 | } else { |
| 5003 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5004 | } |
| 5005 | } finally { |
| 5006 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5007 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | /** |
| 5011 | * Returns the data network type |
| 5012 | */ |
| 5013 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5014 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5015 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5016 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5017 | } |
| 5018 | |
| 5019 | /** |
| 5020 | * Returns the data network type for a subId |
| 5021 | */ |
| 5022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5023 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5024 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5025 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5026 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5027 | mApp, functionName)) { |
| 5028 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5029 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5030 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5031 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
| 5036 | final Phone phone = getPhone(subId); |
| 5037 | if (phone != null) { |
| 5038 | return phone.getServiceState().getDataNetworkType(); |
| 5039 | } else { |
| 5040 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5041 | } |
| 5042 | } finally { |
| 5043 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5045 | } |
| 5046 | |
| 5047 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5048 | * Returns the Voice network type for a subId |
| 5049 | */ |
| 5050 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5051 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5052 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5053 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5054 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5055 | mApp, functionName)) { |
| 5056 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5057 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5058 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5059 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5062 | final long identity = Binder.clearCallingIdentity(); |
| 5063 | try { |
| 5064 | final Phone phone = getPhone(subId); |
| 5065 | if (phone != null) { |
| 5066 | return phone.getServiceState().getVoiceNetworkType(); |
| 5067 | } else { |
| 5068 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5069 | } |
| 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5072 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * @return true if a ICC card is present |
| 5077 | */ |
| 5078 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5079 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5080 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5081 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5082 | } |
| 5083 | |
| 5084 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5085 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5086 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5087 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5088 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
| 5091 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5092 | if (phone != null) { |
| 5093 | return phone.getIccCard().hasIccCard(); |
| 5094 | } else { |
| 5095 | return false; |
| 5096 | } |
| 5097 | } finally { |
| 5098 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5099 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | /** |
| 5103 | * Return if the current radio is LTE on CDMA. This |
| 5104 | * is a tri-state return value as for a period of time |
| 5105 | * the mode may be unknown. |
| 5106 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5107 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5108 | * @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] | 5109 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5110 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5111 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5112 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5113 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5114 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5117 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5118 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5119 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5120 | try { |
| 5121 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5122 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5123 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5124 | } |
| 5125 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5126 | final long identity = Binder.clearCallingIdentity(); |
| 5127 | try { |
| 5128 | final Phone phone = getPhone(subId); |
| 5129 | if (phone == null) { |
| 5130 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5131 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5132 | return TelephonyProperties.lte_on_cdma_device() |
| 5133 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | } |
| 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5137 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5140 | /** |
| 5141 | * {@hide} |
| 5142 | * Returns Default subId, 0 in the case of single standby. |
| 5143 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5144 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5145 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5148 | private int getSlotForDefaultSubscription() { |
| 5149 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5150 | } |
| 5151 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5152 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5153 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5154 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5155 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5156 | private boolean isActiveSubscription(int subId) { |
| 5157 | return mSubscriptionController.isActiveSubId(subId); |
| 5158 | } |
| 5159 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5160 | /** |
| 5161 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5162 | */ |
| 5163 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5166 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5167 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5168 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5169 | } finally { |
| 5170 | Binder.restoreCallingIdentity(identity); |
| 5171 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | /** |
| 5175 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5176 | */ |
| 5177 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | final long identity = Binder.clearCallingIdentity(); |
| 5179 | try { |
| 5180 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5181 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5182 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5183 | } finally { |
| 5184 | Binder.restoreCallingIdentity(identity); |
| 5185 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5186 | } |
| 5187 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5188 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5189 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5190 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5191 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5192 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5193 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5194 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5195 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5196 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5197 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5198 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5199 | } |
| 5200 | return PhoneFactory.getPhone(phoneId); |
| 5201 | } |
| 5202 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5203 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5204 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5205 | @NonNull IccLogicalChannelRequest request) { |
| 5206 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5207 | /*message=*/ "iccOpenLogicalChannel"); |
| 5208 | |
| 5209 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5210 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5211 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5212 | |
| 5213 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5214 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5215 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5216 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5217 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5218 | Phone phone; |
| 5219 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5220 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5221 | mApp, request.subId, message); |
| 5222 | phone = getPhoneFromSubId(request.subId); |
| 5223 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5224 | enforceModifyPermission(); |
| 5225 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5226 | } else { |
| 5227 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5228 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5229 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5233 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5234 | final long identity = Binder.clearCallingIdentity(); |
| 5235 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5236 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5238 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5239 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5240 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5241 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | loge("The calling package is not allowed to access ISD-R."); |
| 5243 | throw new SecurityException( |
| 5244 | "The calling package is not allowed to access ISD-R."); |
| 5245 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5246 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5247 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5248 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5249 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5250 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | return response; |
| 5252 | } finally { |
| 5253 | Binder.restoreCallingIdentity(identity); |
| 5254 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5255 | } |
| 5256 | |
| 5257 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5258 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5259 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5260 | /*message=*/"iccCloseLogicalChannel"); |
| 5261 | |
| 5262 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5263 | |
| 5264 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5265 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5266 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5267 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5268 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5269 | // before this feature is enabled, this API should only return false if |
| 5270 | // the operation fails instead of throwing runtime exception for |
| 5271 | // backward-compatibility. |
| 5272 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5273 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | final long identity = Binder.clearCallingIdentity(); |
| 5275 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5276 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5277 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5278 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5279 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5280 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5281 | Boolean success = false; |
| 5282 | if (result instanceof RuntimeException) { |
| 5283 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5284 | if (shouldThrowExceptionOnFailure) { |
| 5285 | throw (RuntimeException) result; |
| 5286 | } else { |
| 5287 | return false; |
| 5288 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5289 | } else if (result instanceof Boolean) { |
| 5290 | success = (Boolean) result; |
| 5291 | } else { |
| 5292 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5293 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5294 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | return success; |
| 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5298 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5302 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5303 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5305 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5306 | if (DBG) { |
| 5307 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5308 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5309 | + p3 + " data=" + data); |
| 5310 | } |
| 5311 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5312 | command, p1, p2, p3, data); |
| 5313 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5314 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5315 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5316 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5317 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5318 | enforceModifyPermission(); |
| 5319 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5320 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5321 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5322 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5323 | } |
| 5324 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5325 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5326 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5330 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5333 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | return ""; |
| 5335 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5337 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5338 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5339 | null /* workSource */); |
| 5340 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5342 | // Append the returned status code to the end of the response payload. |
| 5343 | String s = Integer.toHexString( |
| 5344 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5345 | if (response.payload != null) { |
| 5346 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5347 | } |
| 5348 | return s; |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5351 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5352 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5353 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5354 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5355 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5356 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5357 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5358 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5360 | if (DBG) { |
| 5361 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5362 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5363 | } |
| 5364 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5365 | cla, command, p1, p2, p3, data); |
| 5366 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5367 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5368 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5369 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5370 | 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] | 5371 | enforceModifyPermission(); |
| 5372 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5373 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5374 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5375 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5376 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5377 | } |
| 5378 | |
| 5379 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5380 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5381 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5385 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5386 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5387 | final long identity = Binder.clearCallingIdentity(); |
| 5388 | try { |
| 5389 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5390 | && TextUtils.equals(ISDR_AID, data)) { |
| 5391 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5392 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5393 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5394 | if (bestComponent == null |
| 5395 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5396 | loge("The calling package is not allowed to select ISD-R."); |
| 5397 | throw new SecurityException( |
| 5398 | "The calling package is not allowed to select ISD-R."); |
| 5399 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5400 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5402 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5403 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5404 | null /* workSource */); |
| 5405 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | // Append the returned status code to the end of the response payload. |
| 5408 | String s = Integer.toHexString( |
| 5409 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5410 | if (response.payload != null) { |
| 5411 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5412 | } |
| 5413 | return s; |
| 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5416 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5417 | } |
| 5418 | |
| 5419 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5420 | 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] | 5421 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5423 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5424 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5425 | final long identity = Binder.clearCallingIdentity(); |
| 5426 | try { |
| 5427 | if (DBG) { |
| 5428 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5429 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5430 | } |
| 5431 | |
| 5432 | IccIoResult response = |
| 5433 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5434 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5435 | subId); |
| 5436 | |
| 5437 | if (DBG) { |
| 5438 | log("Exchange SIM_IO [R]" + response); |
| 5439 | } |
| 5440 | |
| 5441 | byte[] result = null; |
| 5442 | int length = 2; |
| 5443 | if (response.payload != null) { |
| 5444 | length = 2 + response.payload.length; |
| 5445 | result = new byte[length]; |
| 5446 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5447 | } else { |
| 5448 | result = new byte[length]; |
| 5449 | } |
| 5450 | |
| 5451 | result[length - 1] = (byte) response.sw2; |
| 5452 | result[length - 2] = (byte) response.sw1; |
| 5453 | return result; |
| 5454 | } finally { |
| 5455 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5456 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5457 | } |
| 5458 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5459 | /** |
| 5460 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5461 | * on a particular subscription |
| 5462 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5463 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5464 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5466 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5467 | return null; |
| 5468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | |
| 5470 | final long identity = Binder.clearCallingIdentity(); |
| 5471 | try { |
| 5472 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5473 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5474 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5475 | return null; |
| 5476 | } |
| 5477 | Object response = sendRequest( |
| 5478 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5479 | if (response instanceof String[]) { |
| 5480 | return (String[]) response; |
| 5481 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5482 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5484 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5485 | } finally { |
| 5486 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5487 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5490 | /** |
| 5491 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5492 | * subscription. |
| 5493 | * |
| 5494 | * @param subId the id of the subscription. |
| 5495 | * @param appType the uicc app type, must be USIM or SIM. |
| 5496 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5497 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5498 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5499 | * @return number of fplmns that is successfully written to the SIM. |
| 5500 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5501 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5502 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5503 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5504 | mApp, subId, "setForbiddenPlmns"); |
| 5505 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5506 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5507 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5508 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5509 | } |
| 5510 | if (fplmns == null) { |
| 5511 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5512 | } |
| 5513 | for (String fplmn : fplmns) { |
| 5514 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5515 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5516 | } |
| 5517 | } |
| 5518 | final long identity = Binder.clearCallingIdentity(); |
| 5519 | try { |
| 5520 | Object response = sendRequest( |
| 5521 | CMD_SET_FORBIDDEN_PLMNS, |
| 5522 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5523 | subId); |
| 5524 | return (int) response; |
| 5525 | } finally { |
| 5526 | Binder.restoreCallingIdentity(identity); |
| 5527 | } |
| 5528 | } |
| 5529 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5530 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5531 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5532 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5533 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5534 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5535 | final long identity = Binder.clearCallingIdentity(); |
| 5536 | try { |
| 5537 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5538 | if (response.payload == null) { |
| 5539 | return ""; |
| 5540 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5541 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | // Append the returned status code to the end of the response payload. |
| 5543 | String s = Integer.toHexString( |
| 5544 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5545 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5546 | return s; |
| 5547 | } finally { |
| 5548 | Binder.restoreCallingIdentity(identity); |
| 5549 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5550 | } |
| 5551 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5552 | /** |
| 5553 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5554 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5555 | * |
| 5556 | * @param itemID the ID of the item to read |
| 5557 | * @return the NV item as a String, or null on error. |
| 5558 | */ |
| 5559 | @Override |
| 5560 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5561 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5562 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5563 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5564 | |
| 5565 | final long identity = Binder.clearCallingIdentity(); |
| 5566 | try { |
| 5567 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5568 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5570 | return value; |
| 5571 | } finally { |
| 5572 | Binder.restoreCallingIdentity(identity); |
| 5573 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5574 | } |
| 5575 | |
| 5576 | /** |
| 5577 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5578 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5579 | * |
| 5580 | * @param itemID the ID of the item to read |
| 5581 | * @param itemValue the value to write, as a String |
| 5582 | * @return true on success; false on any failure |
| 5583 | */ |
| 5584 | @Override |
| 5585 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5586 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5588 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | |
| 5590 | final long identity = Binder.clearCallingIdentity(); |
| 5591 | try { |
| 5592 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5593 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5594 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5595 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5596 | return success; |
| 5597 | } finally { |
| 5598 | Binder.restoreCallingIdentity(identity); |
| 5599 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | /** |
| 5603 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5604 | * Used for device configuration by some CDMA operators. |
| 5605 | * |
| 5606 | * @param preferredRoamingList byte array containing the new PRL |
| 5607 | * @return true on success; false on any failure |
| 5608 | */ |
| 5609 | @Override |
| 5610 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5612 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | |
| 5614 | final long identity = Binder.clearCallingIdentity(); |
| 5615 | try { |
| 5616 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5617 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5618 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5619 | return success; |
| 5620 | } finally { |
| 5621 | Binder.restoreCallingIdentity(identity); |
| 5622 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5626 | * 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] | 5627 | * Used for device configuration by some CDMA operators. |
| 5628 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5629 | * @param slotIndex - device slot. |
| 5630 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5631 | * @return true on success; false on any failure |
| 5632 | */ |
| 5633 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5634 | public boolean resetModemConfig(int slotIndex) { |
| 5635 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5636 | if (phone != null) { |
| 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5643 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5644 | return success; |
| 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(identity); |
| 5647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5648 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5649 | return false; |
| 5650 | } |
| 5651 | |
| 5652 | /** |
| 5653 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5654 | * |
| 5655 | * @param slotIndex - device slot. |
| 5656 | * |
| 5657 | * @return true on success; false on any failure |
| 5658 | */ |
| 5659 | @Override |
| 5660 | public boolean rebootModem(int slotIndex) { |
| 5661 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5662 | if (phone != null) { |
| 5663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5664 | mApp, phone.getSubId(), "rebootModem"); |
| 5665 | |
| 5666 | final long identity = Binder.clearCallingIdentity(); |
| 5667 | try { |
| 5668 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5669 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5670 | return success; |
| 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
| 5674 | } |
| 5675 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5676 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5677 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5678 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5679 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5680 | * {@link #disableIms(int)}. |
| 5681 | * @param slotIndex device slot. |
| 5682 | */ |
| 5683 | public void resetIms(int slotIndex) { |
| 5684 | enforceModifyPermission(); |
| 5685 | |
| 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
| 5688 | if (mImsResolver == null) { |
| 5689 | // may happen if the does not support IMS. |
| 5690 | return; |
| 5691 | } |
| 5692 | mImsResolver.disableIms(slotIndex); |
| 5693 | mImsResolver.enableIms(slotIndex); |
| 5694 | } finally { |
| 5695 | Binder.restoreCallingIdentity(identity); |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5700 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5701 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5702 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5703 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5704 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5705 | |
| 5706 | final long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5708 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5709 | // may happen if the device does not support IMS. |
| 5710 | return; |
| 5711 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5712 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5713 | } finally { |
| 5714 | Binder.restoreCallingIdentity(identity); |
| 5715 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5716 | } |
| 5717 | |
| 5718 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5719 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5720 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5721 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5722 | public void disableIms(int slotId) { |
| 5723 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | |
| 5725 | final long identity = Binder.clearCallingIdentity(); |
| 5726 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5727 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5728 | // may happen if the device does not support IMS. |
| 5729 | return; |
| 5730 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5731 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
| 5734 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5738 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5739 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5740 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5741 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5742 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | |
| 5745 | final long identity = Binder.clearCallingIdentity(); |
| 5746 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5747 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5748 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5749 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5750 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5751 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
| 5754 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5755 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5756 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5757 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5758 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5759 | @Override |
| 5760 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5761 | enforceModifyPermission(); |
| 5762 | |
| 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
| 5765 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5766 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5767 | } finally { |
| 5768 | Binder.restoreCallingIdentity(identity); |
| 5769 | } |
| 5770 | } |
| 5771 | |
| 5772 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5773 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5774 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5775 | */ |
| 5776 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5777 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5778 | |
| 5779 | final long identity = Binder.clearCallingIdentity(); |
| 5780 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5781 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5782 | // may happen if the device does not support IMS. |
| 5783 | return null; |
| 5784 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5785 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | } finally { |
| 5787 | Binder.restoreCallingIdentity(identity); |
| 5788 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5791 | /** |
| 5792 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5793 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5794 | */ |
| 5795 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5796 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | |
| 5798 | final long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5800 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5801 | // may happen if the device does not support IMS. |
| 5802 | return null; |
| 5803 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5804 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5805 | } finally { |
| 5806 | Binder.restoreCallingIdentity(identity); |
| 5807 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5808 | } |
| 5809 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5810 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5811 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5812 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5813 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5814 | * @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] | 5815 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5816 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5817 | * @param packageName The name of the package that the current configuration will be replaced |
| 5818 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5819 | * @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] | 5820 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5821 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5822 | int[] featureTypes, String packageName) { |
| 5823 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5824 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5825 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5826 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5827 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5829 | final long identity = Binder.clearCallingIdentity(); |
| 5830 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5831 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5832 | // may happen if the device does not support IMS. |
| 5833 | return false; |
| 5834 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5835 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5836 | for (int featureType : featureTypes) { |
| 5837 | featureConfig.put(featureType, packageName); |
| 5838 | } |
| 5839 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5840 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5841 | } finally { |
| 5842 | Binder.restoreCallingIdentity(identity); |
| 5843 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
| 5846 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5847 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5848 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5849 | * |
| 5850 | * This should only be used for testing. |
| 5851 | * |
| 5852 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5853 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5854 | */ |
| 5855 | @Override |
| 5856 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5857 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5858 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5859 | "clearCarrierImsServiceOverride"); |
| 5860 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5861 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5862 | "clearCarrierImsServiceOverride"); |
| 5863 | |
| 5864 | final long identity = Binder.clearCallingIdentity(); |
| 5865 | try { |
| 5866 | if (mImsResolver == null) { |
| 5867 | // may happen if the device does not support IMS. |
| 5868 | return false; |
| 5869 | } |
| 5870 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5871 | } finally { |
| 5872 | Binder.restoreCallingIdentity(identity); |
| 5873 | } |
| 5874 | } |
| 5875 | |
| 5876 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5878 | * |
| 5879 | * @param slotId The slot that the ImsService is associated with. |
| 5880 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5881 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5882 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5883 | * @return the package name of the ImsService configuration. |
| 5884 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5885 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5886 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5887 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5888 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5889 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5890 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5891 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5892 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | final long identity = Binder.clearCallingIdentity(); |
| 5894 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5895 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5896 | // may happen if the device does not support IMS. |
| 5897 | return ""; |
| 5898 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5899 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5900 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5901 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5902 | } finally { |
| 5903 | Binder.restoreCallingIdentity(identity); |
| 5904 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5907 | /** |
| 5908 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5909 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5910 | * @param callback A callback with an integer containing the |
| 5911 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5912 | */ |
| 5913 | @Override |
| 5914 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5915 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5916 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5917 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5918 | "IMS not available on device."); |
| 5919 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5920 | final long token = Binder.clearCallingIdentity(); |
| 5921 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5922 | int slotId = getSlotIndex(subId); |
| 5923 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5924 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5925 | + subId + "'"); |
| 5926 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5927 | } |
| 5928 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5929 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5930 | try { |
| 5931 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5932 | } catch (RemoteException e) { |
| 5933 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5934 | + "Ignore"); |
| 5935 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5936 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5937 | } catch (ImsException e) { |
| 5938 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(token); |
| 5941 | } |
| 5942 | } |
| 5943 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5944 | /** |
| 5945 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5946 | */ |
| 5947 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5948 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | |
| 5950 | final long identity = Binder.clearCallingIdentity(); |
| 5951 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5952 | // NOTE: Before S, this method only set the default phone. |
| 5953 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5954 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5955 | phone.setImsRegistrationState(registered); |
| 5956 | } |
| 5957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | } finally { |
| 5959 | Binder.restoreCallingIdentity(identity); |
| 5960 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5961 | } |
| 5962 | |
| 5963 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5964 | * Set the network selection mode to automatic. |
| 5965 | * |
| 5966 | */ |
| 5967 | @Override |
| 5968 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5970 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | |
| 5972 | final long identity = Binder.clearCallingIdentity(); |
| 5973 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5974 | if (!isActiveSubscription(subId)) { |
| 5975 | return; |
| 5976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5978 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5979 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5980 | } finally { |
| 5981 | Binder.restoreCallingIdentity(identity); |
| 5982 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5983 | } |
| 5984 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5985 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5986 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5987 | * |
| 5988 | * @param subId the id of the subscription. |
| 5989 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5990 | * the operator to attach to. |
| 5991 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5992 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5993 | * normal network selection next time. |
| 5994 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5995 | */ |
| 5996 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5997 | public boolean setNetworkSelectionModeManual( |
| 5998 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6000 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6001 | |
| 6002 | if (!isActiveSubscription(subId)) { |
| 6003 | return false; |
| 6004 | } |
| 6005 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | final long identity = Binder.clearCallingIdentity(); |
| 6007 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6008 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6009 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6010 | if (DBG) { |
| 6011 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6012 | + " operator: " + operatorInfo); |
| 6013 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6015 | } finally { |
| 6016 | Binder.restoreCallingIdentity(identity); |
| 6017 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6018 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6019 | /** |
| 6020 | * Get the manual network selection |
| 6021 | * |
| 6022 | * @param subId the id of the subscription. |
| 6023 | * |
| 6024 | * @return the previously saved user selected PLMN |
| 6025 | */ |
| 6026 | @Override |
| 6027 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6028 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6029 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6030 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6031 | |
| 6032 | final long identity = Binder.clearCallingIdentity(); |
| 6033 | try { |
| 6034 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6035 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | final Phone phone = getPhone(subId); |
| 6039 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6040 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6041 | } |
| 6042 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6043 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6044 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6045 | } finally { |
| 6046 | Binder.restoreCallingIdentity(identity); |
| 6047 | } |
| 6048 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6049 | |
| 6050 | /** |
| 6051 | * Scans for available networks. |
| 6052 | */ |
| 6053 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6054 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6055 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6056 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6057 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6058 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6059 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6060 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6061 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6062 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6063 | .setCallingPid(Binder.getCallingPid()) |
| 6064 | .setCallingUid(Binder.getCallingUid()) |
| 6065 | .setMethod("getCellNetworkScanResults") |
| 6066 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6067 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6068 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6069 | .build()); |
| 6070 | switch (locationResult) { |
| 6071 | case DENIED_HARD: |
| 6072 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6073 | case DENIED_SOFT: |
| 6074 | return null; |
| 6075 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6077 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6078 | try { |
| 6079 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6080 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
| 6084 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6088 | * Get the call forwarding info, given the call forwarding reason. |
| 6089 | */ |
| 6090 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6091 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6092 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6093 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6094 | long identity = Binder.clearCallingIdentity(); |
| 6095 | try { |
| 6096 | if (DBG) { |
| 6097 | log("getCallForwarding: subId " + subId |
| 6098 | + " callForwardingReason" + callForwardingReason); |
| 6099 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6100 | |
| 6101 | Phone phone = getPhone(subId); |
| 6102 | if (phone == null) { |
| 6103 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6104 | callback.onError( |
| 6105 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6106 | } catch (RemoteException e) { |
| 6107 | // ignore |
| 6108 | } |
| 6109 | return; |
| 6110 | } |
| 6111 | |
| 6112 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6113 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6114 | @Override |
| 6115 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6116 | try { |
| 6117 | callback.onCallForwardingInfoAvailable(info); |
| 6118 | } catch (RemoteException e) { |
| 6119 | // ignore |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | @Override |
| 6124 | public void onError(int error) { |
| 6125 | try { |
| 6126 | callback.onError(error); |
| 6127 | } catch (RemoteException e) { |
| 6128 | // ignore |
| 6129 | } |
| 6130 | } |
| 6131 | }); |
| 6132 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6133 | } finally { |
| 6134 | Binder.restoreCallingIdentity(identity); |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | /** |
| 6139 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6140 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6141 | */ |
| 6142 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6143 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6144 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6145 | enforceModifyPermission(); |
| 6146 | long identity = Binder.clearCallingIdentity(); |
| 6147 | try { |
| 6148 | if (DBG) { |
| 6149 | log("setCallForwarding: subId " + subId |
| 6150 | + " callForwardingInfo" + callForwardingInfo); |
| 6151 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6152 | |
| 6153 | Phone phone = getPhone(subId); |
| 6154 | if (phone == null) { |
| 6155 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6156 | callback.accept( |
| 6157 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6158 | } catch (RemoteException e) { |
| 6159 | // ignore |
| 6160 | } |
| 6161 | return; |
| 6162 | } |
| 6163 | |
| 6164 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6165 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6166 | |
| 6167 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6168 | } finally { |
| 6169 | Binder.restoreCallingIdentity(identity); |
| 6170 | } |
| 6171 | } |
| 6172 | |
| 6173 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6174 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6175 | */ |
| 6176 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6177 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6178 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6179 | long identity = Binder.clearCallingIdentity(); |
| 6180 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6181 | Phone phone = getPhone(subId); |
| 6182 | if (phone == null) { |
| 6183 | try { |
| 6184 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6185 | } catch (RemoteException e) { |
| 6186 | // ignore |
| 6187 | } |
| 6188 | return; |
| 6189 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6190 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6191 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6192 | boolean requireUssd = c.getBoolean( |
| 6193 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6194 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6195 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6196 | if (requireUssd) { |
| 6197 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6198 | getSubscriptionCarrierId(subId)); |
| 6199 | String newUssdCommand = ""; |
| 6200 | try { |
| 6201 | newUssdCommand = carrierXmlParser.getFeature( |
| 6202 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6203 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6204 | } catch (NullPointerException e) { |
| 6205 | loge("Failed to generate USSD number" + e); |
| 6206 | } |
| 6207 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6208 | mMainThreadHandler, callback, carrierXmlParser, |
| 6209 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6210 | final String ussdCommand = newUssdCommand; |
| 6211 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6212 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6213 | }); |
| 6214 | } else { |
| 6215 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6216 | callback::accept); |
| 6217 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6218 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
| 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6225 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6226 | */ |
| 6227 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6228 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6229 | enforceModifyPermission(); |
| 6230 | long identity = Binder.clearCallingIdentity(); |
| 6231 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6232 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6233 | |
| 6234 | Phone phone = getPhone(subId); |
| 6235 | if (phone == null) { |
| 6236 | try { |
| 6237 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6238 | } catch (RemoteException e) { |
| 6239 | // ignore |
| 6240 | } |
| 6241 | return; |
| 6242 | } |
| 6243 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6244 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6245 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6246 | boolean requireUssd = c.getBoolean( |
| 6247 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6248 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6249 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6250 | if (requireUssd) { |
| 6251 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6252 | getSubscriptionCarrierId(subId)); |
| 6253 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6254 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6255 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6256 | String newUssdCommand = ""; |
| 6257 | try { |
| 6258 | newUssdCommand = carrierXmlParser.getFeature( |
| 6259 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6260 | .makeCommand(ssAction, null); |
| 6261 | } catch (NullPointerException e) { |
| 6262 | loge("Failed to generate USSD number" + e); |
| 6263 | } |
| 6264 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6265 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6266 | final String ussdCommand = newUssdCommand; |
| 6267 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6268 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6269 | }); |
| 6270 | } else { |
| 6271 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6272 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6273 | |
| 6274 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6275 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6276 | } finally { |
| 6277 | Binder.restoreCallingIdentity(identity); |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6282 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6283 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6284 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6285 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6286 | * location related information which will be sent if the caller already possess |
| 6287 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6288 | * @param request contains the radio access networks with bands/channels to scan |
| 6289 | * @param messenger callback messenger for scan results or errors |
| 6290 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6291 | * @return the id of the requested scan which can be used to stop the scan. |
| 6292 | */ |
| 6293 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6294 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6295 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6296 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6298 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6299 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6300 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6301 | if (!renounceFineLocationAccess) { |
| 6302 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6303 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6304 | .setCallingPackage(callingPackage) |
| 6305 | .setCallingFeatureId(callingFeatureId) |
| 6306 | .setCallingPid(Binder.getCallingPid()) |
| 6307 | .setCallingUid(Binder.getCallingUid()) |
| 6308 | .setMethod("requestNetworkScan") |
| 6309 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6310 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6311 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6312 | .build()); |
| 6313 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6314 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6315 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6316 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6317 | if (e != null) { |
| 6318 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6319 | throw e; |
| 6320 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6321 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6322 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6323 | } |
| 6324 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6325 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6326 | int callingUid = Binder.getCallingUid(); |
| 6327 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6328 | final long identity = Binder.clearCallingIdentity(); |
| 6329 | try { |
| 6330 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6331 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6332 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6333 | } finally { |
| 6334 | Binder.restoreCallingIdentity(identity); |
| 6335 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6336 | } |
| 6337 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6338 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6339 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6340 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6341 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6342 | boolean hasNetworkScanPermission = |
| 6343 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6344 | == PERMISSION_GRANTED; |
| 6345 | |
| 6346 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6347 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6348 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6349 | } |
| 6350 | |
| 6351 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6352 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6353 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6354 | return new SecurityException("Specific channels must not be" |
| 6355 | + " scanned without location access."); |
| 6356 | } |
| 6357 | } |
| 6358 | } |
| 6359 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6360 | return null; |
| 6361 | } |
| 6362 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6363 | /** |
| 6364 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6365 | * |
| 6366 | * @param subId id of the subscription |
| 6367 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6368 | */ |
| 6369 | @Override |
| 6370 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6371 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6372 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6373 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6374 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6375 | final long identity = Binder.clearCallingIdentity(); |
| 6376 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6377 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6378 | } finally { |
| 6379 | Binder.restoreCallingIdentity(identity); |
| 6380 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6384 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6385 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6386 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6387 | */ |
| 6388 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6389 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6390 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6391 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6392 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6393 | |
| 6394 | final long identity = Binder.clearCallingIdentity(); |
| 6395 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6396 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6397 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6398 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6399 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6400 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6407 | * Get the allowed network types for certain reason. |
| 6408 | * |
| 6409 | * @param subId the id of the subscription. |
| 6410 | * @param reason the reason the allowed network type change is taking place |
| 6411 | * @return the allowed network types. |
| 6412 | */ |
| 6413 | @Override |
| 6414 | public long getAllowedNetworkTypesForReason(int subId, |
| 6415 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6416 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6417 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6418 | final long identity = Binder.clearCallingIdentity(); |
| 6419 | try { |
| 6420 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6421 | } finally { |
| 6422 | Binder.restoreCallingIdentity(identity); |
| 6423 | } |
| 6424 | } |
| 6425 | |
| 6426 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6427 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6428 | * @param subId subscription id of the sim card |
| 6429 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6430 | * This can be passed following states |
| 6431 | * <ol> |
| 6432 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6433 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6434 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6435 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6436 | * </ol> |
| 6437 | * @return operation result. |
| 6438 | */ |
| 6439 | @Override |
| 6440 | public int setNrDualConnectivityState(int subId, |
| 6441 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6443 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6444 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6445 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6446 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6447 | } |
| 6448 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6449 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6453 | nrDualConnectivityState, subId, |
| 6454 | workSource); |
| 6455 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6456 | return result; |
| 6457 | } finally { |
| 6458 | Binder.restoreCallingIdentity(identity); |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | /** |
| 6463 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6464 | * @return true if dual connectivity is enabled else false |
| 6465 | */ |
| 6466 | @Override |
| 6467 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6468 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6469 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6470 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6471 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6472 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6473 | return false; |
| 6474 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6475 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6476 | final long identity = Binder.clearCallingIdentity(); |
| 6477 | try { |
| 6478 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6479 | null, subId, workSource); |
| 6480 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6481 | return isEnabled; |
| 6482 | } finally { |
| 6483 | Binder.restoreCallingIdentity(identity); |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6488 | * Set the allowed network types of the device and |
| 6489 | * provide the reason triggering the allowed network change. |
| 6490 | * |
| 6491 | * @param subId the id of the subscription. |
| 6492 | * @param reason the reason the allowed network type change is taking place |
| 6493 | * @param allowedNetworkTypes the allowed network types. |
| 6494 | * @return true on success; false on any failure. |
| 6495 | */ |
| 6496 | @Override |
| 6497 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6498 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6499 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6500 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6501 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6502 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6503 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6504 | return false; |
| 6505 | } |
| 6506 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6507 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6508 | return false; |
| 6509 | } |
| 6510 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6511 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6512 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6513 | |
| 6514 | |
| 6515 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6516 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6517 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6518 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6519 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6520 | final long identity = Binder.clearCallingIdentity(); |
| 6521 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6522 | Boolean success = (Boolean) sendRequest( |
| 6523 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6524 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6525 | |
| 6526 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6527 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6528 | } finally { |
| 6529 | Binder.restoreCallingIdentity(identity); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6534 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6535 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6536 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6537 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6538 | * @hide |
| 6539 | */ |
| 6540 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6541 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6542 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6543 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6544 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6545 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6546 | if (phone != null) { |
| 6547 | return phone.hasMatchedTetherApnSetting(); |
| 6548 | } else { |
| 6549 | return false; |
| 6550 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6553 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6554 | } |
| 6555 | |
| 6556 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6557 | * Get the user enabled state of Mobile Data. |
| 6558 | * |
| 6559 | * TODO: remove and use isUserDataEnabled. |
| 6560 | * This can't be removed now because some vendor codes |
| 6561 | * calls through ITelephony directly while they should |
| 6562 | * use TelephonyManager. |
| 6563 | * |
| 6564 | * @return true on enabled |
| 6565 | */ |
| 6566 | @Override |
| 6567 | public boolean getDataEnabled(int subId) { |
| 6568 | return isUserDataEnabled(subId); |
| 6569 | } |
| 6570 | |
| 6571 | /** |
| 6572 | * Get whether mobile data is enabled per user setting. |
| 6573 | * |
| 6574 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6575 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6576 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6577 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6578 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6579 | * |
| 6580 | * @return {@code true} if data is enabled else {@code false} |
| 6581 | */ |
| 6582 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6583 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6584 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6585 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6586 | try { |
| 6587 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6588 | functionName); |
| 6589 | } catch (Exception e) { |
| 6590 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6591 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6592 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6594 | mApp, subId, functionName); |
| 6595 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6596 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6597 | |
| 6598 | final long identity = Binder.clearCallingIdentity(); |
| 6599 | try { |
| 6600 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6601 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6602 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6603 | if (phone != null) { |
| 6604 | boolean retVal = phone.isUserDataEnabled(); |
| 6605 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6606 | return retVal; |
| 6607 | } else { |
| 6608 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6609 | return false; |
| 6610 | } |
| 6611 | } finally { |
| 6612 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6617 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6618 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6619 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6620 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6621 | * @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] | 6622 | */ |
| 6623 | @Override |
| 6624 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6625 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6626 | try { |
| 6627 | try { |
| 6628 | mApp.enforceCallingOrSelfPermission( |
| 6629 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6630 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6631 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6632 | try { |
| 6633 | mApp.enforceCallingOrSelfPermission( |
| 6634 | android.Manifest.permission.READ_PHONE_STATE, |
| 6635 | functionName); |
| 6636 | } catch (Exception e2) { |
| 6637 | mApp.enforceCallingOrSelfPermission( |
| 6638 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6639 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6640 | } |
| 6641 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6642 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6644 | |
| 6645 | final long identity = Binder.clearCallingIdentity(); |
| 6646 | try { |
| 6647 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6649 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6650 | boolean retVal; |
| 6651 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 2c094c5 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6652 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6653 | } else { |
| 6654 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6655 | } |
| 6656 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | return retVal; |
| 6658 | } else { |
| 6659 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6660 | return false; |
| 6661 | } |
| 6662 | } finally { |
| 6663 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6664 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6665 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6666 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6667 | /** |
| 6668 | * Check if data is enabled for a specific reason |
| 6669 | * @param subId Subscription index |
| 6670 | * @param reason the reason the data enable change is taking place |
| 6671 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6672 | */ |
| 6673 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6674 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6675 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6676 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6677 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6678 | try { |
| 6679 | mApp.enforceCallingOrSelfPermission( |
| 6680 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6681 | functionName); |
| 6682 | } catch (Exception e) { |
| 6683 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6684 | functionName); |
| 6685 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6686 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6687 | try { |
| 6688 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6689 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6690 | } catch (Exception e2) { |
| 6691 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6692 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6693 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6694 | } |
| 6695 | |
| 6696 | |
| 6697 | final long identity = Binder.clearCallingIdentity(); |
| 6698 | try { |
| 6699 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6700 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6701 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6702 | + " reason=" + reason); |
| 6703 | } |
| 6704 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6705 | if (phone != null) { |
| 6706 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6707 | if (phone.isUsingNewDataStack()) { |
| 6708 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6709 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6710 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6711 | retVal = phone.isUserDataEnabled(); |
| 6712 | } else { |
| 6713 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6714 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6715 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6716 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6717 | return retVal; |
| 6718 | } else { |
| 6719 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6720 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6721 | + subId + " retVal=false"); |
| 6722 | } |
| 6723 | return false; |
| 6724 | } |
| 6725 | } finally { |
| 6726 | Binder.restoreCallingIdentity(identity); |
| 6727 | } |
| 6728 | } |
| 6729 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6730 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6731 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6732 | // No permission needed; this only lets the caller inspect their own status. |
| 6733 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6734 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6735 | |
| 6736 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6737 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6738 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6739 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6740 | } |
| 6741 | |
| 6742 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6743 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6744 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6745 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6746 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6747 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6748 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6749 | if (cpt == null) { |
| 6750 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6751 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6752 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6753 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6757 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6758 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6759 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6760 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6761 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6762 | Phone phone = getPhone(subId); |
| 6763 | if (phone == null) { |
| 6764 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6765 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6766 | } |
| 6767 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6768 | if (cpt == null) { |
| 6769 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6770 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6771 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6772 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | @Override |
| 6776 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6777 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6778 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6779 | } |
| 6780 | |
| 6781 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6782 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6783 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6784 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6785 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6786 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6787 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6788 | if (phone == null) { |
| 6789 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6790 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6791 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6792 | if (cpt == null) { |
| 6793 | continue; |
| 6794 | } |
| 6795 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6796 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6797 | break; |
| 6798 | } |
| 6799 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6800 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6801 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6802 | |
| 6803 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6804 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6805 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6806 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6807 | if (phone == null) { |
| 6808 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6809 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6810 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6811 | if (cpt == null) { |
| 6812 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6813 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6814 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6817 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6818 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6819 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6820 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6821 | if (phone == null) { |
| 6822 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6823 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6824 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6825 | if (cpt == null) { |
| 6826 | return Collections.emptyList(); |
| 6827 | } |
| 6828 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6829 | } |
| 6830 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6831 | @Override |
| 6832 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6833 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6834 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6835 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6836 | try { |
| 6837 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6838 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6839 | } |
| 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6842 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6843 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6844 | } |
| 6845 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6846 | @Override |
| 6847 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6848 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6849 | |
| 6850 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6851 | if (phone == null) { |
| 6852 | return null; |
| 6853 | } |
| 6854 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6855 | if (cpt == null) { |
| 6856 | return null; |
| 6857 | } |
| 6858 | return cpt.getCarrierServicePackageName(); |
| 6859 | } |
| 6860 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6861 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6862 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6863 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6864 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6865 | return null; |
| 6866 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6867 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6868 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6869 | return null; |
| 6870 | } |
| 6871 | return iccId; |
| 6872 | } |
| 6873 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6874 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6875 | public void setCallComposerStatus(int subId, int status) { |
| 6876 | enforceModifyPermission(); |
| 6877 | |
| 6878 | final long identity = Binder.clearCallingIdentity(); |
| 6879 | try { |
| 6880 | Phone phone = getPhone(subId); |
| 6881 | if (phone != null) { |
| 6882 | Phone defaultPhone = phone.getImsPhone(); |
| 6883 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6884 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6885 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6886 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6887 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6888 | } |
| 6889 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6890 | } catch (ImsException e) { |
| 6891 | throw new ServiceSpecificException(e.getCode()); |
| 6892 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6893 | Binder.restoreCallingIdentity(identity); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | @Override |
| 6898 | public int getCallComposerStatus(int subId) { |
| 6899 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6900 | |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
| 6902 | try { |
| 6903 | Phone phone = getPhone(subId); |
| 6904 | if (phone != null) { |
| 6905 | Phone defaultPhone = phone.getImsPhone(); |
| 6906 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6907 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6908 | return imsPhone.getCallComposerStatus(); |
| 6909 | } |
| 6910 | } |
| 6911 | } finally { |
| 6912 | Binder.restoreCallingIdentity(identity); |
| 6913 | } |
| 6914 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6915 | } |
| 6916 | |
| 6917 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6918 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6919 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6920 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6921 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6922 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6923 | final long identity = Binder.clearCallingIdentity(); |
| 6924 | try { |
| 6925 | final String iccId = getIccId(subId); |
| 6926 | final Phone phone = getPhone(subId); |
| 6927 | if (phone == null) { |
| 6928 | return false; |
| 6929 | } |
| 6930 | final String subscriberId = phone.getSubscriberId(); |
| 6931 | |
| 6932 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6933 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6934 | + subscriberId + " to " + number); |
| 6935 | } |
| 6936 | |
| 6937 | if (TextUtils.isEmpty(iccId)) { |
| 6938 | return false; |
| 6939 | } |
| 6940 | |
| 6941 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6942 | |
| 6943 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6944 | if (alphaTag == null) { |
| 6945 | editor.remove(alphaTagPrefKey); |
| 6946 | } else { |
| 6947 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6948 | } |
| 6949 | |
| 6950 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6951 | // track all merged IMSIs based on line number |
| 6952 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6953 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6954 | if (number == null) { |
| 6955 | editor.remove(numberPrefKey); |
| 6956 | editor.remove(subscriberPrefKey); |
| 6957 | } else { |
| 6958 | editor.putString(numberPrefKey, number); |
| 6959 | editor.putString(subscriberPrefKey, subscriberId); |
| 6960 | } |
| 6961 | |
| 6962 | editor.commit(); |
| 6963 | return true; |
| 6964 | } finally { |
| 6965 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6966 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6967 | } |
| 6968 | |
| 6969 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6970 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6971 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6972 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6974 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6975 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6976 | return null; |
| 6977 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6979 | final long identity = Binder.clearCallingIdentity(); |
| 6980 | try { |
| 6981 | String iccId = getIccId(subId); |
| 6982 | if (iccId != null) { |
| 6983 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6984 | if (DBG_MERGE) { |
| 6985 | log("getLine1NumberForDisplay returning " |
| 6986 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6987 | } |
| 6988 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6991 | return null; |
| 6992 | } finally { |
| 6993 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6994 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6995 | } |
| 6996 | |
| 6997 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6998 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6999 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7000 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7001 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7002 | return null; |
| 7003 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7004 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | final long identity = Binder.clearCallingIdentity(); |
| 7006 | try { |
| 7007 | String iccId = getIccId(subId); |
| 7008 | if (iccId != null) { |
| 7009 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7010 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7011 | } |
| 7012 | return null; |
| 7013 | } finally { |
| 7014 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7015 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7016 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7017 | |
| 7018 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7019 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7020 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7021 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7022 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7023 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7024 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7025 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7026 | return null; |
| 7027 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7028 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7029 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7030 | // the process, where TelephonyManager was instantiated. |
| 7031 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7032 | final long identity = Binder.clearCallingIdentity(); |
| 7033 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7034 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7036 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7037 | |
| 7038 | // Figure out what subscribers are currently active |
| 7039 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7040 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7041 | // Only consider subs which match the current subId |
| 7042 | // This logic can be simplified. See b/131189269 for progress. |
| 7043 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7044 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | |
| 7047 | // First pass, find a number override for an active subscriber |
| 7048 | String mergeNumber = null; |
| 7049 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7050 | for (String key : prefs.keySet()) { |
| 7051 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7052 | final String subscriberId = (String) prefs.get(key); |
| 7053 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7054 | final String iccId = key.substring( |
| 7055 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7056 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7057 | mergeNumber = (String) prefs.get(numberKey); |
| 7058 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7059 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7060 | + " for active subscriber " + subscriberId); |
| 7061 | } |
| 7062 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7063 | break; |
| 7064 | } |
| 7065 | } |
| 7066 | } |
| 7067 | } |
| 7068 | |
| 7069 | // Shortcut when no active merged subscribers |
| 7070 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7071 | return null; |
| 7072 | } |
| 7073 | |
| 7074 | // Second pass, find all subscribers under that line override |
| 7075 | final ArraySet<String> result = new ArraySet<>(); |
| 7076 | for (String key : prefs.keySet()) { |
| 7077 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7078 | final String number = (String) prefs.get(key); |
| 7079 | if (mergeNumber.equals(number)) { |
| 7080 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7081 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7082 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7083 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7084 | result.add(subscriberId); |
| 7085 | } |
| 7086 | } |
| 7087 | } |
| 7088 | } |
| 7089 | |
| 7090 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7091 | Arrays.sort(resultArray); |
| 7092 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7093 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7095 | } |
| 7096 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7097 | } finally { |
| 7098 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7099 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7100 | } |
| 7101 | |
| 7102 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7103 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7104 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7105 | |
| 7106 | final long identity = Binder.clearCallingIdentity(); |
| 7107 | try { |
| 7108 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7109 | TelephonyManager.class); |
| 7110 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7111 | if (subscriberId == null) { |
| 7112 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7113 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7114 | + subId); |
| 7115 | } |
| 7116 | return null; |
| 7117 | } |
| 7118 | |
| 7119 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7120 | .getSubscriptionInfo(subId); |
| 7121 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7122 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7123 | if (groupUuid == null) { |
| 7124 | return new String[]{subscriberId}; |
| 7125 | } |
| 7126 | |
| 7127 | // Get all subscriberIds from the group. |
| 7128 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7129 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7130 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7131 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7132 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7133 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7134 | if (subscriberId != null) { |
| 7135 | mergedSubscriberIds.add(subscriberId); |
| 7136 | } |
| 7137 | } |
| 7138 | |
| 7139 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | |
| 7143 | } |
| 7144 | } |
| 7145 | |
| 7146 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7147 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7148 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7149 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | |
| 7151 | final long identity = Binder.clearCallingIdentity(); |
| 7152 | try { |
| 7153 | final Phone phone = getPhone(subId); |
| 7154 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7155 | } finally { |
| 7156 | Binder.restoreCallingIdentity(identity); |
| 7157 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7158 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7159 | |
| 7160 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7161 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7162 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7163 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7164 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7165 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7166 | |
| 7167 | final long identity = Binder.clearCallingIdentity(); |
| 7168 | try { |
| 7169 | final Phone phone = getPhone(subId); |
| 7170 | if (phone == null) { |
| 7171 | return false; |
| 7172 | } |
| 7173 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7174 | cdmaNonRoamingList); |
| 7175 | } finally { |
| 7176 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7177 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7178 | } |
| 7179 | |
| 7180 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7181 | @Deprecated |
| 7182 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7183 | enforceModifyPermission(); |
| 7184 | |
| 7185 | int returnValue = 0; |
| 7186 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7187 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7188 | if(result.exception == null) { |
| 7189 | if (result.result != null) { |
| 7190 | byte[] responseData = (byte[])(result.result); |
| 7191 | if(responseData.length > oemResp.length) { |
| 7192 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7193 | responseData.length + "bytes. Buffer Size is " + |
| 7194 | oemResp.length + "bytes."); |
| 7195 | } |
| 7196 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7197 | returnValue = responseData.length; |
| 7198 | } |
| 7199 | } else { |
| 7200 | CommandException ex = (CommandException) result.exception; |
| 7201 | returnValue = ex.getCommandError().ordinal(); |
| 7202 | if(returnValue > 0) returnValue *= -1; |
| 7203 | } |
| 7204 | } catch (RuntimeException e) { |
| 7205 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7206 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7207 | if(returnValue > 0) returnValue *= -1; |
| 7208 | } |
| 7209 | |
| 7210 | return returnValue; |
| 7211 | } |
| 7212 | |
| 7213 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7214 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7215 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7216 | try { |
| 7217 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7218 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7219 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7220 | } catch (SecurityException e) { |
| 7221 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7222 | throw e; |
| 7223 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7224 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7225 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7226 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7227 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | final long identity = Binder.clearCallingIdentity(); |
| 7229 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7230 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7231 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7232 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7233 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | } finally { |
| 7235 | Binder.restoreCallingIdentity(identity); |
| 7236 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7237 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7238 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7239 | |
| 7240 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7241 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7242 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7243 | try { |
| 7244 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7245 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7246 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7247 | } |
| 7248 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7249 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7250 | } |
| 7251 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7252 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7253 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7254 | throw new SecurityException("App must be the dialer role holder to" |
| 7255 | + " upload a call composer pic"); |
| 7256 | } |
| 7257 | |
| 7258 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7259 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7260 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7261 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7262 | boolean readUntilEnd = false; |
| 7263 | int totalBytesRead = 0; |
| 7264 | byte[] buffer = new byte[16 * 1024]; |
| 7265 | while (true) { |
| 7266 | int numRead; |
| 7267 | try { |
| 7268 | numRead = input.read(buffer); |
| 7269 | } catch (IOException e) { |
| 7270 | try { |
| 7271 | fd.checkError(); |
| 7272 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7273 | null); |
| 7274 | } catch (IOException e1) { |
| 7275 | // This means that the other side closed explicitly with an error. If this |
| 7276 | // happens, log and ignore. |
| 7277 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7278 | } |
| 7279 | break; |
| 7280 | } |
| 7281 | if (numRead == -1) { |
| 7282 | readUntilEnd = true; |
| 7283 | break; |
| 7284 | } |
| 7285 | totalBytesRead += numRead; |
| 7286 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7287 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7288 | try { |
| 7289 | input.close(); |
| 7290 | } catch (IOException e) { |
| 7291 | // ignore |
| 7292 | } |
| 7293 | break; |
| 7294 | } |
| 7295 | output.write(buffer, 0, numRead); |
| 7296 | } |
| 7297 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7298 | // close is above, where the picture size is too big. |
| 7299 | |
| 7300 | try { |
| 7301 | fd.checkError(); |
| 7302 | } catch (IOException e) { |
| 7303 | loge("Remote end for call composer closed with an error: " + e); |
| 7304 | return; |
| 7305 | } |
| 7306 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7307 | if (!readUntilEnd) { |
| 7308 | loge("Did not finish reading entire image; aborting"); |
| 7309 | return; |
| 7310 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7311 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7312 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7313 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7314 | new CallComposerPictureTransfer.Factory() {}, |
| 7315 | imageData, |
| 7316 | (result) -> { |
| 7317 | if (result.first != null) { |
| 7318 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7319 | Bundle outputResult = new Bundle(); |
| 7320 | outputResult.putParcelable( |
| 7321 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7322 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7323 | outputResult); |
| 7324 | } else { |
| 7325 | callback.send(result.second, null); |
| 7326 | } |
| 7327 | } |
| 7328 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7329 | }); |
| 7330 | } |
| 7331 | |
| 7332 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7333 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7334 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7335 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7336 | |
| 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7339 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7340 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
| 7343 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7344 | } |
| 7345 | |
| 7346 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7347 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7348 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7349 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7350 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7351 | return false; |
| 7352 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7353 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7354 | final long identity = Binder.clearCallingIdentity(); |
| 7355 | try { |
| 7356 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7357 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7358 | // In the long run, we may instead need to check if there exists a connection service |
| 7359 | // which can support video calling. |
| 7360 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7361 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7362 | return imsManager.isVtEnabledByPlatform() |
| 7363 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7364 | && imsManager.isVtEnabledByUser(); |
| 7365 | } finally { |
| 7366 | Binder.restoreCallingIdentity(identity); |
| 7367 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7368 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7369 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7370 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7371 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7372 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7373 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7374 | mApp, subId, callingPackage, callingFeatureId, |
| 7375 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7376 | return false; |
| 7377 | } |
| 7378 | |
| 7379 | final long identity = Binder.clearCallingIdentity(); |
| 7380 | try { |
| 7381 | CarrierConfigManager configManager = |
| 7382 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7383 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7385 | } finally { |
| 7386 | Binder.restoreCallingIdentity(identity); |
| 7387 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7388 | } |
| 7389 | |
| 7390 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7391 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7393 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7394 | return false; |
| 7395 | } |
| 7396 | |
| 7397 | final long identity = Binder.clearCallingIdentity(); |
| 7398 | try { |
| 7399 | CarrierConfigManager configManager = |
| 7400 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7401 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7402 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7403 | } finally { |
| 7404 | Binder.restoreCallingIdentity(identity); |
| 7405 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7406 | } |
| 7407 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7408 | @Override |
| 7409 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7410 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7411 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | @Override |
| 7415 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | final long identity = Binder.clearCallingIdentity(); |
| 7417 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7418 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7419 | } finally { |
| 7420 | Binder.restoreCallingIdentity(identity); |
| 7421 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7422 | } |
| 7423 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7424 | /** |
| 7425 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7426 | * support for the feature and device firmware support. |
| 7427 | * |
| 7428 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7429 | */ |
| 7430 | @Override |
| 7431 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7433 | final Phone phone = getPhone(subscriptionId); |
| 7434 | if (phone == null) { |
| 7435 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7436 | return false; |
| 7437 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7439 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7440 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7441 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7442 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | return isCarrierSupported && isDeviceSupported; |
| 7444 | } finally { |
| 7445 | Binder.restoreCallingIdentity(identity); |
| 7446 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7447 | } |
| 7448 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7449 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7450 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7451 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7452 | * 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] | 7453 | */ |
| 7454 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | final long identity = Binder.clearCallingIdentity(); |
| 7456 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7457 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7458 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7459 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7460 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7461 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7462 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7463 | } finally { |
| 7464 | Binder.restoreCallingIdentity(identity); |
| 7465 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7466 | } |
| 7467 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7468 | @Deprecated |
| 7469 | @Override |
| 7470 | public String getDeviceId(String callingPackage) { |
| 7471 | return getDeviceIdWithFeature(callingPackage, null); |
| 7472 | } |
| 7473 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7474 | /** |
| 7475 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7476 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7477 | * |
| 7478 | * <p>Requires Permission: |
| 7479 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7480 | */ |
| 7481 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7482 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7483 | try { |
| 7484 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7485 | } catch (SecurityException se) { |
| 7486 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7487 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7488 | + Binder.getCallingUid()); |
| 7489 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7490 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7491 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7492 | return null; |
| 7493 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7494 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7495 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7496 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7497 | return null; |
| 7498 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 | |
| 7500 | final long identity = Binder.clearCallingIdentity(); |
| 7501 | try { |
| 7502 | return phone.getDeviceId(); |
| 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
| 7505 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7506 | } |
| 7507 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7508 | /** |
| 7509 | * {@hide} |
| 7510 | * Returns the IMS Registration Status on a particular subid |
| 7511 | * |
| 7512 | * @param subId |
| 7513 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7514 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7515 | Phone phone = getPhone(subId); |
| 7516 | if (phone != null) { |
| 7517 | return phone.isImsRegistered(); |
| 7518 | } else { |
| 7519 | return false; |
| 7520 | } |
| 7521 | } |
| 7522 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7523 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7524 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7525 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7526 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7527 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7528 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7529 | } |
| 7530 | final long identity = Binder.clearCallingIdentity(); |
| 7531 | try { |
| 7532 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7533 | } finally { |
| 7534 | Binder.restoreCallingIdentity(identity); |
| 7535 | } |
| 7536 | } |
| 7537 | |
| 7538 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7539 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7540 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7541 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7542 | mApp, |
| 7543 | subscriptionId, |
| 7544 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7545 | final long identity = Binder.clearCallingIdentity(); |
| 7546 | try { |
| 7547 | Phone phone = getPhone(subscriptionId); |
| 7548 | if (phone == null) { |
| 7549 | return null; |
| 7550 | } |
| 7551 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7552 | } finally { |
| 7553 | Binder.restoreCallingIdentity(identity); |
| 7554 | } |
| 7555 | } |
| 7556 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7557 | /** |
| 7558 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7559 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7560 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | final long identity = Binder.clearCallingIdentity(); |
| 7562 | try { |
| 7563 | Phone phone = getPhone(subId); |
| 7564 | if (phone != null) { |
| 7565 | return phone.isWifiCallingEnabled(); |
| 7566 | } else { |
| 7567 | return false; |
| 7568 | } |
| 7569 | } finally { |
| 7570 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7571 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7572 | } |
| 7573 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7574 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7575 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7576 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7577 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7578 | final long identity = Binder.clearCallingIdentity(); |
| 7579 | try { |
| 7580 | Phone phone = getPhone(subId); |
| 7581 | if (phone != null) { |
| 7582 | return phone.isVideoEnabled(); |
| 7583 | } else { |
| 7584 | return false; |
| 7585 | } |
| 7586 | } finally { |
| 7587 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | /** |
| 7592 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7593 | * defined in {@link ImsRegistrationImplBase}. |
| 7594 | */ |
| 7595 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | final long identity = Binder.clearCallingIdentity(); |
| 7597 | try { |
| 7598 | Phone phone = getPhone(subId); |
| 7599 | if (phone != null) { |
| 7600 | return phone.getImsRegistrationTech(); |
| 7601 | } else { |
| 7602 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7603 | } |
| 7604 | } finally { |
| 7605 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7606 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7607 | } |
| 7608 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7609 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7610 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7611 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7612 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7613 | return; |
| 7614 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7615 | Phone defaultPhone = getDefaultPhone(); |
| 7616 | if (defaultPhone != null) { |
| 7617 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7618 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7619 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7620 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7621 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7622 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7623 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7624 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7625 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7626 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7627 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7628 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7629 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7630 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7631 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7632 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7633 | // There has been issues when Sms raw table somehow stores orphan |
| 7634 | // fragments. They lead to garbled message when new fragments come |
| 7635 | // in and combined with those stale ones. In case this happens again, |
| 7636 | // user can reset all network settings which will clean up this table. |
| 7637 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7638 | // Clean up IMS settings as well here. |
| 7639 | int slotId = getSlotIndex(subId); |
| 7640 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7641 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7642 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7643 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7644 | if (defaultPhone == null) { |
| 7645 | return; |
| 7646 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7647 | // Erase modem config if erase modem on network setting is enabled. |
| 7648 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7649 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7650 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7651 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7652 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7653 | |
| 7654 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7657 | } |
| 7658 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7659 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7660 | @VisibleForTesting |
| 7661 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7662 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7663 | return; |
| 7664 | } |
| 7665 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7666 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7667 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7668 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7669 | "user=" + defaultNetworkType); |
| 7670 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7671 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7672 | defaultNetworkType, null); |
| 7673 | } |
| 7674 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7675 | private void cleanUpSmsRawTable(Context context) { |
| 7676 | ContentResolver resolver = context.getContentResolver(); |
| 7677 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7678 | resolver.delete(uri, null, null); |
| 7679 | } |
| 7680 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7681 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7682 | public String getSimLocaleForSubscriber(int subId) { |
| 7683 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7684 | final Phone phone = getPhone(subId); |
| 7685 | if (phone == null) { |
| 7686 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7687 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7689 | final long identity = Binder.clearCallingIdentity(); |
| 7690 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7691 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7692 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7693 | if (info == null) { |
| 7694 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7695 | return null; |
| 7696 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7697 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7698 | // preferences (EF-PL and EF-LI)... |
| 7699 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7700 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7701 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7702 | if (localeFromDefaultSim != null) { |
| 7703 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7704 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7705 | + localeFromDefaultSim); |
| 7706 | return localeFromDefaultSim.toLanguageTag(); |
| 7707 | } else { |
| 7708 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7709 | } |
| 7710 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7713 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7714 | // the SIM and carrier preferences does not include a country we add the country |
| 7715 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7716 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7717 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7718 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7719 | return mccLocale.toLanguageTag(); |
| 7720 | } |
| 7721 | |
| 7722 | if (DBG) log("No locale found - returning null"); |
| 7723 | return null; |
| 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
| 7726 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7727 | } |
| 7728 | |
| 7729 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7730 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7731 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7732 | } |
| 7733 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7734 | /** |
| 7735 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7736 | */ |
| 7737 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7738 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7739 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7740 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7741 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7742 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7743 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7744 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7745 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7746 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7747 | * representing the state of the modem. |
| 7748 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7749 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7750 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7751 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7752 | */ |
| 7753 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7754 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7755 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7756 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7760 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7761 | } finally { |
| 7762 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7763 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7764 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7765 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7766 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7767 | // less than total activity duration. |
| 7768 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7769 | if (info == null) { |
| 7770 | return false; |
| 7771 | } |
| 7772 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7773 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7774 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7775 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7776 | return (info.isValid() |
| 7777 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7778 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7779 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7780 | && (totalTxTimeMs <= activityDurationMs)); |
| 7781 | } |
| 7782 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7783 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7784 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7785 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7786 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7787 | |
| 7788 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7789 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7790 | } |
| 7791 | |
| 7792 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7793 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7794 | rat, |
| 7795 | freq, |
| 7796 | info.getReceiveTimeMillis(rat, freq) |
| 7797 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7798 | } |
| 7799 | |
| 7800 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7801 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7802 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7803 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7804 | |
| 7805 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7806 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7807 | } |
| 7808 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7809 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7810 | rat, |
| 7811 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7812 | } |
| 7813 | |
| 7814 | /** |
| 7815 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7816 | * @param info recent ModemActivityInfo |
| 7817 | */ |
| 7818 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7819 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7820 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7821 | boolean matched; |
| 7822 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7823 | matched = false; |
| 7824 | int rat = info.getSpecificInfoRat(i); |
| 7825 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7826 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7827 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7828 | //if it already exists |
| 7829 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7830 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7831 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7832 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7833 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7834 | updateLastModemActivityInfo(info, rat, freq); |
| 7835 | matched = true; |
| 7836 | } |
| 7837 | } else { |
| 7838 | updateLastModemActivityInfo(info, rat); |
| 7839 | matched = true; |
| 7840 | } |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | if (!matched) { |
| 7845 | mDeltaSpecificInfo = |
| 7846 | new ActivityStatsTechSpecificInfo( |
| 7847 | rat, |
| 7848 | freq, |
| 7849 | info.getTransmitTimeMillis(rat, freq), |
| 7850 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7851 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7852 | } |
| 7853 | } |
| 7854 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7855 | mLastModemActivitySpecificInfo = |
| 7856 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7857 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7858 | |
| 7859 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7860 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7861 | info.getSleepTimeMillis() |
| 7862 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7863 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7864 | info.getIdleTimeMillis() |
| 7865 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7866 | } |
| 7867 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7868 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7869 | * Returns the service state information on specified subscription. |
| 7870 | */ |
| 7871 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7872 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7873 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7874 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7875 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7876 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7877 | return null; |
| 7878 | } |
| 7879 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7880 | boolean hasFinePermission = false; |
| 7881 | boolean hasCoarsePermission = false; |
| 7882 | if (!renounceFineLocationAccess) { |
| 7883 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7884 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7885 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7886 | .setCallingPackage(callingPackage) |
| 7887 | .setCallingFeatureId(callingFeatureId) |
| 7888 | .setCallingPid(Binder.getCallingPid()) |
| 7889 | .setCallingUid(Binder.getCallingUid()) |
| 7890 | .setMethod("getServiceStateForSubscriber") |
| 7891 | .setLogAsInfo(true) |
| 7892 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7893 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7894 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7895 | .build()); |
| 7896 | hasFinePermission = |
| 7897 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7898 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7899 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7900 | if (!renounceCoarseLocationAccess) { |
| 7901 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7902 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7903 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7904 | .setCallingPackage(callingPackage) |
| 7905 | .setCallingFeatureId(callingFeatureId) |
| 7906 | .setCallingPid(Binder.getCallingPid()) |
| 7907 | .setCallingUid(Binder.getCallingUid()) |
| 7908 | .setMethod("getServiceStateForSubscriber") |
| 7909 | .setLogAsInfo(true) |
| 7910 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7911 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7912 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7913 | .build()); |
| 7914 | hasCoarsePermission = |
| 7915 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7916 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7917 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7918 | final Phone phone = getPhone(subId); |
| 7919 | if (phone == null) { |
| 7920 | return null; |
| 7921 | } |
| 7922 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7923 | final long identity = Binder.clearCallingIdentity(); |
| 7924 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7925 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7926 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7927 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7928 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7929 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7930 | Rlog.d(LOG_TAG, |
| 7931 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7932 | return null; |
| 7933 | } |
| 7934 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7935 | ServiceState ss = phone.getServiceState(); |
| 7936 | |
| 7937 | // Scrub out the location info in ServiceState depending on what level of access |
| 7938 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7939 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7940 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7941 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | } finally { |
| 7943 | Binder.restoreCallingIdentity(identity); |
| 7944 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7945 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7946 | |
| 7947 | /** |
| 7948 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7949 | * |
| 7950 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7951 | * voicemail ringtone. |
| 7952 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7953 | * PhoneAccount. |
| 7954 | */ |
| 7955 | @Override |
| 7956 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | final long identity = Binder.clearCallingIdentity(); |
| 7958 | try { |
| 7959 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7960 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7961 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7962 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7963 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7964 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
| 7967 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7968 | } |
| 7969 | |
| 7970 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7971 | * Sets the per-account voicemail ringtone. |
| 7972 | * |
| 7973 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7974 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7975 | * |
| 7976 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7977 | * voicemail ringtone. |
| 7978 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7979 | * PhoneAccount. |
| 7980 | */ |
| 7981 | @Override |
| 7982 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7983 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7984 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7985 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7986 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7987 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7988 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7989 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7990 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7991 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7992 | |
| 7993 | final long identity = Binder.clearCallingIdentity(); |
| 7994 | try { |
| 7995 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7996 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7997 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7998 | } |
| 7999 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8000 | } finally { |
| 8001 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8002 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8003 | } |
| 8004 | |
| 8005 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8006 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8007 | * |
| 8008 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8009 | * voicemail vibration setting. |
| 8010 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8011 | */ |
| 8012 | @Override |
| 8013 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8014 | final long identity = Binder.clearCallingIdentity(); |
| 8015 | try { |
| 8016 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8017 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8018 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8019 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8021 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8022 | } finally { |
| 8023 | Binder.restoreCallingIdentity(identity); |
| 8024 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8025 | } |
| 8026 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8027 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8028 | * Sets the per-account voicemail vibration. |
| 8029 | * |
| 8030 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8031 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8032 | * |
| 8033 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8034 | * voicemail vibration setting. |
| 8035 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8036 | * specific PhoneAccount. |
| 8037 | */ |
| 8038 | @Override |
| 8039 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8040 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8041 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8042 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8043 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8044 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8045 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8046 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8047 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8048 | } |
| 8049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8050 | final long identity = Binder.clearCallingIdentity(); |
| 8051 | try { |
| 8052 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8053 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8054 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | } |
| 8056 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8057 | } finally { |
| 8058 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8059 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8060 | } |
| 8061 | |
| 8062 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8063 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8064 | * |
| 8065 | * @throws SecurityException if the caller does not have the required permission |
| 8066 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8067 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8068 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8069 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8070 | } |
| 8071 | |
| 8072 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8073 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8074 | * permission. |
| 8075 | * |
| 8076 | * @throws SecurityException if the caller does not have the required permission |
| 8077 | */ |
| 8078 | private void enforceSendSmsPermission() { |
| 8079 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8080 | } |
| 8081 | |
| 8082 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8083 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8084 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8085 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8086 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8087 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8088 | final long identity = Binder.clearCallingIdentity(); |
| 8089 | try { |
| 8090 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8091 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8092 | if (componentName == null) { |
| 8093 | throw new SecurityException( |
| 8094 | "Caller not current active visual voicemail package[null]"); |
| 8095 | } |
| 8096 | String vvmPackage = componentName.getPackageName(); |
| 8097 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame^] | 8098 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8099 | } |
| 8100 | } finally { |
| 8101 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8102 | } |
| 8103 | } |
| 8104 | |
| 8105 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8106 | * Return the application ID for the app type. |
| 8107 | * |
| 8108 | * @param subId the subscription ID that this request applies to. |
| 8109 | * @param appType the uicc app type. |
| 8110 | * @return Application ID for specificied app type, or null if no uicc. |
| 8111 | */ |
| 8112 | @Override |
| 8113 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8114 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8115 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8116 | |
| 8117 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8118 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8119 | if (phone == null) { |
| 8120 | return null; |
| 8121 | } |
| 8122 | String aid = null; |
| 8123 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8124 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8125 | .getApplicationByType(appType).getAid(); |
| 8126 | } catch (Exception e) { |
| 8127 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8128 | } |
| 8129 | return aid; |
| 8130 | } finally { |
| 8131 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8132 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8133 | } |
| 8134 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8135 | /** |
| 8136 | * Return the Electronic Serial Number. |
| 8137 | * |
| 8138 | * @param subId the subscription ID that this request applies to. |
| 8139 | * @return ESN or null if error. |
| 8140 | */ |
| 8141 | @Override |
| 8142 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8143 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8144 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8145 | |
| 8146 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8147 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8148 | if (phone == null) { |
| 8149 | return null; |
| 8150 | } |
| 8151 | String esn = null; |
| 8152 | try { |
| 8153 | esn = phone.getEsn(); |
| 8154 | } catch (Exception e) { |
| 8155 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8156 | } |
| 8157 | return esn; |
| 8158 | } finally { |
| 8159 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8160 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8161 | } |
| 8162 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8163 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8164 | * Return the Preferred Roaming List Version. |
| 8165 | * |
| 8166 | * @param subId the subscription ID that this request applies to. |
| 8167 | * @return PRLVersion or null if error. |
| 8168 | */ |
| 8169 | @Override |
| 8170 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8171 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8172 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | |
| 8174 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8175 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8176 | if (phone == null) { |
| 8177 | return null; |
| 8178 | } |
| 8179 | String cdmaPrlVersion = null; |
| 8180 | try { |
| 8181 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8182 | } catch (Exception e) { |
| 8183 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8184 | } |
| 8185 | return cdmaPrlVersion; |
| 8186 | } finally { |
| 8187 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8188 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8189 | } |
| 8190 | |
| 8191 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8192 | * Get snapshot of Telephony histograms |
| 8193 | * @return List of Telephony histograms |
| 8194 | * @hide |
| 8195 | */ |
| 8196 | @Override |
| 8197 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8199 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | |
| 8201 | final long identity = Binder.clearCallingIdentity(); |
| 8202 | try { |
| 8203 | return RIL.getTelephonyRILTimingHistograms(); |
| 8204 | } finally { |
| 8205 | Binder.restoreCallingIdentity(identity); |
| 8206 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8207 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8208 | |
| 8209 | /** |
| 8210 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8211 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8212 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8213 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8214 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8215 | * @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] | 8216 | */ |
| 8217 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8218 | @TelephonyManager.SetCarrierRestrictionResult |
| 8219 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8220 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8221 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8222 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8223 | if (carrierRestrictionRules == null) { |
| 8224 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8225 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8226 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8227 | final long identity = Binder.clearCallingIdentity(); |
| 8228 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8229 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8230 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8231 | } finally { |
| 8232 | Binder.restoreCallingIdentity(identity); |
| 8233 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8234 | } |
| 8235 | |
| 8236 | /** |
| 8237 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8238 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8239 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8240 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8241 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8242 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8243 | */ |
| 8244 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8245 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8246 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8247 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8248 | |
| 8249 | final long identity = Binder.clearCallingIdentity(); |
| 8250 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8251 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8252 | if (response instanceof CarrierRestrictionRules) { |
| 8253 | return (CarrierRestrictionRules) response; |
| 8254 | } |
| 8255 | // Response is an Exception of some kind, |
| 8256 | // which is signalled to the user as a NULL retval |
| 8257 | return null; |
| 8258 | } catch (Exception e) { |
| 8259 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8260 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | } finally { |
| 8262 | Binder.restoreCallingIdentity(identity); |
| 8263 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8264 | } |
| 8265 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8266 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8267 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8268 | * @param subId the subscription ID that this action applies to. |
| 8269 | * @param enabled control enable or disable radio. |
| 8270 | * {@hide} |
| 8271 | */ |
| 8272 | @Override |
| 8273 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8274 | enforceModifyPermission(); |
| 8275 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8276 | |
| 8277 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8278 | if (phone == null) { |
| 8279 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8280 | return; |
| 8281 | } |
| 8282 | try { |
| 8283 | phone.carrierActionSetRadioEnabled(enabled); |
| 8284 | } catch (Exception e) { |
| 8285 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8286 | } finally { |
| 8287 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8288 | } |
| 8289 | } |
| 8290 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8291 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8292 | * Enable or disable Voice over NR (VoNR) |
| 8293 | * @param subId the subscription ID that this action applies to. |
| 8294 | * @param enabled enable or disable VoNR. |
| 8295 | * @return operation result. |
| 8296 | */ |
| 8297 | @Override |
| 8298 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8299 | enforceModifyPermission(); |
| 8300 | final Phone phone = getPhone(subId); |
| 8301 | |
| 8302 | final long identity = Binder.clearCallingIdentity(); |
| 8303 | if (phone == null) { |
| 8304 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8305 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8306 | } |
| 8307 | |
| 8308 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8309 | try { |
| 8310 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8311 | workSource); |
| 8312 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8313 | |
| 8314 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8315 | if (DBG) { |
| 8316 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8317 | } |
| 8318 | SubscriptionManager.setSubscriptionProperty( |
| 8319 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8320 | (enabled ? "1" : "0")); |
| 8321 | } |
| 8322 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8323 | return result; |
| 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | /** |
| 8330 | * Is voice over NR enabled |
| 8331 | * @return true if VoNR is enabled else false |
| 8332 | */ |
| 8333 | @Override |
| 8334 | public boolean isVoNrEnabled(int subId) { |
| 8335 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8336 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8337 | final long identity = Binder.clearCallingIdentity(); |
| 8338 | try { |
| 8339 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8340 | null, subId, workSource); |
| 8341 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8342 | return isEnabled; |
| 8343 | } finally { |
| 8344 | Binder.restoreCallingIdentity(identity); |
| 8345 | } |
| 8346 | } |
| 8347 | |
| 8348 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8349 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8350 | * network status based on which carrier apps could apply actions accordingly, |
| 8351 | * enable/disable default url handler for example. |
| 8352 | * |
| 8353 | * @param subId the subscription ID that this action applies to. |
| 8354 | * @param report control start/stop reporting the default network status. |
| 8355 | * {@hide} |
| 8356 | */ |
| 8357 | @Override |
| 8358 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8359 | enforceModifyPermission(); |
| 8360 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8361 | |
| 8362 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8363 | if (phone == null) { |
| 8364 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8365 | return; |
| 8366 | } |
| 8367 | try { |
| 8368 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8369 | } catch (Exception e) { |
| 8370 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8371 | } finally { |
| 8372 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8373 | } |
| 8374 | } |
| 8375 | |
| 8376 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8377 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8378 | * @param subId the subscription ID that this action applies to. |
| 8379 | * {@hide} |
| 8380 | */ |
| 8381 | @Override |
| 8382 | public void carrierActionResetAll(int subId) { |
| 8383 | enforceModifyPermission(); |
| 8384 | final Phone phone = getPhone(subId); |
| 8385 | if (phone == null) { |
| 8386 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8387 | return; |
| 8388 | } |
| 8389 | try { |
| 8390 | phone.carrierActionResetAll(); |
| 8391 | } catch (Exception e) { |
| 8392 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8393 | } |
| 8394 | } |
| 8395 | |
| 8396 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8397 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8398 | * bug report is being generated. |
| 8399 | */ |
| 8400 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8401 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8402 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8403 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8404 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8405 | + Binder.getCallingPid() |
| 8406 | + ", uid=" + Binder.getCallingUid() |
| 8407 | + "without permission " |
| 8408 | + android.Manifest.permission.DUMP); |
| 8409 | return; |
| 8410 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8411 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8412 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8413 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8414 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8415 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8416 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8417 | @NonNull String[] args) { |
| 8418 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8419 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8420 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8421 | } |
| 8422 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8423 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8424 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8425 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8426 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8427 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8428 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8429 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8430 | */ |
| 8431 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8432 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8433 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8434 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8435 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8436 | try { |
| 8437 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8438 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8439 | } catch (SecurityException se) { |
| 8440 | enforceModifyPermission(); |
| 8441 | } |
| 8442 | } else { |
| 8443 | enforceModifyPermission(); |
| 8444 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8445 | |
| 8446 | final long identity = Binder.clearCallingIdentity(); |
| 8447 | try { |
| 8448 | Phone phone = getPhone(subId); |
| 8449 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8450 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8451 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8452 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8453 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8454 | phone.getDataSettingsManager().setDataEnabled( |
| 8455 | reason, enabled, callingPackage); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8456 | } else { |
| 8457 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8458 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8460 | } |
| 8461 | } finally { |
| 8462 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8463 | } |
| 8464 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8465 | |
| 8466 | /** |
| 8467 | * Get Client request stats |
| 8468 | * @return List of Client Request Stats |
| 8469 | * @hide |
| 8470 | */ |
| 8471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8472 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8473 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8475 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8476 | return null; |
| 8477 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8478 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8480 | final long identity = Binder.clearCallingIdentity(); |
| 8481 | try { |
| 8482 | if (phone != null) { |
| 8483 | return phone.getClientRequestStats(); |
| 8484 | } |
| 8485 | |
| 8486 | return null; |
| 8487 | } finally { |
| 8488 | Binder.restoreCallingIdentity(identity); |
| 8489 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8490 | } |
| 8491 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8492 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8493 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8494 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8495 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8496 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8497 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8498 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8499 | // commands that plumb through the RIL as root, like so: |
| 8500 | // $ adb root |
| 8501 | // $ adb shell cmd phone ... |
| 8502 | packageName = "root"; |
| 8503 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8504 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8505 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8506 | |
| 8507 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8508 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8509 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8510 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8511 | * @param state State of SIM (power down, power up, pass through) |
| 8512 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8513 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8514 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8515 | * |
| 8516 | **/ |
| 8517 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8518 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8519 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8520 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8521 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8522 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8523 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | final long identity = Binder.clearCallingIdentity(); |
| 8525 | try { |
| 8526 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8527 | phone.setSimPowerState(state, null, workSource); |
| 8528 | } |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
| 8532 | } |
| 8533 | |
| 8534 | /** |
| 8535 | * Set SIM card power state. |
| 8536 | * |
| 8537 | * @param slotIndex SIM slot id. |
| 8538 | * @param state State of SIM (power down, power up, pass through) |
| 8539 | * @param callback callback to trigger after success or failure |
| 8540 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8541 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8542 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8543 | * |
| 8544 | **/ |
| 8545 | @Override |
| 8546 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8547 | IIntegerConsumer callback) { |
| 8548 | enforceModifyPermission(); |
| 8549 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8550 | |
| 8551 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8552 | |
| 8553 | final long identity = Binder.clearCallingIdentity(); |
| 8554 | try { |
| 8555 | if (phone != null) { |
| 8556 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8557 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8558 | } |
| 8559 | } finally { |
| 8560 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8561 | } |
| 8562 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8563 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8564 | private boolean isUssdApiAllowed(int subId) { |
| 8565 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8566 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8567 | if (configManager == null) { |
| 8568 | return false; |
| 8569 | } |
| 8570 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8571 | if (pb == null) { |
| 8572 | return false; |
| 8573 | } |
| 8574 | return pb.getBoolean( |
| 8575 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8576 | } |
| 8577 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8578 | /** |
| 8579 | * Check if phone is in emergency callback mode |
| 8580 | * @return true if phone is in emergency callback mode |
| 8581 | * @param subId sub id |
| 8582 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8583 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8584 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8585 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8586 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8587 | |
| 8588 | final long identity = Binder.clearCallingIdentity(); |
| 8589 | try { |
| 8590 | if (phone != null) { |
| 8591 | return phone.isInEcm(); |
| 8592 | } else { |
| 8593 | return false; |
| 8594 | } |
| 8595 | } finally { |
| 8596 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8597 | } |
| 8598 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8599 | |
| 8600 | /** |
| 8601 | * Get the current signal strength information for the given subscription. |
| 8602 | * Because this information is not updated when the device is in a low power state |
| 8603 | * it should not be relied-upon to be current. |
| 8604 | * @param subId Subscription index |
| 8605 | * @return the most recent cached signal strength info from the modem |
| 8606 | */ |
| 8607 | @Override |
| 8608 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8609 | final long identity = Binder.clearCallingIdentity(); |
| 8610 | try { |
| 8611 | Phone p = getPhone(subId); |
| 8612 | if (p == null) { |
| 8613 | return null; |
| 8614 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8616 | return p.getSignalStrength(); |
| 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
| 8619 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8620 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8621 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8622 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8623 | * Get the current modem radio state for the given slot. |
| 8624 | * @param slotIndex slot index. |
| 8625 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8626 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8627 | * @return the current radio power state from the modem |
| 8628 | */ |
| 8629 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8630 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8631 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8632 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8633 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8634 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8635 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8636 | } |
| 8637 | |
| 8638 | final long identity = Binder.clearCallingIdentity(); |
| 8639 | try { |
| 8640 | return phone.getRadioPowerState(); |
| 8641 | } finally { |
| 8642 | Binder.restoreCallingIdentity(identity); |
| 8643 | } |
| 8644 | } |
| 8645 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8646 | } |
| 8647 | |
| 8648 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8649 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8650 | * |
| 8651 | * <p>Requires one of the following permissions: |
| 8652 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8653 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8654 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8655 | * privileges. |
| 8656 | * |
| 8657 | * @param subId subscription id |
| 8658 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8659 | * {@code false}. |
| 8660 | */ |
| 8661 | @Override |
| 8662 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8663 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8664 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8665 | try { |
| 8666 | mApp.enforceCallingOrSelfPermission( |
| 8667 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8668 | functionName); |
| 8669 | } catch (Exception e) { |
| 8670 | mApp.enforceCallingOrSelfPermission( |
| 8671 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8672 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8673 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8674 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8675 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8676 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8677 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8678 | boolean isEnabled = false; |
| 8679 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8680 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8681 | Phone phone = getPhone(subId); |
| 8682 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8683 | } finally { |
| 8684 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8685 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8686 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8687 | } |
| 8688 | |
| 8689 | |
| 8690 | /** |
| 8691 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8692 | * |
| 8693 | * <p> Requires permission: |
| 8694 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8695 | * privileges. |
| 8696 | * |
| 8697 | * @param subId subscription id |
| 8698 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8699 | */ |
| 8700 | @Override |
| 8701 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8703 | mApp, subId, "setDataRoamingEnabled"); |
| 8704 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8705 | final long identity = Binder.clearCallingIdentity(); |
| 8706 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8707 | Phone phone = getPhone(subId); |
| 8708 | if (phone != null) { |
| 8709 | phone.setDataRoamingEnabled(isEnabled); |
| 8710 | } |
| 8711 | } finally { |
| 8712 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8713 | } |
| 8714 | } |
| 8715 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8716 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8717 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8718 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8719 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8720 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8721 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8722 | boolean isAllowed = true; |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8725 | Phone phone = getPhone(subId); |
| 8726 | if (phone != null) { |
| 8727 | isAllowed = phone.isCspPlmnEnabled(); |
| 8728 | } |
| 8729 | } finally { |
| 8730 | Binder.restoreCallingIdentity(identity); |
| 8731 | } |
| 8732 | return isAllowed; |
| 8733 | } |
| 8734 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8735 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8736 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8737 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8738 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8739 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8740 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8741 | if (phone == null) { |
| 8742 | return false; |
| 8743 | } |
| 8744 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8745 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8746 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8747 | } |
| 8748 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8749 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8750 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8751 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8752 | mApp.getSystemService(AppOpsManager.class) |
| 8753 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8754 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8755 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8756 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8757 | try { |
| 8758 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8759 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8760 | } catch (SecurityException e) { |
| 8761 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8762 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8763 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8764 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8765 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8766 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8767 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8768 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8769 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8770 | Binder.getCallingUid())) { |
| 8771 | isIccIdAccessRestricted = true; |
| 8772 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8773 | final long identity = Binder.clearCallingIdentity(); |
| 8774 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8775 | UiccController uiccController = UiccController.getInstance(); |
| 8776 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8777 | if (hasReadPermission) { |
| 8778 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8779 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8780 | |
| 8781 | // Remove private info if the caller doesn't have access |
| 8782 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8783 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8784 | //setting the value after compatibility check |
| 8785 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8786 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8787 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8788 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8789 | if (card == null) { |
| 8790 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8791 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8792 | continue; |
| 8793 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8794 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8795 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8796 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8797 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8798 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8799 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8800 | for (UiccPortInfo portInfo : portInfos) { |
| 8801 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8802 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8803 | if (port == null) { |
| 8804 | // assume no access if port is null |
| 8805 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8806 | continue; |
| 8807 | } |
| 8808 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8809 | uiccPortInfos.add(portInfo); |
| 8810 | } else { |
| 8811 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8812 | } |
| 8813 | } |
| 8814 | filteredInfos.add(new UiccCardInfo( |
| 8815 | cardInfo.isEuicc(), |
| 8816 | cardInfo.getCardId(), |
| 8817 | null, |
| 8818 | cardInfo.getPhysicalSlotIndex(), |
| 8819 | cardInfo.isRemovable(), |
| 8820 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8821 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8822 | } |
| 8823 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8824 | } finally { |
| 8825 | Binder.restoreCallingIdentity(identity); |
| 8826 | } |
| 8827 | } |
| 8828 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8829 | /** |
| 8830 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8831 | * generally private and require carrier privileges to view. |
| 8832 | * |
| 8833 | * @hide |
| 8834 | */ |
| 8835 | @NonNull |
| 8836 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8837 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8838 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8839 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8840 | } |
| 8841 | return new UiccCardInfo( |
| 8842 | cardInfo.isEuicc(), |
| 8843 | cardInfo.getCardId(), |
| 8844 | null, |
| 8845 | cardInfo.getPhysicalSlotIndex(), |
| 8846 | cardInfo.isRemovable(), |
| 8847 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8848 | portinfo |
| 8849 | ); |
| 8850 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8851 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8852 | /** |
| 8853 | * @hide |
| 8854 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8855 | * These values are generally private and require carrier privileges to view. |
| 8856 | */ |
| 8857 | @NonNull |
| 8858 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8859 | return new UiccPortInfo( |
| 8860 | UiccPortInfo.ICCID_REDACTED, |
| 8861 | portInfo.getPortIndex(), |
| 8862 | portInfo.getLogicalSlotIndex(), |
| 8863 | portInfo.isActive() |
| 8864 | ); |
| 8865 | } |
| 8866 | @Override |
| 8867 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8868 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8869 | mApp.getSystemService(AppOpsManager.class) |
| 8870 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8871 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8872 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8873 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8874 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8875 | // we are reading iccId which is PII data. |
| 8876 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8877 | |
| 8878 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8879 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8880 | Binder.getCallingUid())) { |
| 8881 | isLogicalSlotAccessRestricted = true; |
| 8882 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8883 | final long identity = Binder.clearCallingIdentity(); |
| 8884 | try { |
| 8885 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8886 | if (slots == null || slots.length == 0) { |
| 8887 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8888 | return null; |
| 8889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8890 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8891 | for (int i = 0; i < slots.length; i++) { |
| 8892 | UiccSlot slot = slots[i]; |
| 8893 | if (slot == null) { |
| 8894 | continue; |
| 8895 | } |
| 8896 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8897 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8898 | UiccCard card = slot.getUiccCard(); |
| 8899 | if (card != null) { |
| 8900 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8901 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8902 | cardId = slot.getEid(); |
| 8903 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8904 | // If cardId is null, use iccId of default port as cardId. |
| 8905 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8907 | } |
| 8908 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8909 | if (cardId != null) { |
| 8910 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8911 | // if cardId is an EID, it's all digits so this is fine |
| 8912 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8913 | } |
| 8914 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8915 | int cardState = 0; |
| 8916 | switch (slot.getCardState()) { |
| 8917 | case CARDSTATE_ABSENT: |
| 8918 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8919 | break; |
| 8920 | case CARDSTATE_PRESENT: |
| 8921 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8922 | break; |
| 8923 | case CARDSTATE_ERROR: |
| 8924 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8925 | break; |
| 8926 | case CARDSTATE_RESTRICTED: |
| 8927 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8928 | break; |
| 8929 | default: |
| 8930 | break; |
| 8931 | |
| 8932 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8933 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8934 | int[] portIndexes = slot.getPortList(); |
| 8935 | for (int portIdx : portIndexes) { |
| 8936 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8937 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 8938 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 8939 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8940 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8941 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8942 | slot.isEuicc(), |
| 8943 | cardId, |
| 8944 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8945 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8946 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8947 | //setting the value after compatibility check |
| 8948 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8949 | } |
| 8950 | return infos; |
| 8951 | } finally { |
| 8952 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8953 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8954 | } |
| 8955 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8956 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8957 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8958 | boolean hasReadPermission) { |
| 8959 | String iccId = slot.getIccId(portIndex); |
| 8960 | if (hasReadPermission) { // if has read permission |
| 8961 | return iccId; |
| 8962 | } else { |
| 8963 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8964 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8965 | // if no read permission, checking carrier privilege access |
| 8966 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8967 | return iccId; |
| 8968 | } |
| 8969 | } |
| 8970 | } |
| 8971 | // No read permission or carrier privilege access. |
| 8972 | return UiccPortInfo.ICCID_REDACTED; |
| 8973 | } |
| 8974 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8975 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8976 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8977 | public boolean switchSlots(int[] physicalSlots) { |
| 8978 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8979 | |
| 8980 | final long identity = Binder.clearCallingIdentity(); |
| 8981 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8982 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 8983 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8984 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 8985 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 8986 | physicalSlots[i], i)); |
| 8987 | } |
| 8988 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8989 | } finally { |
| 8990 | Binder.restoreCallingIdentity(identity); |
| 8991 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8992 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8993 | |
| 8994 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8995 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8996 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8997 | enforceModifyPermission(); |
| 8998 | |
| 8999 | final long identity = Binder.clearCallingIdentity(); |
| 9000 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9001 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9002 | } finally { |
| 9003 | Binder.restoreCallingIdentity(identity); |
| 9004 | } |
| 9005 | } |
| 9006 | |
| 9007 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9008 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9009 | final long identity = Binder.clearCallingIdentity(); |
| 9010 | try { |
| 9011 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9012 | } finally { |
| 9013 | Binder.restoreCallingIdentity(identity); |
| 9014 | } |
| 9015 | } |
| 9016 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9017 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9018 | * A test API to reload the UICC profile. |
| 9019 | * |
| 9020 | * <p>Requires that the calling app has permission |
| 9021 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9022 | * @hide |
| 9023 | */ |
| 9024 | @Override |
| 9025 | public void refreshUiccProfile(int subId) { |
| 9026 | enforceModifyPermission(); |
| 9027 | |
| 9028 | final long identity = Binder.clearCallingIdentity(); |
| 9029 | try { |
| 9030 | Phone phone = getPhone(subId); |
| 9031 | if (phone == null) { |
| 9032 | return; |
| 9033 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9034 | UiccPort uiccPort = phone.getUiccPort(); |
| 9035 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9036 | return; |
| 9037 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9038 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9039 | if (uiccProfile == null) { |
| 9040 | return; |
| 9041 | } |
| 9042 | uiccProfile.refresh(); |
| 9043 | } finally { |
| 9044 | Binder.restoreCallingIdentity(identity); |
| 9045 | } |
| 9046 | } |
| 9047 | |
| 9048 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9049 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9050 | */ |
| 9051 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9052 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | /** |
| 9056 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9057 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9058 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9059 | */ |
| 9060 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9061 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9062 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9063 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9064 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9065 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9066 | return isDataRoamingEnabled; |
| 9067 | } |
| 9068 | |
| 9069 | /** |
| 9070 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9071 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9072 | */ |
| 9073 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9074 | List<Integer> list = TelephonyProperties.default_network(); |
| 9075 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9076 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9077 | return list.get(phoneId); |
| 9078 | } |
| 9079 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9080 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9081 | |
| 9082 | @Override |
| 9083 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9084 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9085 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9086 | |
| 9087 | final long identity = Binder.clearCallingIdentity(); |
| 9088 | try { |
| 9089 | final Phone phone = getPhone(subId); |
| 9090 | if (phone == null) { |
| 9091 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9092 | return; |
| 9093 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9094 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9095 | if (cpt != null) { |
| 9096 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9097 | } |
| 9098 | // 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] | 9099 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9100 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9101 | if (carrierPrivilegeRules == null) { |
| 9102 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9103 | } else { |
| 9104 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9105 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9106 | } finally { |
| 9107 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9108 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9109 | } |
| 9110 | |
| 9111 | @Override |
| 9112 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9113 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9114 | |
| 9115 | final long identity = Binder.clearCallingIdentity(); |
| 9116 | try { |
| 9117 | final Phone phone = getPhone(subId); |
| 9118 | if (phone == null) { |
| 9119 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9120 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9121 | } |
| 9122 | return phone.getCarrierIdListVersion(); |
| 9123 | } finally { |
| 9124 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9125 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9126 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9127 | |
| 9128 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9129 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9130 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9131 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9132 | mApp, subId, callingPackage, callingFeatureId, |
| 9133 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9134 | return -1; |
| 9135 | } |
| 9136 | |
| 9137 | final long identity = Binder.clearCallingIdentity(); |
| 9138 | try { |
| 9139 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9140 | } finally { |
| 9141 | Binder.restoreCallingIdentity(identity); |
| 9142 | } |
| 9143 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9144 | |
| 9145 | @Override |
| 9146 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9147 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9148 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9149 | mApp, subId, "getCdmaRoamingMode"); |
| 9150 | |
| 9151 | final long identity = Binder.clearCallingIdentity(); |
| 9152 | try { |
| 9153 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9154 | } finally { |
| 9155 | Binder.restoreCallingIdentity(identity); |
| 9156 | } |
| 9157 | } |
| 9158 | |
| 9159 | @Override |
| 9160 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9161 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9162 | mApp, subId, "setCdmaRoamingMode"); |
| 9163 | |
| 9164 | final long identity = Binder.clearCallingIdentity(); |
| 9165 | try { |
| 9166 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9167 | } finally { |
| 9168 | Binder.restoreCallingIdentity(identity); |
| 9169 | } |
| 9170 | } |
| 9171 | |
| 9172 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9173 | public int getCdmaSubscriptionMode(int subId) { |
| 9174 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9175 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9176 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9177 | |
| 9178 | final long identity = Binder.clearCallingIdentity(); |
| 9179 | try { |
| 9180 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9181 | } finally { |
| 9182 | Binder.restoreCallingIdentity(identity); |
| 9183 | } |
| 9184 | } |
| 9185 | |
| 9186 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9187 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9188 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9189 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9190 | |
| 9191 | final long identity = Binder.clearCallingIdentity(); |
| 9192 | try { |
| 9193 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9194 | } finally { |
| 9195 | Binder.restoreCallingIdentity(identity); |
| 9196 | } |
| 9197 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9198 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9199 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9200 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9201 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9202 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9203 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9204 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9205 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9206 | } |
| 9207 | final long identity = Binder.clearCallingIdentity(); |
| 9208 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9209 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9210 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9211 | if (phone.getEmergencyNumberTracker() != null |
| 9212 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9213 | emergencyNumberListInternal.put( |
| 9214 | phone.getSubId(), |
| 9215 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9216 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9217 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9218 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9219 | } finally { |
| 9220 | Binder.restoreCallingIdentity(identity); |
| 9221 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9222 | } |
| 9223 | |
| 9224 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9225 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9226 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9227 | if (!exactMatch) { |
| 9228 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9229 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9230 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9231 | } |
| 9232 | final long identity = Binder.clearCallingIdentity(); |
| 9233 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9234 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9235 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9236 | && phone.getEmergencyNumberTracker() |
| 9237 | .isEmergencyNumber(number, exactMatch)) { |
| 9238 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9239 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9240 | } |
| 9241 | return false; |
| 9242 | } finally { |
| 9243 | Binder.restoreCallingIdentity(identity); |
| 9244 | } |
| 9245 | } |
| 9246 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9247 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9248 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9249 | */ |
| 9250 | @Override |
| 9251 | public void startEmergencyCallbackMode() { |
| 9252 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9253 | "startEmergencyCallbackMode"); |
| 9254 | enforceModifyPermission(); |
| 9255 | final long identity = Binder.clearCallingIdentity(); |
| 9256 | try { |
| 9257 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9258 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9259 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9260 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9261 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9262 | gsmCdmaPhone.obtainMessage( |
| 9263 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9264 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9265 | } |
| 9266 | } |
| 9267 | } finally { |
| 9268 | Binder.restoreCallingIdentity(identity); |
| 9269 | } |
| 9270 | } |
| 9271 | |
| 9272 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9273 | * Update emergency number list for test mode. |
| 9274 | */ |
| 9275 | @Override |
| 9276 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9277 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9278 | "updateEmergencyNumberListTestMode"); |
| 9279 | |
| 9280 | final long identity = Binder.clearCallingIdentity(); |
| 9281 | try { |
| 9282 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9283 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9284 | if (tracker != null) { |
| 9285 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9286 | } |
| 9287 | } |
| 9288 | } finally { |
| 9289 | Binder.restoreCallingIdentity(identity); |
| 9290 | } |
| 9291 | } |
| 9292 | |
| 9293 | /** |
| 9294 | * Get the full emergency number list for test mode. |
| 9295 | */ |
| 9296 | @Override |
| 9297 | public List<String> getEmergencyNumberListTestMode() { |
| 9298 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9299 | "getEmergencyNumberListTestMode"); |
| 9300 | |
| 9301 | final long identity = Binder.clearCallingIdentity(); |
| 9302 | try { |
| 9303 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9304 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9305 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9306 | if (tracker != null) { |
| 9307 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9308 | emergencyNumbers.add(num.getNumber()); |
| 9309 | } |
| 9310 | } |
| 9311 | } |
| 9312 | return new ArrayList<>(emergencyNumbers); |
| 9313 | } finally { |
| 9314 | Binder.restoreCallingIdentity(identity); |
| 9315 | } |
| 9316 | } |
| 9317 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9318 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9319 | public int getEmergencyNumberDbVersion(int subId) { |
| 9320 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9321 | |
| 9322 | final long identity = Binder.clearCallingIdentity(); |
| 9323 | try { |
| 9324 | final Phone phone = getPhone(subId); |
| 9325 | if (phone == null) { |
| 9326 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9327 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9328 | } |
| 9329 | return phone.getEmergencyNumberDbVersion(); |
| 9330 | } finally { |
| 9331 | Binder.restoreCallingIdentity(identity); |
| 9332 | } |
| 9333 | } |
| 9334 | |
| 9335 | @Override |
| 9336 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9337 | enforceModifyPermission(); |
| 9338 | |
| 9339 | final long identity = Binder.clearCallingIdentity(); |
| 9340 | try { |
| 9341 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9342 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9343 | if (tracker != null) { |
| 9344 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9345 | } |
| 9346 | } |
| 9347 | } finally { |
| 9348 | Binder.restoreCallingIdentity(identity); |
| 9349 | } |
| 9350 | } |
| 9351 | |
| 9352 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9353 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9354 | enforceActiveEmergencySessionPermission(); |
| 9355 | |
| 9356 | final long identity = Binder.clearCallingIdentity(); |
| 9357 | try { |
| 9358 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9359 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9360 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9361 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9362 | } |
| 9363 | } |
| 9364 | } finally { |
| 9365 | Binder.restoreCallingIdentity(identity); |
| 9366 | } |
| 9367 | } |
| 9368 | |
| 9369 | @Override |
| 9370 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9371 | enforceActiveEmergencySessionPermission(); |
| 9372 | |
| 9373 | final long identity = Binder.clearCallingIdentity(); |
| 9374 | try { |
| 9375 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9376 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9377 | if (tracker != null) { |
| 9378 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9379 | } |
| 9380 | } |
| 9381 | } finally { |
| 9382 | Binder.restoreCallingIdentity(identity); |
| 9383 | } |
| 9384 | } |
| 9385 | |
| 9386 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9387 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9388 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9389 | Phone phone = getPhone(subId); |
| 9390 | if (phone == null) { |
| 9391 | return null; |
| 9392 | } |
| 9393 | final long identity = Binder.clearCallingIdentity(); |
| 9394 | try { |
| 9395 | UiccProfile profile = UiccController.getInstance() |
| 9396 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9397 | if (profile != null) { |
| 9398 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9399 | } |
| 9400 | } finally { |
| 9401 | Binder.restoreCallingIdentity(identity); |
| 9402 | } |
| 9403 | return null; |
| 9404 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9405 | |
| 9406 | /** |
| 9407 | * Enable or disable a modem stack. |
| 9408 | */ |
| 9409 | @Override |
| 9410 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9411 | enforceModifyPermission(); |
| 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
| 9415 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9416 | if (phone == null) { |
| 9417 | return false; |
| 9418 | } else { |
| 9419 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9420 | } |
| 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9425 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9426 | /** |
| 9427 | * Whether a modem stack is enabled or not. |
| 9428 | */ |
| 9429 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9430 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9431 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9432 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9433 | if (phone == null) return false; |
| 9434 | |
| 9435 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9436 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9437 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9438 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9439 | } |
| 9440 | |
| 9441 | final long identity = Binder.clearCallingIdentity(); |
| 9442 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9443 | try { |
| 9444 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9445 | } catch (NoSuchElementException ex) { |
| 9446 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9447 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9448 | } finally { |
| 9449 | Binder.restoreCallingIdentity(identity); |
| 9450 | } |
| 9451 | } |
| 9452 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9453 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9454 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9455 | enforceModifyPermission(); |
| 9456 | |
| 9457 | final long identity = Binder.clearCallingIdentity(); |
| 9458 | try { |
| 9459 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9460 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9461 | .commit(); |
| 9462 | } finally { |
| 9463 | Binder.restoreCallingIdentity(identity); |
| 9464 | } |
| 9465 | } |
| 9466 | |
| 9467 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9468 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9469 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9471 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9472 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9473 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9474 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9475 | |
| 9476 | final long identity = Binder.clearCallingIdentity(); |
| 9477 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9478 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9479 | } finally { |
| 9480 | Binder.restoreCallingIdentity(identity); |
| 9481 | } |
| 9482 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9483 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9484 | @TelephonyManager.IsMultiSimSupportedResult |
| 9485 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9486 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9487 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9488 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9489 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9490 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9491 | } |
| 9492 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9493 | // supported by the modem, indicate that it is restricted. |
| 9494 | PhoneCapability staticCapability = |
| 9495 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9496 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9497 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9498 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9499 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9500 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9501 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9502 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9503 | } |
| 9504 | // Check if support of multiple SIMs is restricted by carrier |
| 9505 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9506 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9507 | } |
| 9508 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9509 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9510 | } |
| 9511 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9512 | /** |
| 9513 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9514 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9515 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9516 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9517 | * @param numOfSims number of active sims we want to switch to |
| 9518 | */ |
| 9519 | @Override |
| 9520 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9521 | if (numOfSims == 1) { |
| 9522 | enforceModifyPermission(); |
| 9523 | } else { |
| 9524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9525 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9526 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9527 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9528 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9529 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9530 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9531 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9532 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9533 | return; |
| 9534 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9535 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9536 | } finally { |
| 9537 | Binder.restoreCallingIdentity(identity); |
| 9538 | } |
| 9539 | } |
| 9540 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9541 | @Override |
| 9542 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9543 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9544 | Phone phone = getPhone(subId); |
| 9545 | if (phone == null) { |
| 9546 | return false; |
| 9547 | } |
| 9548 | final long identity = Binder.clearCallingIdentity(); |
| 9549 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9550 | UiccPort uiccPort = phone.getUiccPort(); |
| 9551 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9552 | return false; |
| 9553 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9554 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9555 | if (uiccProfile == null) { |
| 9556 | return false; |
| 9557 | } |
| 9558 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9559 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9560 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9561 | } |
| 9562 | return false; |
| 9563 | } finally { |
| 9564 | Binder.restoreCallingIdentity(identity); |
| 9565 | } |
| 9566 | } |
| 9567 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9568 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9569 | * Get whether making changes to modem configurations will trigger reboot. |
| 9570 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9571 | */ |
| 9572 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9573 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9574 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9575 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9576 | mApp, subId, callingPackage, callingFeatureId, |
| 9577 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9578 | return false; |
| 9579 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9580 | final long identity = Binder.clearCallingIdentity(); |
| 9581 | try { |
| 9582 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9583 | } finally { |
| 9584 | Binder.restoreCallingIdentity(identity); |
| 9585 | } |
| 9586 | } |
| 9587 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9588 | private void updateModemStateMetrics() { |
| 9589 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9590 | // TODO: check the state for each modem if the api is ready. |
| 9591 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9592 | } |
| 9593 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9594 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9595 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9596 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9597 | // Verify that the callingPackage belongs to the calling UID |
| 9598 | mApp.getSystemService(AppOpsManager.class) |
| 9599 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9600 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9601 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9602 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9603 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9604 | if (slotInfos != null) { |
| 9605 | for (int i = 0; i < slotInfos.length; i++) { |
| 9606 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9607 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9608 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9609 | portInfo.getLogicalSlotIndex())); |
| 9610 | } |
| 9611 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9612 | } |
| 9613 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9614 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9615 | } finally { |
| 9616 | Binder.restoreCallingIdentity(identity); |
| 9617 | } |
| 9618 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9619 | |
| 9620 | /** |
| 9621 | * Get the IRadio HAL Version |
| 9622 | */ |
| 9623 | @Override |
| 9624 | public int getRadioHalVersion() { |
| 9625 | Phone phone = getDefaultPhone(); |
| 9626 | if (phone == null) return -1; |
| 9627 | HalVersion hv = phone.getHalVersion(); |
| 9628 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9629 | return hv.major * 100 + hv.minor; |
| 9630 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9631 | |
| 9632 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9633 | * Get the current calling package name. |
| 9634 | * @return the current calling package name |
| 9635 | */ |
| 9636 | @Override |
| 9637 | public String getCurrentPackageName() { |
| 9638 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9639 | } |
| 9640 | |
| 9641 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9642 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9643 | * corresponding network requests on a subId. |
| 9644 | * |
| 9645 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9646 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9647 | * 2) APN is un-metered for this subscription, or |
| 9648 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9649 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9650 | * |
| 9651 | * @return whether data is allowed for a apn type. |
| 9652 | * |
| 9653 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9654 | */ |
| 9655 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9656 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9657 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9658 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9659 | |
| 9660 | // Now that all security checks passes, perform the operation as ourselves. |
| 9661 | final long identity = Binder.clearCallingIdentity(); |
| 9662 | try { |
| 9663 | Phone phone = getPhone(subId); |
| 9664 | if (phone == null) return false; |
| 9665 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9666 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9667 | boolean isDataEnabled; |
| 9668 | if (phone.isUsingNewDataStack()) { |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9669 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9670 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9671 | phone.getServiceState().getDataRoaming()); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9672 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9673 | } else { |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9674 | isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9675 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9676 | } |
| 9677 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9678 | } finally { |
| 9679 | Binder.restoreCallingIdentity(identity); |
| 9680 | } |
| 9681 | } |
| 9682 | |
| 9683 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9684 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9685 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9686 | |
| 9687 | // Now that all security checks passes, perform the operation as ourselves. |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
| 9690 | Phone phone = getPhone(subId); |
| 9691 | if (phone == null) return true; // By default return true. |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9692 | if (phone.isUsingNewDataStack()) { |
| 9693 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9694 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9695 | phone.getServiceState().getDataRoaming()); |
| 9696 | } |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9697 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9698 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9699 | } finally { |
| 9700 | Binder.restoreCallingIdentity(identity); |
| 9701 | } |
| 9702 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9703 | |
| 9704 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9705 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9706 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9707 | enforceModifyPermission(); |
| 9708 | long token = Binder.clearCallingIdentity(); |
| 9709 | try { |
| 9710 | Phone phone = getPhone(subscriptionId); |
| 9711 | if (phone == null) { |
| 9712 | try { |
| 9713 | if (resultCallback != null) { |
| 9714 | resultCallback.accept(false); |
| 9715 | } |
| 9716 | } catch (RemoteException e) { |
| 9717 | // ignore |
| 9718 | } |
| 9719 | return; |
| 9720 | } |
| 9721 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9722 | Pair.create(specifiers, (x) -> { |
| 9723 | try { |
| 9724 | if (resultCallback != null) { |
| 9725 | resultCallback.accept(x); |
| 9726 | } |
| 9727 | } catch (RemoteException e) { |
| 9728 | // ignore |
| 9729 | } |
| 9730 | }); |
| 9731 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9732 | } finally { |
| 9733 | Binder.restoreCallingIdentity(token); |
| 9734 | } |
| 9735 | } |
| 9736 | |
| 9737 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9738 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9739 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9740 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9741 | mApp, subId, "getSystemSelectionChannels"); |
| 9742 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9743 | final long identity = Binder.clearCallingIdentity(); |
| 9744 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9745 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9746 | if (result instanceof IllegalStateException) { |
| 9747 | throw (IllegalStateException) result; |
| 9748 | } |
| 9749 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9750 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9751 | return specifiers; |
| 9752 | } finally { |
| 9753 | Binder.restoreCallingIdentity(identity); |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9758 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9759 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9760 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9761 | } |
| 9762 | |
| 9763 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9764 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9765 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9766 | if (callingPackage == null) { |
| 9767 | callingPackage = getCurrentPackageName(); |
| 9768 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9769 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9770 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9771 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9772 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9773 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9774 | } |
| 9775 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9776 | Intent intent = new Intent(); |
| 9777 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9778 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9779 | // Bring up choose default SMS subscription dialog right now |
| 9780 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9781 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9782 | mApp.startActivity(intent); |
| 9783 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9784 | |
| 9785 | @Override |
| 9786 | public String getMmsUAProfUrl(int subId) { |
| 9787 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9788 | final long identity = Binder.clearCallingIdentity(); |
| 9789 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9790 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9791 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9792 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9793 | return carrierUAProfUrl; |
| 9794 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9795 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9796 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9797 | } finally { |
| 9798 | Binder.restoreCallingIdentity(identity); |
| 9799 | } |
| 9800 | } |
| 9801 | |
| 9802 | @Override |
| 9803 | public String getMmsUserAgent(int subId) { |
| 9804 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9805 | final long identity = Binder.clearCallingIdentity(); |
| 9806 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9807 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9808 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9809 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9810 | return carrierUserAgent; |
| 9811 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9812 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9813 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9814 | } finally { |
| 9815 | Binder.restoreCallingIdentity(identity); |
| 9816 | } |
| 9817 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9818 | |
| 9819 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9820 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9821 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9822 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9823 | final long identity = Binder.clearCallingIdentity(); |
| 9824 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9825 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9826 | if (phone == null) return false; |
| 9827 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9828 | switch (policy) { |
| 9829 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9830 | if (phone.isUsingNewDataStack()) { |
| 9831 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9832 | } else { |
| 9833 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9834 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9835 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9836 | if (phone.isUsingNewDataStack()) { |
| 9837 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9838 | } else { |
| 9839 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9840 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9841 | default: |
| 9842 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9843 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9844 | } finally { |
| 9845 | Binder.restoreCallingIdentity(identity); |
| 9846 | } |
| 9847 | } |
| 9848 | |
| 9849 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9850 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9851 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9852 | enforceModifyPermission(); |
| 9853 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9854 | final long identity = Binder.clearCallingIdentity(); |
| 9855 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9856 | Phone phone = getPhone(subscriptionId); |
| 9857 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9858 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9859 | switch (policy) { |
| 9860 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9861 | if (phone.isUsingNewDataStack()) { |
| 9862 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9863 | } else { |
| 9864 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9865 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9866 | break; |
| 9867 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9868 | if (phone.isUsingNewDataStack()) { |
| 9869 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9870 | } else { |
| 9871 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9872 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9873 | break; |
| 9874 | default: |
| 9875 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9876 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9877 | } finally { |
| 9878 | Binder.restoreCallingIdentity(identity); |
| 9879 | } |
| 9880 | } |
| 9881 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9882 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9883 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9884 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9885 | * otherwise. |
| 9886 | */ |
| 9887 | @Override |
| 9888 | public void setCepEnabled(boolean isCepEnabled) { |
| 9889 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9890 | |
| 9891 | final long identity = Binder.clearCallingIdentity(); |
| 9892 | try { |
| 9893 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9894 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9895 | Phone defaultPhone = phone.getImsPhone(); |
| 9896 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9897 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9898 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9899 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9900 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9901 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9902 | + imsPhone.getMsisdn()); |
| 9903 | } |
| 9904 | } |
| 9905 | } finally { |
| 9906 | Binder.restoreCallingIdentity(identity); |
| 9907 | } |
| 9908 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9909 | |
| 9910 | /** |
| 9911 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9912 | * |
| 9913 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9914 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9915 | * before being read. |
| 9916 | */ |
| 9917 | @Override |
| 9918 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9919 | isCompressed) { |
| 9920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9921 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9922 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9923 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9924 | } |
| 9925 | if (!isImsAvailableOnDevice()) { |
| 9926 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9927 | "IMS not available on device."); |
| 9928 | } |
| 9929 | |
| 9930 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9931 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9932 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9933 | } finally { |
| 9934 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9935 | } |
| 9936 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9937 | |
| 9938 | @Override |
| 9939 | public boolean isIccLockEnabled(int subId) { |
| 9940 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9941 | |
| 9942 | // Now that all security checks passes, perform the operation as ourselves. |
| 9943 | final long identity = Binder.clearCallingIdentity(); |
| 9944 | try { |
| 9945 | Phone phone = getPhone(subId); |
| 9946 | if (phone != null && phone.getIccCard() != null) { |
| 9947 | return phone.getIccCard().getIccLockEnabled(); |
| 9948 | } else { |
| 9949 | return false; |
| 9950 | } |
| 9951 | } finally { |
| 9952 | Binder.restoreCallingIdentity(identity); |
| 9953 | } |
| 9954 | } |
| 9955 | |
| 9956 | /** |
| 9957 | * Set the ICC pin lock enabled or disabled. |
| 9958 | * |
| 9959 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9960 | * three cases: |
| 9961 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9962 | * successfully. |
| 9963 | * - Positive number and zero for remaining password attempts. |
| 9964 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9965 | * |
| 9966 | */ |
| 9967 | @Override |
| 9968 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9969 | enforceModifyPermission(); |
| 9970 | |
| 9971 | Phone phone = getPhone(subId); |
| 9972 | if (phone == null) { |
| 9973 | return 0; |
| 9974 | } |
| 9975 | // Now that all security checks passes, perform the operation as ourselves. |
| 9976 | final long identity = Binder.clearCallingIdentity(); |
| 9977 | try { |
| 9978 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9979 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9980 | return attemptsRemaining; |
| 9981 | |
| 9982 | } catch (Exception e) { |
| 9983 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9984 | } finally { |
| 9985 | Binder.restoreCallingIdentity(identity); |
| 9986 | } |
| 9987 | return 0; |
| 9988 | } |
| 9989 | |
| 9990 | /** |
| 9991 | * Change the ICC password used in ICC pin lock. |
| 9992 | * |
| 9993 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9994 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9995 | * - Positive number and zero for remaining password attempts. |
| 9996 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9997 | * |
| 9998 | */ |
| 9999 | @Override |
| 10000 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10001 | enforceModifyPermission(); |
| 10002 | |
| 10003 | Phone phone = getPhone(subId); |
| 10004 | if (phone == null) { |
| 10005 | return 0; |
| 10006 | } |
| 10007 | // Now that all security checks passes, perform the operation as ourselves. |
| 10008 | final long identity = Binder.clearCallingIdentity(); |
| 10009 | try { |
| 10010 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10011 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10012 | return attemptsRemaining; |
| 10013 | |
| 10014 | } catch (Exception e) { |
| 10015 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10016 | } finally { |
| 10017 | Binder.restoreCallingIdentity(identity); |
| 10018 | } |
| 10019 | return 0; |
| 10020 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10021 | |
| 10022 | /** |
| 10023 | * Request for receiving user activity notification |
| 10024 | */ |
| 10025 | @Override |
| 10026 | public void requestUserActivityNotification() { |
| 10027 | if (!mNotifyUserActivity.get() |
| 10028 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10029 | mNotifyUserActivity.set(true); |
| 10030 | } |
| 10031 | } |
| 10032 | |
| 10033 | /** |
| 10034 | * Called when userActivity is signalled in the power manager. |
| 10035 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10036 | */ |
| 10037 | @Override |
| 10038 | public void userActivity() { |
| 10039 | // *************************************** |
| 10040 | // * Inherited from PhoneWindowManager * |
| 10041 | // *************************************** |
| 10042 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10043 | // WITH ITS LOCKS HELD. |
| 10044 | // |
| 10045 | // This code must be VERY careful about the locks |
| 10046 | // it acquires. |
| 10047 | // In fact, the current code acquires way too many, |
| 10048 | // and probably has lurking deadlocks. |
| 10049 | |
| 10050 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10051 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10052 | } |
| 10053 | |
| 10054 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10055 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10056 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10057 | } |
| 10058 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10059 | |
| 10060 | @Override |
| 10061 | public boolean canConnectTo5GInDsdsMode() { |
| 10062 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10063 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10064 | |
| 10065 | @Override |
| 10066 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10067 | String callingFeatureId) { |
| 10068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10069 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10070 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10071 | } |
| 10072 | |
| 10073 | Phone phone = getPhone(subId); |
| 10074 | if (phone == null) { |
| 10075 | throw new RuntimeException("phone is not available"); |
| 10076 | } |
| 10077 | // Now that all security checks passes, perform the operation as ourselves. |
| 10078 | final long identity = Binder.clearCallingIdentity(); |
| 10079 | try { |
| 10080 | return phone.getEquivalentHomePlmns(); |
| 10081 | } finally { |
| 10082 | Binder.restoreCallingIdentity(identity); |
| 10083 | } |
| 10084 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10085 | |
| 10086 | @Override |
| 10087 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10088 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10089 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10090 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10091 | if (radioInterfaceCapabilities == null) { |
| 10092 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10093 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10094 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10095 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10096 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10097 | @Override |
| 10098 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10099 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10100 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10101 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10102 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10103 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10104 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10105 | if (DBG) { |
| 10106 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10107 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10108 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10109 | } |
| 10110 | |
| 10111 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10112 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10113 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10114 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10115 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10116 | if (callback != null) { |
| 10117 | try { |
| 10118 | callback.onAuthenticationFailure( |
| 10119 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10120 | } catch (RemoteException exception) { |
| 10121 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10122 | } |
| 10123 | return; |
| 10124 | } |
| 10125 | } |
| 10126 | |
| 10127 | final long token = Binder.clearCallingIdentity(); |
| 10128 | try { |
| 10129 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10130 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10131 | forceBootStrapping, callback)); |
| 10132 | } finally { |
| 10133 | Binder.restoreCallingIdentity(token); |
| 10134 | } |
| 10135 | } |
| 10136 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10137 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10138 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10139 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10140 | * requested radio power state will actually be set. See {@link |
| 10141 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10142 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10143 | * @param enable {@code true} if trying to turn radio on. |
| 10144 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10145 | * false}. |
| 10146 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10147 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10148 | boolean isPhoneAvailable = false; |
| 10149 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10150 | Phone phone = PhoneFactory.getPhone(i); |
| 10151 | if (phone != null) { |
| 10152 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10153 | isPhoneAvailable = true; |
| 10154 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10155 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10156 | |
| 10157 | // return true if successfully informed the phone object about the thermal radio power |
| 10158 | // request. |
| 10159 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10160 | } |
| 10161 | |
| 10162 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10163 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10164 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10165 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10166 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10167 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10168 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10169 | } |
| 10170 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10171 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10172 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10173 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10174 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10175 | } |
| 10176 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10177 | setDataEnabledForReason( |
| 10178 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10179 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10180 | if (isDataThrottlingSupported) { |
| 10181 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10182 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10183 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10184 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10185 | } else if (thermalMitigationResult |
| 10186 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10187 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10188 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10189 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10190 | } |
| 10191 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10192 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10193 | |
| 10194 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10195 | } |
| 10196 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10197 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10198 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10199 | for (String pckg : context.getResources() |
| 10200 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10201 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10202 | } |
| 10203 | } |
| 10204 | |
| 10205 | return sThermalMitigationAllowlistedPackages; |
| 10206 | } |
| 10207 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10208 | private boolean isAnyPhoneInEmergencyState() { |
| 10209 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10210 | if (tm.isInEmergencyCall()) { |
| 10211 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10212 | return true; |
| 10213 | } |
| 10214 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10215 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10216 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10217 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10218 | + phone.isInEcm()); |
| 10219 | return true; |
| 10220 | } |
| 10221 | } |
| 10222 | |
| 10223 | return false; |
| 10224 | } |
| 10225 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10226 | /** |
| 10227 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10228 | * @param packageName name of package to be allowlisted |
| 10229 | * @param context |
| 10230 | */ |
| 10231 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10232 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10233 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10234 | } |
| 10235 | |
| 10236 | /** |
| 10237 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10238 | * @param packageName name of package to remove from allowlist |
| 10239 | * @param context |
| 10240 | */ |
| 10241 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10242 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10243 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10244 | } |
| 10245 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10246 | /** |
| 10247 | * Thermal mitigation request to control functionalities at modem. |
| 10248 | * |
| 10249 | * @param subId the id of the subscription. |
| 10250 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10251 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10252 | * |
| 10253 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10254 | */ |
| 10255 | @Override |
| 10256 | @ThermalMitigationResult |
| 10257 | public int sendThermalMitigationRequest( |
| 10258 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10259 | ThermalMitigationRequest thermalMitigationRequest, |
| 10260 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10261 | enforceModifyPermission(); |
| 10262 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10263 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10264 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10265 | .contains(callingPackage)) { |
| 10266 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10267 | + "calling package: " + callingPackage); |
| 10268 | } |
| 10269 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10270 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10271 | final long identity = Binder.clearCallingIdentity(); |
| 10272 | |
| 10273 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10274 | try { |
| 10275 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10276 | switch (thermalMitigationAction) { |
| 10277 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10278 | thermalMitigationResult = |
| 10279 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10280 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10281 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10282 | break; |
| 10283 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10284 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10285 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10286 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10287 | } |
| 10288 | |
| 10289 | // Ensure that radio is on. If not able to power on due to phone being |
| 10290 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10291 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10292 | thermalMitigationResult = |
| 10293 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10294 | break; |
| 10295 | } |
| 10296 | |
| 10297 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10298 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10299 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10300 | break; |
| 10301 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10302 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10303 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10304 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10305 | } |
| 10306 | |
| 10307 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10308 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10309 | Phone phone = getPhone(subId); |
| 10310 | if (phone == null) { |
| 10311 | thermalMitigationResult = |
| 10312 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10313 | break; |
| 10314 | } |
| 10315 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10316 | TelephonyConnectionService service = |
| 10317 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10318 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10319 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10320 | thermalMitigationResult = |
| 10321 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10322 | break; |
| 10323 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10324 | thermalMitigationResult = |
| 10325 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10326 | break; |
| 10327 | } |
| 10328 | } else { |
| 10329 | thermalMitigationResult = |
| 10330 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10331 | break; |
| 10332 | } |
| 10333 | |
| 10334 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10335 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10336 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10337 | thermalMitigationResult = |
| 10338 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10339 | break; |
| 10340 | } |
| 10341 | thermalMitigationResult = |
| 10342 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10343 | break; |
| 10344 | default: |
| 10345 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10346 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10347 | } |
| 10348 | } catch (IllegalArgumentException e) { |
| 10349 | throw e; |
| 10350 | } catch (Exception e) { |
| 10351 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10352 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10353 | } finally { |
| 10354 | Binder.restoreCallingIdentity(identity); |
| 10355 | } |
| 10356 | |
| 10357 | if (DBG) { |
| 10358 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10359 | + thermalMitigationResult); |
| 10360 | } |
| 10361 | |
| 10362 | return thermalMitigationResult; |
| 10363 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10364 | |
| 10365 | /** |
| 10366 | * Set the GbaService Package Name that Telephony will bind to. |
| 10367 | * |
| 10368 | * @param subId The sim that the GbaService is associated with. |
| 10369 | * @param packageName The name of the package to be replaced with. |
| 10370 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10371 | */ |
| 10372 | @Override |
| 10373 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10374 | enforceModifyPermission(); |
| 10375 | |
| 10376 | final long identity = Binder.clearCallingIdentity(); |
| 10377 | try { |
| 10378 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10379 | } finally { |
| 10380 | Binder.restoreCallingIdentity(identity); |
| 10381 | } |
| 10382 | } |
| 10383 | |
| 10384 | /** |
| 10385 | * Return the package name of the currently bound GbaService. |
| 10386 | * |
| 10387 | * @param subId The sim that the GbaService is associated with. |
| 10388 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10389 | */ |
| 10390 | @Override |
| 10391 | public String getBoundGbaService(int subId) { |
| 10392 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10393 | |
| 10394 | final long identity = Binder.clearCallingIdentity(); |
| 10395 | try { |
| 10396 | return getGbaManager(subId).getServicePackage(); |
| 10397 | } finally { |
| 10398 | Binder.restoreCallingIdentity(identity); |
| 10399 | } |
| 10400 | } |
| 10401 | |
| 10402 | /** |
| 10403 | * Set the release time for telephony to unbind GbaService. |
| 10404 | * |
| 10405 | * @param subId The sim that the GbaService is associated with. |
| 10406 | * @param interval The release time to unbind GbaService by millisecond. |
| 10407 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10408 | */ |
| 10409 | @Override |
| 10410 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10411 | enforceModifyPermission(); |
| 10412 | |
| 10413 | final long identity = Binder.clearCallingIdentity(); |
| 10414 | try { |
| 10415 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10416 | } finally { |
| 10417 | Binder.restoreCallingIdentity(identity); |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | /** |
| 10422 | * Return the release time for telephony to unbind GbaService. |
| 10423 | * |
| 10424 | * @param subId The sim that the GbaService is associated with. |
| 10425 | * @return The release time to unbind GbaService by millisecond. |
| 10426 | */ |
| 10427 | @Override |
| 10428 | public int getGbaReleaseTime(int subId) { |
| 10429 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10430 | |
| 10431 | final long identity = Binder.clearCallingIdentity(); |
| 10432 | try { |
| 10433 | return getGbaManager(subId).getReleaseTime(); |
| 10434 | } finally { |
| 10435 | Binder.restoreCallingIdentity(identity); |
| 10436 | } |
| 10437 | } |
| 10438 | |
| 10439 | private GbaManager getGbaManager(int subId) { |
| 10440 | GbaManager instance = GbaManager.getInstance(subId); |
| 10441 | if (instance == null) { |
| 10442 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10443 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10444 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10445 | } |
| 10446 | return instance; |
| 10447 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10448 | |
| 10449 | /** |
| 10450 | * indicate whether the device and the carrier can support |
| 10451 | * RCS VoLTE single registration. |
| 10452 | */ |
| 10453 | @Override |
| 10454 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10455 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10456 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10457 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10458 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10459 | |
| 10460 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10461 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10462 | } |
| 10463 | |
| 10464 | final long identity = Binder.clearCallingIdentity(); |
| 10465 | try { |
| 10466 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10467 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10468 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10469 | if (isCapable != null) { |
| 10470 | return isCapable; |
| 10471 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10472 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10473 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10474 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10475 | } finally { |
| 10476 | Binder.restoreCallingIdentity(identity); |
| 10477 | } |
| 10478 | } |
| 10479 | |
| 10480 | /** |
| 10481 | * Register RCS provisioning callback. |
| 10482 | */ |
| 10483 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10484 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10485 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10486 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10487 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10488 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10489 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10490 | |
| 10491 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10492 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10493 | } |
| 10494 | if (!isImsAvailableOnDevice()) { |
| 10495 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10496 | "IMS not available on device."); |
| 10497 | } |
| 10498 | |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10501 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10502 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10504 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10505 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10506 | } finally { |
| 10507 | Binder.restoreCallingIdentity(identity); |
| 10508 | } |
| 10509 | } |
| 10510 | |
| 10511 | /** |
| 10512 | * Unregister RCS provisioning callback. |
| 10513 | */ |
| 10514 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10515 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10516 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10517 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10518 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10519 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10520 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10521 | |
| 10522 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10523 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10524 | } |
| 10525 | if (!isImsAvailableOnDevice()) { |
| 10526 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10527 | "IMS not available on device."); |
| 10528 | } |
| 10529 | |
| 10530 | final long identity = Binder.clearCallingIdentity(); |
| 10531 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10532 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10533 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10534 | } finally { |
| 10535 | Binder.restoreCallingIdentity(identity); |
| 10536 | } |
| 10537 | } |
| 10538 | |
| 10539 | /** |
| 10540 | * trigger RCS reconfiguration. |
| 10541 | */ |
| 10542 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10543 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10544 | "triggerRcsReconfiguration", |
| 10545 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10546 | |
| 10547 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10548 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10549 | } |
| 10550 | if (!isImsAvailableOnDevice()) { |
| 10551 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10552 | "IMS not available on device."); |
| 10553 | } |
| 10554 | |
| 10555 | final long identity = Binder.clearCallingIdentity(); |
| 10556 | try { |
| 10557 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
| 10563 | /** |
| 10564 | * Provide the client configuration parameters of the RCS application. |
| 10565 | */ |
| 10566 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10567 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10568 | "setRcsClientConfiguration", |
| 10569 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10570 | |
| 10571 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10572 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10573 | } |
| 10574 | if (!isImsAvailableOnDevice()) { |
| 10575 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10576 | "IMS not available on device."); |
| 10577 | } |
| 10578 | |
| 10579 | final long identity = Binder.clearCallingIdentity(); |
| 10580 | |
| 10581 | try { |
| 10582 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10583 | if (configBinder == null) { |
| 10584 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10585 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10586 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10587 | } else { |
| 10588 | configBinder.setRcsClientConfiguration(rcc); |
| 10589 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10590 | |
| 10591 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10592 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10593 | } catch (RemoteException e) { |
| 10594 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10595 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10596 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10597 | } finally { |
| 10598 | Binder.restoreCallingIdentity(identity); |
| 10599 | } |
| 10600 | } |
| 10601 | |
| 10602 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10603 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10604 | */ |
| 10605 | @Override |
| 10606 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10607 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10608 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10609 | |
| 10610 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10611 | } |
| 10612 | |
| 10613 | /** |
| 10614 | * Gets the test mode for RCS VoLTE single registration. |
| 10615 | */ |
| 10616 | @Override |
| 10617 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10618 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10619 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10620 | |
| 10621 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10622 | } |
| 10623 | |
| 10624 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10625 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10626 | */ |
| 10627 | @Override |
| 10628 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10629 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10630 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10631 | enforceModifyPermission(); |
| 10632 | |
| 10633 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10634 | : Boolean.parseBoolean(enabledStr); |
| 10635 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10636 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10637 | } |
| 10638 | |
| 10639 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10640 | * Sends a device to device communication message. Only usable via shell. |
| 10641 | * @param message message to send. |
| 10642 | * @param value message value. |
| 10643 | */ |
| 10644 | @Override |
| 10645 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10646 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10647 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10648 | enforceModifyPermission(); |
| 10649 | |
| 10650 | final long identity = Binder.clearCallingIdentity(); |
| 10651 | try { |
| 10652 | TelephonyConnectionService service = |
| 10653 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10654 | if (service == null) { |
| 10655 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10656 | return; |
| 10657 | } |
| 10658 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10659 | } finally { |
| 10660 | Binder.restoreCallingIdentity(identity); |
| 10661 | } |
| 10662 | } |
| 10663 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10664 | /** |
| 10665 | * Sets the specified device to device transport active. |
| 10666 | * @param transport The transport to set active. |
| 10667 | */ |
| 10668 | @Override |
| 10669 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10670 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10671 | "setActiveDeviceToDeviceTransport"); |
| 10672 | enforceModifyPermission(); |
| 10673 | |
| 10674 | final long identity = Binder.clearCallingIdentity(); |
| 10675 | try { |
| 10676 | TelephonyConnectionService service = |
| 10677 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10678 | if (service == null) { |
| 10679 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10680 | return; |
| 10681 | } |
| 10682 | service.setActiveDeviceToDeviceTransport(transport); |
| 10683 | } finally { |
| 10684 | Binder.restoreCallingIdentity(identity); |
| 10685 | } |
| 10686 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10687 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10688 | @Override |
| 10689 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10690 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10691 | "setDeviceToDeviceForceEnabled"); |
| 10692 | |
| 10693 | final long identity = Binder.clearCallingIdentity(); |
| 10694 | try { |
| 10695 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10696 | p -> { |
| 10697 | Phone thePhone = p.getImsPhone(); |
| 10698 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10699 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10700 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10701 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10702 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10703 | (ImsPhoneCallTracker) tracker; |
| 10704 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10705 | } |
| 10706 | } |
| 10707 | } |
| 10708 | ); |
| 10709 | } finally { |
| 10710 | Binder.restoreCallingIdentity(identity); |
| 10711 | } |
| 10712 | } |
| 10713 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10714 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10715 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10716 | */ |
| 10717 | @Override |
| 10718 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10719 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10720 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10721 | } |
| 10722 | |
| 10723 | /** |
| 10724 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10725 | */ |
| 10726 | @Override |
| 10727 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10728 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10729 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10730 | enforceModifyPermission(); |
| 10731 | |
| 10732 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10733 | : Boolean.parseBoolean(enabledStr); |
| 10734 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10735 | subId, enabled); |
| 10736 | } |
| 10737 | |
| 10738 | /** |
| 10739 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10740 | */ |
| 10741 | @Override |
| 10742 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10743 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10744 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10745 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10746 | |
| 10747 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10748 | * Overrides the ims feature validation result |
| 10749 | */ |
| 10750 | @Override |
| 10751 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10752 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10753 | "setImsFeatureValidationOverride"); |
| 10754 | |
| 10755 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10756 | : Boolean.parseBoolean(enabledStr); |
| 10757 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10758 | subId, enabled); |
| 10759 | } |
| 10760 | |
| 10761 | /** |
| 10762 | * Gets the ims feature validation override value |
| 10763 | */ |
| 10764 | @Override |
| 10765 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10766 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10767 | "getImsFeatureValidationOverride"); |
| 10768 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10769 | } |
| 10770 | |
| 10771 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10772 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10773 | * their mobile plan. |
| 10774 | */ |
| 10775 | @Override |
| 10776 | public String getMobileProvisioningUrl() { |
| 10777 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10778 | final long identity = Binder.clearCallingIdentity(); |
| 10779 | try { |
| 10780 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10781 | } finally { |
| 10782 | Binder.restoreCallingIdentity(identity); |
| 10783 | } |
| 10784 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10785 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10786 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10787 | * Get the EAB contact from the EAB database. |
| 10788 | */ |
| 10789 | @Override |
| 10790 | public String getContactFromEab(String contact) { |
| 10791 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10792 | enforceModifyPermission(); |
| 10793 | final long identity = Binder.clearCallingIdentity(); |
| 10794 | try { |
| 10795 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10796 | } finally { |
| 10797 | Binder.restoreCallingIdentity(identity); |
| 10798 | } |
| 10799 | } |
| 10800 | |
| 10801 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10802 | * Get the EAB capability from the EAB database. |
| 10803 | */ |
| 10804 | @Override |
| 10805 | public String getCapabilityFromEab(String contact) { |
| 10806 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10807 | enforceModifyPermission(); |
| 10808 | final long identity = Binder.clearCallingIdentity(); |
| 10809 | try { |
| 10810 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10811 | } finally { |
| 10812 | Binder.restoreCallingIdentity(identity); |
| 10813 | } |
| 10814 | } |
| 10815 | |
| 10816 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10817 | * Remove the EAB contacts from the EAB database. |
| 10818 | */ |
| 10819 | @Override |
| 10820 | public int removeContactFromEab(int subId, String contacts) { |
| 10821 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10822 | enforceModifyPermission(); |
| 10823 | final long identity = Binder.clearCallingIdentity(); |
| 10824 | try { |
| 10825 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10826 | } finally { |
| 10827 | Binder.restoreCallingIdentity(identity); |
| 10828 | } |
| 10829 | } |
| 10830 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10831 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10832 | public boolean getDeviceUceEnabled() { |
| 10833 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10834 | final long identity = Binder.clearCallingIdentity(); |
| 10835 | try { |
| 10836 | return mApp.getDeviceUceEnabled(); |
| 10837 | } finally { |
| 10838 | Binder.restoreCallingIdentity(identity); |
| 10839 | } |
| 10840 | } |
| 10841 | |
| 10842 | @Override |
| 10843 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10844 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10845 | final long identity = Binder.clearCallingIdentity(); |
| 10846 | try { |
| 10847 | mApp.setDeviceUceEnabled(isEnabled); |
| 10848 | } finally { |
| 10849 | Binder.restoreCallingIdentity(identity); |
| 10850 | } |
| 10851 | } |
| 10852 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10853 | /** |
| 10854 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10855 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10856 | */ |
| 10857 | // Used for SHELL command only right now. |
| 10858 | @Override |
| 10859 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10860 | List<String> featureTags) { |
| 10861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10862 | "addUceRegistrationOverrideShell"); |
| 10863 | final long identity = Binder.clearCallingIdentity(); |
| 10864 | try { |
| 10865 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10866 | new ArraySet<>(featureTags)); |
| 10867 | } catch (ImsException e) { |
| 10868 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10869 | } finally { |
| 10870 | Binder.restoreCallingIdentity(identity); |
| 10871 | } |
| 10872 | } |
| 10873 | |
| 10874 | /** |
| 10875 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10876 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10877 | */ |
| 10878 | // Used for SHELL command only right now. |
| 10879 | @Override |
| 10880 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10881 | List<String> featureTags) { |
| 10882 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10883 | "removeUceRegistrationOverrideShell"); |
| 10884 | final long identity = Binder.clearCallingIdentity(); |
| 10885 | try { |
| 10886 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10887 | new ArraySet<>(featureTags)); |
| 10888 | } catch (ImsException e) { |
| 10889 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10890 | } finally { |
| 10891 | Binder.restoreCallingIdentity(identity); |
| 10892 | } |
| 10893 | } |
| 10894 | |
| 10895 | /** |
| 10896 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10897 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10898 | */ |
| 10899 | // Used for SHELL command only right now. |
| 10900 | @Override |
| 10901 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10902 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10903 | "clearUceRegistrationOverrideShell"); |
| 10904 | final long identity = Binder.clearCallingIdentity(); |
| 10905 | try { |
| 10906 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10907 | } catch (ImsException e) { |
| 10908 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10909 | } finally { |
| 10910 | Binder.restoreCallingIdentity(identity); |
| 10911 | } |
| 10912 | } |
| 10913 | |
| 10914 | /** |
| 10915 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10916 | */ |
| 10917 | // Used for SHELL command only right now. |
| 10918 | @Override |
| 10919 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10920 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10921 | "getLatestRcsContactUceCapabilityShell"); |
| 10922 | final long identity = Binder.clearCallingIdentity(); |
| 10923 | try { |
| 10924 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10925 | } catch (ImsException e) { |
| 10926 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10927 | } finally { |
| 10928 | Binder.restoreCallingIdentity(identity); |
| 10929 | } |
| 10930 | } |
| 10931 | |
| 10932 | /** |
| 10933 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10934 | * device does not have an active PUBLISH. |
| 10935 | */ |
| 10936 | // Used for SHELL command only right now. |
| 10937 | @Override |
| 10938 | public String getLastUcePidfXmlShell(int subId) { |
| 10939 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10940 | final long identity = Binder.clearCallingIdentity(); |
| 10941 | try { |
| 10942 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10943 | } catch (ImsException e) { |
| 10944 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10945 | } finally { |
| 10946 | Binder.restoreCallingIdentity(identity); |
| 10947 | } |
| 10948 | } |
| 10949 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10950 | /** |
| 10951 | * Remove UCE requests cannot be sent to the network status. |
| 10952 | */ |
| 10953 | // Used for SHELL command only right now. |
| 10954 | @Override |
| 10955 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10956 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10957 | final long identity = Binder.clearCallingIdentity(); |
| 10958 | try { |
| 10959 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10960 | } catch (ImsException e) { |
| 10961 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10962 | } finally { |
| 10963 | Binder.restoreCallingIdentity(identity); |
| 10964 | } |
| 10965 | } |
| 10966 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10967 | /** |
| 10968 | * Remove UCE requests cannot be sent to the network status. |
| 10969 | */ |
| 10970 | // Used for SHELL command only. |
| 10971 | @Override |
| 10972 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10973 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10974 | final long identity = Binder.clearCallingIdentity(); |
| 10975 | try { |
| 10976 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10977 | } catch (ImsException e) { |
| 10978 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10979 | } finally { |
| 10980 | Binder.restoreCallingIdentity(identity); |
| 10981 | } |
| 10982 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10983 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10984 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10985 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10986 | String callingPackage) { |
| 10987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10988 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10989 | |
| 10990 | final int callingUid = Binder.getCallingUid(); |
| 10991 | // Verify that tha callingPackage belongs to the calling UID |
| 10992 | mApp.getSystemService(AppOpsManager.class) |
| 10993 | .checkPackage(callingUid, callingPackage); |
| 10994 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10995 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10996 | |
| 10997 | final long identity = Binder.clearCallingIdentity(); |
| 10998 | try { |
| 10999 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11000 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11001 | |
| 11002 | if (result instanceof IllegalStateException) { |
| 11003 | throw (IllegalStateException) result; |
| 11004 | } |
| 11005 | } finally { |
| 11006 | Binder.restoreCallingIdentity(identity); |
| 11007 | } |
| 11008 | } |
| 11009 | |
| 11010 | @Override |
| 11011 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11012 | String callingPackage) { |
| 11013 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11014 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11015 | |
| 11016 | final int callingUid = Binder.getCallingUid(); |
| 11017 | // Verify that tha callingPackage belongs to the calling UID |
| 11018 | mApp.getSystemService(AppOpsManager.class) |
| 11019 | .checkPackage(callingUid, callingPackage); |
| 11020 | |
| 11021 | final long identity = Binder.clearCallingIdentity(); |
| 11022 | try { |
| 11023 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11024 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11025 | |
| 11026 | if (result instanceof IllegalStateException) { |
| 11027 | throw (IllegalStateException) result; |
| 11028 | } |
| 11029 | } finally { |
| 11030 | Binder.restoreCallingIdentity(identity); |
| 11031 | } |
| 11032 | } |
| 11033 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11034 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11035 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11036 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11037 | // phone/system process do not have further restriction on request |
| 11038 | return; |
| 11039 | } |
| 11040 | |
| 11041 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11042 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11043 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11044 | context.enforceCallingOrSelfPermission( |
| 11045 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11046 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11047 | } |
| 11048 | |
| 11049 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11050 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11051 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11052 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11053 | || info.isEnabled()) { |
| 11054 | throw new IllegalArgumentException( |
| 11055 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11056 | } |
| 11057 | |
| 11058 | // Thresholds length for each RAN need in range. This has been validated in |
| 11059 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11060 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11061 | final int[] thresholds = info.getThresholds(); |
| 11062 | Objects.requireNonNull(thresholds); |
| 11063 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11064 | || thresholds.length |
| 11065 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11066 | throw new IllegalArgumentException( |
| 11067 | "thresholds length is out of range: " + thresholds.length); |
| 11068 | } |
| 11069 | } |
| 11070 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11071 | |
| 11072 | /** |
| 11073 | * Gets the current phone capability. |
| 11074 | * |
| 11075 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11076 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11077 | * It's used to evaluate possible phone config change, for example from single |
| 11078 | * SIM device to multi-SIM device. |
| 11079 | */ |
| 11080 | @Override |
| 11081 | public PhoneCapability getPhoneCapability() { |
| 11082 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11083 | final long identity = Binder.clearCallingIdentity(); |
| 11084 | try { |
| 11085 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11086 | } finally { |
| 11087 | Binder.restoreCallingIdentity(identity); |
| 11088 | } |
| 11089 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11090 | |
| 11091 | /** |
| 11092 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11093 | * required to be done shortly after the API is invoked. |
| 11094 | */ |
| 11095 | @Override |
| 11096 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11097 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11098 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11099 | enforceRebootPermission(); |
| 11100 | |
| 11101 | final long identity = Binder.clearCallingIdentity(); |
| 11102 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11103 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11104 | } finally { |
| 11105 | Binder.restoreCallingIdentity(identity); |
| 11106 | } |
| 11107 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11108 | |
| 11109 | /** |
| 11110 | * Request to get the current slicing configuration including URSP rules and |
| 11111 | * NSSAIs (configured, allowed and rejected). |
| 11112 | * |
| 11113 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11114 | */ |
| 11115 | @Override |
| 11116 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11117 | TelephonyPermissions |
| 11118 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11119 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11120 | |
| 11121 | final long identity = Binder.clearCallingIdentity(); |
| 11122 | try { |
| 11123 | Phone phone = getDefaultPhone(); |
| 11124 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11125 | } finally { |
| 11126 | Binder.restoreCallingIdentity(identity); |
| 11127 | } |
| 11128 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11129 | |
| 11130 | /** |
| 11131 | * Register an IMS connection state callback |
| 11132 | */ |
| 11133 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11134 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11135 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11136 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11137 | // ImsMmTelManager |
| 11138 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11139 | TelephonyPermissions |
| 11140 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11141 | mApp, subId, "registerImsStateCallback"); |
| 11142 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11143 | // ImsRcsManager or SipDelegateManager |
| 11144 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11145 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11146 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11147 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11148 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11149 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11150 | } |
| 11151 | |
| 11152 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11153 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11154 | "IMS not available on device."); |
| 11155 | } |
| 11156 | |
| 11157 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11158 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11159 | } |
| 11160 | |
| 11161 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11162 | if (controller == null) { |
| 11163 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11164 | "IMS not available on device."); |
| 11165 | } |
| 11166 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11167 | if (callingPackage == null) { |
| 11168 | callingPackage = getCurrentPackageName(); |
| 11169 | } |
| 11170 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11171 | final long token = Binder.clearCallingIdentity(); |
| 11172 | try { |
| 11173 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11174 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11175 | } catch (ImsException e) { |
| 11176 | throw new ServiceSpecificException(e.getCode()); |
| 11177 | } finally { |
| 11178 | Binder.restoreCallingIdentity(token); |
| 11179 | } |
| 11180 | } |
| 11181 | |
| 11182 | /** |
| 11183 | * Unregister an IMS connection state callback |
| 11184 | */ |
| 11185 | @Override |
| 11186 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11187 | final long token = Binder.clearCallingIdentity(); |
| 11188 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11189 | if (controller == null) { |
| 11190 | return; |
| 11191 | } |
| 11192 | try { |
| 11193 | controller.unregisterImsStateCallback(cb); |
| 11194 | } finally { |
| 11195 | Binder.restoreCallingIdentity(token); |
| 11196 | } |
| 11197 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11198 | |
| 11199 | /** |
| 11200 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11201 | * |
| 11202 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11203 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11204 | * SecurityException. |
| 11205 | * If there is current registered network this value will be same as the registered cell |
| 11206 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11207 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11208 | * it will be cleared and null will be returned. |
| 11209 | * |
| 11210 | */ |
| 11211 | @Override |
| 11212 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11213 | String callingFeatureId) { |
| 11214 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11215 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11216 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11217 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11218 | .setCallingPackage(callingPackage) |
| 11219 | .setCallingFeatureId(callingFeatureId) |
| 11220 | .setCallingPid(Binder.getCallingPid()) |
| 11221 | .setCallingUid(Binder.getCallingUid()) |
| 11222 | .setMethod("getLastKnownCellIdentity") |
| 11223 | .setLogAsInfo(true) |
| 11224 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11225 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11226 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11227 | .build()); |
| 11228 | |
| 11229 | boolean hasFinePermission = |
| 11230 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11231 | if (!hasFinePermission |
| 11232 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11233 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11234 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11235 | } |
| 11236 | |
| 11237 | final long identity = Binder.clearCallingIdentity(); |
| 11238 | try { |
| 11239 | Phone phone = getPhone(subId); |
| 11240 | if (phone == null) return null; |
| 11241 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11242 | if (sst == null) return null; |
| 11243 | return sst.getLastKnownCellIdentity(); |
| 11244 | } finally { |
| 11245 | Binder.restoreCallingIdentity(identity); |
| 11246 | } |
| 11247 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11248 | |
| 11249 | @Override |
| 11250 | public boolean isUsingNewDataStack() { |
| 11251 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11252 | return getDefaultPhone().isUsingNewDataStack(); |
| 11253 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11254 | |
| 11255 | /** |
| 11256 | * Sets the modem service class Name that Telephony will bind to. |
| 11257 | * |
| 11258 | * @param serviceName The class name of the modem service. |
| 11259 | * @return true if the operation is succeed, otherwise false. |
| 11260 | */ |
| 11261 | public boolean setModemService(String serviceName) { |
| 11262 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11263 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11264 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11265 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11266 | "setModemService"); |
| 11267 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11268 | } |
| 11269 | |
| 11270 | /** |
| 11271 | * Return the class name of the currently bounded modem service. |
| 11272 | * |
| 11273 | * @return the class name of the modem service. |
| 11274 | */ |
| 11275 | public String getModemService() { |
| 11276 | String result; |
| 11277 | Log.d(LOG_TAG, "getModemService"); |
| 11278 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11279 | TelephonyPermissions |
| 11280 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11281 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11282 | "getModemService"); |
| 11283 | result = mPhoneConfigurationManager.getModemService(); |
| 11284 | Log.d(LOG_TAG, "result = " + result); |
| 11285 | return result; |
| 11286 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11287 | |
| 11288 | @Override |
| 11289 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11290 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11291 | mApp.enforceCallingOrSelfPermission( |
| 11292 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11293 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11294 | |
| 11295 | final long identity = Binder.clearCallingIdentity(); |
| 11296 | try { |
| 11297 | Phone phone = getPhone(subId); |
| 11298 | if (phone == null) return; |
| 11299 | phone.setVoiceServiceStateOverride(hasService); |
| 11300 | } finally { |
| 11301 | Binder.restoreCallingIdentity(identity); |
| 11302 | } |
| 11303 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11304 | |
| 11305 | /** |
| 11306 | * set removable eSIM as default eUICC. |
| 11307 | * |
| 11308 | * @hide |
| 11309 | */ |
| 11310 | @Override |
| 11311 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11312 | enforceModifyPermission(); |
| 11313 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11314 | |
| 11315 | final long identity = Binder.clearCallingIdentity(); |
| 11316 | try { |
| 11317 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11318 | } finally { |
| 11319 | Binder.restoreCallingIdentity(identity); |
| 11320 | } |
| 11321 | } |
| 11322 | |
| 11323 | /** |
| 11324 | * Returns whether the removable eSIM is default eUICC or not. |
| 11325 | * |
| 11326 | * @hide |
| 11327 | */ |
| 11328 | @Override |
| 11329 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11330 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11331 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11332 | |
| 11333 | final long identity = Binder.clearCallingIdentity(); |
| 11334 | try { |
| 11335 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11336 | } finally { |
| 11337 | Binder.restoreCallingIdentity(identity); |
| 11338 | } |
| 11339 | } |
| 11340 | |
| 11341 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11342 | } |