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; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 191 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 192 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 194 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccIoResult; |
| 196 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 204 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 205 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 206 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 207 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 208 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 209 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 210 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 211 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 212 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 213 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 216 | import com.android.services.telephony.TelecomAccountRegistry; |
| 217 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 218 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 219 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 220 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 221 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.io.IOException; |
| 223 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 224 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 225 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 226 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 227 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 228 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 229 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 230 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 231 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 232 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 233 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 234 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 235 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 236 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 237 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 238 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 239 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * Implementation of the ITelephony interface. |
| 243 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 244 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 245 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 246 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 247 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 248 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 249 | |
| 250 | // Message codes used with mMainThreadHandler |
| 251 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 252 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 253 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 254 | private static final int CMD_OPEN_CHANNEL = 9; |
| 255 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 256 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 257 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 258 | private static final int CMD_NV_READ_ITEM = 13; |
| 259 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 260 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 261 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 262 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 263 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 265 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 266 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 267 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 268 | private static final int CMD_SEND_ENVELOPE = 25; |
| 269 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 270 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 271 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 272 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 273 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 274 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 275 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 276 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 277 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 278 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 279 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 280 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 281 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 282 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 283 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 284 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 285 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 286 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 287 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 288 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 289 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 290 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 291 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 292 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 293 | private static final int CMD_SWITCH_SLOTS = 50; |
| 294 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 295 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 296 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 297 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 298 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 299 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 300 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 301 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 302 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 303 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 304 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 305 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 306 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 307 | private static final int CMD_MODEM_REBOOT = 64; |
| 308 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 309 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 310 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 311 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 312 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 314 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 315 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 316 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 317 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 318 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 319 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 320 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 321 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 322 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 323 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 324 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 325 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 326 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 327 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 328 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 329 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 330 | private static final int CMD_GET_CALL_WAITING = 87; |
| 331 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 332 | private static final int CMD_SET_CALL_WAITING = 89; |
| 333 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 334 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 335 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 336 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 337 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 338 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 339 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 340 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 341 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 342 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 343 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 344 | private static final int CMD_SET_SIM_POWER = 101; |
| 345 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 347 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 348 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 349 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 350 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 351 | 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] | 352 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 353 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 354 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 355 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 356 | private static final int CMD_ENABLE_VONR = 113; |
| 357 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 358 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 359 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 361 | // Parameters of select command. |
| 362 | private static final int SELECT_COMMAND = 0xA4; |
| 363 | private static final int SELECT_P1 = 0x04; |
| 364 | private static final int SELECT_P2 = 0; |
| 365 | private static final int SELECT_P3 = 0x10; |
| 366 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 367 | /** The singleton instance. */ |
| 368 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 369 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 371 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 372 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 373 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 374 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 376 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 378 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 380 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 381 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 383 | /** User Activity */ |
| 384 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 385 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 386 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 387 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 388 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 389 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 390 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 391 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 392 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 393 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 394 | // String to store multi SIM allowed |
| 395 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 396 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 397 | // The AID of ISD-R. |
| 398 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 399 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 400 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 401 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 402 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 403 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 404 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 405 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 406 | 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] | 407 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 408 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 409 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 410 | */ |
| 411 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 412 | "reset_network_erase_modem_config_enabled"; |
| 413 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 414 | 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] | 415 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 416 | /** |
| 417 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 418 | * one ICCID active at the same time. |
| 419 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 420 | * |
| 421 | * @hide |
| 422 | */ |
| 423 | @ChangeId |
| 424 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 425 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 426 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 427 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 428 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 429 | * operation fails. |
| 430 | */ |
| 431 | @ChangeId |
| 432 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 433 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 434 | |
| 435 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 436 | * A request object to use for transmitting data to an ICC. |
| 437 | */ |
| 438 | private static final class IccAPDUArgument { |
| 439 | public int channel, cla, command, p1, p2, p3; |
| 440 | public String data; |
| 441 | |
| 442 | public IccAPDUArgument(int channel, int cla, int command, |
| 443 | int p1, int p2, int p3, String data) { |
| 444 | this.channel = channel; |
| 445 | this.cla = cla; |
| 446 | this.command = command; |
| 447 | this.p1 = p1; |
| 448 | this.p2 = p2; |
| 449 | this.p3 = p3; |
| 450 | this.data = data; |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 455 | * A request object to use for transmitting data to an ICC. |
| 456 | */ |
| 457 | private static final class ManualNetworkSelectionArgument { |
| 458 | public OperatorInfo operatorInfo; |
| 459 | public boolean persistSelection; |
| 460 | |
| 461 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 462 | this.operatorInfo = operatorInfo; |
| 463 | this.persistSelection = persistSelection; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 468 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 469 | * request after sending. The main thread will notify the request when it is complete. |
| 470 | */ |
| 471 | private static final class MainThreadRequest { |
| 472 | /** The argument to use for the request */ |
| 473 | public Object argument; |
| 474 | /** The result of the request that is run on the main thread */ |
| 475 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 476 | // The subscriber id that this request applies to. Defaults to |
| 477 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 478 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 480 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 481 | public Phone phone; |
| 482 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 483 | public WorkSource workSource; |
| 484 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | public MainThreadRequest(Object argument) { |
| 486 | this.argument = argument; |
| 487 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 488 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 489 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 490 | this.argument = argument; |
| 491 | if (phone != null) { |
| 492 | this.phone = phone; |
| 493 | } |
| 494 | this.workSource = workSource; |
| 495 | } |
| 496 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 497 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 498 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 499 | if (subId != null) { |
| 500 | this.subId = subId; |
| 501 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 502 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 506 | private static final class IncomingThirdPartyCallArgs { |
| 507 | public final ComponentName component; |
| 508 | public final String callId; |
| 509 | public final String callerDisplayName; |
| 510 | |
| 511 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 512 | String callerDisplayName) { |
| 513 | this.component = component; |
| 514 | this.callId = callId; |
| 515 | this.callerDisplayName = callerDisplayName; |
| 516 | } |
| 517 | } |
| 518 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | /** |
| 520 | * A handler that processes messages on the main thread in the phone process. Since many |
| 521 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 522 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 523 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 524 | * on, which will be notified when the operation completes and will contain the result of the |
| 525 | * request. |
| 526 | * |
| 527 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 528 | * note that request.result must be set to something non-null for the calling thread to |
| 529 | * unblock. |
| 530 | */ |
| 531 | private final class MainThreadHandler extends Handler { |
| 532 | @Override |
| 533 | public void handleMessage(Message msg) { |
| 534 | MainThreadRequest request; |
| 535 | Message onCompleted; |
| 536 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 537 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 539 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 540 | |
| 541 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | case CMD_HANDLE_USSD_REQUEST: { |
| 543 | request = (MainThreadRequest) msg.obj; |
| 544 | final Phone phone = getPhoneFromRequest(request); |
| 545 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 546 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 547 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 548 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 549 | if (!isUssdApiAllowed(request.subId)) { |
| 550 | // Carrier does not support use of this API, return failure. |
| 551 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 552 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 553 | Bundle returnData = new Bundle(); |
| 554 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 555 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 556 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 557 | request.result = true; |
| 558 | notifyRequester(request); |
| 559 | return; |
| 560 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 561 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 562 | try { |
| 563 | request.result = phone != null |
| 564 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 565 | } catch (CallStateException cse) { |
| 566 | request.result = false; |
| 567 | } |
| 568 | // Wake up the requesting thread |
| 569 | notifyRequester(request); |
| 570 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 573 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 574 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 575 | final Phone phone = getPhoneFromRequest(request); |
| 576 | request.result = phone != null ? |
| 577 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 578 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 579 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 582 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 585 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 587 | uiccPort = getUiccPortFromRequest(request); |
| 588 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 589 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 590 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 594 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 595 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 596 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 597 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 598 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 599 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | break; |
| 601 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | ar = (AsyncResult) msg.obj; |
| 604 | request = (MainThreadRequest) ar.userObj; |
| 605 | if (ar.exception == null && ar.result != null) { |
| 606 | request.result = ar.result; |
| 607 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 608 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 609 | if (ar.result == null) { |
| 610 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 611 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 613 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | } else { |
| 615 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 616 | } |
| 617 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 618 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | break; |
| 620 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 622 | request = (MainThreadRequest) msg.obj; |
| 623 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 624 | uiccPort = getUiccPortFromRequest(request); |
| 625 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 626 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 627 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | } else { |
| 630 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 631 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 632 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 633 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 634 | iccArgument.p2, |
| 635 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 636 | } |
| 637 | break; |
| 638 | |
| 639 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 640 | ar = (AsyncResult) msg.obj; |
| 641 | request = (MainThreadRequest) ar.userObj; |
| 642 | if (ar.exception == null && ar.result != null) { |
| 643 | request.result = ar.result; |
| 644 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 645 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | if (ar.result == null) { |
| 647 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 648 | } else if (ar.exception instanceof CommandException) { |
| 649 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 650 | ar.exception); |
| 651 | } else { |
| 652 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 653 | } |
| 654 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case CMD_EXCHANGE_SIM_IO: |
| 659 | request = (MainThreadRequest) msg.obj; |
| 660 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 661 | uiccPort = getUiccPortFromRequest(request); |
| 662 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 663 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 664 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 665 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | } else { |
| 667 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 668 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 669 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 671 | iccArgument.data, onCompleted); |
| 672 | } |
| 673 | break; |
| 674 | |
| 675 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
| 678 | if (ar.exception == null && ar.result != null) { |
| 679 | request.result = ar.result; |
| 680 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 681 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 683 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | break; |
| 685 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 686 | case CMD_SEND_ENVELOPE: |
| 687 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 688 | uiccPort = getUiccPortFromRequest(request); |
| 689 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 690 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 691 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 692 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 693 | } else { |
| 694 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 695 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 696 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | case EVENT_SEND_ENVELOPE_DONE: |
| 700 | ar = (AsyncResult) msg.obj; |
| 701 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 702 | if (ar.exception == null && ar.result != null) { |
| 703 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 704 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 705 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 706 | if (ar.result == null) { |
| 707 | loge("sendEnvelopeWithStatus: Empty response"); |
| 708 | } else if (ar.exception instanceof CommandException) { |
| 709 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 710 | ar.exception); |
| 711 | } else { |
| 712 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 713 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 714 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 715 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 716 | break; |
| 717 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 718 | case CMD_OPEN_CHANNEL: |
| 719 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 720 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 721 | IccLogicalChannelRequest openChannelRequest = |
| 722 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 723 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 724 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 725 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 726 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 727 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 728 | } else { |
| 729 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 730 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 731 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 732 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_OPEN_CHANNEL_DONE: |
| 736 | ar = (AsyncResult) msg.obj; |
| 737 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 738 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 739 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 740 | int[] result = (int[]) ar.result; |
| 741 | int channelId = result[0]; |
| 742 | byte[] selectResponse = null; |
| 743 | if (result.length > 1) { |
| 744 | selectResponse = new byte[result.length - 1]; |
| 745 | for (int i = 1; i < result.length; ++i) { |
| 746 | selectResponse[i - 1] = (byte) result[i]; |
| 747 | } |
| 748 | } |
| 749 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 750 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 751 | |
| 752 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 753 | if (uiccPort == null) { |
| 754 | loge("EVENT_OPEN_CHANNEL_DONE: UiccPort is null"); |
| 755 | } else { |
| 756 | IccLogicalChannelRequest channelRequest = |
| 757 | (IccLogicalChannelRequest) request.argument; |
| 758 | channelRequest.channel = channelId; |
| 759 | uiccPort.onLogicalChannelOpened(channelRequest); |
| 760 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | if (ar.result == null) { |
| 763 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 765 | if (ar.exception != null) { |
| 766 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 767 | } |
| 768 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 769 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 770 | if (ar.exception instanceof CommandException) { |
| 771 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 772 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 773 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 774 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 775 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 776 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 780 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 782 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 783 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case CMD_CLOSE_CHANNEL: |
| 787 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 788 | uiccPort = getUiccPortFromRequest(request); |
| 789 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 790 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 791 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 793 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 794 | } else { |
| 795 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 796 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 797 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 801 | ar = (AsyncResult) msg.obj; |
| 802 | request = (MainThreadRequest) ar.userObj; |
| 803 | if (ar.exception == null) { |
| 804 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 805 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 806 | if (uiccPort == null) { |
| 807 | loge("EVENT_CLOSE_CHANNEL_DONE: UiccPort is null"); |
| 808 | } else { |
| 809 | final int channelId = (Integer) request.argument; |
| 810 | uiccPort.onLogicalChannelClosed(channelId); |
| 811 | } |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 812 | } else { |
| 813 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 815 | if (ar.exception instanceof CommandException) { |
| 816 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 817 | CommandException.Error error = |
| 818 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 819 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 820 | // should only throw exceptions from the binder threads. |
| 821 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 822 | "iccCloseLogicalChannel: invalid argument "); |
| 823 | } |
| 824 | } else { |
| 825 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 826 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 827 | request.result = (exception != null) ? exception : |
| 828 | new IllegalStateException( |
| 829 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 830 | } |
| 831 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 832 | break; |
| 833 | |
| 834 | case CMD_NV_READ_ITEM: |
| 835 | request = (MainThreadRequest) msg.obj; |
| 836 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 837 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 838 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 839 | break; |
| 840 | |
| 841 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 842 | ar = (AsyncResult) msg.obj; |
| 843 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 844 | if (ar.exception == null && ar.result != null) { |
| 845 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 846 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 847 | request.result = ""; |
| 848 | if (ar.result == null) { |
| 849 | loge("nvReadItem: Empty response"); |
| 850 | } else if (ar.exception instanceof CommandException) { |
| 851 | loge("nvReadItem: CommandException: " + |
| 852 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 853 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 854 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 855 | } |
| 856 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 857 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 858 | break; |
| 859 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 860 | case CMD_NV_WRITE_ITEM: |
| 861 | request = (MainThreadRequest) msg.obj; |
| 862 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 863 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 864 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 865 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 866 | break; |
| 867 | |
| 868 | case EVENT_NV_WRITE_ITEM_DONE: |
| 869 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 870 | break; |
| 871 | |
| 872 | case CMD_NV_WRITE_CDMA_PRL: |
| 873 | request = (MainThreadRequest) msg.obj; |
| 874 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 875 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 876 | break; |
| 877 | |
| 878 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 879 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 880 | break; |
| 881 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 882 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 883 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 884 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 885 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 886 | break; |
| 887 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 888 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 889 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 892 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 893 | request = (MainThreadRequest) msg.obj; |
| 894 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 895 | request); |
| 896 | Phone phone = getPhoneFromRequest(request); |
| 897 | if (phone != null) { |
| 898 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 899 | } else { |
| 900 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 901 | request.result = false; |
| 902 | notifyRequester(request); |
| 903 | } |
| 904 | break; |
| 905 | } |
| 906 | |
| 907 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 908 | ar = (AsyncResult) msg.obj; |
| 909 | request = (MainThreadRequest) ar.userObj; |
| 910 | if (ar.exception == null && ar.result != null) { |
| 911 | request.result = ar.result; |
| 912 | } else { |
| 913 | // request.result must be set to something non-null |
| 914 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 915 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 916 | request.result = ar.result; |
| 917 | } else { |
| 918 | request.result = false; |
| 919 | } |
| 920 | if (ar.result == null) { |
| 921 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 922 | } else if (ar.exception instanceof CommandException) { |
| 923 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 924 | + ar.exception); |
| 925 | } else { |
| 926 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 927 | } |
| 928 | } |
| 929 | notifyRequester(request); |
| 930 | break; |
| 931 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 932 | case CMD_IS_VONR_ENABLED: { |
| 933 | request = (MainThreadRequest) msg.obj; |
| 934 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 935 | request); |
| 936 | Phone phone = getPhoneFromRequest(request); |
| 937 | if (phone != null) { |
| 938 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 939 | } else { |
| 940 | loge("isVoNrEnabled: No phone object"); |
| 941 | request.result = false; |
| 942 | notifyRequester(request); |
| 943 | } |
| 944 | break; |
| 945 | } |
| 946 | |
| 947 | case EVENT_IS_VONR_ENABLED_DONE: |
| 948 | ar = (AsyncResult) msg.obj; |
| 949 | request = (MainThreadRequest) ar.userObj; |
| 950 | if (ar.exception == null && ar.result != null) { |
| 951 | request.result = ar.result; |
| 952 | } else { |
| 953 | // request.result must be set to something non-null |
| 954 | // for the calling thread to unblock |
| 955 | if (ar.result != null) { |
| 956 | request.result = ar.result; |
| 957 | } else { |
| 958 | request.result = false; |
| 959 | } |
| 960 | if (ar.result == null) { |
| 961 | loge("isVoNrEnabled: Empty response"); |
| 962 | } else if (ar.exception instanceof CommandException) { |
| 963 | loge("isVoNrEnabled: CommandException: " |
| 964 | + ar.exception); |
| 965 | } else { |
| 966 | loge("isVoNrEnabled: Unknown exception"); |
| 967 | } |
| 968 | } |
| 969 | notifyRequester(request); |
| 970 | break; |
| 971 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 972 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 973 | request = (MainThreadRequest) msg.obj; |
| 974 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 975 | Phone phone = getPhoneFromRequest(request); |
| 976 | if (phone != null) { |
| 977 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 978 | request.workSource); |
| 979 | } else { |
| 980 | loge("enableNrDualConnectivity: No phone object"); |
| 981 | request.result = |
| 982 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 983 | notifyRequester(request); |
| 984 | } |
| 985 | break; |
| 986 | } |
| 987 | |
| 988 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 989 | ar = (AsyncResult) msg.obj; |
| 990 | request = (MainThreadRequest) ar.userObj; |
| 991 | if (ar.exception == null) { |
| 992 | request.result = |
| 993 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 994 | } else { |
| 995 | request.result = |
| 996 | TelephonyManager |
| 997 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 998 | if (ar.exception instanceof CommandException) { |
| 999 | CommandException.Error error = |
| 1000 | ((CommandException) (ar.exception)).getCommandError(); |
| 1001 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1002 | request.result = |
| 1003 | TelephonyManager |
| 1004 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1005 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1006 | request.result = |
| 1007 | TelephonyManager |
| 1008 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1009 | } |
| 1010 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1011 | + ar.exception); |
| 1012 | } else { |
| 1013 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1014 | } |
| 1015 | } |
| 1016 | notifyRequester(request); |
| 1017 | break; |
| 1018 | } |
| 1019 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1020 | case CMD_ENABLE_VONR: { |
| 1021 | request = (MainThreadRequest) msg.obj; |
| 1022 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1023 | Phone phone = getPhoneFromRequest(request); |
| 1024 | if (phone != null) { |
| 1025 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1026 | request.workSource); |
| 1027 | } else { |
| 1028 | loge("setVoNrEnabled: No phone object"); |
| 1029 | request.result = |
| 1030 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1031 | notifyRequester(request); |
| 1032 | } |
| 1033 | break; |
| 1034 | } |
| 1035 | |
| 1036 | case EVENT_ENABLE_VONR_DONE: { |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | if (ar.exception == null) { |
| 1040 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1041 | } else { |
| 1042 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1043 | if (ar.exception instanceof CommandException) { |
| 1044 | CommandException.Error error = |
| 1045 | ((CommandException) (ar.exception)).getCommandError(); |
| 1046 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1047 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1048 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1049 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1050 | } else { |
| 1051 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1052 | } |
| 1053 | loge("setVoNrEnabled" + ": CommandException: " |
| 1054 | + ar.exception); |
| 1055 | } else { |
| 1056 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1057 | } |
| 1058 | } |
| 1059 | notifyRequester(request); |
| 1060 | break; |
| 1061 | } |
| 1062 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1063 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1064 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1065 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1066 | request); |
| 1067 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1068 | break; |
| 1069 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1070 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1071 | ar = (AsyncResult) msg.obj; |
| 1072 | request = (MainThreadRequest) ar.userObj; |
| 1073 | if (ar.exception == null && ar.result != null) { |
| 1074 | request.result = ar.result; // Integer |
| 1075 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1076 | // request.result must be set to something non-null |
| 1077 | // for the calling thread to unblock |
| 1078 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1079 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1080 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1081 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1082 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1083 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1084 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1085 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1086 | } |
| 1087 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1088 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1089 | break; |
| 1090 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1091 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1092 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1093 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1094 | request); |
| 1095 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1096 | (Pair<Integer, Long>) request.argument; |
| 1097 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1098 | reasonWithNetworkTypes.first, |
| 1099 | reasonWithNetworkTypes.second, |
| 1100 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1101 | break; |
| 1102 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1103 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1104 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1105 | break; |
| 1106 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1107 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1108 | request = (MainThreadRequest)msg.obj; |
| 1109 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1110 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1111 | break; |
| 1112 | |
| 1113 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1114 | ar = (AsyncResult)msg.obj; |
| 1115 | request = (MainThreadRequest)ar.userObj; |
| 1116 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1117 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1118 | break; |
| 1119 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1120 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1121 | request = (MainThreadRequest) msg.obj; |
| 1122 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1123 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1124 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1125 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1126 | break; |
| 1127 | |
| 1128 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1129 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1130 | break; |
| 1131 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1132 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1133 | request = (MainThreadRequest) msg.obj; |
| 1134 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1135 | request); |
| 1136 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1137 | break; |
| 1138 | |
| 1139 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1140 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1141 | break; |
| 1142 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1143 | case CMD_PERFORM_NETWORK_SCAN: |
| 1144 | request = (MainThreadRequest) msg.obj; |
| 1145 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1146 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1147 | break; |
| 1148 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1150 | request = (MainThreadRequest) msg.obj; |
| 1151 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1152 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1153 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1154 | request.argument; |
| 1155 | int callForwardingReason = args.first; |
| 1156 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1157 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | } |
| 1159 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | ar = (AsyncResult) msg.obj; |
| 1161 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1162 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1163 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1164 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1165 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1166 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1167 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1168 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1169 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1170 | // any service for voice call. |
| 1171 | if ((callForwardInfo.serviceClass |
| 1172 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1173 | callForwardingInfo = new CallForwardingInfo( |
| 1174 | callForwardInfo.status |
| 1175 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1176 | callForwardInfo.reason, |
| 1177 | callForwardInfo.number, |
| 1178 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1179 | break; |
| 1180 | } |
| 1181 | } |
| 1182 | // Didn't find a call forward info for voice call. |
| 1183 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1184 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1185 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1186 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1187 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1188 | } else { |
| 1189 | if (ar.result == null) { |
| 1190 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1191 | } |
| 1192 | if (ar.exception != null) { |
| 1193 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1194 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1195 | int errorCode = TelephonyManager |
| 1196 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1197 | if (ar.exception instanceof CommandException) { |
| 1198 | CommandException.Error error = |
| 1199 | ((CommandException) (ar.exception)).getCommandError(); |
| 1200 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1201 | errorCode = TelephonyManager |
| 1202 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1203 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1204 | errorCode = TelephonyManager |
| 1205 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1206 | } |
| 1207 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1208 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1214 | request = (MainThreadRequest) msg.obj; |
| 1215 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1216 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1217 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1219 | request.argument).first; |
| 1220 | request.phone.setCallForwardingOption( |
| 1221 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1222 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | callForwardingInfoToSet.getReason(), |
| 1225 | callForwardingInfoToSet.getNumber(), |
| 1226 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1227 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1229 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1230 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1231 | ar = (AsyncResult) msg.obj; |
| 1232 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1233 | Consumer<Integer> callback = |
| 1234 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1235 | request.argument).second; |
| 1236 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1237 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1238 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1239 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1240 | if (ar.exception instanceof CommandException) { |
| 1241 | CommandException.Error error = |
| 1242 | ((CommandException) (ar.exception)).getCommandError(); |
| 1243 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1244 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1245 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1246 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1247 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1248 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1249 | } |
| 1250 | } |
| 1251 | callback.accept(errorCode); |
| 1252 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1253 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1256 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1257 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | request = (MainThreadRequest) msg.obj; |
| 1260 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1261 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1262 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1265 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1268 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1269 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1270 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1271 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1272 | // Service Class is a bit mask per 3gpp 27.007. |
| 1273 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1274 | if (callForwardResults.length > 1 |
| 1275 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1277 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1278 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1279 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1280 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1281 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1282 | } |
| 1283 | } else { |
| 1284 | if (ar.result == null) { |
| 1285 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1286 | } |
| 1287 | if (ar.exception != null) { |
| 1288 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1289 | } |
| 1290 | if (ar.exception instanceof CommandException) { |
| 1291 | CommandException.Error error = |
| 1292 | ((CommandException) (ar.exception)).getCommandError(); |
| 1293 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1294 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1296 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1297 | callWaitingStatus = |
| 1298 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | } |
| 1300 | } |
| 1301 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1302 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | request = (MainThreadRequest) msg.obj; |
| 1308 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1310 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1315 | ar = (AsyncResult) msg.obj; |
| 1316 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1318 | Consumer<Integer> callback = |
| 1319 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1320 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1321 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1322 | if (ar.exception instanceof CommandException) { |
| 1323 | CommandException.Error error = |
| 1324 | ((CommandException) (ar.exception)).getCommandError(); |
| 1325 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1326 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1327 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1328 | callback.accept( |
| 1329 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | } else { |
| 1331 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1332 | } |
| 1333 | } else { |
| 1334 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1335 | } |
| 1336 | } else { |
| 1337 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1338 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1339 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1340 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1341 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1342 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1343 | ar = (AsyncResult) msg.obj; |
| 1344 | request = (MainThreadRequest) ar.userObj; |
| 1345 | CellNetworkScanResult cellScanResult; |
| 1346 | if (ar.exception == null && ar.result != null) { |
| 1347 | cellScanResult = new CellNetworkScanResult( |
| 1348 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1349 | (List<OperatorInfo>) ar.result); |
| 1350 | } else { |
| 1351 | if (ar.result == null) { |
| 1352 | loge("getCellNetworkScanResults: Empty response"); |
| 1353 | } |
| 1354 | if (ar.exception != null) { |
| 1355 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1356 | } |
| 1357 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1358 | if (ar.exception instanceof CommandException) { |
| 1359 | CommandException.Error error = |
| 1360 | ((CommandException) (ar.exception)).getCommandError(); |
| 1361 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1362 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1363 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1364 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1365 | } |
| 1366 | } |
| 1367 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1368 | } |
| 1369 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1370 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1371 | break; |
| 1372 | |
| 1373 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1374 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1375 | ManualNetworkSelectionArgument selArg = |
| 1376 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1377 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1378 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1379 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1380 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1381 | break; |
| 1382 | |
| 1383 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1384 | ar = (AsyncResult) msg.obj; |
| 1385 | request = (MainThreadRequest) ar.userObj; |
| 1386 | if (ar.exception == null) { |
| 1387 | request.result = true; |
| 1388 | } else { |
| 1389 | request.result = false; |
| 1390 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1391 | } |
| 1392 | notifyRequester(request); |
| 1393 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1394 | break; |
| 1395 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1396 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1397 | request = (MainThreadRequest) msg.obj; |
| 1398 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1399 | if (defaultPhone != null) { |
| 1400 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1401 | } else { |
| 1402 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1403 | Bundle bundle = new Bundle(); |
| 1404 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1405 | new ModemActivityInfo(0, 0, 0, |
| 1406 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1407 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1408 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1409 | break; |
| 1410 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1411 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1412 | ar = (AsyncResult) msg.obj; |
| 1413 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1414 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1415 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1416 | if (mLastModemActivityInfo == null) { |
| 1417 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1418 | mLastModemActivitySpecificInfo[0] = |
| 1419 | new ActivityStatsTechSpecificInfo( |
| 1420 | 0, |
| 1421 | 0, |
| 1422 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1423 | 0); |
| 1424 | mLastModemActivityInfo = |
| 1425 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1426 | } |
| 1427 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1428 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1429 | // Update the last modem activity info and the result of the request. |
| 1430 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1431 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1432 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1433 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1434 | mLastModemActivityInfo = |
| 1435 | new ModemActivityInfo( |
| 1436 | mLastModemActivityInfo.getTimestampMillis(), |
| 1437 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1438 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1439 | mLastModemActivitySpecificInfo); |
| 1440 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1441 | } else { |
| 1442 | if (ar.result == null) { |
| 1443 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1444 | error = TelephonyManager.ModemActivityInfoException |
| 1445 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1446 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1447 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1448 | error = TelephonyManager.ModemActivityInfoException |
| 1449 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1450 | } else { |
| 1451 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1452 | error = TelephonyManager.ModemActivityInfoException |
| 1453 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1454 | } |
| 1455 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1456 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1457 | if (mLastModemActivityInfo != null) { |
| 1458 | bundle.putParcelable( |
| 1459 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1460 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1461 | } else { |
| 1462 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1463 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1464 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1465 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1466 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1467 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1468 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1469 | case CMD_SET_ALLOWED_CARRIERS: |
| 1470 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1471 | CarrierRestrictionRules argument = |
| 1472 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1473 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1474 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1475 | break; |
| 1476 | |
| 1477 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1478 | ar = (AsyncResult) msg.obj; |
| 1479 | request = (MainThreadRequest) ar.userObj; |
| 1480 | if (ar.exception == null && ar.result != null) { |
| 1481 | request.result = ar.result; |
| 1482 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1483 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1484 | if (ar.exception instanceof CommandException) { |
| 1485 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1486 | CommandException.Error error = |
| 1487 | ((CommandException) (ar.exception)).getCommandError(); |
| 1488 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1489 | request.result = |
| 1490 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1491 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1492 | } else { |
| 1493 | loge("setAllowedCarriers: Unknown exception"); |
| 1494 | } |
| 1495 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1496 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1497 | break; |
| 1498 | |
| 1499 | case CMD_GET_ALLOWED_CARRIERS: |
| 1500 | request = (MainThreadRequest) msg.obj; |
| 1501 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1502 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1503 | break; |
| 1504 | |
| 1505 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1506 | ar = (AsyncResult) msg.obj; |
| 1507 | request = (MainThreadRequest) ar.userObj; |
| 1508 | if (ar.exception == null && ar.result != null) { |
| 1509 | request.result = ar.result; |
| 1510 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1511 | request.result = new IllegalStateException( |
| 1512 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1513 | if (ar.result == null) { |
| 1514 | loge("getAllowedCarriers: Empty response"); |
| 1515 | } else if (ar.exception instanceof CommandException) { |
| 1516 | loge("getAllowedCarriers: CommandException: " + |
| 1517 | ar.exception); |
| 1518 | } else { |
| 1519 | loge("getAllowedCarriers: Unknown exception"); |
| 1520 | } |
| 1521 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1522 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1523 | break; |
| 1524 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1525 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception == null && ar.result != null) { |
| 1529 | request.result = ar.result; |
| 1530 | } else { |
| 1531 | request.result = new IllegalArgumentException( |
| 1532 | "Failed to retrieve Forbidden Plmns"); |
| 1533 | if (ar.result == null) { |
| 1534 | loge("getForbiddenPlmns: Empty response"); |
| 1535 | } else { |
| 1536 | loge("getForbiddenPlmns: Unknown exception"); |
| 1537 | } |
| 1538 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1539 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1540 | break; |
| 1541 | |
| 1542 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1543 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1544 | uiccPort = getUiccPortFromRequest(request); |
| 1545 | if (uiccPort == null) { |
| 1546 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1547 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1548 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1549 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1550 | break; |
| 1551 | } |
| 1552 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1553 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1554 | if (uiccApp == null) { |
| 1555 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1556 | + appType); |
| 1557 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1558 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1559 | break; |
| 1560 | } else { |
| 1561 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1562 | + " specified type -- " + appType); |
| 1563 | } |
| 1564 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1565 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1566 | onCompleted); |
| 1567 | break; |
| 1568 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1569 | case CMD_SWITCH_SLOTS: |
| 1570 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1571 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1572 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1573 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1574 | break; |
| 1575 | |
| 1576 | case EVENT_SWITCH_SLOTS_DONE: |
| 1577 | ar = (AsyncResult) msg.obj; |
| 1578 | request = (MainThreadRequest) ar.userObj; |
| 1579 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1580 | notifyRequester(request); |
| 1581 | break; |
| 1582 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1583 | request = (MainThreadRequest) msg.obj; |
| 1584 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1585 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1586 | break; |
| 1587 | |
| 1588 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1589 | ar = (AsyncResult) msg.obj; |
| 1590 | request = (MainThreadRequest) ar.userObj; |
| 1591 | if (ar.exception != null) { |
| 1592 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1593 | } else { |
| 1594 | int mode = ((int[]) ar.result)[0]; |
| 1595 | if (mode == 0) { |
| 1596 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1597 | } else { |
| 1598 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1599 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1600 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1601 | notifyRequester(request); |
| 1602 | break; |
| 1603 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1604 | request = (MainThreadRequest) msg.obj; |
| 1605 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1606 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1607 | break; |
| 1608 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1609 | ar = (AsyncResult) msg.obj; |
| 1610 | request = (MainThreadRequest) ar.userObj; |
| 1611 | if (ar.exception != null) { |
| 1612 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1613 | } else { |
| 1614 | request.result = ((int[]) ar.result)[0]; |
| 1615 | } |
| 1616 | notifyRequester(request); |
| 1617 | break; |
| 1618 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1619 | request = (MainThreadRequest) msg.obj; |
| 1620 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1621 | int mode = (int) request.argument; |
| 1622 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1623 | break; |
| 1624 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1625 | ar = (AsyncResult) msg.obj; |
| 1626 | request = (MainThreadRequest) ar.userObj; |
| 1627 | request.result = ar.exception == null; |
| 1628 | notifyRequester(request); |
| 1629 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1630 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1631 | request = (MainThreadRequest) msg.obj; |
| 1632 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1633 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1634 | break; |
| 1635 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1636 | ar = (AsyncResult) msg.obj; |
| 1637 | request = (MainThreadRequest) ar.userObj; |
| 1638 | if (ar.exception != null) { |
| 1639 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1640 | } else { |
| 1641 | request.result = ((int[]) ar.result)[0]; |
| 1642 | } |
| 1643 | notifyRequester(request); |
| 1644 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1645 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1646 | request = (MainThreadRequest) msg.obj; |
| 1647 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1648 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1649 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1650 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1651 | break; |
| 1652 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1653 | ar = (AsyncResult) msg.obj; |
| 1654 | request = (MainThreadRequest) ar.userObj; |
| 1655 | request.result = ar.exception == null; |
| 1656 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1657 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | case CMD_GET_ALL_CELL_INFO: |
| 1659 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1661 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1662 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1663 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1664 | ar = (AsyncResult) msg.obj; |
| 1665 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1666 | // If a timeout occurs, the response will be null |
| 1667 | request.result = (ar.exception == null && ar.result != null) |
| 1668 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1669 | synchronized (request) { |
| 1670 | request.notifyAll(); |
| 1671 | } |
| 1672 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1673 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1674 | request = (MainThreadRequest) msg.obj; |
| 1675 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1676 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1677 | break; |
| 1678 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1679 | ar = (AsyncResult) msg.obj; |
| 1680 | request = (MainThreadRequest) ar.userObj; |
| 1681 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1682 | try { |
| 1683 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1684 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1685 | cb.onError( |
| 1686 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1687 | ar.exception.getClass().getName(), |
| 1688 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1689 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1690 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1691 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1692 | } else { |
| 1693 | // use the result as returned |
| 1694 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1695 | } |
| 1696 | } catch (RemoteException re) { |
| 1697 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1698 | } |
| 1699 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1700 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | request = (MainThreadRequest) msg.obj; |
| 1702 | WorkSource ws = (WorkSource) request.argument; |
| 1703 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1704 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1705 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1706 | } |
| 1707 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1708 | ar = (AsyncResult) msg.obj; |
| 1709 | request = (MainThreadRequest) ar.userObj; |
| 1710 | if (ar.exception == null) { |
| 1711 | request.result = ar.result; |
| 1712 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1713 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1714 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1715 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
| 1718 | synchronized (request) { |
| 1719 | request.notifyAll(); |
| 1720 | } |
| 1721 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1722 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1723 | case CMD_MODEM_REBOOT: |
| 1724 | request = (MainThreadRequest) msg.obj; |
| 1725 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1726 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1727 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1728 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1729 | handleNullReturnEvent(msg, "rebootModem"); |
| 1730 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1731 | case CMD_REQUEST_ENABLE_MODEM: |
| 1732 | request = (MainThreadRequest) msg.obj; |
| 1733 | boolean enable = (boolean) request.argument; |
| 1734 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1735 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1736 | PhoneConfigurationManager.getInstance() |
| 1737 | .enablePhone(request.phone, enable, onCompleted); |
| 1738 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1739 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1740 | ar = (AsyncResult) msg.obj; |
| 1741 | request = (MainThreadRequest) ar.userObj; |
| 1742 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1743 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1744 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1745 | if ((boolean) request.result) { |
| 1746 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1747 | updateModemStateMetrics(); |
| 1748 | } else { |
| 1749 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1750 | + ar.exception); |
| 1751 | } |
| 1752 | notifyRequester(request); |
| 1753 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1754 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1755 | case CMD_GET_MODEM_STATUS: |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1758 | PhoneConfigurationManager.getInstance() |
| 1759 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1760 | break; |
| 1761 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1762 | ar = (AsyncResult) msg.obj; |
| 1763 | request = (MainThreadRequest) ar.userObj; |
| 1764 | int id = request.phone.getPhoneId(); |
| 1765 | if (ar.exception == null && ar.result != null) { |
| 1766 | request.result = ar.result; |
| 1767 | //update the cache as modem status has changed |
| 1768 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1769 | (boolean) request.result); |
| 1770 | } else { |
| 1771 | // Return true if modem status cannot be retrieved. For most cases, |
| 1772 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1773 | // and disable modem are not supported. Modem is always on. |
| 1774 | // TODO: this should be fixed in R to support a third |
| 1775 | // status UNKNOWN b/131631629 |
| 1776 | request.result = true; |
| 1777 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1778 | + ar.exception); |
| 1779 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1780 | notifyRequester(request); |
| 1781 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1782 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1783 | request = (MainThreadRequest) msg.obj; |
| 1784 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1785 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1786 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1787 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1788 | break; |
| 1789 | } |
| 1790 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1791 | ar = (AsyncResult) msg.obj; |
| 1792 | request = (MainThreadRequest) ar.userObj; |
| 1793 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1794 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1795 | args.second.accept(ar.exception == null); |
| 1796 | notifyRequester(request); |
| 1797 | break; |
| 1798 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1799 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1800 | request = (MainThreadRequest) msg.obj; |
| 1801 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1802 | Phone phone = getPhoneFromRequest(request); |
| 1803 | if (phone != null) { |
| 1804 | phone.getSystemSelectionChannels(onCompleted); |
| 1805 | } else { |
| 1806 | loge("getSystemSelectionChannels: No phone object"); |
| 1807 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1808 | notifyRequester(request); |
| 1809 | } |
| 1810 | break; |
| 1811 | } |
| 1812 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1813 | ar = (AsyncResult) msg.obj; |
| 1814 | request = (MainThreadRequest) ar.userObj; |
| 1815 | if (ar.exception == null && ar.result != null) { |
| 1816 | request.result = ar.result; |
| 1817 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1818 | request.result = new IllegalStateException( |
| 1819 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1820 | if (ar.result == null) { |
| 1821 | loge("getSystemSelectionChannels: Empty response"); |
| 1822 | } else { |
| 1823 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1824 | } |
| 1825 | } |
| 1826 | notifyRequester(request); |
| 1827 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1828 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1829 | ar = (AsyncResult) msg.obj; |
| 1830 | request = (MainThreadRequest) ar.userObj; |
| 1831 | if (ar.exception == null && ar.result != null) { |
| 1832 | request.result = ar.result; |
| 1833 | } else { |
| 1834 | request.result = -1; |
| 1835 | loge("Failed to set Forbidden Plmns"); |
| 1836 | if (ar.result == null) { |
| 1837 | loge("setForbidenPlmns: Empty response"); |
| 1838 | } else if (ar.exception != null) { |
| 1839 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1840 | request.result = -1; |
| 1841 | } else { |
| 1842 | loge("setForbiddenPlmns: Unknown exception"); |
| 1843 | } |
| 1844 | } |
| 1845 | notifyRequester(request); |
| 1846 | break; |
| 1847 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1848 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1849 | uiccPort = getUiccPortFromRequest(request); |
| 1850 | if (uiccPort == null) { |
| 1851 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1852 | request.result = -1; |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
| 1856 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1857 | (Pair<Integer, List<String>>) request.argument; |
| 1858 | appType = setFplmnsArgs.first; |
| 1859 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1860 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1861 | if (uiccApp == null) { |
| 1862 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1863 | request.result = -1; |
| 1864 | loge("Failed to get UICC App"); |
| 1865 | notifyRequester(request); |
| 1866 | } else { |
| 1867 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1868 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1869 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1870 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1871 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1872 | case CMD_ERASE_MODEM_CONFIG: |
| 1873 | request = (MainThreadRequest) msg.obj; |
| 1874 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1875 | defaultPhone.eraseModemConfig(onCompleted); |
| 1876 | break; |
| 1877 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1878 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1879 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1880 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1881 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1882 | request = (MainThreadRequest) msg.obj; |
| 1883 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1884 | notifyRequester(request); |
| 1885 | break; |
| 1886 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1887 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1888 | request = (MainThreadRequest) msg.obj; |
| 1889 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1890 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1891 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1892 | changed.first, changed.second, onCompleted); |
| 1893 | break; |
| 1894 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
| 1897 | if (ar.exception == null) { |
| 1898 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1899 | // If the operation is successful, update the PIN storage |
| 1900 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1901 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1902 | UiccController.getInstance().getPinStorage() |
| 1903 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1904 | } else { |
| 1905 | request.result = msg.arg1; |
| 1906 | } |
| 1907 | notifyRequester(request); |
| 1908 | break; |
| 1909 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1910 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1911 | request = (MainThreadRequest) msg.obj; |
| 1912 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1913 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1914 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1915 | enabled.first, enabled.second, onCompleted); |
| 1916 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1917 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1918 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1919 | ar = (AsyncResult) msg.obj; |
| 1920 | request = (MainThreadRequest) ar.userObj; |
| 1921 | if (ar.exception == null) { |
| 1922 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1923 | // If the operation is successful, update the PIN storage |
| 1924 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1925 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1926 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1927 | UiccController.getInstance().getPinStorage() |
| 1928 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1929 | } else { |
| 1930 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1931 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1932 | } else { |
| 1933 | request.result = msg.arg1; |
| 1934 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1935 | |
| 1936 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1937 | notifyRequester(request); |
| 1938 | break; |
| 1939 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1940 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1941 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1942 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1943 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1944 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1945 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1946 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1947 | |
| 1948 | case CMD_SET_DATA_THROTTLING: { |
| 1949 | request = (MainThreadRequest) msg.obj; |
| 1950 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1951 | DataThrottlingRequest dataThrottlingRequest = |
| 1952 | (DataThrottlingRequest) request.argument; |
| 1953 | Phone phone = getPhoneFromRequest(request); |
| 1954 | if (phone != null) { |
| 1955 | phone.setDataThrottling(onCompleted, |
| 1956 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1957 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1958 | } else { |
| 1959 | loge("setDataThrottling: No phone object"); |
| 1960 | request.result = |
| 1961 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1962 | notifyRequester(request); |
| 1963 | } |
| 1964 | |
| 1965 | break; |
| 1966 | } |
| 1967 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1968 | ar = (AsyncResult) msg.obj; |
| 1969 | request = (MainThreadRequest) ar.userObj; |
| 1970 | |
| 1971 | if (ar.exception == null) { |
| 1972 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1973 | } else if (ar.exception instanceof CommandException) { |
| 1974 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1975 | CommandException.Error error = |
| 1976 | ((CommandException) (ar.exception)).getCommandError(); |
| 1977 | |
| 1978 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1979 | request.result = TelephonyManager |
| 1980 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1981 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1982 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1983 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1984 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1985 | } else { |
| 1986 | request.result = |
| 1987 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1988 | } |
| 1989 | } else { |
| 1990 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1991 | } |
| 1992 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1993 | notifyRequester(request); |
| 1994 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1995 | |
| 1996 | case CMD_SET_SIM_POWER: { |
| 1997 | request = (MainThreadRequest) msg.obj; |
| 1998 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1999 | request = (MainThreadRequest) msg.obj; |
| 2000 | int stateToSet = |
| 2001 | ((Pair<Integer, IIntegerConsumer>) |
| 2002 | request.argument).first; |
| 2003 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2004 | break; |
| 2005 | } |
| 2006 | case EVENT_SET_SIM_POWER_DONE: { |
| 2007 | ar = (AsyncResult) msg.obj; |
| 2008 | request = (MainThreadRequest) ar.userObj; |
| 2009 | IIntegerConsumer callback = |
| 2010 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2011 | if (ar.exception != null) { |
| 2012 | loge("setSimPower exception: " + ar.exception); |
| 2013 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2014 | .RESULT_ERROR_UNKNOWN; |
| 2015 | if (ar.exception instanceof CommandException) { |
| 2016 | CommandException.Error error = |
| 2017 | ((CommandException) (ar.exception)).getCommandError(); |
| 2018 | if (error == CommandException.Error.SIM_ERR) { |
| 2019 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2020 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2021 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2022 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2023 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2024 | } else { |
| 2025 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2026 | } |
| 2027 | } |
| 2028 | try { |
| 2029 | callback.accept(errorCode); |
| 2030 | } catch (RemoteException e) { |
| 2031 | // Ignore if the remote process is no longer available to call back. |
| 2032 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2033 | } |
| 2034 | } else { |
| 2035 | try { |
| 2036 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2037 | } catch (RemoteException e) { |
| 2038 | // Ignore if the remote process is no longer available to call back. |
| 2039 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2040 | } |
| 2041 | } |
| 2042 | break; |
| 2043 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2044 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2045 | request = (MainThreadRequest) msg.obj; |
| 2046 | |
| 2047 | final Phone phone = getPhoneFromRequest(request); |
| 2048 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2049 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2050 | notifyRequester(request); |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2055 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2056 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2057 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2058 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2059 | request.subId, pair.first /*callingUid*/, |
| 2060 | pair.second /*request*/, onCompleted); |
| 2061 | break; |
| 2062 | } |
| 2063 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2064 | ar = (AsyncResult) msg.obj; |
| 2065 | request = (MainThreadRequest) ar.userObj; |
| 2066 | // request.result will be the exception of ar if present, true otherwise. |
| 2067 | // Be cautious not to leave result null which will wait() forever |
| 2068 | request.result = ar.exception != null ? ar.exception : true; |
| 2069 | notifyRequester(request); |
| 2070 | break; |
| 2071 | } |
| 2072 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2073 | request = (MainThreadRequest) msg.obj; |
| 2074 | |
| 2075 | Phone phone = getPhoneFromRequest(request); |
| 2076 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2077 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2078 | notifyRequester(request); |
| 2079 | break; |
| 2080 | } |
| 2081 | |
| 2082 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2083 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2084 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2085 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2086 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2087 | request.subId, pair.first /*callingUid*/, |
| 2088 | pair.second /*request*/, onCompleted); |
| 2089 | break; |
| 2090 | } |
| 2091 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2092 | ar = (AsyncResult) msg.obj; |
| 2093 | request = (MainThreadRequest) ar.userObj; |
| 2094 | request.result = ar.exception != null ? ar.exception : true; |
| 2095 | notifyRequester(request); |
| 2096 | break; |
| 2097 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2098 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2099 | case CMD_GET_SLICING_CONFIG: { |
| 2100 | request = (MainThreadRequest) msg.obj; |
| 2101 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2102 | request.phone.getSlicingConfig(onCompleted); |
| 2103 | break; |
| 2104 | } |
| 2105 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2106 | ar = (AsyncResult) msg.obj; |
| 2107 | request = (MainThreadRequest) ar.userObj; |
| 2108 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2109 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2110 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2111 | Bundle bundle = new Bundle(); |
| 2112 | int resultCode = 0; |
| 2113 | if (ar.exception != null) { |
| 2114 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2115 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2116 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2117 | } else if (ar.result == null) { |
| 2118 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2119 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2120 | } else { |
| 2121 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2122 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2123 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2127 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2128 | } |
| 2129 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2130 | result.send(resultCode, bundle); |
| 2131 | notifyRequester(request); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2135 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2136 | request = (MainThreadRequest) msg.obj; |
| 2137 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2138 | UiccController.getInstance().getPinStorage() |
| 2139 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2140 | notifyRequester(request); |
| 2141 | break; |
| 2142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | default: |
| 2144 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2145 | break; |
| 2146 | } |
| 2147 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2148 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2149 | private void notifyRequester(MainThreadRequest request) { |
| 2150 | synchronized (request) { |
| 2151 | request.notifyAll(); |
| 2152 | } |
| 2153 | } |
| 2154 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2155 | private void handleNullReturnEvent(Message msg, String command) { |
| 2156 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2157 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2158 | if (ar.exception == null) { |
| 2159 | request.result = true; |
| 2160 | } else { |
| 2161 | request.result = false; |
| 2162 | if (ar.exception instanceof CommandException) { |
| 2163 | loge(command + ": CommandException: " + ar.exception); |
| 2164 | } else { |
| 2165 | loge(command + ": Unknown exception"); |
| 2166 | } |
| 2167 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2168 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Posts the specified command to be executed on the main thread, |
| 2174 | * waits for the request to complete, and returns the result. |
| 2175 | * @see #sendRequestAsync |
| 2176 | */ |
| 2177 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2178 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2179 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * Posts the specified command to be executed on the main thread, |
| 2184 | * waits for the request to complete, and returns the result. |
| 2185 | * @see #sendRequestAsync |
| 2186 | */ |
| 2187 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2188 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2189 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | /** |
| 2193 | * Posts the specified command to be executed on the main thread, |
| 2194 | * waits for the request to complete, and returns the result. |
| 2195 | * @see #sendRequestAsync |
| 2196 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2197 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2198 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2199 | } |
| 2200 | |
| 2201 | /** |
| 2202 | * Posts the specified command to be executed on the main thread, |
| 2203 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2204 | * if not timeout or null otherwise. |
| 2205 | * @see #sendRequestAsync |
| 2206 | */ |
| 2207 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2208 | long timeoutInMs) { |
| 2209 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | /** |
| 2213 | * Posts the specified command to be executed on the main thread, |
| 2214 | * waits for the request to complete, and returns the result. |
| 2215 | * @see #sendRequestAsync |
| 2216 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2217 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2218 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * Posts the specified command to be executed on the main thread, |
| 2223 | * waits for the request to complete, and returns the result. |
| 2224 | * @see #sendRequestAsync |
| 2225 | */ |
| 2226 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2227 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2228 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2232 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2233 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2234 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2235 | * @see #sendRequestAsync |
| 2236 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2237 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2238 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2240 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2241 | } |
| 2242 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2243 | MainThreadRequest request = null; |
| 2244 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2245 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2246 | } else if (phone != null) { |
| 2247 | request = new MainThreadRequest(argument, phone, workSource); |
| 2248 | } else { |
| 2249 | request = new MainThreadRequest(argument, subId, workSource); |
| 2250 | } |
| 2251 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2253 | msg.sendToTarget(); |
| 2254 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2255 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2257 | if (timeoutInMs >= 0) { |
| 2258 | // Wait for at least timeoutInMs before returning null request result |
| 2259 | long now = SystemClock.elapsedRealtime(); |
| 2260 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2261 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2262 | try { |
| 2263 | request.wait(deadline - now); |
| 2264 | } catch (InterruptedException e) { |
| 2265 | // Do nothing, go back and check if request is completed or timeout |
| 2266 | } finally { |
| 2267 | now = SystemClock.elapsedRealtime(); |
| 2268 | } |
| 2269 | } |
| 2270 | } else { |
| 2271 | // Wait for the request to complete |
| 2272 | while (request.result == null) { |
| 2273 | try { |
| 2274 | request.wait(); |
| 2275 | } catch (InterruptedException e) { |
| 2276 | // Do nothing, go back and wait until the request is complete |
| 2277 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2278 | } |
| 2279 | } |
| 2280 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2281 | if (request.result == null) { |
| 2282 | Log.wtf(LOG_TAG, |
| 2283 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2285 | return request.result; |
| 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2290 | * Posts the specified command to be executed on the main thread, and |
| 2291 | * returns immediately. |
| 2292 | * @see #sendRequest |
| 2293 | */ |
| 2294 | private void sendRequestAsync(int command) { |
| 2295 | mMainThreadHandler.sendEmptyMessage(command); |
| 2296 | } |
| 2297 | |
| 2298 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2299 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2300 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2301 | */ |
| 2302 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2303 | sendRequestAsync(command, argument, null, null); |
| 2304 | } |
| 2305 | |
| 2306 | /** |
| 2307 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2308 | * @see {@link #sendRequest(int,Object)} |
| 2309 | */ |
| 2310 | private void sendRequestAsync( |
| 2311 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2312 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2313 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2314 | msg.sendToTarget(); |
| 2315 | } |
| 2316 | |
| 2317 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2319 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2320 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2321 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2322 | synchronized (PhoneInterfaceManager.class) { |
| 2323 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2324 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | } else { |
| 2326 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2327 | } |
| 2328 | return sInstance; |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2333 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2336 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2337 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2339 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2341 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2342 | mTelephonySharedPreferences = |
| 2343 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2344 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2345 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2346 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2347 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame] | 2348 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | publish(); |
| 2350 | } |
| 2351 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2352 | private Phone getDefaultPhone() { |
| 2353 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2354 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2355 | } |
| 2356 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | private void publish() { |
| 2358 | if (DBG) log("publish: " + this); |
| 2359 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2360 | TelephonyFrameworkInitializer |
| 2361 | .getTelephonyServiceManager() |
| 2362 | .getTelephonyServiceRegisterer() |
| 2363 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2366 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2367 | if (request.phone != null) { |
| 2368 | return request.phone; |
| 2369 | } else { |
| 2370 | return getPhoneFromSubId(request.subId); |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | private Phone getPhoneFromSubId(int subId) { |
| 2375 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2376 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2377 | } |
| 2378 | |
Rambo Wang | e53e07d | 2022-05-10 13:01:13 -0700 | [diff] [blame] | 2379 | @Nullable |
| 2380 | private UiccPort getUiccPortFromRequest(@NonNull MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2381 | Phone phone = getPhoneFromRequest(request); |
| 2382 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2383 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2384 | } |
| 2385 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2387 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2388 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2391 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2392 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2393 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2394 | } |
| 2395 | |
| 2396 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2397 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2398 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2401 | private boolean isImsAvailableOnDevice() { |
| 2402 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2403 | if (pm == null) { |
| 2404 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2405 | // so do not throw error and allow. |
| 2406 | return true; |
| 2407 | } |
| 2408 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2409 | } |
| 2410 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2412 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2415 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | if (DBG) log("dial: " + number); |
| 2417 | // No permission check needed here: This is just a wrapper around the |
| 2418 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2419 | // the UI before it does anything. |
| 2420 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2421 | final long identity = Binder.clearCallingIdentity(); |
| 2422 | try { |
| 2423 | String url = createTelUrl(number); |
| 2424 | if (url == null) { |
| 2425 | return; |
| 2426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2428 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2429 | PhoneConstants.State state = mCM.getState(subId); |
| 2430 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2431 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2432 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2433 | mApp.startActivity(intent); |
| 2434 | } |
| 2435 | } finally { |
| 2436 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2441 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2444 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2445 | if (DBG) log("call: " + number); |
| 2446 | |
| 2447 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2448 | // need to do a permission check since we're calling startActivity() |
| 2449 | // from the context of the phone app. |
| 2450 | enforceCallPermission(); |
| 2451 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2452 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | != AppOpsManager.MODE_ALLOWED) { |
| 2454 | return; |
| 2455 | } |
| 2456 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | final long identity = Binder.clearCallingIdentity(); |
| 2458 | try { |
| 2459 | String url = createTelUrl(number); |
| 2460 | if (url == null) { |
| 2461 | return; |
| 2462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2464 | boolean isValid = false; |
| 2465 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2466 | if (slist != null) { |
| 2467 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2468 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2469 | isValid = true; |
| 2470 | break; |
| 2471 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2472 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2473 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2474 | if (!isValid) { |
| 2475 | return; |
| 2476 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2477 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2479 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2480 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2481 | mApp.startActivity(intent); |
| 2482 | } finally { |
| 2483 | Binder.restoreCallingIdentity(identity); |
| 2484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | } |
| 2486 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2487 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2488 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2489 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2490 | } |
| 2491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2492 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2493 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2494 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2495 | } |
| 2496 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2497 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2502 | Phone phone = getPhone(subId); |
| 2503 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2504 | checkSimPin.start(); |
| 2505 | return checkSimPin.unlockSim(null, pin); |
| 2506 | } finally { |
| 2507 | Binder.restoreCallingIdentity(identity); |
| 2508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2511 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2512 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | |
| 2514 | final long identity = Binder.clearCallingIdentity(); |
| 2515 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2516 | Phone phone = getPhone(subId); |
| 2517 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | checkSimPuk.start(); |
| 2519 | return checkSimPuk.unlockSim(puk, pin); |
| 2520 | } finally { |
| 2521 | Binder.restoreCallingIdentity(identity); |
| 2522 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2526 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2527 | * a synchronous one. |
| 2528 | */ |
| 2529 | private static class UnlockSim extends Thread { |
| 2530 | |
| 2531 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2532 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2533 | |
| 2534 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2535 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2536 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | |
| 2538 | // For replies from SimCard interface |
| 2539 | private Handler mHandler; |
| 2540 | |
| 2541 | // For async handler to identify request type |
| 2542 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2543 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2544 | UnlockSim(int phoneId, IccCard simCard) { |
| 2545 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2546 | mSimCard = simCard; |
| 2547 | } |
| 2548 | |
| 2549 | @Override |
| 2550 | public void run() { |
| 2551 | Looper.prepare(); |
| 2552 | synchronized (UnlockSim.this) { |
| 2553 | mHandler = new Handler() { |
| 2554 | @Override |
| 2555 | public void handleMessage(Message msg) { |
| 2556 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2557 | switch (msg.what) { |
| 2558 | case SUPPLY_PIN_COMPLETE: |
| 2559 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2560 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2561 | mRetryCount = msg.arg1; |
| 2562 | if (ar.exception != null) { |
| 2563 | if (ar.exception instanceof CommandException && |
| 2564 | ((CommandException)(ar.exception)).getCommandError() |
| 2565 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2566 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2567 | } //When UiccCardApp dispose,handle message and return exception |
| 2568 | else if (ar.exception instanceof CommandException && |
| 2569 | ((CommandException) (ar.exception)).getCommandError() |
| 2570 | == CommandException.Error.ABORTED) { |
| 2571 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2572 | } else { |
| 2573 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2574 | } |
| 2575 | } else { |
| 2576 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2577 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2578 | mDone = true; |
| 2579 | UnlockSim.this.notifyAll(); |
| 2580 | } |
| 2581 | break; |
| 2582 | } |
| 2583 | } |
| 2584 | }; |
| 2585 | UnlockSim.this.notifyAll(); |
| 2586 | } |
| 2587 | Looper.loop(); |
| 2588 | } |
| 2589 | |
| 2590 | /* |
| 2591 | * Use PIN or PUK to unlock SIM card |
| 2592 | * |
| 2593 | * If PUK is null, unlock SIM card with PIN |
| 2594 | * |
| 2595 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2596 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2597 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | |
| 2599 | while (mHandler == null) { |
| 2600 | try { |
| 2601 | wait(); |
| 2602 | } catch (InterruptedException e) { |
| 2603 | Thread.currentThread().interrupt(); |
| 2604 | } |
| 2605 | } |
| 2606 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2607 | |
| 2608 | if (puk == null) { |
| 2609 | mSimCard.supplyPin(pin, callback); |
| 2610 | } else { |
| 2611 | mSimCard.supplyPuk(puk, pin, callback); |
| 2612 | } |
| 2613 | |
| 2614 | while (!mDone) { |
| 2615 | try { |
| 2616 | Log.d(LOG_TAG, "wait for done"); |
| 2617 | wait(); |
| 2618 | } catch (InterruptedException e) { |
| 2619 | // Restore the interrupted status |
| 2620 | Thread.currentThread().interrupt(); |
| 2621 | } |
| 2622 | } |
| 2623 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2624 | int[] resultArray = new int[2]; |
| 2625 | resultArray[0] = mResult; |
| 2626 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2627 | |
| 2628 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2629 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2630 | } |
| 2631 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2632 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2636 | /** |
| 2637 | * This method has been removed due to privacy and stability concerns. |
| 2638 | */ |
| 2639 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2640 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2641 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2642 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2645 | @Override |
| 2646 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2647 | mApp.getSystemService(AppOpsManager.class) |
| 2648 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2649 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2650 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2651 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2652 | // Callers targeting S have no business invoking this method. |
| 2653 | return; |
| 2654 | } |
| 2655 | |
| 2656 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2657 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2658 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2659 | .setCallingPackage(callingPackage) |
| 2660 | .setCallingFeatureId(null) |
| 2661 | .setCallingPid(Binder.getCallingPid()) |
| 2662 | .setCallingUid(Binder.getCallingUid()) |
| 2663 | .setMethod("updateServiceLocation") |
| 2664 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2665 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2666 | .build()); |
| 2667 | // Apps that lack location permission have no business calling this method; |
| 2668 | // however, because no permission was declared in the public API, denials must |
| 2669 | // all be "soft". |
| 2670 | switch (locationResult) { |
| 2671 | case DENIED_HARD: /* fall through */ |
| 2672 | case DENIED_SOFT: |
| 2673 | return; |
| 2674 | } |
| 2675 | |
| 2676 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | final long identity = Binder.clearCallingIdentity(); |
| 2678 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2679 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2681 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2682 | } |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2685 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | } |
| 2687 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2688 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2689 | @Override |
| 2690 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2691 | return isRadioOnWithFeature(callingPackage, null); |
| 2692 | } |
| 2693 | |
| 2694 | |
| 2695 | @Override |
| 2696 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2697 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2698 | callingFeatureId); |
| 2699 | } |
| 2700 | |
| 2701 | @Deprecated |
| 2702 | @Override |
| 2703 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2704 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2707 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2708 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2709 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2710 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2711 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2712 | return false; |
| 2713 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | |
| 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
| 2717 | return isRadioOnForSubscriber(subId); |
| 2718 | } finally { |
| 2719 | Binder.restoreCallingIdentity(identity); |
| 2720 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | final long identity = Binder.clearCallingIdentity(); |
| 2725 | try { |
| 2726 | final Phone phone = getPhone(subId); |
| 2727 | if (phone != null) { |
| 2728 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2729 | } else { |
| 2730 | return false; |
| 2731 | } |
| 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2734 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2738 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2740 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2741 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2742 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2743 | |
| 2744 | final long identity = Binder.clearCallingIdentity(); |
| 2745 | try { |
| 2746 | final Phone phone = getPhone(subId); |
| 2747 | if (phone != null) { |
| 2748 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2749 | } |
| 2750 | } finally { |
| 2751 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2752 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2756 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2759 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2761 | |
| 2762 | final long identity = Binder.clearCallingIdentity(); |
| 2763 | try { |
| 2764 | final Phone phone = getPhone(subId); |
| 2765 | if (phone == null) { |
| 2766 | return false; |
| 2767 | } |
| 2768 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2769 | toggleRadioOnOffForSubscriber(subId); |
| 2770 | } |
| 2771 | return true; |
| 2772 | } finally { |
| 2773 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2774 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2775 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2776 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2777 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2778 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2779 | /* |
| 2780 | * If any of the Radios are available, it will need to be |
| 2781 | * shutdown. So return true if any Radio is available. |
| 2782 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
| 2785 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2786 | Phone phone = PhoneFactory.getPhone(i); |
| 2787 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2788 | } |
| 2789 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2790 | return false; |
| 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2793 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2796 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2797 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | enforceModifyPermission(); |
| 2799 | |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
| 2802 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2803 | logv("Shutting down Phone " + i); |
| 2804 | shutdownRadioUsingPhoneId(i); |
| 2805 | } |
| 2806 | } finally { |
| 2807 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2808 | } |
| 2809 | } |
| 2810 | |
| 2811 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2812 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2813 | if (phone != null && phone.isRadioAvailable()) { |
| 2814 | phone.shutdownRadio(); |
| 2815 | } |
| 2816 | } |
| 2817 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2820 | |
| 2821 | final long identity = Binder.clearCallingIdentity(); |
| 2822 | try { |
| 2823 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2824 | if (defaultPhone != null) { |
| 2825 | defaultPhone.setRadioPower(turnOn); |
| 2826 | return true; |
| 2827 | } else { |
| 2828 | loge("There's no default phone."); |
| 2829 | return false; |
| 2830 | } |
| 2831 | } finally { |
| 2832 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2833 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2836 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2837 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | |
| 2839 | final long identity = Binder.clearCallingIdentity(); |
| 2840 | try { |
| 2841 | final Phone phone = getPhone(subId); |
| 2842 | if (phone != null) { |
| 2843 | phone.setRadioPower(turnOn); |
| 2844 | return true; |
| 2845 | } else { |
| 2846 | return false; |
| 2847 | } |
| 2848 | } finally { |
| 2849 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2850 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 2853 | /** |
| 2854 | * Vote on powering off the radio for a reason. The radio will be turned on only when there is |
| 2855 | * no reason to power it off. When any of the voters want to power it off, it will be turned |
| 2856 | * off. In case of emergency, the radio will be turned on even if there are some reasons for |
| 2857 | * powering it off, and these radio off votes will be cleared. |
| 2858 | * Multiple apps can vote for the same reason and the last vote will take effect. Each app is |
| 2859 | * responsible for its vote. A powering-off vote of a reason will be maintained until it is |
| 2860 | * cleared by calling {@link clearRadioPowerOffForReason} for that reason, or an emergency call |
| 2861 | * is made, or the device is rebooted. When an app comes backup from a crash, it needs to make |
| 2862 | * sure if its vote is as expected. An app can use the API {@link getRadioPowerOffReasons} to |
| 2863 | * check its vote. |
| 2864 | * |
| 2865 | * @param subId The subscription ID. |
| 2866 | * @param reason The reason for powering off radio. |
| 2867 | * @return true on success and false on failure. |
| 2868 | */ |
| 2869 | public boolean requestRadioPowerOffForReason(int subId, |
| 2870 | @TelephonyManager.RadioPowerReason int reason) { |
| 2871 | enforceModifyPermission(); |
| 2872 | |
| 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | final Phone phone = getPhone(subId); |
| 2876 | if (phone != null) { |
| 2877 | phone.setRadioPowerForReason(false, reason); |
| 2878 | return true; |
| 2879 | } else { |
| 2880 | return false; |
| 2881 | } |
| 2882 | } finally { |
| 2883 | Binder.restoreCallingIdentity(identity); |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | /** |
| 2888 | * Remove the vote on powering off the radio for a reason, as requested by |
| 2889 | * {@link requestRadioPowerOffForReason}. |
| 2890 | * |
| 2891 | * @param subId The subscription ID. |
| 2892 | * @param reason The reason for powering off radio. |
| 2893 | * @return true on success and false on failure. |
| 2894 | */ |
| 2895 | public boolean clearRadioPowerOffForReason(int subId, |
| 2896 | @TelephonyManager.RadioPowerReason int reason) { |
| 2897 | enforceModifyPermission(); |
| 2898 | |
| 2899 | final long identity = Binder.clearCallingIdentity(); |
| 2900 | try { |
| 2901 | final Phone phone = getPhone(subId); |
| 2902 | if (phone != null) { |
| 2903 | phone.setRadioPowerForReason(true, reason); |
| 2904 | return true; |
| 2905 | } else { |
| 2906 | return false; |
| 2907 | } |
| 2908 | } finally { |
| 2909 | Binder.restoreCallingIdentity(identity); |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | /** |
| 2914 | * Get reasons for powering off radio, as requested by {@link requestRadioPowerOffForReason}. |
| 2915 | * |
| 2916 | * @param subId The subscription ID. |
| 2917 | * @param callingPackage The package making the call. |
| 2918 | * @param callingFeatureId The feature in the package. |
| 2919 | * @return List of reasons for powering off radio. |
| 2920 | */ |
| 2921 | public List getRadioPowerOffReasons(int subId, String callingPackage, String callingFeatureId) { |
| 2922 | enforceReadPrivilegedPermission("getRadioPowerOffReasons"); |
| 2923 | |
| 2924 | final long identity = Binder.clearCallingIdentity(); |
| 2925 | List result = new ArrayList(); |
| 2926 | try { |
| 2927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, |
| 2928 | callingPackage, callingFeatureId, "getRadioPowerOffReasons")) { |
| 2929 | return result; |
| 2930 | } |
| 2931 | |
| 2932 | final Phone phone = getPhone(subId); |
| 2933 | if (phone != null) { |
| 2934 | result.addAll(phone.getRadioPowerOffReasons()); |
| 2935 | } |
| 2936 | } finally { |
| 2937 | Binder.restoreCallingIdentity(identity); |
| 2938 | } |
| 2939 | return result; |
| 2940 | } |
| 2941 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2942 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2943 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2944 | public boolean enableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | |
| 2947 | final long identity = Binder.clearCallingIdentity(); |
| 2948 | try { |
| 2949 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2950 | final Phone phone = getPhone(subId); |
| 2951 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 2952 | phone.getDataSettingsManager().setDataEnabled( |
| 2953 | TelephonyManager.DATA_ENABLED_REASON_USER, true, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | return true; |
| 2955 | } else { |
| 2956 | return false; |
| 2957 | } |
| 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2960 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2961 | } |
| 2962 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2963 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2964 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 2965 | public boolean disableDataConnectivity(String callingPackage) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | |
| 2968 | final long identity = Binder.clearCallingIdentity(); |
| 2969 | try { |
| 2970 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2971 | final Phone phone = getPhone(subId); |
| 2972 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 2973 | phone.getDataSettingsManager().setDataEnabled( |
| 2974 | TelephonyManager.DATA_ENABLED_REASON_USER, false, callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2975 | return true; |
| 2976 | } else { |
| 2977 | return false; |
| 2978 | } |
| 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2981 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2984 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2985 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | final Phone phone = getPhone(subId); |
| 2989 | if (phone != null) { |
Jack Yu | 59824e1 | 2022-03-23 01:42:44 -0700 | [diff] [blame] | 2990 | return phone.isDataAllowed(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2991 | } else { |
| 2992 | return false; |
| 2993 | } |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 3000 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 3003 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | enforceCallPermission(); |
| 3005 | |
| 3006 | final long identity = Binder.clearCallingIdentity(); |
| 3007 | try { |
| 3008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3009 | return; |
| 3010 | } |
| 3011 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 3012 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
| 3015 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 3016 | }; |
| 3017 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3018 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3019 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | |
| 3021 | final long identity = Binder.clearCallingIdentity(); |
| 3022 | try { |
| 3023 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3024 | return false; |
| 3025 | } |
| 3026 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3032 | /** |
| 3033 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 3034 | * tag on getCallState Binder call. |
| 3035 | */ |
| 3036 | @Deprecated |
| 3037 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3038 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3039 | if (CompatChanges.isChangeEnabled( |
| 3040 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3041 | Binder.getCallingUid())) { |
| 3042 | // Do not allow this API to be called on API version 31+, it should only be |
| 3043 | // called on old apps using this Binder call directly. |
| 3044 | throw new SecurityException("This method can only be used for applications " |
| 3045 | + "targeting API version 30 or less."); |
| 3046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 3049 | Phone phone = getPhone(getDefaultSubscription()); |
| 3050 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3051 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3052 | } finally { |
| 3053 | Binder.restoreCallingIdentity(identity); |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | @Override |
| 3058 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 3059 | if (CompatChanges.isChangeEnabled( |
| 3060 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 3061 | Binder.getCallingUid())) { |
| 3062 | // Check READ_PHONE_STATE for API version 31+ |
| 3063 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 3064 | featureId, "getCallStateForSubscription")) { |
| 3065 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 3066 | + "targeting API level 31+."); |
| 3067 | } |
| 3068 | } |
| 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3072 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 3073 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 3074 | } finally { |
| 3075 | Binder.restoreCallingIdentity(identity); |
| 3076 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3077 | } |
| 3078 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3079 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3080 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3081 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3082 | } |
| 3083 | |
| 3084 | @Override |
| 3085 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3086 | final long identity = Binder.clearCallingIdentity(); |
| 3087 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3088 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | if (phone != null) { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 3090 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | } else { |
| 3092 | return PhoneConstantConversions.convertDataState( |
| 3093 | PhoneConstants.DataState.DISCONNECTED); |
| 3094 | } |
| 3095 | } finally { |
| 3096 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3098 | } |
| 3099 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3100 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3101 | public @DataActivityType int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3102 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3103 | } |
| 3104 | |
| 3105 | @Override |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3106 | public @DataActivityType int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3107 | final long identity = Binder.clearCallingIdentity(); |
| 3108 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3109 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3110 | if (phone != null) { |
Jack Yu | 0eda684 | 2022-04-18 00:34:46 -0700 | [diff] [blame] | 3111 | return phone.getDataActivityState(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3112 | } else { |
| 3113 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3114 | } |
| 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3117 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3121 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3122 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3123 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3124 | |
| 3125 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3126 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3127 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3128 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3129 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3130 | .setCallingPid(Binder.getCallingPid()) |
| 3131 | .setCallingUid(Binder.getCallingUid()) |
| 3132 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3133 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3134 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3135 | .build()); |
| 3136 | switch (locationResult) { |
| 3137 | case DENIED_HARD: |
| 3138 | throw new SecurityException("Not allowed to access cell location"); |
| 3139 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3140 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3141 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3142 | } |
| 3143 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3144 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3148 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3149 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(identity); |
| 3152 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3155 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3156 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3157 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3158 | // registered cell info, so return a NULL country instead. |
| 3159 | final long identity = Binder.clearCallingIdentity(); |
| 3160 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3161 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3162 | // Get default phone in this case. |
| 3163 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3164 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3165 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3167 | if (phone == null) return ""; |
| 3168 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3169 | if (sst == null) return ""; |
| 3170 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3171 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3172 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3173 | } finally { |
| 3174 | Binder.restoreCallingIdentity(identity); |
| 3175 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3176 | } |
| 3177 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3178 | /** |
| 3179 | * This method was removed due to potential issues caused by performing partial |
| 3180 | * updates of service state, and lack of a credible use case. |
| 3181 | * |
| 3182 | * This has the ability to break the telephony implementation by disabling notification of |
| 3183 | * changes in device connectivity. DO NOT USE THIS! |
| 3184 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3185 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3186 | public void enableLocationUpdates() { |
| 3187 | mApp.enforceCallingOrSelfPermission( |
| 3188 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3191 | /** |
| 3192 | * This method was removed due to potential issues caused by performing partial |
| 3193 | * updates of service state, and lack of a credible use case. |
| 3194 | * |
| 3195 | * This has the ability to break the telephony implementation by disabling notification of |
| 3196 | * changes in device connectivity. DO NOT USE THIS! |
| 3197 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3198 | @Override |
| 3199 | public void disableLocationUpdates() { |
| 3200 | mApp.enforceCallingOrSelfPermission( |
| 3201 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | @Override |
| 3205 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3206 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3207 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3208 | try { |
| 3209 | mApp.getSystemService(AppOpsManager.class) |
| 3210 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3211 | } catch (SecurityException e) { |
| 3212 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3213 | throw e; |
| 3214 | } |
| 3215 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3216 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3217 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3218 | throw new SecurityException( |
| 3219 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3220 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3221 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3222 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3223 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3224 | return null; |
| 3225 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3226 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3227 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3228 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3229 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3230 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3231 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3232 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3233 | for (CellInfo ci : info) { |
| 3234 | if (ci instanceof CellInfoGsm) { |
| 3235 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3236 | } else if (ci instanceof CellInfoWcdma) { |
| 3237 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3238 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3239 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3240 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3243 | private List<CellInfo> getCachedCellInfo() { |
| 3244 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3245 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3246 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3247 | if (info != null) cellInfos.addAll(info); |
| 3248 | } |
| 3249 | return cellInfos; |
| 3250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3251 | |
| 3252 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3253 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3254 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3255 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3256 | |
| 3257 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3258 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3259 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3260 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3261 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3262 | .setCallingPid(Binder.getCallingPid()) |
| 3263 | .setCallingUid(Binder.getCallingUid()) |
| 3264 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3265 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3266 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3267 | .build()); |
| 3268 | switch (locationResult) { |
| 3269 | case DENIED_HARD: |
| 3270 | throw new SecurityException("Not allowed to access cell info"); |
| 3271 | case DENIED_SOFT: |
| 3272 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3273 | } |
| 3274 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3275 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3276 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3277 | return getCachedCellInfo(); |
| 3278 | } |
| 3279 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3280 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3281 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | final long identity = Binder.clearCallingIdentity(); |
| 3283 | try { |
| 3284 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3285 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3286 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3287 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3288 | if (info != null) cellInfos.addAll(info); |
| 3289 | } |
| 3290 | return cellInfos; |
| 3291 | } finally { |
| 3292 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3293 | } |
| 3294 | } |
| 3295 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3296 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3297 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3298 | String callingFeatureId) { |
| 3299 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3300 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
| 3303 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3304 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3305 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3306 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3307 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3310 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3311 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3312 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3313 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3314 | |
| 3315 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3316 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3317 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3318 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3319 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3320 | .setCallingPid(Binder.getCallingPid()) |
| 3321 | .setCallingUid(Binder.getCallingUid()) |
| 3322 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3323 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3324 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3325 | .build()); |
| 3326 | switch (locationResult) { |
| 3327 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3328 | if (TelephonyPermissions |
| 3329 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3330 | // Safetynet logging for b/154934934 |
| 3331 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3332 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3333 | throw new SecurityException("Not allowed to access cell info"); |
| 3334 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3335 | if (TelephonyPermissions |
| 3336 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3337 | // Safetynet logging for b/154934934 |
| 3338 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3339 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3340 | try { |
| 3341 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3342 | } catch (RemoteException re) { |
| 3343 | // Drop without consequences |
| 3344 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3345 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3348 | |
| 3349 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3350 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3351 | |
| 3352 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3353 | } |
| 3354 | |
| 3355 | @Override |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3356 | public void setCellInfoListRate(int rateInMillis, int subId) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3357 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3358 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3359 | |
| 3360 | final long identity = Binder.clearCallingIdentity(); |
| 3361 | try { |
Aishwarya Mallampati | 0603fb1 | 2022-08-24 21:16:56 +0000 | [diff] [blame] | 3362 | Phone phone = getPhone(subId); |
| 3363 | if (phone == null) { |
| 3364 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
| 3365 | } else { |
| 3366 | phone.setCellInfoListRate(rateInMillis, workSource); |
| 3367 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3368 | } finally { |
| 3369 | Binder.restoreCallingIdentity(identity); |
| 3370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3371 | } |
| 3372 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3373 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3374 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3375 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3376 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3377 | return null; |
| 3378 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3379 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3380 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3381 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3382 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3383 | return null; |
| 3384 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3385 | |
| 3386 | final long identity = Binder.clearCallingIdentity(); |
| 3387 | try { |
| 3388 | return phone.getImei(); |
| 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
| 3391 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3395 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3396 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3397 | String tac = null; |
| 3398 | if (phone != null) { |
| 3399 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3400 | try { |
| 3401 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3402 | } catch (IndexOutOfBoundsException e) { |
| 3403 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3404 | return null; |
| 3405 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3406 | } |
| 3407 | return tac; |
| 3408 | } |
| 3409 | |
| 3410 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3411 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3412 | try { |
| 3413 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3414 | } catch (SecurityException se) { |
| 3415 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3416 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3417 | + Binder.getCallingUid()); |
| 3418 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3419 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3420 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3421 | return null; |
| 3422 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3423 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3424 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3425 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3426 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3427 | return null; |
| 3428 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3429 | |
| 3430 | final long identity = Binder.clearCallingIdentity(); |
| 3431 | try { |
| 3432 | return phone.getMeid(); |
| 3433 | } finally { |
| 3434 | Binder.restoreCallingIdentity(identity); |
| 3435 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3439 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3440 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3441 | String manufacturerCode = null; |
| 3442 | if (phone != null) { |
| 3443 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3444 | try { |
| 3445 | manufacturerCode = |
| 3446 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3447 | } catch (IndexOutOfBoundsException e) { |
| 3448 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3449 | return null; |
| 3450 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3451 | } |
| 3452 | return manufacturerCode; |
| 3453 | } |
| 3454 | |
| 3455 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3456 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3457 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3458 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3459 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3460 | return null; |
| 3461 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3462 | int subId = phone.getSubId(); |
| 3463 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3464 | mApp, subId, callingPackage, callingFeatureId, |
| 3465 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3466 | return null; |
| 3467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | |
| 3469 | final long identity = Binder.clearCallingIdentity(); |
| 3470 | try { |
| 3471 | return phone.getDeviceSvn(); |
| 3472 | } finally { |
| 3473 | Binder.restoreCallingIdentity(identity); |
| 3474 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3477 | @Override |
| 3478 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | final long identity = Binder.clearCallingIdentity(); |
| 3480 | try { |
| 3481 | final Phone phone = getPhone(subId); |
| 3482 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(identity); |
| 3485 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3486 | } |
| 3487 | |
| 3488 | @Override |
| 3489 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3490 | final long identity = Binder.clearCallingIdentity(); |
| 3491 | try { |
| 3492 | final Phone phone = getPhone(subId); |
| 3493 | return phone == null ? null : phone.getCarrierName(); |
| 3494 | } finally { |
| 3495 | Binder.restoreCallingIdentity(identity); |
| 3496 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3497 | } |
| 3498 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3499 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3500 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3501 | final long identity = Binder.clearCallingIdentity(); |
| 3502 | try { |
| 3503 | final Phone phone = getPhone(subId); |
| 3504 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3505 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3512 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3513 | final long identity = Binder.clearCallingIdentity(); |
| 3514 | try { |
| 3515 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3516 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3517 | } finally { |
| 3518 | Binder.restoreCallingIdentity(identity); |
| 3519 | } |
| 3520 | } |
| 3521 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3522 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3523 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3524 | if (!isSubscriptionMccMnc) { |
| 3525 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3526 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3527 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3528 | if (phone == null) { |
| 3529 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3530 | } |
| 3531 | final long identity = Binder.clearCallingIdentity(); |
| 3532 | try { |
| 3533 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3534 | } finally { |
| 3535 | Binder.restoreCallingIdentity(identity); |
| 3536 | } |
| 3537 | } |
| 3538 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3539 | // |
| 3540 | // Internal helper methods. |
| 3541 | // |
| 3542 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3543 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3544 | * Make sure the caller is the calling package itself |
| 3545 | * |
| 3546 | * @throws SecurityException if the caller is not the calling package |
| 3547 | */ |
| 3548 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3549 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3550 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3551 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3552 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3553 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3554 | } catch (PackageManager.NameNotFoundException e) { |
| 3555 | // packageUid is -1 |
| 3556 | } |
| 3557 | if (packageUid != callingUid) { |
| 3558 | throw new SecurityException(message + ": Package " + callingPackage |
| 3559 | + " does not belong to " + callingUid); |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3564 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3565 | * |
| 3566 | * @throws SecurityException if the caller does not have the required permission |
| 3567 | */ |
| 3568 | private void enforceModifyPermission() { |
| 3569 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3570 | } |
| 3571 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3572 | private void enforceActiveEmergencySessionPermission() { |
| 3573 | mApp.enforceCallingOrSelfPermission( |
| 3574 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3575 | } |
| 3576 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3577 | /** |
| 3578 | * Make sure the caller has the CALL_PHONE permission. |
| 3579 | * |
| 3580 | * @throws SecurityException if the caller does not have the required permission |
| 3581 | */ |
| 3582 | private void enforceCallPermission() { |
| 3583 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3584 | } |
| 3585 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3586 | private void enforceSettingsPermission() { |
| 3587 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3590 | private void enforceRebootPermission() { |
| 3591 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3592 | } |
| 3593 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3594 | private String createTelUrl(String number) { |
| 3595 | if (TextUtils.isEmpty(number)) { |
| 3596 | return null; |
| 3597 | } |
| 3598 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3599 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3602 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3603 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3604 | } |
| 3605 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3606 | private static void logv(String msg) { |
| 3607 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3608 | } |
| 3609 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3610 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3611 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3612 | } |
| 3613 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3614 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3615 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3616 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3619 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3620 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3621 | final long identity = Binder.clearCallingIdentity(); |
| 3622 | try { |
| 3623 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3624 | if (phone == null) { |
| 3625 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3626 | } else { |
| 3627 | return phone.getPhoneType(); |
| 3628 | } |
| 3629 | } finally { |
| 3630 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3631 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | /** |
| 3635 | * Returns the CDMA ERI icon index to display |
| 3636 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3637 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3638 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3639 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3640 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3643 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3644 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3645 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3646 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3647 | mApp, subId, callingPackage, callingFeatureId, |
| 3648 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3649 | return -1; |
| 3650 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3651 | |
| 3652 | final long identity = Binder.clearCallingIdentity(); |
| 3653 | try { |
| 3654 | final Phone phone = getPhone(subId); |
| 3655 | if (phone != null) { |
| 3656 | return phone.getCdmaEriIconIndex(); |
| 3657 | } else { |
| 3658 | return -1; |
| 3659 | } |
| 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3662 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3663 | } |
| 3664 | |
| 3665 | /** |
| 3666 | * Returns the CDMA ERI icon mode, |
| 3667 | * 0 - ON |
| 3668 | * 1 - FLASHING |
| 3669 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3670 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3671 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3672 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3673 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3674 | } |
| 3675 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3676 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3677 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3678 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3679 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3680 | mApp, subId, callingPackage, callingFeatureId, |
| 3681 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3682 | return -1; |
| 3683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3684 | |
| 3685 | final long identity = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | final Phone phone = getPhone(subId); |
| 3688 | if (phone != null) { |
| 3689 | return phone.getCdmaEriIconMode(); |
| 3690 | } else { |
| 3691 | return -1; |
| 3692 | } |
| 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3695 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | /** |
| 3699 | * Returns the CDMA ERI text, |
| 3700 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3701 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3702 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3703 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3704 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3707 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3708 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3709 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3710 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3711 | mApp, subId, callingPackage, callingFeatureId, |
| 3712 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3713 | return null; |
| 3714 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | |
| 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
| 3718 | final Phone phone = getPhone(subId); |
| 3719 | if (phone != null) { |
| 3720 | return phone.getCdmaEriText(); |
| 3721 | } else { |
| 3722 | return null; |
| 3723 | } |
| 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3726 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3730 | * Returns the CDMA MDN. |
| 3731 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3732 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3733 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3735 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3736 | |
| 3737 | final long identity = Binder.clearCallingIdentity(); |
| 3738 | try { |
| 3739 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3741 | return phone.getLine1Number(); |
| 3742 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3743 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | return null; |
| 3745 | } |
| 3746 | } finally { |
| 3747 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
| 3751 | /** |
| 3752 | * Returns the CDMA MIN. |
| 3753 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3754 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3755 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3756 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3757 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3758 | |
| 3759 | final long identity = Binder.clearCallingIdentity(); |
| 3760 | try { |
| 3761 | final Phone phone = getPhone(subId); |
| 3762 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3763 | return phone.getCdmaMin(); |
| 3764 | } else { |
| 3765 | return null; |
| 3766 | } |
| 3767 | } finally { |
| 3768 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3769 | } |
| 3770 | } |
| 3771 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3772 | @Override |
| 3773 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3774 | INumberVerificationCallback callback, String callingPackage) { |
| 3775 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3776 | != PERMISSION_GRANTED) { |
| 3777 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3778 | } |
| 3779 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3780 | |
| 3781 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3782 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3783 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3784 | + "calling package: " + callingPackage |
| 3785 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3786 | } |
| 3787 | |
| 3788 | if (range == null) { |
| 3789 | throw new NullPointerException("Range must be non-null"); |
| 3790 | } |
| 3791 | |
| 3792 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3793 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3794 | |
| 3795 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3796 | } |
| 3797 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3798 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3799 | * Returns true if CDMA provisioning needs to run. |
| 3800 | */ |
| 3801 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | final long identity = Binder.clearCallingIdentity(); |
| 3803 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3804 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3805 | } finally { |
| 3806 | Binder.restoreCallingIdentity(identity); |
| 3807 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3811 | * Sets the voice mail number of a given subId. |
| 3812 | */ |
| 3813 | @Override |
| 3814 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3815 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3816 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3817 | |
| 3818 | final long identity = Binder.clearCallingIdentity(); |
| 3819 | try { |
| 3820 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3821 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3822 | return success; |
| 3823 | } finally { |
| 3824 | Binder.restoreCallingIdentity(identity); |
| 3825 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3826 | } |
| 3827 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3828 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3829 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3830 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3831 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3832 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3833 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3834 | throw new SecurityException("caller must be system dialer"); |
| 3835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3836 | |
| 3837 | final long identity = Binder.clearCallingIdentity(); |
| 3838 | try { |
| 3839 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3840 | if (phoneAccountHandle == null) { |
| 3841 | return null; |
| 3842 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3843 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3846 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
| 3849 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3850 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3851 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3852 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3853 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3854 | mApp, subId, callingPackage, callingFeatureId, |
| 3855 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3856 | return null; |
| 3857 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3858 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3859 | final long identity = Binder.clearCallingIdentity(); |
| 3860 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3861 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
| 3864 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3868 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3869 | VisualVoicemailSmsFilterSettings settings) { |
| 3870 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | |
| 3872 | final long identity = Binder.clearCallingIdentity(); |
| 3873 | try { |
| 3874 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3875 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(identity); |
| 3878 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3882 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3883 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3884 | |
| 3885 | final long identity = Binder.clearCallingIdentity(); |
| 3886 | try { |
| 3887 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3888 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | } finally { |
| 3890 | Binder.restoreCallingIdentity(identity); |
| 3891 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3895 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3896 | String callingPackage, int subId) { |
| 3897 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | |
| 3899 | final long identity = Binder.clearCallingIdentity(); |
| 3900 | try { |
| 3901 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3902 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
| 3905 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
| 3908 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3909 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | |
| 3912 | final long identity = Binder.clearCallingIdentity(); |
| 3913 | try { |
| 3914 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3915 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3916 | } finally { |
| 3917 | Binder.restoreCallingIdentity(identity); |
| 3918 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3922 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3923 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3924 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3925 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3926 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3927 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3928 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3929 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3930 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3931 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3932 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3933 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3934 | * Sets the voice activation state of a given subId. |
| 3935 | */ |
| 3936 | @Override |
| 3937 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3939 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3940 | |
| 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
| 3943 | final Phone phone = getPhone(subId); |
| 3944 | if (phone != null) { |
| 3945 | phone.setVoiceActivationState(activationState); |
| 3946 | } else { |
| 3947 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3948 | } |
| 3949 | } finally { |
| 3950 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3951 | } |
| 3952 | } |
| 3953 | |
| 3954 | /** |
| 3955 | * Sets the data activation state of a given subId. |
| 3956 | */ |
| 3957 | @Override |
| 3958 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3959 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3960 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3961 | |
| 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | final Phone phone = getPhone(subId); |
| 3965 | if (phone != null) { |
| 3966 | phone.setDataActivationState(activationState); |
| 3967 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3968 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3969 | } |
| 3970 | } finally { |
| 3971 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | /** |
| 3976 | * Returns the voice activation state of a given subId. |
| 3977 | */ |
| 3978 | @Override |
| 3979 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3982 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
| 3985 | if (phone != null) { |
| 3986 | return phone.getVoiceActivationState(); |
| 3987 | } else { |
| 3988 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3989 | } |
| 3990 | } finally { |
| 3991 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3992 | } |
| 3993 | } |
| 3994 | |
| 3995 | /** |
| 3996 | * Returns the data activation state of a given subId. |
| 3997 | */ |
| 3998 | @Override |
| 3999 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4001 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4002 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4003 | final long identity = Binder.clearCallingIdentity(); |
| 4004 | try { |
| 4005 | if (phone != null) { |
| 4006 | return phone.getDataActivationState(); |
| 4007 | } else { |
| 4008 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4009 | } |
| 4010 | } finally { |
| 4011 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4016 | * Returns the unread count of voicemails for a subId |
| 4017 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4018 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4019 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4020 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4022 | mApp, subId, callingPackage, callingFeatureId, |
| 4023 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4024 | return 0; |
| 4025 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4026 | final long identity = Binder.clearCallingIdentity(); |
| 4027 | try { |
| 4028 | final Phone phone = getPhone(subId); |
| 4029 | if (phone != null) { |
| 4030 | return phone.getVoiceMessageCount(); |
| 4031 | } else { |
| 4032 | return 0; |
| 4033 | } |
| 4034 | } finally { |
| 4035 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4036 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4040 | * returns true, if the device is in a state where both voice and data |
| 4041 | * are supported simultaneously. This can change based on location or network condition. |
| 4042 | */ |
| 4043 | @Override |
| 4044 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4045 | final long identity = Binder.clearCallingIdentity(); |
| 4046 | try { |
| 4047 | final Phone phone = getPhone(subId); |
| 4048 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4049 | } finally { |
| 4050 | Binder.restoreCallingIdentity(identity); |
| 4051 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4052 | } |
| 4053 | |
| 4054 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4055 | * Send the dialer code if called from the current default dialer or the caller has |
| 4056 | * carrier privilege. |
| 4057 | * @param inputCode The dialer code to send |
| 4058 | */ |
| 4059 | @Override |
| 4060 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4061 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4062 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4063 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4064 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4065 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4066 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4067 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4069 | |
| 4070 | final long identity = Binder.clearCallingIdentity(); |
| 4071 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4072 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4073 | } finally { |
| 4074 | Binder.restoreCallingIdentity(identity); |
| 4075 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4078 | @Override |
| 4079 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4080 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4081 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4082 | mApp, subId, "getNetworkSelectionMode"); |
| 4083 | final long identity = Binder.clearCallingIdentity(); |
| 4084 | try { |
| 4085 | if (!isActiveSubscription(subId)) { |
| 4086 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4087 | } |
| 4088 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4089 | } finally { |
| 4090 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4091 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4095 | public boolean isInEmergencySmsMode() { |
| 4096 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4097 | final long identity = Binder.clearCallingIdentity(); |
| 4098 | try { |
| 4099 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4100 | if (phone.isInEmergencySmsMode()) { |
| 4101 | return true; |
| 4102 | } |
| 4103 | } |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(identity); |
| 4106 | } |
| 4107 | return false; |
| 4108 | } |
| 4109 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4110 | /** |
| 4111 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4112 | * @param subId The subscription to use to check the configuration. |
| 4113 | * @param c The callback that will be used to send the result. |
| 4114 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4115 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4116 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4117 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4118 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4119 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4120 | |
| 4121 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4122 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4123 | "IMS not available on device."); |
| 4124 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4125 | final long token = Binder.clearCallingIdentity(); |
| 4126 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4127 | int slotId = getSlotIndexOrException(subId); |
| 4128 | verifyImsMmTelConfiguredOrThrow(slotId); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4129 | |
| 4130 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4131 | if (controller != null) { |
| 4132 | ImsManager imsManager = controller.getImsManager(subId); |
| 4133 | if (imsManager != null) { |
| 4134 | imsManager.addRegistrationCallbackForSubscription(c, subId); |
| 4135 | } else { |
| 4136 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE); |
| 4137 | } |
| 4138 | } else { |
| 4139 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4140 | } |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4141 | } catch (ImsException e) { |
| 4142 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4143 | } finally { |
| 4144 | Binder.restoreCallingIdentity(token); |
| 4145 | } |
| 4146 | } |
| 4147 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4148 | /** |
| 4149 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4150 | * @param subId The subscription to use to check the configuration. |
| 4151 | * @param c The callback that will be used to send the result. |
| 4152 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4153 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4154 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4155 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4156 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4157 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4158 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4159 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4160 | final long token = Binder.clearCallingIdentity(); |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4161 | |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4162 | try { |
joonhunshin | 49f0aed | 2022-08-05 08:33:05 +0000 | [diff] [blame] | 4163 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 4164 | if (controller != null) { |
| 4165 | ImsManager imsManager = controller.getImsManager(subId); |
| 4166 | if (imsManager != null) { |
| 4167 | imsManager.removeRegistrationCallbackForSubscription(c, subId); |
| 4168 | } else { |
| 4169 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4170 | + "is inactive, ignoring unregister."); |
| 4171 | // If the ImsManager is not valid, just return, since the callback |
| 4172 | // will already have been removed internally. |
| 4173 | } |
| 4174 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4175 | } finally { |
| 4176 | Binder.restoreCallingIdentity(token); |
| 4177 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4180 | /** |
| 4181 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4182 | */ |
| 4183 | @Override |
| 4184 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4185 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4186 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4187 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4188 | "IMS not available on device."); |
| 4189 | } |
| 4190 | final long token = Binder.clearCallingIdentity(); |
| 4191 | try { |
| 4192 | Phone phone = getPhone(subId); |
| 4193 | if (phone == null) { |
| 4194 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4195 | + subId + "'"); |
| 4196 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4197 | } |
| 4198 | phone.getImsRegistrationState(regState -> { |
| 4199 | try { |
| 4200 | consumer.accept((regState == null) |
| 4201 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4202 | } catch (RemoteException e) { |
| 4203 | // Ignore if the remote process is no longer available to call back. |
| 4204 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4205 | } |
| 4206 | }); |
| 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(token); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | /** |
| 4213 | * Get the transport type for the IMS service registration state. |
| 4214 | */ |
| 4215 | @Override |
| 4216 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4217 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4218 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4219 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4220 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4221 | "IMS not available on device."); |
| 4222 | } |
| 4223 | final long token = Binder.clearCallingIdentity(); |
| 4224 | try { |
| 4225 | Phone phone = getPhone(subId); |
| 4226 | if (phone == null) { |
| 4227 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4228 | + subId + "'"); |
| 4229 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4230 | } |
| 4231 | phone.getImsRegistrationTech(regTech -> { |
| 4232 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4233 | int regTechConverted = (regTech == null) |
| 4234 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4235 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4236 | regTechConverted); |
| 4237 | try { |
| 4238 | consumer.accept(regTechConverted); |
| 4239 | } catch (RemoteException e) { |
| 4240 | // Ignore if the remote process is no longer available to call back. |
| 4241 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4242 | } |
| 4243 | }); |
| 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(token); |
| 4246 | } |
| 4247 | } |
| 4248 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4249 | /** |
| 4250 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4251 | * @param subId The subscription to use to check the configuration. |
| 4252 | * @param c The callback that will be used to send the result. |
| 4253 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4254 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4255 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4256 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4257 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4258 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4259 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4260 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4261 | "IMS not available on device."); |
| 4262 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4263 | final long token = Binder.clearCallingIdentity(); |
| 4264 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4265 | int slotId = getSlotIndexOrException(subId); |
| 4266 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4267 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4268 | } catch (ImsException e) { |
| 4269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(token); |
| 4272 | } |
| 4273 | } |
| 4274 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4275 | /** |
| 4276 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4277 | * @param subId The subscription to use to check the configuration. |
| 4278 | * @param c The callback that will be used to send the result. |
| 4279 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4280 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4281 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4282 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4283 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4284 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4285 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4286 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4287 | |
| 4288 | final long token = Binder.clearCallingIdentity(); |
| 4289 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4290 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4291 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4292 | } catch (ImsException e) { |
| 4293 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4294 | + "is inactive, ignoring unregister."); |
| 4295 | // If the subscription is no longer active, just return, since the callback |
| 4296 | // will already have been removed internally. |
| 4297 | } finally { |
| 4298 | Binder.restoreCallingIdentity(token); |
| 4299 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
| 4302 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4303 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4304 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4305 | final long token = Binder.clearCallingIdentity(); |
| 4306 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4307 | int slotId = getSlotIndexOrException(subId); |
| 4308 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4309 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4310 | } catch (com.android.ims.ImsException e) { |
| 4311 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4312 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4313 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4314 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4315 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4316 | } finally { |
| 4317 | Binder.restoreCallingIdentity(token); |
| 4318 | } |
| 4319 | } |
| 4320 | |
| 4321 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4322 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4323 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4324 | final long token = Binder.clearCallingIdentity(); |
| 4325 | try { |
| 4326 | Phone phone = getPhone(subId); |
| 4327 | if (phone == null) return false; |
| 4328 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4329 | } catch (com.android.ims.ImsException e) { |
| 4330 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4331 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4332 | } finally { |
| 4333 | Binder.restoreCallingIdentity(token); |
| 4334 | } |
| 4335 | } |
| 4336 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4337 | /** |
| 4338 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4339 | * subscription. |
| 4340 | * @param subId The subscription to use to check the configuration. |
| 4341 | * @param callback The callback that will be used to send the result. |
| 4342 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4343 | * @param transportType The transport type of the MmTelFeature capability. |
| 4344 | */ |
| 4345 | @Override |
| 4346 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4347 | int transportType) { |
| 4348 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4349 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4350 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4351 | "IMS not available on device."); |
| 4352 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4353 | final long token = Binder.clearCallingIdentity(); |
| 4354 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4355 | int slotId = getSlotIndex(subId); |
| 4356 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4357 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4358 | + subId + "'"); |
| 4359 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4360 | } |
| 4361 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4362 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4363 | transportType, aBoolean -> { |
| 4364 | try { |
| 4365 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4366 | } catch (RemoteException e) { |
| 4367 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4368 | + "running. Ignore"); |
| 4369 | } |
| 4370 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4371 | } catch (ImsException e) { |
| 4372 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(token); |
| 4375 | } |
| 4376 | } |
| 4377 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4378 | /** |
| 4379 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4380 | * @param subId The subscription to use to check the configuration. |
| 4381 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4382 | @Override |
| 4383 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4384 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4385 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4386 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4387 | final long token = Binder.clearCallingIdentity(); |
| 4388 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4389 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4390 | // 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] | 4391 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4392 | } catch (ImsException e) { |
| 4393 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4394 | } finally { |
| 4395 | Binder.restoreCallingIdentity(token); |
| 4396 | } |
| 4397 | } |
| 4398 | |
| 4399 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4400 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4402 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4403 | final long identity = Binder.clearCallingIdentity(); |
| 4404 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4405 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4406 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4407 | // 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] | 4408 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4409 | } catch (ImsException e) { |
| 4410 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
| 4413 | } |
| 4414 | } |
| 4415 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4416 | /** |
| 4417 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4418 | * @param subId The subscription to use to check the configuration. |
| 4419 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4420 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4421 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4422 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4423 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4424 | final long identity = Binder.clearCallingIdentity(); |
| 4425 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4426 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4427 | // 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] | 4428 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4429 | } catch (ImsException e) { |
| 4430 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4431 | } finally { |
| 4432 | Binder.restoreCallingIdentity(identity); |
| 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4437 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4438 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4439 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | final long identity = Binder.clearCallingIdentity(); |
| 4441 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4442 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4443 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4444 | // 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] | 4445 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4446 | } catch (ImsException e) { |
| 4447 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
| 4451 | } |
| 4452 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4453 | /** |
| 4454 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4455 | * @param subId The subscription to use to check the configuration. |
| 4456 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4457 | @Override |
| 4458 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4459 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4460 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4463 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4464 | // 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] | 4465 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4466 | } catch (ImsException e) { |
| 4467 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4468 | } finally { |
| 4469 | Binder.restoreCallingIdentity(identity); |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4474 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4475 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4476 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4477 | final long identity = Binder.clearCallingIdentity(); |
| 4478 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4479 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4480 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4481 | // 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] | 4482 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4483 | } catch (ImsException e) { |
| 4484 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
| 4488 | } |
| 4489 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4490 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4491 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4492 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4493 | * @param subId The subscription to use to check the configuration. |
| 4494 | */ |
| 4495 | @Override |
| 4496 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4497 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4498 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4499 | final long identity = Binder.clearCallingIdentity(); |
| 4500 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4501 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4502 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4503 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4504 | } catch (ImsException e) { |
| 4505 | throw new ServiceSpecificException(e.getCode()); |
| 4506 | } finally { |
| 4507 | Binder.restoreCallingIdentity(identity); |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | /** |
| 4512 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4513 | * Requires MODIFY_PHONE_STATE permission. |
| 4514 | * @param subId The subscription to use to check the configuration. |
| 4515 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4516 | * false otherwise |
| 4517 | */ |
| 4518 | @Override |
| 4519 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4521 | "setCrossSimCallingEnabled"); |
| 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4524 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4525 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4526 | // 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] | 4527 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4528 | } catch (ImsException e) { |
| 4529 | throw new ServiceSpecificException(e.getCode()); |
| 4530 | } finally { |
| 4531 | Binder.restoreCallingIdentity(identity); |
| 4532 | } |
| 4533 | } |
| 4534 | |
| 4535 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4536 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4537 | * @param subId The subscription to use to check the configuration. |
| 4538 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4539 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4540 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4541 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4542 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4543 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | final long identity = Binder.clearCallingIdentity(); |
| 4545 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4546 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4547 | // 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] | 4548 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4549 | } catch (ImsException e) { |
| 4550 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4551 | } finally { |
| 4552 | Binder.restoreCallingIdentity(identity); |
| 4553 | } |
| 4554 | } |
| 4555 | |
| 4556 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4557 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4559 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4560 | final long identity = Binder.clearCallingIdentity(); |
| 4561 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4562 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4563 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4564 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4565 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4566 | } catch (ImsException e) { |
| 4567 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4568 | } finally { |
| 4569 | Binder.restoreCallingIdentity(identity); |
| 4570 | } |
| 4571 | } |
| 4572 | |
| 4573 | @Override |
| 4574 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4576 | "setVoWiFiNonPersistent"); |
| 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4579 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4580 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4581 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4582 | } catch (ImsException e) { |
| 4583 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4584 | } finally { |
| 4585 | Binder.restoreCallingIdentity(identity); |
| 4586 | } |
| 4587 | } |
| 4588 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4589 | /** |
| 4590 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4591 | * @param subId The subscription to use to check the configuration. |
| 4592 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4593 | @Override |
| 4594 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4595 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4596 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4597 | final long identity = Binder.clearCallingIdentity(); |
| 4598 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4599 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4600 | // 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] | 4601 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4602 | } catch (ImsException e) { |
| 4603 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4604 | } finally { |
| 4605 | Binder.restoreCallingIdentity(identity); |
| 4606 | } |
| 4607 | } |
| 4608 | |
| 4609 | @Override |
| 4610 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4611 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4612 | "setVoWiFiModeSetting"); |
| 4613 | final long identity = Binder.clearCallingIdentity(); |
| 4614 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4615 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4616 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4617 | // 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] | 4618 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4619 | } catch (ImsException e) { |
| 4620 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4621 | } finally { |
| 4622 | Binder.restoreCallingIdentity(identity); |
| 4623 | } |
| 4624 | } |
| 4625 | |
| 4626 | @Override |
| 4627 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4628 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4629 | final long identity = Binder.clearCallingIdentity(); |
| 4630 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4631 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4632 | // 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] | 4633 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4634 | } catch (ImsException e) { |
| 4635 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4636 | } finally { |
| 4637 | Binder.restoreCallingIdentity(identity); |
| 4638 | } |
| 4639 | } |
| 4640 | |
| 4641 | @Override |
| 4642 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4643 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4644 | "setVoWiFiRoamingModeSetting"); |
| 4645 | final long identity = Binder.clearCallingIdentity(); |
| 4646 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4647 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4648 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4649 | // 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] | 4650 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4651 | } catch (ImsException e) { |
| 4652 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4653 | } finally { |
| 4654 | Binder.restoreCallingIdentity(identity); |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | @Override |
| 4659 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4661 | "setRttCapabilityEnabled"); |
| 4662 | final long identity = Binder.clearCallingIdentity(); |
| 4663 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4664 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4665 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4666 | // 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] | 4667 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4668 | } catch (ImsException e) { |
| 4669 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4670 | } finally { |
| 4671 | Binder.restoreCallingIdentity(identity); |
| 4672 | } |
| 4673 | } |
| 4674 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4675 | /** |
| 4676 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4677 | * @param subId The subscription to use to check the configuration. |
| 4678 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4679 | @Override |
| 4680 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4681 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4682 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4683 | final long identity = Binder.clearCallingIdentity(); |
| 4684 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4685 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4686 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4687 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4688 | } catch (ImsException e) { |
| 4689 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4690 | } finally { |
| 4691 | Binder.restoreCallingIdentity(identity); |
| 4692 | } |
| 4693 | } |
| 4694 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4695 | @Override |
| 4696 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4697 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4698 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4699 | final long identity = Binder.clearCallingIdentity(); |
| 4700 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4701 | if (!isImsAvailableOnDevice()) { |
| 4702 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4703 | "IMS not available on device."); |
| 4704 | } |
| 4705 | int slotId = getSlotIndexOrException(subId); |
| 4706 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4707 | ImsManager.getInstance(mApp, slotId) |
| 4708 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4709 | } catch (ImsException e) { |
| 4710 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4711 | } finally { |
| 4712 | Binder.restoreCallingIdentity(identity); |
| 4713 | } |
| 4714 | } |
| 4715 | |
| 4716 | @Override |
| 4717 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4718 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4719 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4720 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4721 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4722 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4723 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4724 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4725 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4726 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4727 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4728 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4729 | + "is inactive, ignoring unregister."); |
| 4730 | // If the subscription is no longer active, just return, since the callback will already |
| 4731 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4732 | } finally { |
| 4733 | Binder.restoreCallingIdentity(identity); |
| 4734 | } |
| 4735 | } |
| 4736 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4737 | @Override |
| 4738 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4739 | IFeatureProvisioningCallback callback) { |
| 4740 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4741 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4742 | |
| 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4745 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4746 | } |
| 4747 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4748 | try { |
| 4749 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4750 | if (controller == null) { |
| 4751 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4752 | "Device does not support IMS"); |
| 4753 | } |
| 4754 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4755 | } finally { |
| 4756 | Binder.restoreCallingIdentity(identity); |
| 4757 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | @Override |
| 4761 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4762 | IFeatureProvisioningCallback callback) { |
| 4763 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4764 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4765 | |
| 4766 | final long identity = Binder.clearCallingIdentity(); |
| 4767 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4768 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4769 | } |
| 4770 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4771 | try { |
| 4772 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4773 | if (controller == null) { |
| 4774 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4775 | return; |
| 4776 | } |
| 4777 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4778 | } finally { |
| 4779 | Binder.restoreCallingIdentity(identity); |
| 4780 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4781 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4782 | |
| 4783 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4785 | message); |
| 4786 | } |
| 4787 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4788 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4789 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4790 | boolean isProvisioned) { |
| 4791 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4792 | |
| 4793 | final long identity = Binder.clearCallingIdentity(); |
| 4794 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4795 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4796 | if (controller == null) { |
| 4797 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4798 | return; |
| 4799 | } |
| 4800 | controller.setRcsProvisioningStatusForCapability( |
| 4801 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4802 | } finally { |
| 4803 | Binder.restoreCallingIdentity(identity); |
| 4804 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | |
| 4808 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4809 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4810 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4811 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4812 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4813 | final long identity = Binder.clearCallingIdentity(); |
| 4814 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4815 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4816 | if (controller == null) { |
| 4817 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4818 | |
| 4819 | // device does not support IMS, this method will return true always. |
| 4820 | return true; |
| 4821 | } |
| 4822 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
| 4825 | } |
| 4826 | } |
| 4827 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4828 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4829 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4830 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4831 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4832 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4833 | final long identity = Binder.clearCallingIdentity(); |
| 4834 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4835 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4836 | if (controller == null) { |
| 4837 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4838 | return; |
| 4839 | } |
| 4840 | controller.setImsProvisioningStatusForCapability( |
| 4841 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
| 4844 | } |
| 4845 | } |
| 4846 | |
| 4847 | @Override |
| 4848 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4849 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4850 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4851 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4852 | final long identity = Binder.clearCallingIdentity(); |
| 4853 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4854 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4855 | if (controller == null) { |
| 4856 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4857 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4858 | // device does not support IMS, this method will return true always. |
| 4859 | return true; |
| 4860 | } |
| 4861 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4862 | } finally { |
| 4863 | Binder.restoreCallingIdentity(identity); |
| 4864 | } |
| 4865 | } |
| 4866 | |
| 4867 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4868 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4869 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4870 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4871 | |
| 4872 | final long identity = Binder.clearCallingIdentity(); |
| 4873 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4874 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4875 | if (controller == null) { |
| 4876 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4877 | |
| 4878 | // device does not support IMS, this method will return false |
| 4879 | return false; |
| 4880 | } |
| 4881 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4882 | } finally { |
| 4883 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4884 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4885 | } |
| 4886 | |
| 4887 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4888 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4889 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4890 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4891 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4892 | final long identity = Binder.clearCallingIdentity(); |
| 4893 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4894 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4895 | if (controller == null) { |
| 4896 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4897 | |
| 4898 | // device does not support IMS, this method will return false |
| 4899 | return false; |
| 4900 | } |
| 4901 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4902 | } finally { |
| 4903 | Binder.restoreCallingIdentity(identity); |
| 4904 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4905 | } |
| 4906 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4907 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4908 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4909 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4910 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4911 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4912 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4913 | mApp, subId, "getImsProvisioningInt"); |
| 4914 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4915 | final long identity = Binder.clearCallingIdentity(); |
| 4916 | try { |
| 4917 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4918 | int slotId = getSlotIndex(subId); |
| 4919 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4920 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4921 | + subId + "' for key:" + key); |
| 4922 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4923 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4924 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4925 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4926 | if (controller == null) { |
| 4927 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4928 | |
| 4929 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4930 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4931 | } |
| 4932 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4933 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4934 | return retVal; |
| 4935 | } |
| 4936 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4937 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4938 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4939 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4940 | + subId + "' for key:" + key); |
| 4941 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4942 | } finally { |
| 4943 | Binder.restoreCallingIdentity(identity); |
| 4944 | } |
| 4945 | } |
| 4946 | |
| 4947 | @Override |
| 4948 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4949 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4950 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4951 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4952 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4953 | mApp, subId, "getImsProvisioningString"); |
| 4954 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4955 | final long identity = Binder.clearCallingIdentity(); |
| 4956 | try { |
| 4957 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4958 | int slotId = getSlotIndex(subId); |
| 4959 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4960 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4961 | + subId + "' for key:" + key); |
| 4962 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4963 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4964 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4965 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4966 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4967 | + subId + "' for key:" + key); |
| 4968 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
| 4972 | } |
| 4973 | |
| 4974 | @Override |
| 4975 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4976 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4977 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4978 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4979 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4980 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4981 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4982 | final long identity = Binder.clearCallingIdentity(); |
| 4983 | try { |
| 4984 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4985 | int slotId = getSlotIndex(subId); |
| 4986 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4987 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4988 | + subId + "' for key:" + key); |
| 4989 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4990 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4991 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4992 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4993 | if (controller == null) { |
| 4994 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 4995 | |
| 4996 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 4997 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4998 | } |
| 4999 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 5000 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 5001 | return retVal; |
| 5002 | } |
| 5003 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5004 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5005 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5006 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5007 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5008 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5009 | } finally { |
| 5010 | Binder.restoreCallingIdentity(identity); |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | @Override |
| 5015 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5016 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 5017 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 5018 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 5019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 5020 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5021 | final long identity = Binder.clearCallingIdentity(); |
| 5022 | try { |
| 5023 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5024 | int slotId = getSlotIndex(subId); |
| 5025 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5026 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5027 | + subId + "' for key:" + key); |
| 5028 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5029 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5030 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5031 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5032 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5033 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5034 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5035 | } finally { |
| 5036 | Binder.restoreCallingIdentity(identity); |
| 5037 | } |
| 5038 | } |
| 5039 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5040 | /** |
| 5041 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5042 | * for the given slot ID or no ImsResolver instance has been created. |
| 5043 | * @param slotId The slot ID that the IMS service is created for. |
| 5044 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5045 | */ |
| 5046 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5047 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5048 | ImsFeature.FEATURE_MMTEL)) { |
| 5049 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5050 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5051 | } |
| 5052 | } |
| 5053 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5054 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5055 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5056 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5057 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5058 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5059 | } |
| 5060 | return slotId; |
| 5061 | } |
| 5062 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5063 | private int getSlotIndex(int subId) { |
| 5064 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5065 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5066 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5067 | } |
| 5068 | return slotId; |
| 5069 | } |
| 5070 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5071 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5072 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5073 | */ |
| 5074 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5075 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5076 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5077 | try { |
| 5078 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5079 | } catch (SecurityException se) { |
| 5080 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5081 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5082 | + Binder.getCallingUid()); |
| 5083 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5084 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5085 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5086 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5087 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5088 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5089 | mApp, subId, callingPackage, callingFeatureId, |
| 5090 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5091 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5092 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5094 | final long identity = Binder.clearCallingIdentity(); |
| 5095 | try { |
| 5096 | final Phone phone = getPhone(subId); |
| 5097 | if (phone != null) { |
| 5098 | return phone.getServiceState().getDataNetworkType(); |
| 5099 | } else { |
| 5100 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5101 | } |
| 5102 | } finally { |
| 5103 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
| 5108 | * Returns the data network type |
| 5109 | */ |
| 5110 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5111 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5112 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5113 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5114 | } |
| 5115 | |
| 5116 | /** |
| 5117 | * Returns the data network type for a subId |
| 5118 | */ |
| 5119 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5120 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5121 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5122 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5123 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5124 | mApp, functionName)) { |
| 5125 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5126 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5127 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5128 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5131 | final long identity = Binder.clearCallingIdentity(); |
| 5132 | try { |
| 5133 | final Phone phone = getPhone(subId); |
| 5134 | if (phone != null) { |
| 5135 | return phone.getServiceState().getDataNetworkType(); |
| 5136 | } else { |
| 5137 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5138 | } |
| 5139 | } finally { |
| 5140 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5141 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5142 | } |
| 5143 | |
| 5144 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5145 | * Returns the Voice network type for a subId |
| 5146 | */ |
| 5147 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5148 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5149 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5150 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5151 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5152 | mApp, functionName)) { |
| 5153 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5154 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5155 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5156 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5159 | final long identity = Binder.clearCallingIdentity(); |
| 5160 | try { |
| 5161 | final Phone phone = getPhone(subId); |
| 5162 | if (phone != null) { |
| 5163 | return phone.getServiceState().getVoiceNetworkType(); |
| 5164 | } else { |
| 5165 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5166 | } |
| 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | /** |
| 5173 | * @return true if a ICC card is present |
| 5174 | */ |
| 5175 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5176 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5177 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5178 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
| 5181 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5182 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5183 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5184 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5185 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
| 5188 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5189 | if (phone != null) { |
| 5190 | return phone.getIccCard().hasIccCard(); |
| 5191 | } else { |
| 5192 | return false; |
| 5193 | } |
| 5194 | } finally { |
| 5195 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5196 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * Return if the current radio is LTE on CDMA. This |
| 5201 | * is a tri-state return value as for a period of time |
| 5202 | * the mode may be unknown. |
| 5203 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5204 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5205 | * @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] | 5206 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5207 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5208 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5209 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5210 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5211 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5214 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5215 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5216 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5217 | try { |
| 5218 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5219 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5220 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5221 | } |
| 5222 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
| 5225 | final Phone phone = getPhone(subId); |
| 5226 | if (phone == null) { |
| 5227 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5228 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5229 | return TelephonyProperties.lte_on_cdma_device() |
| 5230 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5231 | } |
| 5232 | } finally { |
| 5233 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5234 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5235 | } |
| 5236 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5237 | /** |
| 5238 | * {@hide} |
| 5239 | * Returns Default subId, 0 in the case of single standby. |
| 5240 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5241 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5242 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5245 | private int getSlotForDefaultSubscription() { |
| 5246 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5247 | } |
| 5248 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5249 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5250 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5251 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5252 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5253 | private boolean isActiveSubscription(int subId) { |
| 5254 | return mSubscriptionController.isActiveSubId(subId); |
| 5255 | } |
| 5256 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5257 | /** |
| 5258 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5259 | */ |
| 5260 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5261 | final long identity = Binder.clearCallingIdentity(); |
| 5262 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5263 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5264 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5265 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5266 | } finally { |
| 5267 | Binder.restoreCallingIdentity(identity); |
| 5268 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5269 | } |
| 5270 | |
| 5271 | /** |
| 5272 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5273 | */ |
| 5274 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | final long identity = Binder.clearCallingIdentity(); |
| 5276 | try { |
| 5277 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5278 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5279 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5280 | } finally { |
| 5281 | Binder.restoreCallingIdentity(identity); |
| 5282 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5283 | } |
| 5284 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5285 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5286 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5287 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5288 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5289 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5290 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5291 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5292 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5293 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5294 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5295 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5296 | } |
| 5297 | return PhoneFactory.getPhone(phoneId); |
| 5298 | } |
| 5299 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5300 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5301 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5302 | @NonNull IccLogicalChannelRequest request) { |
| 5303 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5304 | /*message=*/ "iccOpenLogicalChannel"); |
| 5305 | |
| 5306 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5307 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5308 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5309 | |
| 5310 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5311 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5312 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5313 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5314 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5315 | Phone phone; |
| 5316 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5318 | mApp, request.subId, message); |
| 5319 | phone = getPhoneFromSubId(request.subId); |
| 5320 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5321 | enforceModifyPermission(); |
| 5322 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5323 | } else { |
| 5324 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5325 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5326 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5330 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | final long identity = Binder.clearCallingIdentity(); |
| 5332 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5333 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5335 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5336 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5337 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5338 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | loge("The calling package is not allowed to access ISD-R."); |
| 5340 | throw new SecurityException( |
| 5341 | "The calling package is not allowed to access ISD-R."); |
| 5342 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5343 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5344 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5345 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5346 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5347 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5348 | return response; |
| 5349 | } finally { |
| 5350 | Binder.restoreCallingIdentity(identity); |
| 5351 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5352 | } |
| 5353 | |
| 5354 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5355 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5356 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5357 | /*message=*/"iccCloseLogicalChannel"); |
| 5358 | |
| 5359 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5360 | |
| 5361 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5362 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5363 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5364 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5365 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5366 | // before this feature is enabled, this API should only return false if |
| 5367 | // the operation fails instead of throwing runtime exception for |
| 5368 | // backward-compatibility. |
| 5369 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5370 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | final long identity = Binder.clearCallingIdentity(); |
| 5372 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5373 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5374 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5376 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5377 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5378 | Boolean success = false; |
| 5379 | if (result instanceof RuntimeException) { |
| 5380 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5381 | if (shouldThrowExceptionOnFailure) { |
| 5382 | throw (RuntimeException) result; |
| 5383 | } else { |
| 5384 | return false; |
| 5385 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5386 | } else if (result instanceof Boolean) { |
| 5387 | success = (Boolean) result; |
| 5388 | } else { |
| 5389 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5390 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5391 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5392 | return success; |
| 5393 | } finally { |
| 5394 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5395 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5396 | } |
| 5397 | |
| 5398 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5399 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5400 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5402 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5403 | if (DBG) { |
| 5404 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5405 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5406 | + p3 + " data=" + data); |
| 5407 | } |
| 5408 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5409 | command, p1, p2, p3, data); |
| 5410 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5411 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5412 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5413 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5414 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5415 | enforceModifyPermission(); |
| 5416 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5417 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5418 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5419 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5420 | } |
| 5421 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5422 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5423 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5427 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | final long identity = Binder.clearCallingIdentity(); |
| 5429 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5430 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5431 | return ""; |
| 5432 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5433 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5435 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5436 | null /* workSource */); |
| 5437 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5439 | // Append the returned status code to the end of the response payload. |
| 5440 | String s = Integer.toHexString( |
| 5441 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5442 | if (response.payload != null) { |
| 5443 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5444 | } |
| 5445 | return s; |
| 5446 | } finally { |
| 5447 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5448 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5449 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5450 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5451 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5452 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5453 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5455 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5456 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5457 | if (DBG) { |
| 5458 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5459 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5460 | } |
| 5461 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5462 | cla, command, p1, p2, p3, data); |
| 5463 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5464 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5465 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5466 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5467 | 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] | 5468 | enforceModifyPermission(); |
| 5469 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5470 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5471 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5472 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5473 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5474 | } |
| 5475 | |
| 5476 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5477 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5478 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5482 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5483 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5484 | final long identity = Binder.clearCallingIdentity(); |
| 5485 | try { |
| 5486 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5487 | && TextUtils.equals(ISDR_AID, data)) { |
| 5488 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5489 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5490 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | if (bestComponent == null |
| 5492 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5493 | loge("The calling package is not allowed to select ISD-R."); |
| 5494 | throw new SecurityException( |
| 5495 | "The calling package is not allowed to select ISD-R."); |
| 5496 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5497 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5498 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5500 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5501 | null /* workSource */); |
| 5502 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5503 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | // Append the returned status code to the end of the response payload. |
| 5505 | String s = Integer.toHexString( |
| 5506 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5507 | if (response.payload != null) { |
| 5508 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5509 | } |
| 5510 | return s; |
| 5511 | } finally { |
| 5512 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5513 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5517 | 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] | 5518 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5520 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final long identity = Binder.clearCallingIdentity(); |
| 5523 | try { |
| 5524 | if (DBG) { |
| 5525 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5526 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5527 | } |
| 5528 | |
| 5529 | IccIoResult response = |
| 5530 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5531 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5532 | subId); |
| 5533 | |
| 5534 | if (DBG) { |
| 5535 | log("Exchange SIM_IO [R]" + response); |
| 5536 | } |
| 5537 | |
| 5538 | byte[] result = null; |
| 5539 | int length = 2; |
| 5540 | if (response.payload != null) { |
| 5541 | length = 2 + response.payload.length; |
| 5542 | result = new byte[length]; |
| 5543 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5544 | } else { |
| 5545 | result = new byte[length]; |
| 5546 | } |
| 5547 | |
| 5548 | result[length - 1] = (byte) response.sw2; |
| 5549 | result[length - 2] = (byte) response.sw1; |
| 5550 | return result; |
| 5551 | } finally { |
| 5552 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5553 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5554 | } |
| 5555 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5556 | /** |
| 5557 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5558 | * on a particular subscription |
| 5559 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5560 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5561 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5562 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5563 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5564 | return null; |
| 5565 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | |
| 5567 | final long identity = Binder.clearCallingIdentity(); |
| 5568 | try { |
| 5569 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5570 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5571 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5572 | return null; |
| 5573 | } |
| 5574 | Object response = sendRequest( |
| 5575 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5576 | if (response instanceof String[]) { |
| 5577 | return (String[]) response; |
| 5578 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5579 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5580 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5581 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | } finally { |
| 5583 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5584 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5585 | } |
| 5586 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5587 | /** |
| 5588 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5589 | * subscription. |
| 5590 | * |
| 5591 | * @param subId the id of the subscription. |
| 5592 | * @param appType the uicc app type, must be USIM or SIM. |
| 5593 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5594 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5595 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5596 | * @return number of fplmns that is successfully written to the SIM. |
| 5597 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5598 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5599 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5600 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5601 | mApp, subId, "setForbiddenPlmns"); |
| 5602 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5603 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5604 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5605 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5606 | } |
| 5607 | if (fplmns == null) { |
| 5608 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5609 | } |
| 5610 | for (String fplmn : fplmns) { |
| 5611 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5612 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5613 | } |
| 5614 | } |
| 5615 | final long identity = Binder.clearCallingIdentity(); |
| 5616 | try { |
| 5617 | Object response = sendRequest( |
| 5618 | CMD_SET_FORBIDDEN_PLMNS, |
| 5619 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5620 | subId); |
| 5621 | return (int) response; |
| 5622 | } finally { |
| 5623 | Binder.restoreCallingIdentity(identity); |
| 5624 | } |
| 5625 | } |
| 5626 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5627 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5628 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5630 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5631 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5632 | final long identity = Binder.clearCallingIdentity(); |
| 5633 | try { |
| 5634 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5635 | if (response.payload == null) { |
| 5636 | return ""; |
| 5637 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | // Append the returned status code to the end of the response payload. |
| 5640 | String s = Integer.toHexString( |
| 5641 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5642 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5643 | return s; |
| 5644 | } finally { |
| 5645 | Binder.restoreCallingIdentity(identity); |
| 5646 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5647 | } |
| 5648 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5649 | /** |
| 5650 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5651 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5652 | * |
| 5653 | * @param itemID the ID of the item to read |
| 5654 | * @return the NV item as a String, or null on error. |
| 5655 | */ |
| 5656 | @Override |
| 5657 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5658 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5660 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5661 | |
| 5662 | final long identity = Binder.clearCallingIdentity(); |
| 5663 | try { |
| 5664 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5665 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5667 | return value; |
| 5668 | } finally { |
| 5669 | Binder.restoreCallingIdentity(identity); |
| 5670 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5671 | } |
| 5672 | |
| 5673 | /** |
| 5674 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5675 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5676 | * |
| 5677 | * @param itemID the ID of the item to read |
| 5678 | * @param itemValue the value to write, as a String |
| 5679 | * @return true on success; false on any failure |
| 5680 | */ |
| 5681 | @Override |
| 5682 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5683 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5685 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | |
| 5687 | final long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5690 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5691 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5693 | return success; |
| 5694 | } finally { |
| 5695 | Binder.restoreCallingIdentity(identity); |
| 5696 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5697 | } |
| 5698 | |
| 5699 | /** |
| 5700 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5701 | * Used for device configuration by some CDMA operators. |
| 5702 | * |
| 5703 | * @param preferredRoamingList byte array containing the new PRL |
| 5704 | * @return true on success; false on any failure |
| 5705 | */ |
| 5706 | @Override |
| 5707 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5708 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5709 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | |
| 5711 | final long identity = Binder.clearCallingIdentity(); |
| 5712 | try { |
| 5713 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5714 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5715 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5716 | return success; |
| 5717 | } finally { |
| 5718 | Binder.restoreCallingIdentity(identity); |
| 5719 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5720 | } |
| 5721 | |
| 5722 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5723 | * 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] | 5724 | * Used for device configuration by some CDMA operators. |
| 5725 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5726 | * @param slotIndex - device slot. |
| 5727 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5728 | * @return true on success; false on any failure |
| 5729 | */ |
| 5730 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5731 | public boolean resetModemConfig(int slotIndex) { |
| 5732 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5733 | if (phone != null) { |
| 5734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5735 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5736 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5737 | final long identity = Binder.clearCallingIdentity(); |
| 5738 | try { |
| 5739 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5740 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5741 | return success; |
| 5742 | } finally { |
| 5743 | Binder.restoreCallingIdentity(identity); |
| 5744 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5746 | return false; |
| 5747 | } |
| 5748 | |
| 5749 | /** |
| 5750 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5751 | * |
| 5752 | * @param slotIndex - device slot. |
| 5753 | * |
| 5754 | * @return true on success; false on any failure |
| 5755 | */ |
| 5756 | @Override |
| 5757 | public boolean rebootModem(int slotIndex) { |
| 5758 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5759 | if (phone != null) { |
| 5760 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5761 | mApp, phone.getSubId(), "rebootModem"); |
| 5762 | |
| 5763 | final long identity = Binder.clearCallingIdentity(); |
| 5764 | try { |
| 5765 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5766 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5767 | return success; |
| 5768 | } finally { |
| 5769 | Binder.restoreCallingIdentity(identity); |
| 5770 | } |
| 5771 | } |
| 5772 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5773 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5774 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5775 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5776 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5777 | * {@link #disableIms(int)}. |
| 5778 | * @param slotIndex device slot. |
| 5779 | */ |
| 5780 | public void resetIms(int slotIndex) { |
| 5781 | enforceModifyPermission(); |
| 5782 | |
| 5783 | final long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
| 5785 | if (mImsResolver == null) { |
| 5786 | // may happen if the does not support IMS. |
| 5787 | return; |
| 5788 | } |
Hyunho | a17ac7c | 2022-08-30 12:03:04 +0000 | [diff] [blame] | 5789 | mImsResolver.resetIms(slotIndex); |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5790 | } finally { |
| 5791 | Binder.restoreCallingIdentity(identity); |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5796 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5797 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5798 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5799 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5801 | |
| 5802 | final long identity = Binder.clearCallingIdentity(); |
| 5803 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5804 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5805 | // may happen if the device does not support IMS. |
| 5806 | return; |
| 5807 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5808 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5809 | } finally { |
| 5810 | Binder.restoreCallingIdentity(identity); |
| 5811 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5815 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5816 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5817 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5818 | public void disableIms(int slotId) { |
| 5819 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5820 | |
| 5821 | final long identity = Binder.clearCallingIdentity(); |
| 5822 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5823 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5824 | // may happen if the device does not support IMS. |
| 5825 | return; |
| 5826 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5827 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
| 5830 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5834 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5835 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5836 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5837 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5838 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5839 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5840 | |
| 5841 | final long identity = Binder.clearCallingIdentity(); |
| 5842 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5843 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5845 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5846 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5847 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5848 | } finally { |
| 5849 | Binder.restoreCallingIdentity(identity); |
| 5850 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5851 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5852 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5853 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5854 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5855 | @Override |
| 5856 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5857 | enforceModifyPermission(); |
| 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
| 5861 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5862 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5863 | } finally { |
| 5864 | Binder.restoreCallingIdentity(identity); |
| 5865 | } |
| 5866 | } |
| 5867 | |
| 5868 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5869 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5870 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5871 | */ |
| 5872 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5873 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5874 | |
| 5875 | final long identity = Binder.clearCallingIdentity(); |
| 5876 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5877 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5878 | // may happen if the device does not support IMS. |
| 5879 | return null; |
| 5880 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5881 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5882 | } finally { |
| 5883 | Binder.restoreCallingIdentity(identity); |
| 5884 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5885 | } |
| 5886 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5887 | /** |
| 5888 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5889 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5890 | */ |
| 5891 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5892 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | |
| 5894 | final long identity = Binder.clearCallingIdentity(); |
| 5895 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5896 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5897 | // may happen if the device does not support IMS. |
| 5898 | return null; |
| 5899 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5900 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5901 | } finally { |
| 5902 | Binder.restoreCallingIdentity(identity); |
| 5903 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5904 | } |
| 5905 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5906 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5907 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5908 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5909 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5910 | * @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] | 5911 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5912 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5913 | * @param packageName The name of the package that the current configuration will be replaced |
| 5914 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5915 | * @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] | 5916 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5917 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5918 | int[] featureTypes, String packageName) { |
| 5919 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5920 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5921 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5922 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5923 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5925 | final long identity = Binder.clearCallingIdentity(); |
| 5926 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5928 | // may happen if the device does not support IMS. |
| 5929 | return false; |
| 5930 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5931 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5932 | for (int featureType : featureTypes) { |
| 5933 | featureConfig.put(featureType, packageName); |
| 5934 | } |
| 5935 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5936 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | } finally { |
| 5938 | Binder.restoreCallingIdentity(identity); |
| 5939 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5940 | } |
| 5941 | |
| 5942 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5943 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5944 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5945 | * |
| 5946 | * This should only be used for testing. |
| 5947 | * |
| 5948 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5949 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5950 | */ |
| 5951 | @Override |
| 5952 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5953 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5955 | "clearCarrierImsServiceOverride"); |
| 5956 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5957 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5958 | "clearCarrierImsServiceOverride"); |
| 5959 | |
| 5960 | final long identity = Binder.clearCallingIdentity(); |
| 5961 | try { |
| 5962 | if (mImsResolver == null) { |
| 5963 | // may happen if the device does not support IMS. |
| 5964 | return false; |
| 5965 | } |
| 5966 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5967 | } finally { |
| 5968 | Binder.restoreCallingIdentity(identity); |
| 5969 | } |
| 5970 | } |
| 5971 | |
| 5972 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5973 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5974 | * |
| 5975 | * @param slotId The slot that the ImsService is associated with. |
| 5976 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5977 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5978 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5979 | * @return the package name of the ImsService configuration. |
| 5980 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5981 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5982 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5983 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5984 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5985 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5986 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5987 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5988 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5989 | final long identity = Binder.clearCallingIdentity(); |
| 5990 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5991 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5992 | // may happen if the device does not support IMS. |
| 5993 | return ""; |
| 5994 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5995 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5996 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5997 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
| 6000 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6003 | /** |
| 6004 | * Get the MmTelFeature state associated with the requested subscription id. |
| 6005 | * @param subId The subscription that the MmTelFeature is associated with. |
| 6006 | * @param callback A callback with an integer containing the |
| 6007 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 6008 | */ |
| 6009 | @Override |
| 6010 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 6011 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6012 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 6013 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 6014 | "IMS not available on device."); |
| 6015 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6016 | final long token = Binder.clearCallingIdentity(); |
| 6017 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 6018 | int slotId = getSlotIndex(subId); |
| 6019 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6020 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6021 | + subId + "'"); |
| 6022 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6023 | } |
| 6024 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6025 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6026 | try { |
| 6027 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6028 | } catch (RemoteException e) { |
| 6029 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6030 | + "Ignore"); |
| 6031 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6032 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6033 | } catch (ImsException e) { |
| 6034 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6035 | } finally { |
| 6036 | Binder.restoreCallingIdentity(token); |
| 6037 | } |
| 6038 | } |
| 6039 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6040 | /** |
| 6041 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6042 | */ |
| 6043 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6044 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6045 | |
| 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6048 | // NOTE: Before S, this method only set the default phone. |
| 6049 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6050 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6051 | phone.setImsRegistrationState(registered); |
| 6052 | } |
| 6053 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6054 | } finally { |
| 6055 | Binder.restoreCallingIdentity(identity); |
| 6056 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6057 | } |
| 6058 | |
| 6059 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6060 | * Set the network selection mode to automatic. |
| 6061 | * |
| 6062 | */ |
| 6063 | @Override |
| 6064 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6066 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | |
| 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6070 | if (!isActiveSubscription(subId)) { |
| 6071 | return; |
| 6072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6074 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6075 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6076 | } finally { |
| 6077 | Binder.restoreCallingIdentity(identity); |
| 6078 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6079 | } |
| 6080 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6081 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6082 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6083 | * |
| 6084 | * @param subId the id of the subscription. |
| 6085 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6086 | * the operator to attach to. |
| 6087 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6088 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6089 | * normal network selection next time. |
| 6090 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6091 | */ |
| 6092 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6093 | public boolean setNetworkSelectionModeManual( |
| 6094 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6095 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6096 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6097 | |
| 6098 | if (!isActiveSubscription(subId)) { |
| 6099 | return false; |
| 6100 | } |
| 6101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | final long identity = Binder.clearCallingIdentity(); |
| 6103 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6104 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6105 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6106 | if (DBG) { |
| 6107 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6108 | + " operator: " + operatorInfo); |
| 6109 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6110 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6111 | } finally { |
| 6112 | Binder.restoreCallingIdentity(identity); |
| 6113 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6114 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6115 | /** |
| 6116 | * Get the manual network selection |
| 6117 | * |
| 6118 | * @param subId the id of the subscription. |
| 6119 | * |
| 6120 | * @return the previously saved user selected PLMN |
| 6121 | */ |
| 6122 | @Override |
| 6123 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6124 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6125 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6126 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6127 | |
| 6128 | final long identity = Binder.clearCallingIdentity(); |
| 6129 | try { |
| 6130 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6131 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | final Phone phone = getPhone(subId); |
| 6135 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6136 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6137 | } |
| 6138 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6139 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6140 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6141 | } finally { |
| 6142 | Binder.restoreCallingIdentity(identity); |
| 6143 | } |
| 6144 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6145 | |
| 6146 | /** |
| 6147 | * Scans for available networks. |
| 6148 | */ |
| 6149 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6150 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6151 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6153 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6154 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6155 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6156 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6157 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6158 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6159 | .setCallingPid(Binder.getCallingPid()) |
| 6160 | .setCallingUid(Binder.getCallingUid()) |
| 6161 | .setMethod("getCellNetworkScanResults") |
| 6162 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6163 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6164 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6165 | .build()); |
| 6166 | switch (locationResult) { |
| 6167 | case DENIED_HARD: |
| 6168 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6169 | case DENIED_SOFT: |
| 6170 | return null; |
| 6171 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6172 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6173 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | try { |
| 6175 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6176 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6177 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6178 | } finally { |
| 6179 | Binder.restoreCallingIdentity(identity); |
| 6180 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6184 | * Get the call forwarding info, given the call forwarding reason. |
| 6185 | */ |
| 6186 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6187 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6188 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6189 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6190 | long identity = Binder.clearCallingIdentity(); |
| 6191 | try { |
| 6192 | if (DBG) { |
| 6193 | log("getCallForwarding: subId " + subId |
| 6194 | + " callForwardingReason" + callForwardingReason); |
| 6195 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6196 | |
| 6197 | Phone phone = getPhone(subId); |
| 6198 | if (phone == null) { |
| 6199 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6200 | callback.onError( |
| 6201 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6202 | } catch (RemoteException e) { |
| 6203 | // ignore |
| 6204 | } |
| 6205 | return; |
| 6206 | } |
| 6207 | |
| 6208 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6209 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6210 | @Override |
| 6211 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6212 | try { |
| 6213 | callback.onCallForwardingInfoAvailable(info); |
| 6214 | } catch (RemoteException e) { |
| 6215 | // ignore |
| 6216 | } |
| 6217 | } |
| 6218 | |
| 6219 | @Override |
| 6220 | public void onError(int error) { |
| 6221 | try { |
| 6222 | callback.onError(error); |
| 6223 | } catch (RemoteException e) { |
| 6224 | // ignore |
| 6225 | } |
| 6226 | } |
| 6227 | }); |
| 6228 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6229 | } finally { |
| 6230 | Binder.restoreCallingIdentity(identity); |
| 6231 | } |
| 6232 | } |
| 6233 | |
| 6234 | /** |
| 6235 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6236 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6237 | */ |
| 6238 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6239 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6240 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6241 | enforceModifyPermission(); |
| 6242 | long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
| 6244 | if (DBG) { |
| 6245 | log("setCallForwarding: subId " + subId |
| 6246 | + " callForwardingInfo" + callForwardingInfo); |
| 6247 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6248 | |
| 6249 | Phone phone = getPhone(subId); |
| 6250 | if (phone == null) { |
| 6251 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6252 | callback.accept( |
| 6253 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6254 | } catch (RemoteException e) { |
| 6255 | // ignore |
| 6256 | } |
| 6257 | return; |
| 6258 | } |
| 6259 | |
| 6260 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6261 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6262 | |
| 6263 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6264 | } finally { |
| 6265 | Binder.restoreCallingIdentity(identity); |
| 6266 | } |
| 6267 | } |
| 6268 | |
| 6269 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6270 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6271 | */ |
| 6272 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6273 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6274 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6275 | long identity = Binder.clearCallingIdentity(); |
| 6276 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6277 | Phone phone = getPhone(subId); |
| 6278 | if (phone == null) { |
| 6279 | try { |
| 6280 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6281 | } catch (RemoteException e) { |
| 6282 | // ignore |
| 6283 | } |
| 6284 | return; |
| 6285 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6286 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6287 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6288 | boolean requireUssd = c.getBoolean( |
| 6289 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6290 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6291 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6292 | if (requireUssd) { |
| 6293 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6294 | getSubscriptionCarrierId(subId)); |
| 6295 | String newUssdCommand = ""; |
| 6296 | try { |
| 6297 | newUssdCommand = carrierXmlParser.getFeature( |
| 6298 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6299 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6300 | } catch (NullPointerException e) { |
| 6301 | loge("Failed to generate USSD number" + e); |
| 6302 | } |
| 6303 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6304 | mMainThreadHandler, callback, carrierXmlParser, |
| 6305 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6306 | final String ussdCommand = newUssdCommand; |
| 6307 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6308 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6309 | }); |
| 6310 | } else { |
| 6311 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6312 | callback::accept); |
| 6313 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6314 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6315 | } finally { |
| 6316 | Binder.restoreCallingIdentity(identity); |
| 6317 | } |
| 6318 | } |
| 6319 | |
| 6320 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6321 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6322 | */ |
| 6323 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6324 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6325 | enforceModifyPermission(); |
| 6326 | long identity = Binder.clearCallingIdentity(); |
| 6327 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6328 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6329 | |
| 6330 | Phone phone = getPhone(subId); |
| 6331 | if (phone == null) { |
| 6332 | try { |
| 6333 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6334 | } catch (RemoteException e) { |
| 6335 | // ignore |
| 6336 | } |
| 6337 | return; |
| 6338 | } |
| 6339 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6340 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6341 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6342 | boolean requireUssd = c.getBoolean( |
| 6343 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6344 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6345 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6346 | if (requireUssd) { |
| 6347 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6348 | getSubscriptionCarrierId(subId)); |
| 6349 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6350 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6351 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6352 | String newUssdCommand = ""; |
| 6353 | try { |
| 6354 | newUssdCommand = carrierXmlParser.getFeature( |
| 6355 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6356 | .makeCommand(ssAction, null); |
| 6357 | } catch (NullPointerException e) { |
| 6358 | loge("Failed to generate USSD number" + e); |
| 6359 | } |
| 6360 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6361 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6362 | final String ussdCommand = newUssdCommand; |
| 6363 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6364 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6365 | }); |
| 6366 | } else { |
| 6367 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6368 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6369 | |
| 6370 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6371 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6372 | } finally { |
| 6373 | Binder.restoreCallingIdentity(identity); |
| 6374 | } |
| 6375 | } |
| 6376 | |
| 6377 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6378 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6379 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6380 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6381 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6382 | * location related information which will be sent if the caller already possess |
| 6383 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6384 | * @param request contains the radio access networks with bands/channels to scan |
| 6385 | * @param messenger callback messenger for scan results or errors |
| 6386 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6387 | * @return the id of the requested scan which can be used to stop the scan. |
| 6388 | */ |
| 6389 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6390 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6391 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6392 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6393 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6394 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6395 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6396 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6397 | if (!renounceFineLocationAccess) { |
| 6398 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6399 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6400 | .setCallingPackage(callingPackage) |
| 6401 | .setCallingFeatureId(callingFeatureId) |
| 6402 | .setCallingPid(Binder.getCallingPid()) |
| 6403 | .setCallingUid(Binder.getCallingUid()) |
| 6404 | .setMethod("requestNetworkScan") |
| 6405 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6406 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6407 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6408 | .build()); |
| 6409 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6410 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6411 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6412 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6413 | if (e != null) { |
| 6414 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6415 | throw e; |
| 6416 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6417 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6418 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6419 | } |
| 6420 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6422 | int callingUid = Binder.getCallingUid(); |
| 6423 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6424 | final long identity = Binder.clearCallingIdentity(); |
| 6425 | try { |
| 6426 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6427 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6428 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
| 6431 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6434 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6435 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6436 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6437 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6438 | boolean hasNetworkScanPermission = |
| 6439 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6440 | == PERMISSION_GRANTED; |
| 6441 | |
| 6442 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6443 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6444 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6448 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6449 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6450 | return new SecurityException("Specific channels must not be" |
| 6451 | + " scanned without location access."); |
| 6452 | } |
| 6453 | } |
| 6454 | } |
| 6455 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6456 | return null; |
| 6457 | } |
| 6458 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6459 | /** |
| 6460 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6461 | * |
| 6462 | * @param subId id of the subscription |
| 6463 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6464 | */ |
| 6465 | @Override |
| 6466 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6467 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6468 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6469 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6470 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6471 | final long identity = Binder.clearCallingIdentity(); |
| 6472 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6473 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6474 | } finally { |
| 6475 | Binder.restoreCallingIdentity(identity); |
| 6476 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6480 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6481 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6482 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6483 | */ |
| 6484 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6485 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6486 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6487 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6488 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6489 | |
| 6490 | final long identity = Binder.clearCallingIdentity(); |
| 6491 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6492 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6493 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6494 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6495 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6496 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6497 | } finally { |
| 6498 | Binder.restoreCallingIdentity(identity); |
| 6499 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6500 | } |
| 6501 | |
| 6502 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6503 | * Get the allowed network types for certain reason. |
| 6504 | * |
| 6505 | * @param subId the id of the subscription. |
| 6506 | * @param reason the reason the allowed network type change is taking place |
| 6507 | * @return the allowed network types. |
| 6508 | */ |
| 6509 | @Override |
| 6510 | public long getAllowedNetworkTypesForReason(int subId, |
| 6511 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6512 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6513 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6514 | final long identity = Binder.clearCallingIdentity(); |
| 6515 | try { |
| 6516 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6517 | } finally { |
| 6518 | Binder.restoreCallingIdentity(identity); |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6523 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6524 | * @param subId subscription id of the sim card |
| 6525 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6526 | * This can be passed following states |
| 6527 | * <ol> |
| 6528 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6529 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6530 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6531 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6532 | * </ol> |
| 6533 | * @return operation result. |
| 6534 | */ |
| 6535 | @Override |
| 6536 | public int setNrDualConnectivityState(int subId, |
| 6537 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6539 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6540 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6541 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6542 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6543 | } |
| 6544 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6545 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6546 | final long identity = Binder.clearCallingIdentity(); |
| 6547 | try { |
| 6548 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6549 | nrDualConnectivityState, subId, |
| 6550 | workSource); |
| 6551 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6552 | return result; |
| 6553 | } finally { |
| 6554 | Binder.restoreCallingIdentity(identity); |
| 6555 | } |
| 6556 | } |
| 6557 | |
| 6558 | /** |
| 6559 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6560 | * @return true if dual connectivity is enabled else false |
| 6561 | */ |
| 6562 | @Override |
| 6563 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6564 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6565 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6566 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6567 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6568 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6569 | return false; |
| 6570 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6571 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6572 | final long identity = Binder.clearCallingIdentity(); |
| 6573 | try { |
| 6574 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6575 | null, subId, workSource); |
| 6576 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6577 | return isEnabled; |
| 6578 | } finally { |
| 6579 | Binder.restoreCallingIdentity(identity); |
| 6580 | } |
| 6581 | } |
| 6582 | |
| 6583 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6584 | * Set the allowed network types of the device and |
| 6585 | * provide the reason triggering the allowed network change. |
| 6586 | * |
| 6587 | * @param subId the id of the subscription. |
| 6588 | * @param reason the reason the allowed network type change is taking place |
| 6589 | * @param allowedNetworkTypes the allowed network types. |
| 6590 | * @return true on success; false on any failure. |
| 6591 | */ |
| 6592 | @Override |
| 6593 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6594 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6595 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6596 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6597 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6598 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6599 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6600 | return false; |
| 6601 | } |
| 6602 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6603 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6604 | return false; |
| 6605 | } |
| 6606 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6607 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6608 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6609 | |
| 6610 | |
| 6611 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6612 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6613 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6614 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6615 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6616 | final long identity = Binder.clearCallingIdentity(); |
| 6617 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6618 | Boolean success = (Boolean) sendRequest( |
| 6619 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6620 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6621 | |
| 6622 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6623 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6624 | } finally { |
| 6625 | Binder.restoreCallingIdentity(identity); |
| 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6630 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6631 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6632 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6633 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6634 | * @hide |
| 6635 | */ |
| 6636 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6637 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6638 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6639 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6640 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6641 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6642 | if (phone != null) { |
| 6643 | return phone.hasMatchedTetherApnSetting(); |
| 6644 | } else { |
| 6645 | return false; |
| 6646 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6647 | } finally { |
| 6648 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6649 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6653 | * Get the user enabled state of Mobile Data. |
| 6654 | * |
| 6655 | * TODO: remove and use isUserDataEnabled. |
| 6656 | * This can't be removed now because some vendor codes |
| 6657 | * calls through ITelephony directly while they should |
| 6658 | * use TelephonyManager. |
| 6659 | * |
| 6660 | * @return true on enabled |
| 6661 | */ |
| 6662 | @Override |
| 6663 | public boolean getDataEnabled(int subId) { |
| 6664 | return isUserDataEnabled(subId); |
| 6665 | } |
| 6666 | |
| 6667 | /** |
| 6668 | * Get whether mobile data is enabled per user setting. |
| 6669 | * |
| 6670 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6671 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6672 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6673 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6674 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6675 | * |
| 6676 | * @return {@code true} if data is enabled else {@code false} |
| 6677 | */ |
| 6678 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6679 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6680 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6681 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6682 | try { |
| 6683 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6684 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6685 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6686 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6687 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6688 | } catch (SecurityException e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6689 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6690 | mApp, subId, functionName); |
| 6691 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6692 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6693 | |
| 6694 | final long identity = Binder.clearCallingIdentity(); |
| 6695 | try { |
| 6696 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6697 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6698 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6699 | if (phone != null) { |
| 6700 | boolean retVal = phone.isUserDataEnabled(); |
| 6701 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6702 | return retVal; |
| 6703 | } else { |
| 6704 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6705 | return false; |
| 6706 | } |
| 6707 | } finally { |
| 6708 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6709 | } |
| 6710 | } |
| 6711 | |
| 6712 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6713 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6714 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6715 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6716 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6717 | * @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] | 6718 | */ |
| 6719 | @Override |
| 6720 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6721 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6722 | try { |
| 6723 | try { |
| 6724 | mApp.enforceCallingOrSelfPermission( |
| 6725 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6726 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6727 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6728 | try { |
| 6729 | mApp.enforceCallingOrSelfPermission( |
| 6730 | android.Manifest.permission.READ_PHONE_STATE, |
| 6731 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6732 | } catch (SecurityException e2) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6733 | mApp.enforceCallingOrSelfPermission( |
| 6734 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6735 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6736 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6737 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6738 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6739 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | |
| 6741 | final long identity = Binder.clearCallingIdentity(); |
| 6742 | try { |
| 6743 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6745 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6746 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 6747 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6748 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6749 | return retVal; |
| 6750 | } else { |
| 6751 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6752 | return false; |
| 6753 | } |
| 6754 | } finally { |
| 6755 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6756 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6757 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6758 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6759 | /** |
| 6760 | * Check if data is enabled for a specific reason |
| 6761 | * @param subId Subscription index |
| 6762 | * @param reason the reason the data enable change is taking place |
| 6763 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6764 | */ |
| 6765 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6766 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6767 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6768 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6769 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6770 | try { |
| 6771 | mApp.enforceCallingOrSelfPermission( |
| 6772 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6773 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6774 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6775 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6776 | functionName); |
| 6777 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6778 | } catch (SecurityException e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6779 | try { |
| 6780 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6781 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 6782 | } catch (SecurityException e2) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6784 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6785 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | |
| 6789 | final long identity = Binder.clearCallingIdentity(); |
| 6790 | try { |
| 6791 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6792 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6793 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6794 | + " reason=" + reason); |
| 6795 | } |
| 6796 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6797 | if (phone != null) { |
| 6798 | boolean retVal; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 6799 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6800 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6801 | return retVal; |
| 6802 | } else { |
| 6803 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6804 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6805 | + subId + " retVal=false"); |
| 6806 | } |
| 6807 | return false; |
| 6808 | } |
| 6809 | } finally { |
| 6810 | Binder.restoreCallingIdentity(identity); |
| 6811 | } |
| 6812 | } |
| 6813 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6814 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6815 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6816 | // No permission needed; this only lets the caller inspect their own status. |
| 6817 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6818 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6819 | |
| 6820 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6821 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6822 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6823 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6824 | } |
| 6825 | |
| 6826 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6827 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6828 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6829 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6830 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6831 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6832 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6833 | if (cpt == null) { |
| 6834 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6835 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6836 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6837 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6838 | } |
| 6839 | |
| 6840 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6841 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6842 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6843 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6844 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6845 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6846 | Phone phone = getPhone(subId); |
| 6847 | if (phone == null) { |
| 6848 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6849 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6850 | } |
| 6851 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6852 | if (cpt == null) { |
| 6853 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6854 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6855 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6856 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | @Override |
| 6860 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6861 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6862 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6863 | } |
| 6864 | |
| 6865 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6866 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6867 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6868 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6869 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6870 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6871 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6872 | if (phone == null) { |
| 6873 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6874 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6875 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6876 | if (cpt == null) { |
| 6877 | continue; |
| 6878 | } |
| 6879 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6880 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6881 | break; |
| 6882 | } |
| 6883 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6884 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6885 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6886 | |
| 6887 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6888 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6889 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6890 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6891 | if (phone == null) { |
| 6892 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6893 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6894 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6895 | if (cpt == null) { |
| 6896 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6897 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6898 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6901 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6902 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6903 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6904 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6905 | if (phone == null) { |
| 6906 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6907 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6908 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6909 | if (cpt == null) { |
| 6910 | return Collections.emptyList(); |
| 6911 | } |
| 6912 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6913 | } |
| 6914 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6915 | @Override |
| 6916 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6917 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6918 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6919 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6920 | try { |
| 6921 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6922 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6923 | } |
| 6924 | } finally { |
| 6925 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6926 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6927 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6928 | } |
| 6929 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6930 | @Override |
| 6931 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6932 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6933 | |
| 6934 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6935 | if (phone == null) { |
| 6936 | return null; |
| 6937 | } |
| 6938 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6939 | if (cpt == null) { |
| 6940 | return null; |
| 6941 | } |
| 6942 | return cpt.getCarrierServicePackageName(); |
| 6943 | } |
| 6944 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6945 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6946 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6947 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6948 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6949 | return null; |
| 6950 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6951 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6952 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6953 | return null; |
| 6954 | } |
| 6955 | return iccId; |
| 6956 | } |
| 6957 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6958 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6959 | public void setCallComposerStatus(int subId, int status) { |
| 6960 | enforceModifyPermission(); |
| 6961 | |
| 6962 | final long identity = Binder.clearCallingIdentity(); |
| 6963 | try { |
| 6964 | Phone phone = getPhone(subId); |
| 6965 | if (phone != null) { |
| 6966 | Phone defaultPhone = phone.getImsPhone(); |
| 6967 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6968 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6969 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6970 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6971 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6972 | } |
| 6973 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6974 | } catch (ImsException e) { |
| 6975 | throw new ServiceSpecificException(e.getCode()); |
| 6976 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6977 | Binder.restoreCallingIdentity(identity); |
| 6978 | } |
| 6979 | } |
| 6980 | |
| 6981 | @Override |
| 6982 | public int getCallComposerStatus(int subId) { |
| 6983 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6984 | |
| 6985 | final long identity = Binder.clearCallingIdentity(); |
| 6986 | try { |
| 6987 | Phone phone = getPhone(subId); |
| 6988 | if (phone != null) { |
| 6989 | Phone defaultPhone = phone.getImsPhone(); |
| 6990 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6991 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6992 | return imsPhone.getCallComposerStatus(); |
| 6993 | } |
| 6994 | } |
| 6995 | } finally { |
| 6996 | Binder.restoreCallingIdentity(identity); |
| 6997 | } |
| 6998 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6999 | } |
| 7000 | |
| 7001 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7002 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7003 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7004 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7005 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7006 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7007 | final long identity = Binder.clearCallingIdentity(); |
| 7008 | try { |
| 7009 | final String iccId = getIccId(subId); |
| 7010 | final Phone phone = getPhone(subId); |
| 7011 | if (phone == null) { |
| 7012 | return false; |
| 7013 | } |
| 7014 | final String subscriberId = phone.getSubscriberId(); |
| 7015 | |
| 7016 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7017 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | + subscriberId + " to " + number); |
| 7019 | } |
| 7020 | |
| 7021 | if (TextUtils.isEmpty(iccId)) { |
| 7022 | return false; |
| 7023 | } |
| 7024 | |
| 7025 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7026 | |
| 7027 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7028 | if (alphaTag == null) { |
| 7029 | editor.remove(alphaTagPrefKey); |
| 7030 | } else { |
| 7031 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7032 | } |
| 7033 | |
| 7034 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7035 | // track all merged IMSIs based on line number |
| 7036 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7037 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7038 | if (number == null) { |
| 7039 | editor.remove(numberPrefKey); |
| 7040 | editor.remove(subscriberPrefKey); |
| 7041 | } else { |
| 7042 | editor.putString(numberPrefKey, number); |
| 7043 | editor.putString(subscriberPrefKey, subscriberId); |
| 7044 | } |
| 7045 | |
| 7046 | editor.commit(); |
| 7047 | return true; |
| 7048 | } finally { |
| 7049 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7050 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7051 | } |
| 7052 | |
| 7053 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7054 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7055 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7056 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7057 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7058 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7059 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7060 | return null; |
| 7061 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7062 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7063 | final long identity = Binder.clearCallingIdentity(); |
| 7064 | try { |
| 7065 | String iccId = getIccId(subId); |
| 7066 | if (iccId != null) { |
| 7067 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7068 | if (DBG_MERGE) { |
| 7069 | log("getLine1NumberForDisplay returning " |
| 7070 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7071 | } |
| 7072 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7074 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7075 | return null; |
| 7076 | } finally { |
| 7077 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7078 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7079 | } |
| 7080 | |
| 7081 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7082 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7083 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7084 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7085 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7086 | return null; |
| 7087 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | String iccId = getIccId(subId); |
| 7092 | if (iccId != null) { |
| 7093 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7094 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7095 | } |
| 7096 | return null; |
| 7097 | } finally { |
| 7098 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7099 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7100 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7101 | |
| 7102 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7103 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7104 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7105 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7106 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7107 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7108 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7109 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7110 | return null; |
| 7111 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7112 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7113 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7114 | // the process, where TelephonyManager was instantiated. |
| 7115 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7116 | final long identity = Binder.clearCallingIdentity(); |
| 7117 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7118 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7120 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7121 | |
| 7122 | // Figure out what subscribers are currently active |
| 7123 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7124 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7125 | // Only consider subs which match the current subId |
| 7126 | // This logic can be simplified. See b/131189269 for progress. |
| 7127 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7128 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7129 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | |
| 7131 | // First pass, find a number override for an active subscriber |
| 7132 | String mergeNumber = null; |
| 7133 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7134 | for (String key : prefs.keySet()) { |
| 7135 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7136 | final String subscriberId = (String) prefs.get(key); |
| 7137 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7138 | final String iccId = key.substring( |
| 7139 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7140 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7141 | mergeNumber = (String) prefs.get(numberKey); |
| 7142 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7143 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7144 | + " for active subscriber " + subscriberId); |
| 7145 | } |
| 7146 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7147 | break; |
| 7148 | } |
| 7149 | } |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | // Shortcut when no active merged subscribers |
| 7154 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7155 | return null; |
| 7156 | } |
| 7157 | |
| 7158 | // Second pass, find all subscribers under that line override |
| 7159 | final ArraySet<String> result = new ArraySet<>(); |
| 7160 | for (String key : prefs.keySet()) { |
| 7161 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7162 | final String number = (String) prefs.get(key); |
| 7163 | if (mergeNumber.equals(number)) { |
| 7164 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7165 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7166 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7167 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7168 | result.add(subscriberId); |
| 7169 | } |
| 7170 | } |
| 7171 | } |
| 7172 | } |
| 7173 | |
| 7174 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7175 | Arrays.sort(resultArray); |
| 7176 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7177 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7178 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7179 | } |
| 7180 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7181 | } finally { |
| 7182 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7183 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7184 | } |
| 7185 | |
| 7186 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7187 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7188 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7189 | |
| 7190 | final long identity = Binder.clearCallingIdentity(); |
| 7191 | try { |
| 7192 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7193 | TelephonyManager.class); |
| 7194 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7195 | if (subscriberId == null) { |
| 7196 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7197 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7198 | + subId); |
| 7199 | } |
| 7200 | return null; |
| 7201 | } |
| 7202 | |
| 7203 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7204 | .getSubscriptionInfo(subId); |
| 7205 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7206 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7207 | if (groupUuid == null) { |
| 7208 | return new String[]{subscriberId}; |
| 7209 | } |
| 7210 | |
| 7211 | // Get all subscriberIds from the group. |
| 7212 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7213 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7214 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7215 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7216 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7217 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7218 | if (subscriberId != null) { |
| 7219 | mergedSubscriberIds.add(subscriberId); |
| 7220 | } |
| 7221 | } |
| 7222 | |
| 7223 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7224 | } finally { |
| 7225 | Binder.restoreCallingIdentity(identity); |
| 7226 | |
| 7227 | } |
| 7228 | } |
| 7229 | |
| 7230 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7231 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7232 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7233 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | |
| 7235 | final long identity = Binder.clearCallingIdentity(); |
| 7236 | try { |
| 7237 | final Phone phone = getPhone(subId); |
| 7238 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7239 | } finally { |
| 7240 | Binder.restoreCallingIdentity(identity); |
| 7241 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7242 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7243 | |
| 7244 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7245 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7246 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7247 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7248 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7249 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7250 | |
| 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | final Phone phone = getPhone(subId); |
| 7254 | if (phone == null) { |
| 7255 | return false; |
| 7256 | } |
| 7257 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7258 | cdmaNonRoamingList); |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7261 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7262 | } |
| 7263 | |
| 7264 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7265 | @Deprecated |
| 7266 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7267 | enforceModifyPermission(); |
| 7268 | |
| 7269 | int returnValue = 0; |
| 7270 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7271 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7272 | if(result.exception == null) { |
| 7273 | if (result.result != null) { |
| 7274 | byte[] responseData = (byte[])(result.result); |
| 7275 | if(responseData.length > oemResp.length) { |
| 7276 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7277 | responseData.length + "bytes. Buffer Size is " + |
| 7278 | oemResp.length + "bytes."); |
| 7279 | } |
| 7280 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7281 | returnValue = responseData.length; |
| 7282 | } |
| 7283 | } else { |
| 7284 | CommandException ex = (CommandException) result.exception; |
| 7285 | returnValue = ex.getCommandError().ordinal(); |
| 7286 | if(returnValue > 0) returnValue *= -1; |
| 7287 | } |
| 7288 | } catch (RuntimeException e) { |
| 7289 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7290 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7291 | if(returnValue > 0) returnValue *= -1; |
| 7292 | } |
| 7293 | |
| 7294 | return returnValue; |
| 7295 | } |
| 7296 | |
| 7297 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7298 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7299 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7300 | try { |
| 7301 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7302 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7303 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7304 | } catch (SecurityException e) { |
| 7305 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7306 | throw e; |
| 7307 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7308 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7309 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7310 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7311 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7314 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7315 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7316 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7317 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7318 | } finally { |
| 7319 | Binder.restoreCallingIdentity(identity); |
| 7320 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7321 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7322 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7323 | |
| 7324 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7325 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7326 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7327 | try { |
| 7328 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7329 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7330 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7331 | } |
| 7332 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7333 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7334 | } |
| 7335 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7336 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7337 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7338 | throw new SecurityException("App must be the dialer role holder to" |
| 7339 | + " upload a call composer pic"); |
| 7340 | } |
| 7341 | |
| 7342 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7343 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7344 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7345 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7346 | boolean readUntilEnd = false; |
| 7347 | int totalBytesRead = 0; |
| 7348 | byte[] buffer = new byte[16 * 1024]; |
| 7349 | while (true) { |
| 7350 | int numRead; |
| 7351 | try { |
| 7352 | numRead = input.read(buffer); |
| 7353 | } catch (IOException e) { |
| 7354 | try { |
| 7355 | fd.checkError(); |
| 7356 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7357 | null); |
| 7358 | } catch (IOException e1) { |
| 7359 | // This means that the other side closed explicitly with an error. If this |
| 7360 | // happens, log and ignore. |
| 7361 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7362 | } |
| 7363 | break; |
| 7364 | } |
| 7365 | if (numRead == -1) { |
| 7366 | readUntilEnd = true; |
| 7367 | break; |
| 7368 | } |
| 7369 | totalBytesRead += numRead; |
| 7370 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7371 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7372 | try { |
| 7373 | input.close(); |
| 7374 | } catch (IOException e) { |
| 7375 | // ignore |
| 7376 | } |
| 7377 | break; |
| 7378 | } |
| 7379 | output.write(buffer, 0, numRead); |
| 7380 | } |
| 7381 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7382 | // close is above, where the picture size is too big. |
| 7383 | |
| 7384 | try { |
| 7385 | fd.checkError(); |
| 7386 | } catch (IOException e) { |
| 7387 | loge("Remote end for call composer closed with an error: " + e); |
| 7388 | return; |
| 7389 | } |
| 7390 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7391 | if (!readUntilEnd) { |
| 7392 | loge("Did not finish reading entire image; aborting"); |
| 7393 | return; |
| 7394 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7395 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7396 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7397 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7398 | new CallComposerPictureTransfer.Factory() {}, |
| 7399 | imageData, |
| 7400 | (result) -> { |
| 7401 | if (result.first != null) { |
| 7402 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7403 | Bundle outputResult = new Bundle(); |
| 7404 | outputResult.putParcelable( |
| 7405 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7406 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7407 | outputResult); |
| 7408 | } else { |
| 7409 | callback.send(result.second, null); |
| 7410 | } |
| 7411 | } |
| 7412 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7413 | }); |
| 7414 | } |
| 7415 | |
| 7416 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7417 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7418 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7419 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7420 | |
| 7421 | final long identity = Binder.clearCallingIdentity(); |
| 7422 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7423 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7424 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
| 7427 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7431 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7432 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7434 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7435 | return false; |
| 7436 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7437 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | final long identity = Binder.clearCallingIdentity(); |
| 7439 | try { |
| 7440 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7441 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7442 | // In the long run, we may instead need to check if there exists a connection service |
| 7443 | // which can support video calling. |
| 7444 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7445 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | return imsManager.isVtEnabledByPlatform() |
| 7447 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7448 | && imsManager.isVtEnabledByUser(); |
| 7449 | } finally { |
| 7450 | Binder.restoreCallingIdentity(identity); |
| 7451 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7452 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7453 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7454 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7455 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7456 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7458 | mApp, subId, callingPackage, callingFeatureId, |
| 7459 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | return false; |
| 7461 | } |
| 7462 | |
| 7463 | final long identity = Binder.clearCallingIdentity(); |
| 7464 | try { |
| 7465 | CarrierConfigManager configManager = |
| 7466 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7467 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7469 | } finally { |
| 7470 | Binder.restoreCallingIdentity(identity); |
| 7471 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7475 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7477 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7478 | return false; |
| 7479 | } |
| 7480 | |
| 7481 | final long identity = Binder.clearCallingIdentity(); |
| 7482 | try { |
| 7483 | CarrierConfigManager configManager = |
| 7484 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7485 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7486 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7490 | } |
| 7491 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7492 | @Override |
| 7493 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7494 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7495 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7496 | } |
| 7497 | |
| 7498 | @Override |
| 7499 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | final long identity = Binder.clearCallingIdentity(); |
| 7501 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7502 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
| 7505 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7506 | } |
| 7507 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7508 | /** |
| 7509 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7510 | * support for the feature and device firmware support. |
| 7511 | * |
| 7512 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7513 | */ |
| 7514 | @Override |
| 7515 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7516 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7517 | final Phone phone = getPhone(subscriptionId); |
| 7518 | if (phone == null) { |
| 7519 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7520 | return false; |
| 7521 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7523 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7525 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7526 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | return isCarrierSupported && isDeviceSupported; |
| 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
| 7530 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7531 | } |
| 7532 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7533 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7534 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7535 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7536 | * 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] | 7537 | */ |
| 7538 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | final long identity = Binder.clearCallingIdentity(); |
| 7540 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7541 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7542 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7543 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7544 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7545 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7546 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
| 7549 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7550 | } |
| 7551 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7552 | @Deprecated |
| 7553 | @Override |
| 7554 | public String getDeviceId(String callingPackage) { |
| 7555 | return getDeviceIdWithFeature(callingPackage, null); |
| 7556 | } |
| 7557 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7558 | /** |
| 7559 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7560 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7561 | * |
| 7562 | * <p>Requires Permission: |
| 7563 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7564 | */ |
| 7565 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7566 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7567 | try { |
| 7568 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7569 | } catch (SecurityException se) { |
| 7570 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7571 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7572 | + Binder.getCallingUid()); |
| 7573 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7574 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7575 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7576 | return null; |
| 7577 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7578 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7579 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7580 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7581 | return null; |
| 7582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | |
| 7584 | final long identity = Binder.clearCallingIdentity(); |
| 7585 | try { |
| 7586 | return phone.getDeviceId(); |
| 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
| 7589 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7590 | } |
| 7591 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7592 | /** |
| 7593 | * {@hide} |
| 7594 | * Returns the IMS Registration Status on a particular subid |
| 7595 | * |
| 7596 | * @param subId |
| 7597 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7598 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7599 | Phone phone = getPhone(subId); |
| 7600 | if (phone != null) { |
| 7601 | return phone.isImsRegistered(); |
| 7602 | } else { |
| 7603 | return false; |
| 7604 | } |
| 7605 | } |
| 7606 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7607 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7608 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7609 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7611 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7612 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7613 | } |
| 7614 | final long identity = Binder.clearCallingIdentity(); |
| 7615 | try { |
| 7616 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7617 | } finally { |
| 7618 | Binder.restoreCallingIdentity(identity); |
| 7619 | } |
| 7620 | } |
| 7621 | |
| 7622 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7623 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7624 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7625 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7626 | mApp, |
| 7627 | subscriptionId, |
| 7628 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7629 | final long identity = Binder.clearCallingIdentity(); |
| 7630 | try { |
| 7631 | Phone phone = getPhone(subscriptionId); |
| 7632 | if (phone == null) { |
| 7633 | return null; |
| 7634 | } |
| 7635 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7636 | } finally { |
| 7637 | Binder.restoreCallingIdentity(identity); |
| 7638 | } |
| 7639 | } |
| 7640 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7641 | /** |
| 7642 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7643 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7644 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | final long identity = Binder.clearCallingIdentity(); |
| 7646 | try { |
| 7647 | Phone phone = getPhone(subId); |
| 7648 | if (phone != null) { |
| 7649 | return phone.isWifiCallingEnabled(); |
| 7650 | } else { |
| 7651 | return false; |
| 7652 | } |
| 7653 | } finally { |
| 7654 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7655 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7656 | } |
| 7657 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7658 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7659 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7660 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7661 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7662 | final long identity = Binder.clearCallingIdentity(); |
| 7663 | try { |
| 7664 | Phone phone = getPhone(subId); |
| 7665 | if (phone != null) { |
| 7666 | return phone.isVideoEnabled(); |
| 7667 | } else { |
| 7668 | return false; |
| 7669 | } |
| 7670 | } finally { |
| 7671 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7672 | } |
| 7673 | } |
| 7674 | |
| 7675 | /** |
| 7676 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7677 | * defined in {@link ImsRegistrationImplBase}. |
| 7678 | */ |
| 7679 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | Phone phone = getPhone(subId); |
| 7683 | if (phone != null) { |
| 7684 | return phone.getImsRegistrationTech(); |
| 7685 | } else { |
| 7686 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7687 | } |
| 7688 | } finally { |
| 7689 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7690 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7691 | } |
| 7692 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7693 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7694 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7695 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7696 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7697 | return; |
| 7698 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7699 | Phone defaultPhone = getDefaultPhone(); |
| 7700 | if (defaultPhone != null) { |
| 7701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7702 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7703 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7704 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7705 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7706 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7707 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7708 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7709 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7710 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7711 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7712 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7713 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7714 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7715 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7716 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7717 | // There has been issues when Sms raw table somehow stores orphan |
| 7718 | // fragments. They lead to garbled message when new fragments come |
| 7719 | // in and combined with those stale ones. In case this happens again, |
| 7720 | // user can reset all network settings which will clean up this table. |
| 7721 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7722 | // Clean up IMS settings as well here. |
| 7723 | int slotId = getSlotIndex(subId); |
| 7724 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7725 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7726 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7727 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7728 | if (defaultPhone == null) { |
| 7729 | return; |
| 7730 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7731 | // Erase modem config if erase modem on network setting is enabled. |
| 7732 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7733 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7734 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7735 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7736 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7737 | |
| 7738 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7739 | } finally { |
| 7740 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7741 | } |
| 7742 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7743 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7744 | @VisibleForTesting |
| 7745 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7746 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7747 | return; |
| 7748 | } |
| 7749 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7750 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7751 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7752 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7753 | "user=" + defaultNetworkType); |
| 7754 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7755 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7756 | defaultNetworkType, null); |
| 7757 | } |
| 7758 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7759 | private void cleanUpSmsRawTable(Context context) { |
| 7760 | ContentResolver resolver = context.getContentResolver(); |
| 7761 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7762 | resolver.delete(uri, null, null); |
| 7763 | } |
| 7764 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7765 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7766 | public String getSimLocaleForSubscriber(int subId) { |
| 7767 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7768 | final Phone phone = getPhone(subId); |
| 7769 | if (phone == null) { |
| 7770 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7771 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7772 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7773 | final long identity = Binder.clearCallingIdentity(); |
| 7774 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7775 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7776 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7777 | if (info == null) { |
| 7778 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7779 | return null; |
| 7780 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7781 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7782 | // preferences (EF-PL and EF-LI)... |
| 7783 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7785 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7786 | if (localeFromDefaultSim != null) { |
| 7787 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7788 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7789 | + localeFromDefaultSim); |
| 7790 | return localeFromDefaultSim.toLanguageTag(); |
| 7791 | } else { |
| 7792 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7793 | } |
| 7794 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7795 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7797 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7798 | // the SIM and carrier preferences does not include a country we add the country |
| 7799 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7800 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7801 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7802 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | return mccLocale.toLanguageTag(); |
| 7804 | } |
| 7805 | |
| 7806 | if (DBG) log("No locale found - returning null"); |
| 7807 | return null; |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
| 7810 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7811 | } |
| 7812 | |
| 7813 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7814 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7815 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7816 | } |
| 7817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7818 | /** |
| 7819 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7820 | */ |
| 7821 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7822 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7823 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7824 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7825 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7826 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7827 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7828 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7829 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7830 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7831 | * representing the state of the modem. |
| 7832 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7833 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7834 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7835 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7836 | */ |
| 7837 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7838 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7839 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7840 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7841 | |
| 7842 | final long identity = Binder.clearCallingIdentity(); |
| 7843 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7844 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7845 | } finally { |
| 7846 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7847 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7848 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7849 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7850 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7851 | // less than total activity duration. |
| 7852 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7853 | if (info == null) { |
| 7854 | return false; |
| 7855 | } |
| 7856 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7857 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7858 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7859 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7860 | return (info.isValid() |
| 7861 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7862 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7863 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7864 | && (totalTxTimeMs <= activityDurationMs)); |
| 7865 | } |
| 7866 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7867 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7868 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7869 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7870 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7871 | |
| 7872 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7873 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7874 | } |
| 7875 | |
| 7876 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7877 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7878 | rat, |
| 7879 | freq, |
| 7880 | info.getReceiveTimeMillis(rat, freq) |
| 7881 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7882 | } |
| 7883 | |
| 7884 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7885 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7886 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7887 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7888 | |
| 7889 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7890 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7891 | } |
| 7892 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7893 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7894 | rat, |
| 7895 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7896 | } |
| 7897 | |
| 7898 | /** |
| 7899 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7900 | * @param info recent ModemActivityInfo |
| 7901 | */ |
| 7902 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7903 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7904 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7905 | boolean matched; |
| 7906 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7907 | matched = false; |
| 7908 | int rat = info.getSpecificInfoRat(i); |
| 7909 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7910 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7911 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7912 | //if it already exists |
| 7913 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7914 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7915 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7916 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7917 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7918 | updateLastModemActivityInfo(info, rat, freq); |
| 7919 | matched = true; |
| 7920 | } |
| 7921 | } else { |
| 7922 | updateLastModemActivityInfo(info, rat); |
| 7923 | matched = true; |
| 7924 | } |
| 7925 | } |
| 7926 | } |
| 7927 | |
| 7928 | if (!matched) { |
| 7929 | mDeltaSpecificInfo = |
| 7930 | new ActivityStatsTechSpecificInfo( |
| 7931 | rat, |
| 7932 | freq, |
| 7933 | info.getTransmitTimeMillis(rat, freq), |
| 7934 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7935 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7936 | } |
| 7937 | } |
| 7938 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7939 | mLastModemActivitySpecificInfo = |
| 7940 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7941 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7942 | |
| 7943 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7944 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7945 | info.getSleepTimeMillis() |
| 7946 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7947 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7948 | info.getIdleTimeMillis() |
| 7949 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7950 | } |
| 7951 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7952 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7953 | * Returns the service state information on specified subscription. |
| 7954 | */ |
| 7955 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7956 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7957 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7958 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7959 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7960 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7961 | return null; |
| 7962 | } |
| 7963 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7964 | boolean hasFinePermission = false; |
| 7965 | boolean hasCoarsePermission = false; |
| 7966 | if (!renounceFineLocationAccess) { |
| 7967 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7968 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7969 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7970 | .setCallingPackage(callingPackage) |
| 7971 | .setCallingFeatureId(callingFeatureId) |
| 7972 | .setCallingPid(Binder.getCallingPid()) |
| 7973 | .setCallingUid(Binder.getCallingUid()) |
| 7974 | .setMethod("getServiceStateForSubscriber") |
| 7975 | .setLogAsInfo(true) |
| 7976 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7977 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7978 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7979 | .build()); |
| 7980 | hasFinePermission = |
| 7981 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7982 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7983 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7984 | if (!renounceCoarseLocationAccess) { |
| 7985 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7986 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7987 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7988 | .setCallingPackage(callingPackage) |
| 7989 | .setCallingFeatureId(callingFeatureId) |
| 7990 | .setCallingPid(Binder.getCallingPid()) |
| 7991 | .setCallingUid(Binder.getCallingUid()) |
| 7992 | .setMethod("getServiceStateForSubscriber") |
| 7993 | .setLogAsInfo(true) |
| 7994 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7995 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7996 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7997 | .build()); |
| 7998 | hasCoarsePermission = |
| 7999 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8000 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8001 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8002 | final Phone phone = getPhone(subId); |
| 8003 | if (phone == null) { |
| 8004 | return null; |
| 8005 | } |
| 8006 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8007 | final long identity = Binder.clearCallingIdentity(); |
| 8008 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8009 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8010 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8011 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8012 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8013 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8014 | Rlog.d(LOG_TAG, |
| 8015 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8016 | return null; |
| 8017 | } |
| 8018 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8019 | ServiceState ss = phone.getServiceState(); |
| 8020 | |
| 8021 | // Scrub out the location info in ServiceState depending on what level of access |
| 8022 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8023 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8024 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8025 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| 8028 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8029 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8030 | |
| 8031 | /** |
| 8032 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8033 | * |
| 8034 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8035 | * voicemail ringtone. |
| 8036 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8037 | * PhoneAccount. |
| 8038 | */ |
| 8039 | @Override |
| 8040 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8041 | final long identity = Binder.clearCallingIdentity(); |
| 8042 | try { |
| 8043 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8044 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8045 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8046 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8047 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8049 | } finally { |
| 8050 | Binder.restoreCallingIdentity(identity); |
| 8051 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8052 | } |
| 8053 | |
| 8054 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8055 | * Sets the per-account voicemail ringtone. |
| 8056 | * |
| 8057 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8058 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8059 | * |
| 8060 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8061 | * voicemail ringtone. |
| 8062 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8063 | * PhoneAccount. |
| 8064 | */ |
| 8065 | @Override |
| 8066 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8067 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8068 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8069 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8070 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8071 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8072 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8073 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8074 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8075 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8076 | |
| 8077 | final long identity = Binder.clearCallingIdentity(); |
| 8078 | try { |
| 8079 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8080 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8081 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | } |
| 8083 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8084 | } finally { |
| 8085 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8086 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8087 | } |
| 8088 | |
| 8089 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8090 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8091 | * |
| 8092 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8093 | * voicemail vibration setting. |
| 8094 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8095 | */ |
| 8096 | @Override |
| 8097 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8098 | final long identity = Binder.clearCallingIdentity(); |
| 8099 | try { |
| 8100 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8101 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8102 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8103 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8104 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8105 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8106 | } finally { |
| 8107 | Binder.restoreCallingIdentity(identity); |
| 8108 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8109 | } |
| 8110 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8111 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8112 | * Sets the per-account voicemail vibration. |
| 8113 | * |
| 8114 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8115 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8116 | * |
| 8117 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8118 | * voicemail vibration setting. |
| 8119 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8120 | * specific PhoneAccount. |
| 8121 | */ |
| 8122 | @Override |
| 8123 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8124 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8125 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8126 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8127 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8128 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8130 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8131 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8132 | } |
| 8133 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8134 | final long identity = Binder.clearCallingIdentity(); |
| 8135 | try { |
| 8136 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8137 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8138 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | } |
| 8140 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8141 | } finally { |
| 8142 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8143 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8144 | } |
| 8145 | |
| 8146 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8147 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8148 | * |
| 8149 | * @throws SecurityException if the caller does not have the required permission |
| 8150 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8151 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8152 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8153 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8154 | } |
| 8155 | |
| 8156 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8157 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8158 | * permission. |
| 8159 | * |
| 8160 | * @throws SecurityException if the caller does not have the required permission |
| 8161 | */ |
| 8162 | private void enforceSendSmsPermission() { |
| 8163 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8164 | } |
| 8165 | |
| 8166 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8167 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8168 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8169 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8170 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8171 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8172 | final long identity = Binder.clearCallingIdentity(); |
| 8173 | try { |
| 8174 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8175 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8176 | if (componentName == null) { |
| 8177 | throw new SecurityException( |
| 8178 | "Caller not current active visual voicemail package[null]"); |
| 8179 | } |
| 8180 | String vvmPackage = componentName.getPackageName(); |
| 8181 | if (!callingPackage.equals(vvmPackage)) { |
Hui Wang | 7f65755 | 2022-08-16 16:58:25 +0000 | [diff] [blame] | 8182 | throw new SecurityException("Caller not current active visual voicemail package"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8183 | } |
| 8184 | } finally { |
| 8185 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8186 | } |
| 8187 | } |
| 8188 | |
| 8189 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8190 | * Return the application ID for the app type. |
| 8191 | * |
| 8192 | * @param subId the subscription ID that this request applies to. |
| 8193 | * @param appType the uicc app type. |
| 8194 | * @return Application ID for specificied app type, or null if no uicc. |
| 8195 | */ |
| 8196 | @Override |
| 8197 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8198 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8199 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | |
| 8201 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8202 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8203 | if (phone == null) { |
| 8204 | return null; |
| 8205 | } |
| 8206 | String aid = null; |
| 8207 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8208 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | .getApplicationByType(appType).getAid(); |
| 8210 | } catch (Exception e) { |
| 8211 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8212 | } |
| 8213 | return aid; |
| 8214 | } finally { |
| 8215 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8216 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8217 | } |
| 8218 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8219 | /** |
| 8220 | * Return the Electronic Serial Number. |
| 8221 | * |
| 8222 | * @param subId the subscription ID that this request applies to. |
| 8223 | * @return ESN or null if error. |
| 8224 | */ |
| 8225 | @Override |
| 8226 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8227 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8228 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8229 | |
| 8230 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8231 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8232 | if (phone == null) { |
| 8233 | return null; |
| 8234 | } |
| 8235 | String esn = null; |
| 8236 | try { |
| 8237 | esn = phone.getEsn(); |
| 8238 | } catch (Exception e) { |
| 8239 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8240 | } |
| 8241 | return esn; |
| 8242 | } finally { |
| 8243 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8244 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8245 | } |
| 8246 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8247 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8248 | * Return the Preferred Roaming List Version. |
| 8249 | * |
| 8250 | * @param subId the subscription ID that this request applies to. |
| 8251 | * @return PRLVersion or null if error. |
| 8252 | */ |
| 8253 | @Override |
| 8254 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8255 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8256 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8257 | |
| 8258 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8259 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8260 | if (phone == null) { |
| 8261 | return null; |
| 8262 | } |
| 8263 | String cdmaPrlVersion = null; |
| 8264 | try { |
| 8265 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8266 | } catch (Exception e) { |
| 8267 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8268 | } |
| 8269 | return cdmaPrlVersion; |
| 8270 | } finally { |
| 8271 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8272 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8273 | } |
| 8274 | |
| 8275 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8276 | * Get snapshot of Telephony histograms |
| 8277 | * @return List of Telephony histograms |
| 8278 | * @hide |
| 8279 | */ |
| 8280 | @Override |
| 8281 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8282 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8283 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8284 | |
| 8285 | final long identity = Binder.clearCallingIdentity(); |
| 8286 | try { |
| 8287 | return RIL.getTelephonyRILTimingHistograms(); |
| 8288 | } finally { |
| 8289 | Binder.restoreCallingIdentity(identity); |
| 8290 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8291 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8292 | |
| 8293 | /** |
| 8294 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8295 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8296 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8297 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8298 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8299 | * @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] | 8300 | */ |
| 8301 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8302 | @TelephonyManager.SetCarrierRestrictionResult |
| 8303 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8304 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8305 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8306 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8307 | if (carrierRestrictionRules == null) { |
| 8308 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8309 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8311 | final long identity = Binder.clearCallingIdentity(); |
| 8312 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8313 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8314 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8315 | } finally { |
| 8316 | Binder.restoreCallingIdentity(identity); |
| 8317 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8318 | } |
| 8319 | |
| 8320 | /** |
| 8321 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8322 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8323 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8324 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8325 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8326 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8327 | */ |
| 8328 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8329 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8330 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8331 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8332 | |
| 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8335 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8336 | if (response instanceof CarrierRestrictionRules) { |
| 8337 | return (CarrierRestrictionRules) response; |
| 8338 | } |
| 8339 | // Response is an Exception of some kind, |
| 8340 | // which is signalled to the user as a NULL retval |
| 8341 | return null; |
| 8342 | } catch (Exception e) { |
| 8343 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8344 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8345 | } finally { |
| 8346 | Binder.restoreCallingIdentity(identity); |
| 8347 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8348 | } |
| 8349 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8350 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8351 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8352 | * @param subId the subscription ID that this action applies to. |
| 8353 | * @param enabled control enable or disable radio. |
| 8354 | * {@hide} |
| 8355 | */ |
| 8356 | @Override |
| 8357 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8358 | enforceModifyPermission(); |
| 8359 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8360 | |
| 8361 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8362 | if (phone == null) { |
| 8363 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8364 | return; |
| 8365 | } |
| 8366 | try { |
| 8367 | phone.carrierActionSetRadioEnabled(enabled); |
| 8368 | } catch (Exception e) { |
| 8369 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8370 | } finally { |
| 8371 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8372 | } |
| 8373 | } |
| 8374 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8375 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8376 | * Enable or disable Voice over NR (VoNR) |
| 8377 | * @param subId the subscription ID that this action applies to. |
| 8378 | * @param enabled enable or disable VoNR. |
| 8379 | * @return operation result. |
| 8380 | */ |
| 8381 | @Override |
| 8382 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8383 | enforceModifyPermission(); |
| 8384 | final Phone phone = getPhone(subId); |
| 8385 | |
| 8386 | final long identity = Binder.clearCallingIdentity(); |
| 8387 | if (phone == null) { |
| 8388 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8389 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8390 | } |
| 8391 | |
| 8392 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8393 | try { |
| 8394 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8395 | workSource); |
| 8396 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8397 | |
| 8398 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8399 | if (DBG) { |
| 8400 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8401 | } |
| 8402 | SubscriptionManager.setSubscriptionProperty( |
| 8403 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8404 | (enabled ? "1" : "0")); |
| 8405 | } |
| 8406 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8407 | return result; |
| 8408 | } finally { |
| 8409 | Binder.restoreCallingIdentity(identity); |
| 8410 | } |
| 8411 | } |
| 8412 | |
| 8413 | /** |
| 8414 | * Is voice over NR enabled |
| 8415 | * @return true if VoNR is enabled else false |
| 8416 | */ |
| 8417 | @Override |
| 8418 | public boolean isVoNrEnabled(int subId) { |
| 8419 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8420 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8421 | final long identity = Binder.clearCallingIdentity(); |
| 8422 | try { |
| 8423 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8424 | null, subId, workSource); |
| 8425 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8426 | return isEnabled; |
| 8427 | } finally { |
| 8428 | Binder.restoreCallingIdentity(identity); |
| 8429 | } |
| 8430 | } |
| 8431 | |
| 8432 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8433 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8434 | * network status based on which carrier apps could apply actions accordingly, |
| 8435 | * enable/disable default url handler for example. |
| 8436 | * |
| 8437 | * @param subId the subscription ID that this action applies to. |
| 8438 | * @param report control start/stop reporting the default network status. |
| 8439 | * {@hide} |
| 8440 | */ |
| 8441 | @Override |
| 8442 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8443 | enforceModifyPermission(); |
| 8444 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8445 | |
| 8446 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8447 | if (phone == null) { |
| 8448 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8449 | return; |
| 8450 | } |
| 8451 | try { |
| 8452 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8453 | } catch (Exception e) { |
| 8454 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8461 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8462 | * @param subId the subscription ID that this action applies to. |
| 8463 | * {@hide} |
| 8464 | */ |
| 8465 | @Override |
| 8466 | public void carrierActionResetAll(int subId) { |
| 8467 | enforceModifyPermission(); |
| 8468 | final Phone phone = getPhone(subId); |
| 8469 | if (phone == null) { |
| 8470 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8471 | return; |
| 8472 | } |
| 8473 | try { |
| 8474 | phone.carrierActionResetAll(); |
| 8475 | } catch (Exception e) { |
| 8476 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8481 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8482 | * bug report is being generated. |
| 8483 | */ |
| 8484 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8485 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8486 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8487 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8488 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8489 | + Binder.getCallingPid() |
| 8490 | + ", uid=" + Binder.getCallingUid() |
| 8491 | + "without permission " |
| 8492 | + android.Manifest.permission.DUMP); |
| 8493 | return; |
| 8494 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8495 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8496 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8497 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8498 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8499 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8500 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8501 | @NonNull String[] args) { |
| 8502 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8503 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8504 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8505 | } |
| 8506 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8507 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8508 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8509 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8510 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8511 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8512 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8513 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8514 | */ |
| 8515 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8516 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8517 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8518 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8519 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8520 | try { |
| 8521 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8522 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8523 | } catch (SecurityException se) { |
| 8524 | enforceModifyPermission(); |
| 8525 | } |
| 8526 | } else { |
| 8527 | enforceModifyPermission(); |
| 8528 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8529 | |
| 8530 | final long identity = Binder.clearCallingIdentity(); |
| 8531 | try { |
| 8532 | Phone phone = getPhone(subId); |
| 8533 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8534 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8535 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8536 | } else { |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 8537 | phone.getDataSettingsManager().setDataEnabled( |
| 8538 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8539 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | } |
| 8541 | } finally { |
| 8542 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8543 | } |
| 8544 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8545 | |
| 8546 | /** |
| 8547 | * Get Client request stats |
| 8548 | * @return List of Client Request Stats |
| 8549 | * @hide |
| 8550 | */ |
| 8551 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8552 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8553 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8555 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8556 | return null; |
| 8557 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8558 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8559 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8560 | final long identity = Binder.clearCallingIdentity(); |
| 8561 | try { |
| 8562 | if (phone != null) { |
| 8563 | return phone.getClientRequestStats(); |
| 8564 | } |
| 8565 | |
| 8566 | return null; |
| 8567 | } finally { |
| 8568 | Binder.restoreCallingIdentity(identity); |
| 8569 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8570 | } |
| 8571 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8572 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8573 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8574 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8575 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8576 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8577 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8578 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8579 | // commands that plumb through the RIL as root, like so: |
| 8580 | // $ adb root |
| 8581 | // $ adb shell cmd phone ... |
| 8582 | packageName = "root"; |
| 8583 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8584 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8585 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8586 | |
| 8587 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8588 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8589 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8590 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8591 | * @param state State of SIM (power down, power up, pass through) |
| 8592 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8593 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8594 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8595 | * |
| 8596 | **/ |
| 8597 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8598 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8599 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8600 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8601 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8602 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8603 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8604 | final long identity = Binder.clearCallingIdentity(); |
| 8605 | try { |
| 8606 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8607 | phone.setSimPowerState(state, null, workSource); |
| 8608 | } |
| 8609 | } finally { |
| 8610 | Binder.restoreCallingIdentity(identity); |
| 8611 | } |
| 8612 | } |
| 8613 | |
| 8614 | /** |
| 8615 | * Set SIM card power state. |
| 8616 | * |
| 8617 | * @param slotIndex SIM slot id. |
| 8618 | * @param state State of SIM (power down, power up, pass through) |
| 8619 | * @param callback callback to trigger after success or failure |
| 8620 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8621 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8622 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8623 | * |
| 8624 | **/ |
| 8625 | @Override |
| 8626 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8627 | IIntegerConsumer callback) { |
| 8628 | enforceModifyPermission(); |
| 8629 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8630 | |
| 8631 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8632 | |
| 8633 | final long identity = Binder.clearCallingIdentity(); |
| 8634 | try { |
| 8635 | if (phone != null) { |
| 8636 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8637 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8638 | } |
| 8639 | } finally { |
| 8640 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8641 | } |
| 8642 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8643 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8644 | private boolean isUssdApiAllowed(int subId) { |
| 8645 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8646 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8647 | if (configManager == null) { |
| 8648 | return false; |
| 8649 | } |
| 8650 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8651 | if (pb == null) { |
| 8652 | return false; |
| 8653 | } |
| 8654 | return pb.getBoolean( |
| 8655 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8656 | } |
| 8657 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8658 | /** |
| 8659 | * Check if phone is in emergency callback mode |
| 8660 | * @return true if phone is in emergency callback mode |
| 8661 | * @param subId sub id |
| 8662 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8663 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8664 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8665 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8666 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8667 | |
| 8668 | final long identity = Binder.clearCallingIdentity(); |
| 8669 | try { |
| 8670 | if (phone != null) { |
| 8671 | return phone.isInEcm(); |
| 8672 | } else { |
| 8673 | return false; |
| 8674 | } |
| 8675 | } finally { |
| 8676 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8677 | } |
| 8678 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8679 | |
| 8680 | /** |
| 8681 | * Get the current signal strength information for the given subscription. |
| 8682 | * Because this information is not updated when the device is in a low power state |
| 8683 | * it should not be relied-upon to be current. |
| 8684 | * @param subId Subscription index |
| 8685 | * @return the most recent cached signal strength info from the modem |
| 8686 | */ |
| 8687 | @Override |
| 8688 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8689 | final long identity = Binder.clearCallingIdentity(); |
| 8690 | try { |
| 8691 | Phone p = getPhone(subId); |
| 8692 | if (p == null) { |
| 8693 | return null; |
| 8694 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8695 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8696 | return p.getSignalStrength(); |
| 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8700 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8701 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8702 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8703 | * Get the current modem radio state for the given slot. |
| 8704 | * @param slotIndex slot index. |
| 8705 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8706 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8707 | * @return the current radio power state from the modem |
| 8708 | */ |
| 8709 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8710 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8711 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8712 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8713 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8714 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8715 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8716 | } |
| 8717 | |
| 8718 | final long identity = Binder.clearCallingIdentity(); |
| 8719 | try { |
| 8720 | return phone.getRadioPowerState(); |
| 8721 | } finally { |
| 8722 | Binder.restoreCallingIdentity(identity); |
| 8723 | } |
| 8724 | } |
| 8725 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8726 | } |
| 8727 | |
| 8728 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8729 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8730 | * |
| 8731 | * <p>Requires one of the following permissions: |
| 8732 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8733 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8734 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8735 | * privileges. |
| 8736 | * |
| 8737 | * @param subId subscription id |
| 8738 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8739 | * {@code false}. |
| 8740 | */ |
| 8741 | @Override |
| 8742 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8743 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8744 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8745 | try { |
| 8746 | mApp.enforceCallingOrSelfPermission( |
| 8747 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8748 | functionName); |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8749 | } catch (SecurityException e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8750 | mApp.enforceCallingOrSelfPermission( |
| 8751 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8752 | } |
Sooraj Sasindran | 12545cc | 2022-08-22 14:30:25 -0700 | [diff] [blame] | 8753 | } catch (SecurityException e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8754 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8755 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8756 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8757 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8758 | boolean isEnabled = false; |
| 8759 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8760 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8761 | Phone phone = getPhone(subId); |
| 8762 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8763 | } finally { |
| 8764 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8765 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8766 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8767 | } |
| 8768 | |
| 8769 | |
| 8770 | /** |
| 8771 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8772 | * |
| 8773 | * <p> Requires permission: |
| 8774 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8775 | * privileges. |
| 8776 | * |
| 8777 | * @param subId subscription id |
| 8778 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8779 | */ |
| 8780 | @Override |
| 8781 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8783 | mApp, subId, "setDataRoamingEnabled"); |
| 8784 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8785 | final long identity = Binder.clearCallingIdentity(); |
| 8786 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8787 | Phone phone = getPhone(subId); |
| 8788 | if (phone != null) { |
| 8789 | phone.setDataRoamingEnabled(isEnabled); |
| 8790 | } |
| 8791 | } finally { |
| 8792 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8793 | } |
| 8794 | } |
| 8795 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8796 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8797 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8798 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8799 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8800 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8801 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8802 | boolean isAllowed = true; |
| 8803 | final long identity = Binder.clearCallingIdentity(); |
| 8804 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8805 | Phone phone = getPhone(subId); |
| 8806 | if (phone != null) { |
| 8807 | isAllowed = phone.isCspPlmnEnabled(); |
| 8808 | } |
| 8809 | } finally { |
| 8810 | Binder.restoreCallingIdentity(identity); |
| 8811 | } |
| 8812 | return isAllowed; |
| 8813 | } |
| 8814 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8815 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8816 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8817 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8818 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8819 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8820 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8821 | if (phone == null) { |
| 8822 | return false; |
| 8823 | } |
| 8824 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8825 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8826 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8827 | } |
| 8828 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8829 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8830 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8831 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8832 | mApp.getSystemService(AppOpsManager.class) |
| 8833 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8834 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8835 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8836 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8837 | try { |
| 8838 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8839 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8840 | } catch (SecurityException e) { |
| 8841 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8842 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8843 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8844 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8845 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8846 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8847 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8848 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8849 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8850 | Binder.getCallingUid())) { |
| 8851 | isIccIdAccessRestricted = true; |
| 8852 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8853 | final long identity = Binder.clearCallingIdentity(); |
| 8854 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8855 | UiccController uiccController = UiccController.getInstance(); |
| 8856 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8857 | if (hasReadPermission) { |
| 8858 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8859 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8860 | |
| 8861 | // Remove private info if the caller doesn't have access |
| 8862 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8863 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8864 | //setting the value after compatibility check |
| 8865 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8866 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8867 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8868 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8869 | if (card == null) { |
| 8870 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8871 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8872 | continue; |
| 8873 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8874 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8875 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8876 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8877 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8878 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8879 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8880 | for (UiccPortInfo portInfo : portInfos) { |
| 8881 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8882 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8883 | if (port == null) { |
| 8884 | // assume no access if port is null |
| 8885 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8886 | continue; |
| 8887 | } |
| 8888 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8889 | uiccPortInfos.add(portInfo); |
| 8890 | } else { |
| 8891 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8892 | } |
| 8893 | } |
| 8894 | filteredInfos.add(new UiccCardInfo( |
| 8895 | cardInfo.isEuicc(), |
| 8896 | cardInfo.getCardId(), |
| 8897 | null, |
| 8898 | cardInfo.getPhysicalSlotIndex(), |
| 8899 | cardInfo.isRemovable(), |
| 8900 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8901 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8902 | } |
| 8903 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8904 | } finally { |
| 8905 | Binder.restoreCallingIdentity(identity); |
| 8906 | } |
| 8907 | } |
| 8908 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8909 | /** |
| 8910 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8911 | * generally private and require carrier privileges to view. |
| 8912 | * |
| 8913 | * @hide |
| 8914 | */ |
| 8915 | @NonNull |
| 8916 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8917 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8918 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8919 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8920 | } |
| 8921 | return new UiccCardInfo( |
| 8922 | cardInfo.isEuicc(), |
| 8923 | cardInfo.getCardId(), |
| 8924 | null, |
| 8925 | cardInfo.getPhysicalSlotIndex(), |
| 8926 | cardInfo.isRemovable(), |
| 8927 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8928 | portinfo |
| 8929 | ); |
| 8930 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8931 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8932 | /** |
| 8933 | * @hide |
| 8934 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8935 | * These values are generally private and require carrier privileges to view. |
| 8936 | */ |
| 8937 | @NonNull |
| 8938 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8939 | return new UiccPortInfo( |
| 8940 | UiccPortInfo.ICCID_REDACTED, |
| 8941 | portInfo.getPortIndex(), |
| 8942 | portInfo.getLogicalSlotIndex(), |
| 8943 | portInfo.isActive() |
| 8944 | ); |
| 8945 | } |
| 8946 | @Override |
| 8947 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8948 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8949 | mApp.getSystemService(AppOpsManager.class) |
| 8950 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8951 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8952 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8953 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8954 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8955 | // we are reading iccId which is PII data. |
| 8956 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8957 | |
| 8958 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8959 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8960 | Binder.getCallingUid())) { |
| 8961 | isLogicalSlotAccessRestricted = true; |
| 8962 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8963 | final long identity = Binder.clearCallingIdentity(); |
| 8964 | try { |
| 8965 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8966 | if (slots == null || slots.length == 0) { |
| 8967 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8968 | return null; |
| 8969 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8970 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8971 | for (int i = 0; i < slots.length; i++) { |
| 8972 | UiccSlot slot = slots[i]; |
| 8973 | if (slot == null) { |
| 8974 | continue; |
| 8975 | } |
| 8976 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8977 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8978 | UiccCard card = slot.getUiccCard(); |
| 8979 | if (card != null) { |
| 8980 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8981 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8982 | cardId = slot.getEid(); |
| 8983 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8984 | // If cardId is null, use iccId of default port as cardId. |
| 8985 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8987 | } |
| 8988 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8989 | if (cardId != null) { |
| 8990 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8991 | // if cardId is an EID, it's all digits so this is fine |
| 8992 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8993 | } |
| 8994 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8995 | int cardState = 0; |
| 8996 | switch (slot.getCardState()) { |
| 8997 | case CARDSTATE_ABSENT: |
| 8998 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8999 | break; |
| 9000 | case CARDSTATE_PRESENT: |
| 9001 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9002 | break; |
| 9003 | case CARDSTATE_ERROR: |
| 9004 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9005 | break; |
| 9006 | case CARDSTATE_RESTRICTED: |
| 9007 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9008 | break; |
| 9009 | default: |
| 9010 | break; |
| 9011 | |
| 9012 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9013 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9014 | int[] portIndexes = slot.getPortList(); |
| 9015 | for (int portIdx : portIndexes) { |
| 9016 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 9017 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9018 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9019 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9020 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9021 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9022 | slot.isEuicc(), |
| 9023 | cardId, |
| 9024 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9025 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9026 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9027 | //setting the value after compatibility check |
| 9028 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9029 | } |
| 9030 | return infos; |
| 9031 | } finally { |
| 9032 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9033 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9034 | } |
| 9035 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9036 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9037 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9038 | boolean hasReadPermission) { |
| 9039 | String iccId = slot.getIccId(portIndex); |
| 9040 | if (hasReadPermission) { // if has read permission |
| 9041 | return iccId; |
| 9042 | } else { |
| 9043 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9044 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9045 | // if no read permission, checking carrier privilege access |
| 9046 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9047 | return iccId; |
| 9048 | } |
| 9049 | } |
| 9050 | } |
| 9051 | // No read permission or carrier privilege access. |
| 9052 | return UiccPortInfo.ICCID_REDACTED; |
| 9053 | } |
| 9054 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9055 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9056 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9057 | public boolean switchSlots(int[] physicalSlots) { |
| 9058 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9059 | |
| 9060 | final long identity = Binder.clearCallingIdentity(); |
| 9061 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9062 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9063 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9064 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9065 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9066 | physicalSlots[i], i)); |
| 9067 | } |
| 9068 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
| 9071 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9072 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9073 | |
| 9074 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9075 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9076 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9077 | enforceModifyPermission(); |
| 9078 | |
| 9079 | final long identity = Binder.clearCallingIdentity(); |
| 9080 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9081 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9082 | } finally { |
| 9083 | Binder.restoreCallingIdentity(identity); |
| 9084 | } |
| 9085 | } |
| 9086 | |
| 9087 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9088 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9089 | final long identity = Binder.clearCallingIdentity(); |
| 9090 | try { |
| 9091 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9092 | } finally { |
| 9093 | Binder.restoreCallingIdentity(identity); |
| 9094 | } |
| 9095 | } |
| 9096 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9097 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9098 | * A test API to reload the UICC profile. |
| 9099 | * |
| 9100 | * <p>Requires that the calling app has permission |
| 9101 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9102 | * @hide |
| 9103 | */ |
| 9104 | @Override |
| 9105 | public void refreshUiccProfile(int subId) { |
| 9106 | enforceModifyPermission(); |
| 9107 | |
| 9108 | final long identity = Binder.clearCallingIdentity(); |
| 9109 | try { |
| 9110 | Phone phone = getPhone(subId); |
| 9111 | if (phone == null) { |
| 9112 | return; |
| 9113 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9114 | UiccPort uiccPort = phone.getUiccPort(); |
| 9115 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9116 | return; |
| 9117 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9118 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9119 | if (uiccProfile == null) { |
| 9120 | return; |
| 9121 | } |
| 9122 | uiccProfile.refresh(); |
| 9123 | } finally { |
| 9124 | Binder.restoreCallingIdentity(identity); |
| 9125 | } |
| 9126 | } |
| 9127 | |
| 9128 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9129 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9130 | */ |
| 9131 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9132 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9133 | } |
| 9134 | |
| 9135 | /** |
| 9136 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9137 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9138 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9139 | */ |
| 9140 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9141 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9142 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9143 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9144 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9145 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9146 | return isDataRoamingEnabled; |
| 9147 | } |
| 9148 | |
| 9149 | /** |
| 9150 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9151 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9152 | */ |
| 9153 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9154 | List<Integer> list = TelephonyProperties.default_network(); |
| 9155 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9156 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9157 | return list.get(phoneId); |
| 9158 | } |
| 9159 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9160 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9161 | |
| 9162 | @Override |
| 9163 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9164 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9165 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9166 | |
| 9167 | final long identity = Binder.clearCallingIdentity(); |
| 9168 | try { |
| 9169 | final Phone phone = getPhone(subId); |
| 9170 | if (phone == null) { |
| 9171 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9172 | return; |
| 9173 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9174 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9175 | if (cpt != null) { |
| 9176 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9177 | } |
| 9178 | // 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] | 9179 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9180 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9181 | if (carrierPrivilegeRules == null) { |
| 9182 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9183 | } else { |
| 9184 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9186 | } finally { |
| 9187 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9188 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9189 | } |
| 9190 | |
| 9191 | @Override |
| 9192 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9193 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9194 | |
| 9195 | final long identity = Binder.clearCallingIdentity(); |
| 9196 | try { |
| 9197 | final Phone phone = getPhone(subId); |
| 9198 | if (phone == null) { |
| 9199 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9200 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9201 | } |
| 9202 | return phone.getCarrierIdListVersion(); |
| 9203 | } finally { |
| 9204 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9205 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9206 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9207 | |
| 9208 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9209 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9210 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9211 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9212 | mApp, subId, callingPackage, callingFeatureId, |
| 9213 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9214 | return -1; |
| 9215 | } |
| 9216 | |
| 9217 | final long identity = Binder.clearCallingIdentity(); |
| 9218 | try { |
| 9219 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9220 | } finally { |
| 9221 | Binder.restoreCallingIdentity(identity); |
| 9222 | } |
| 9223 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9224 | |
| 9225 | @Override |
| 9226 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9227 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9228 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9229 | mApp, subId, "getCdmaRoamingMode"); |
| 9230 | |
| 9231 | final long identity = Binder.clearCallingIdentity(); |
| 9232 | try { |
| 9233 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9234 | } finally { |
| 9235 | Binder.restoreCallingIdentity(identity); |
| 9236 | } |
| 9237 | } |
| 9238 | |
| 9239 | @Override |
| 9240 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9242 | mApp, subId, "setCdmaRoamingMode"); |
| 9243 | |
| 9244 | final long identity = Binder.clearCallingIdentity(); |
| 9245 | try { |
| 9246 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9247 | } finally { |
| 9248 | Binder.restoreCallingIdentity(identity); |
| 9249 | } |
| 9250 | } |
| 9251 | |
| 9252 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9253 | public int getCdmaSubscriptionMode(int subId) { |
| 9254 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9255 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9256 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9257 | |
| 9258 | final long identity = Binder.clearCallingIdentity(); |
| 9259 | try { |
| 9260 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9261 | } finally { |
| 9262 | Binder.restoreCallingIdentity(identity); |
| 9263 | } |
| 9264 | } |
| 9265 | |
| 9266 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9267 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9268 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9269 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9270 | |
| 9271 | final long identity = Binder.clearCallingIdentity(); |
| 9272 | try { |
| 9273 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9274 | } finally { |
| 9275 | Binder.restoreCallingIdentity(identity); |
| 9276 | } |
| 9277 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9278 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9279 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9280 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9281 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9283 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9284 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9285 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9286 | } |
| 9287 | final long identity = Binder.clearCallingIdentity(); |
| 9288 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9289 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9290 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9291 | if (phone.getEmergencyNumberTracker() != null |
| 9292 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9293 | emergencyNumberListInternal.put( |
| 9294 | phone.getSubId(), |
| 9295 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9296 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9297 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9298 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9299 | } finally { |
| 9300 | Binder.restoreCallingIdentity(identity); |
| 9301 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9302 | } |
| 9303 | |
| 9304 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9305 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9306 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9307 | if (!exactMatch) { |
| 9308 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9309 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9310 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9311 | } |
| 9312 | final long identity = Binder.clearCallingIdentity(); |
| 9313 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9314 | for (Phone phone: PhoneFactory.getPhones()) { |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9315 | //Note: we ignore passed in param exactMatch. We can remove it once |
| 9316 | // TelephonyManager#isPotentialEmergencyNumber is removed completely |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9317 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9318 | && phone.getEmergencyNumberTracker() |
Chinmay Dhodapkar | d521bb1 | 2022-08-16 15:49:54 -0700 | [diff] [blame] | 9319 | .isEmergencyNumber(number)) { |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9320 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9321 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9322 | } |
| 9323 | return false; |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
| 9328 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9329 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9330 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9331 | */ |
| 9332 | @Override |
| 9333 | public void startEmergencyCallbackMode() { |
| 9334 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9335 | "startEmergencyCallbackMode"); |
| 9336 | enforceModifyPermission(); |
| 9337 | final long identity = Binder.clearCallingIdentity(); |
| 9338 | try { |
| 9339 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9340 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9341 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9342 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9343 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9344 | gsmCdmaPhone.obtainMessage( |
| 9345 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9346 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9347 | } |
| 9348 | } |
| 9349 | } finally { |
| 9350 | Binder.restoreCallingIdentity(identity); |
| 9351 | } |
| 9352 | } |
| 9353 | |
| 9354 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9355 | * Update emergency number list for test mode. |
| 9356 | */ |
| 9357 | @Override |
| 9358 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9359 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9360 | "updateEmergencyNumberListTestMode"); |
| 9361 | |
| 9362 | final long identity = Binder.clearCallingIdentity(); |
| 9363 | try { |
| 9364 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9365 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9366 | if (tracker != null) { |
| 9367 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9368 | } |
| 9369 | } |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
| 9375 | /** |
| 9376 | * Get the full emergency number list for test mode. |
| 9377 | */ |
| 9378 | @Override |
| 9379 | public List<String> getEmergencyNumberListTestMode() { |
| 9380 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9381 | "getEmergencyNumberListTestMode"); |
| 9382 | |
| 9383 | final long identity = Binder.clearCallingIdentity(); |
| 9384 | try { |
| 9385 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9386 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9387 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9388 | if (tracker != null) { |
| 9389 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9390 | emergencyNumbers.add(num.getNumber()); |
| 9391 | } |
| 9392 | } |
| 9393 | } |
| 9394 | return new ArrayList<>(emergencyNumbers); |
| 9395 | } finally { |
| 9396 | Binder.restoreCallingIdentity(identity); |
| 9397 | } |
| 9398 | } |
| 9399 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9400 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9401 | public int getEmergencyNumberDbVersion(int subId) { |
| 9402 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9403 | |
| 9404 | final long identity = Binder.clearCallingIdentity(); |
| 9405 | try { |
| 9406 | final Phone phone = getPhone(subId); |
| 9407 | if (phone == null) { |
| 9408 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9409 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9410 | } |
| 9411 | return phone.getEmergencyNumberDbVersion(); |
| 9412 | } finally { |
| 9413 | Binder.restoreCallingIdentity(identity); |
| 9414 | } |
| 9415 | } |
| 9416 | |
| 9417 | @Override |
| 9418 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9419 | enforceModifyPermission(); |
| 9420 | |
| 9421 | final long identity = Binder.clearCallingIdentity(); |
| 9422 | try { |
| 9423 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9424 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9425 | if (tracker != null) { |
| 9426 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9427 | } |
| 9428 | } |
| 9429 | } finally { |
| 9430 | Binder.restoreCallingIdentity(identity); |
| 9431 | } |
| 9432 | } |
| 9433 | |
| 9434 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9435 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9436 | enforceActiveEmergencySessionPermission(); |
| 9437 | |
| 9438 | final long identity = Binder.clearCallingIdentity(); |
| 9439 | try { |
| 9440 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9441 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9442 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9443 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9444 | } |
| 9445 | } |
| 9446 | } finally { |
| 9447 | Binder.restoreCallingIdentity(identity); |
| 9448 | } |
| 9449 | } |
| 9450 | |
| 9451 | @Override |
| 9452 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9453 | enforceActiveEmergencySessionPermission(); |
| 9454 | |
| 9455 | final long identity = Binder.clearCallingIdentity(); |
| 9456 | try { |
| 9457 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9458 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9459 | if (tracker != null) { |
| 9460 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9461 | } |
| 9462 | } |
| 9463 | } finally { |
| 9464 | Binder.restoreCallingIdentity(identity); |
| 9465 | } |
| 9466 | } |
| 9467 | |
| 9468 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9469 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9470 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9471 | Phone phone = getPhone(subId); |
| 9472 | if (phone == null) { |
| 9473 | return null; |
| 9474 | } |
| 9475 | final long identity = Binder.clearCallingIdentity(); |
| 9476 | try { |
| 9477 | UiccProfile profile = UiccController.getInstance() |
| 9478 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9479 | if (profile != null) { |
| 9480 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9481 | } |
| 9482 | } finally { |
| 9483 | Binder.restoreCallingIdentity(identity); |
| 9484 | } |
| 9485 | return null; |
| 9486 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9487 | |
| 9488 | /** |
| 9489 | * Enable or disable a modem stack. |
| 9490 | */ |
| 9491 | @Override |
| 9492 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9493 | enforceModifyPermission(); |
| 9494 | |
| 9495 | final long identity = Binder.clearCallingIdentity(); |
| 9496 | try { |
| 9497 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9498 | if (phone == null) { |
| 9499 | return false; |
| 9500 | } else { |
| 9501 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9502 | } |
| 9503 | } finally { |
| 9504 | Binder.restoreCallingIdentity(identity); |
| 9505 | } |
| 9506 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9507 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9508 | /** |
| 9509 | * Whether a modem stack is enabled or not. |
| 9510 | */ |
| 9511 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9512 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9513 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9514 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9515 | if (phone == null) return false; |
| 9516 | |
| 9517 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9518 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9519 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9520 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9521 | } |
| 9522 | |
| 9523 | final long identity = Binder.clearCallingIdentity(); |
| 9524 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9525 | try { |
| 9526 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9527 | } catch (NoSuchElementException ex) { |
| 9528 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9529 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9530 | } finally { |
| 9531 | Binder.restoreCallingIdentity(identity); |
| 9532 | } |
| 9533 | } |
| 9534 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9535 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9536 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9537 | enforceModifyPermission(); |
| 9538 | |
| 9539 | final long identity = Binder.clearCallingIdentity(); |
| 9540 | try { |
| 9541 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9542 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9543 | .commit(); |
| 9544 | } finally { |
| 9545 | Binder.restoreCallingIdentity(identity); |
| 9546 | } |
| 9547 | } |
| 9548 | |
| 9549 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9550 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9551 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9552 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9553 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9554 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9555 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9556 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9557 | |
| 9558 | final long identity = Binder.clearCallingIdentity(); |
| 9559 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9560 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9561 | } finally { |
| 9562 | Binder.restoreCallingIdentity(identity); |
| 9563 | } |
| 9564 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9565 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9566 | @TelephonyManager.IsMultiSimSupportedResult |
| 9567 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9568 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9569 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9570 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9571 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9572 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9573 | } |
| 9574 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9575 | // supported by the modem, indicate that it is restricted. |
| 9576 | PhoneCapability staticCapability = |
| 9577 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9578 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9579 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9580 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9581 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9582 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9583 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9584 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9585 | } |
| 9586 | // Check if support of multiple SIMs is restricted by carrier |
| 9587 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9588 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9589 | } |
| 9590 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9591 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9592 | } |
| 9593 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9594 | /** |
| 9595 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9596 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9597 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9598 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9599 | * @param numOfSims number of active sims we want to switch to |
| 9600 | */ |
| 9601 | @Override |
| 9602 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9603 | if (numOfSims == 1) { |
| 9604 | enforceModifyPermission(); |
| 9605 | } else { |
| 9606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9607 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9608 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9609 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9610 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9611 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9612 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9613 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9614 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9615 | return; |
| 9616 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9617 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9618 | } finally { |
| 9619 | Binder.restoreCallingIdentity(identity); |
| 9620 | } |
| 9621 | } |
| 9622 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9623 | @Override |
| 9624 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9625 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9626 | Phone phone = getPhone(subId); |
| 9627 | if (phone == null) { |
| 9628 | return false; |
| 9629 | } |
| 9630 | final long identity = Binder.clearCallingIdentity(); |
| 9631 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9632 | UiccPort uiccPort = phone.getUiccPort(); |
| 9633 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9634 | return false; |
| 9635 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9636 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9637 | if (uiccProfile == null) { |
| 9638 | return false; |
| 9639 | } |
| 9640 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9641 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9642 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9643 | } |
| 9644 | return false; |
| 9645 | } finally { |
| 9646 | Binder.restoreCallingIdentity(identity); |
| 9647 | } |
| 9648 | } |
| 9649 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9650 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9651 | * Get whether making changes to modem configurations will trigger reboot. |
| 9652 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9653 | */ |
| 9654 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9655 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9656 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9657 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9658 | mApp, subId, callingPackage, callingFeatureId, |
| 9659 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9660 | return false; |
| 9661 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9662 | final long identity = Binder.clearCallingIdentity(); |
| 9663 | try { |
| 9664 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9665 | } finally { |
| 9666 | Binder.restoreCallingIdentity(identity); |
| 9667 | } |
| 9668 | } |
| 9669 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9670 | private void updateModemStateMetrics() { |
| 9671 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9672 | // TODO: check the state for each modem if the api is ready. |
| 9673 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9674 | } |
| 9675 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9676 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9677 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9678 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9679 | // Verify that the callingPackage belongs to the calling UID |
| 9680 | mApp.getSystemService(AppOpsManager.class) |
| 9681 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9682 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9683 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9684 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9685 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9686 | if (slotInfos != null) { |
| 9687 | for (int i = 0; i < slotInfos.length; i++) { |
| 9688 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9689 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9690 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9691 | portInfo.getLogicalSlotIndex())); |
| 9692 | } |
| 9693 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9694 | } |
| 9695 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9696 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9701 | |
| 9702 | /** |
| 9703 | * Get the IRadio HAL Version |
| 9704 | */ |
| 9705 | @Override |
| 9706 | public int getRadioHalVersion() { |
| 9707 | Phone phone = getDefaultPhone(); |
| 9708 | if (phone == null) return -1; |
| 9709 | HalVersion hv = phone.getHalVersion(); |
| 9710 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9711 | return hv.major * 100 + hv.minor; |
| 9712 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9713 | |
| 9714 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9715 | * Get the current calling package name. |
| 9716 | * @return the current calling package name |
| 9717 | */ |
| 9718 | @Override |
| 9719 | public String getCurrentPackageName() { |
| 9720 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9721 | } |
| 9722 | |
| 9723 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9724 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9725 | * corresponding network requests on a subId. |
| 9726 | * |
| 9727 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9728 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9729 | * 2) APN is un-metered for this subscription, or |
| 9730 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9731 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9732 | * |
| 9733 | * @return whether data is allowed for a apn type. |
| 9734 | * |
| 9735 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9736 | */ |
| 9737 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9738 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9739 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9740 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9741 | |
| 9742 | // Now that all security checks passes, perform the operation as ourselves. |
| 9743 | final long identity = Binder.clearCallingIdentity(); |
| 9744 | try { |
| 9745 | Phone phone = getPhone(subId); |
| 9746 | if (phone == null) return false; |
| 9747 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9748 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9749 | boolean isDataEnabled; |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9750 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9751 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9752 | phone.getServiceState().getDataRoaming()); |
| 9753 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9754 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9755 | } finally { |
| 9756 | Binder.restoreCallingIdentity(identity); |
| 9757 | } |
| 9758 | } |
| 9759 | |
| 9760 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9761 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9762 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9763 | |
| 9764 | // Now that all security checks passes, perform the operation as ourselves. |
| 9765 | final long identity = Binder.clearCallingIdentity(); |
| 9766 | try { |
| 9767 | Phone phone = getPhone(subId); |
| 9768 | if (phone == null) return true; // By default return true. |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9769 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9770 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9771 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9772 | } finally { |
| 9773 | Binder.restoreCallingIdentity(identity); |
| 9774 | } |
| 9775 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9776 | |
| 9777 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9778 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9779 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9780 | enforceModifyPermission(); |
| 9781 | long token = Binder.clearCallingIdentity(); |
| 9782 | try { |
| 9783 | Phone phone = getPhone(subscriptionId); |
| 9784 | if (phone == null) { |
| 9785 | try { |
| 9786 | if (resultCallback != null) { |
| 9787 | resultCallback.accept(false); |
| 9788 | } |
| 9789 | } catch (RemoteException e) { |
| 9790 | // ignore |
| 9791 | } |
| 9792 | return; |
| 9793 | } |
| 9794 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9795 | Pair.create(specifiers, (x) -> { |
| 9796 | try { |
| 9797 | if (resultCallback != null) { |
| 9798 | resultCallback.accept(x); |
| 9799 | } |
| 9800 | } catch (RemoteException e) { |
| 9801 | // ignore |
| 9802 | } |
| 9803 | }); |
| 9804 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9805 | } finally { |
| 9806 | Binder.restoreCallingIdentity(token); |
| 9807 | } |
| 9808 | } |
| 9809 | |
| 9810 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9811 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9812 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9813 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9814 | mApp, subId, "getSystemSelectionChannels"); |
| 9815 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9816 | final long identity = Binder.clearCallingIdentity(); |
| 9817 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9818 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9819 | if (result instanceof IllegalStateException) { |
| 9820 | throw (IllegalStateException) result; |
| 9821 | } |
| 9822 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9823 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9824 | return specifiers; |
| 9825 | } finally { |
| 9826 | Binder.restoreCallingIdentity(identity); |
| 9827 | } |
| 9828 | } |
| 9829 | |
| 9830 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9831 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9832 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9833 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9837 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9838 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9839 | if (callingPackage == null) { |
| 9840 | callingPackage = getCurrentPackageName(); |
| 9841 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9842 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9843 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9844 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9845 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9846 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9847 | } |
| 9848 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9849 | Intent intent = new Intent(); |
| 9850 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9851 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9852 | // Bring up choose default SMS subscription dialog right now |
| 9853 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9854 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9855 | mApp.startActivity(intent); |
| 9856 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9857 | |
| 9858 | @Override |
| 9859 | public String getMmsUAProfUrl(int subId) { |
| 9860 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9861 | final long identity = Binder.clearCallingIdentity(); |
| 9862 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9863 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9864 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9865 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9866 | return carrierUAProfUrl; |
| 9867 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9868 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9869 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9870 | } finally { |
| 9871 | Binder.restoreCallingIdentity(identity); |
| 9872 | } |
| 9873 | } |
| 9874 | |
| 9875 | @Override |
| 9876 | public String getMmsUserAgent(int subId) { |
| 9877 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9878 | final long identity = Binder.clearCallingIdentity(); |
| 9879 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9880 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9881 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9882 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9883 | return carrierUserAgent; |
| 9884 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9885 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9886 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9887 | } finally { |
| 9888 | Binder.restoreCallingIdentity(identity); |
| 9889 | } |
| 9890 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9891 | |
| 9892 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9893 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9894 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9895 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9896 | final long identity = Binder.clearCallingIdentity(); |
| 9897 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9898 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9899 | if (phone == null) return false; |
| 9900 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9901 | switch (policy) { |
| 9902 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9903 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9904 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9905 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9906 | default: |
| 9907 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9908 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9909 | } finally { |
| 9910 | Binder.restoreCallingIdentity(identity); |
| 9911 | } |
| 9912 | } |
| 9913 | |
| 9914 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9915 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9916 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9917 | enforceModifyPermission(); |
| 9918 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9919 | final long identity = Binder.clearCallingIdentity(); |
| 9920 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9921 | Phone phone = getPhone(subscriptionId); |
| 9922 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9923 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9924 | switch (policy) { |
| 9925 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9926 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9927 | break; |
| 9928 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 7968c6d | 2022-07-31 00:43:21 -0700 | [diff] [blame^] | 9929 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9930 | break; |
| 9931 | default: |
| 9932 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9933 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9934 | } finally { |
| 9935 | Binder.restoreCallingIdentity(identity); |
| 9936 | } |
| 9937 | } |
| 9938 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9939 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9940 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9941 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9942 | * otherwise. |
| 9943 | */ |
| 9944 | @Override |
| 9945 | public void setCepEnabled(boolean isCepEnabled) { |
| 9946 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9947 | |
| 9948 | final long identity = Binder.clearCallingIdentity(); |
| 9949 | try { |
| 9950 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9951 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9952 | Phone defaultPhone = phone.getImsPhone(); |
| 9953 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9954 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9955 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9956 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9957 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9958 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9959 | + imsPhone.getMsisdn()); |
| 9960 | } |
| 9961 | } |
| 9962 | } finally { |
| 9963 | Binder.restoreCallingIdentity(identity); |
| 9964 | } |
| 9965 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9966 | |
| 9967 | /** |
| 9968 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9969 | * |
| 9970 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9971 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9972 | * before being read. |
| 9973 | */ |
| 9974 | @Override |
| 9975 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9976 | isCompressed) { |
| 9977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9978 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9979 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9980 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9981 | } |
| 9982 | if (!isImsAvailableOnDevice()) { |
| 9983 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9984 | "IMS not available on device."); |
| 9985 | } |
| 9986 | |
| 9987 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9988 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9989 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9990 | } finally { |
| 9991 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9992 | } |
| 9993 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9994 | |
| 9995 | @Override |
| 9996 | public boolean isIccLockEnabled(int subId) { |
| 9997 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9998 | |
| 9999 | // Now that all security checks passes, perform the operation as ourselves. |
| 10000 | final long identity = Binder.clearCallingIdentity(); |
| 10001 | try { |
| 10002 | Phone phone = getPhone(subId); |
| 10003 | if (phone != null && phone.getIccCard() != null) { |
| 10004 | return phone.getIccCard().getIccLockEnabled(); |
| 10005 | } else { |
| 10006 | return false; |
| 10007 | } |
| 10008 | } finally { |
| 10009 | Binder.restoreCallingIdentity(identity); |
| 10010 | } |
| 10011 | } |
| 10012 | |
| 10013 | /** |
| 10014 | * Set the ICC pin lock enabled or disabled. |
| 10015 | * |
| 10016 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10017 | * three cases: |
| 10018 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10019 | * successfully. |
| 10020 | * - Positive number and zero for remaining password attempts. |
| 10021 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10022 | * |
| 10023 | */ |
| 10024 | @Override |
| 10025 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10026 | enforceModifyPermission(); |
| 10027 | |
| 10028 | Phone phone = getPhone(subId); |
| 10029 | if (phone == null) { |
| 10030 | return 0; |
| 10031 | } |
| 10032 | // Now that all security checks passes, perform the operation as ourselves. |
| 10033 | final long identity = Binder.clearCallingIdentity(); |
| 10034 | try { |
| 10035 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10036 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10037 | return attemptsRemaining; |
| 10038 | |
| 10039 | } catch (Exception e) { |
| 10040 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10041 | } finally { |
| 10042 | Binder.restoreCallingIdentity(identity); |
| 10043 | } |
| 10044 | return 0; |
| 10045 | } |
| 10046 | |
| 10047 | /** |
| 10048 | * Change the ICC password used in ICC pin lock. |
| 10049 | * |
| 10050 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10051 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10052 | * - Positive number and zero for remaining password attempts. |
| 10053 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10054 | * |
| 10055 | */ |
| 10056 | @Override |
| 10057 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10058 | enforceModifyPermission(); |
| 10059 | |
| 10060 | Phone phone = getPhone(subId); |
| 10061 | if (phone == null) { |
| 10062 | return 0; |
| 10063 | } |
| 10064 | // Now that all security checks passes, perform the operation as ourselves. |
| 10065 | final long identity = Binder.clearCallingIdentity(); |
| 10066 | try { |
| 10067 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10068 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10069 | return attemptsRemaining; |
| 10070 | |
| 10071 | } catch (Exception e) { |
| 10072 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10073 | } finally { |
| 10074 | Binder.restoreCallingIdentity(identity); |
| 10075 | } |
| 10076 | return 0; |
| 10077 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10078 | |
| 10079 | /** |
| 10080 | * Request for receiving user activity notification |
| 10081 | */ |
| 10082 | @Override |
| 10083 | public void requestUserActivityNotification() { |
| 10084 | if (!mNotifyUserActivity.get() |
| 10085 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10086 | mNotifyUserActivity.set(true); |
| 10087 | } |
| 10088 | } |
| 10089 | |
| 10090 | /** |
| 10091 | * Called when userActivity is signalled in the power manager. |
| 10092 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10093 | */ |
| 10094 | @Override |
| 10095 | public void userActivity() { |
| 10096 | // *************************************** |
| 10097 | // * Inherited from PhoneWindowManager * |
| 10098 | // *************************************** |
| 10099 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10100 | // WITH ITS LOCKS HELD. |
| 10101 | // |
| 10102 | // This code must be VERY careful about the locks |
| 10103 | // it acquires. |
| 10104 | // In fact, the current code acquires way too many, |
| 10105 | // and probably has lurking deadlocks. |
| 10106 | |
| 10107 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10108 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10109 | } |
| 10110 | |
| 10111 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10112 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10113 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10114 | } |
| 10115 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10116 | |
| 10117 | @Override |
| 10118 | public boolean canConnectTo5GInDsdsMode() { |
| 10119 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10120 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10121 | |
| 10122 | @Override |
| 10123 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10124 | String callingFeatureId) { |
| 10125 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10126 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10127 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10128 | } |
| 10129 | |
| 10130 | Phone phone = getPhone(subId); |
| 10131 | if (phone == null) { |
| 10132 | throw new RuntimeException("phone is not available"); |
| 10133 | } |
| 10134 | // Now that all security checks passes, perform the operation as ourselves. |
| 10135 | final long identity = Binder.clearCallingIdentity(); |
| 10136 | try { |
| 10137 | return phone.getEquivalentHomePlmns(); |
| 10138 | } finally { |
| 10139 | Binder.restoreCallingIdentity(identity); |
| 10140 | } |
| 10141 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10142 | |
| 10143 | @Override |
| 10144 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10145 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10146 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10147 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10148 | if (radioInterfaceCapabilities == null) { |
| 10149 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10150 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10151 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10152 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10153 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10154 | @Override |
| 10155 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10156 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10157 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10158 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10159 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10160 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10161 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10162 | if (DBG) { |
| 10163 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10164 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10165 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10166 | } |
| 10167 | |
| 10168 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10169 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10170 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10171 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10172 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10173 | if (callback != null) { |
| 10174 | try { |
| 10175 | callback.onAuthenticationFailure( |
| 10176 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10177 | } catch (RemoteException exception) { |
| 10178 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10179 | } |
| 10180 | return; |
| 10181 | } |
| 10182 | } |
| 10183 | |
| 10184 | final long token = Binder.clearCallingIdentity(); |
| 10185 | try { |
| 10186 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10187 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10188 | forceBootStrapping, callback)); |
| 10189 | } finally { |
| 10190 | Binder.restoreCallingIdentity(token); |
| 10191 | } |
| 10192 | } |
| 10193 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10194 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10195 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10196 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10197 | * requested radio power state will actually be set. See {@link |
| 10198 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10199 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10200 | * @param enable {@code true} if trying to turn radio on. |
| 10201 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10202 | * false}. |
| 10203 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10204 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10205 | boolean isPhoneAvailable = false; |
| 10206 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10207 | Phone phone = PhoneFactory.getPhone(i); |
| 10208 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame] | 10209 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10210 | isPhoneAvailable = true; |
| 10211 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10212 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10213 | |
| 10214 | // return true if successfully informed the phone object about the thermal radio power |
| 10215 | // request. |
| 10216 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10217 | } |
| 10218 | |
| 10219 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10220 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10221 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10222 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10223 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10224 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10225 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10226 | } |
| 10227 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10228 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10229 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10230 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10231 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10232 | } |
| 10233 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10234 | setDataEnabledForReason( |
| 10235 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10236 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10237 | if (isDataThrottlingSupported) { |
| 10238 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10239 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10240 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10241 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10242 | } else if (thermalMitigationResult |
| 10243 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10244 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10245 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10246 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10247 | } |
| 10248 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10249 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10250 | |
| 10251 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10252 | } |
| 10253 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10254 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10255 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10256 | for (String pckg : context.getResources() |
| 10257 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10258 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10259 | } |
| 10260 | } |
| 10261 | |
| 10262 | return sThermalMitigationAllowlistedPackages; |
| 10263 | } |
| 10264 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10265 | private boolean isAnyPhoneInEmergencyState() { |
| 10266 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10267 | if (tm.isInEmergencyCall()) { |
| 10268 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10269 | return true; |
| 10270 | } |
| 10271 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10272 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10273 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10274 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10275 | + phone.isInEcm()); |
| 10276 | return true; |
| 10277 | } |
| 10278 | } |
| 10279 | |
| 10280 | return false; |
| 10281 | } |
| 10282 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10283 | /** |
| 10284 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10285 | * @param packageName name of package to be allowlisted |
| 10286 | * @param context |
| 10287 | */ |
| 10288 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10289 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10290 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10291 | } |
| 10292 | |
| 10293 | /** |
| 10294 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10295 | * @param packageName name of package to remove from allowlist |
| 10296 | * @param context |
| 10297 | */ |
| 10298 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10299 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10300 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10301 | } |
| 10302 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10303 | /** |
| 10304 | * Thermal mitigation request to control functionalities at modem. |
| 10305 | * |
| 10306 | * @param subId the id of the subscription. |
| 10307 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10308 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10309 | * |
| 10310 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10311 | */ |
| 10312 | @Override |
| 10313 | @ThermalMitigationResult |
| 10314 | public int sendThermalMitigationRequest( |
| 10315 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10316 | ThermalMitigationRequest thermalMitigationRequest, |
| 10317 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10318 | enforceModifyPermission(); |
| 10319 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10320 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10321 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10322 | .contains(callingPackage)) { |
| 10323 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10324 | + "calling package: " + callingPackage); |
| 10325 | } |
| 10326 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10327 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10328 | final long identity = Binder.clearCallingIdentity(); |
| 10329 | |
| 10330 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10331 | try { |
| 10332 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10333 | switch (thermalMitigationAction) { |
| 10334 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10335 | thermalMitigationResult = |
| 10336 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10337 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10338 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10339 | break; |
| 10340 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10341 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10342 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10343 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10344 | } |
| 10345 | |
| 10346 | // Ensure that radio is on. If not able to power on due to phone being |
| 10347 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10348 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10349 | thermalMitigationResult = |
| 10350 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10351 | break; |
| 10352 | } |
| 10353 | |
| 10354 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10355 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10356 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10357 | break; |
| 10358 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10359 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10360 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10361 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10362 | } |
| 10363 | |
| 10364 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10365 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10366 | Phone phone = getPhone(subId); |
| 10367 | if (phone == null) { |
| 10368 | thermalMitigationResult = |
| 10369 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10370 | break; |
| 10371 | } |
| 10372 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10373 | TelephonyConnectionService service = |
| 10374 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10375 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10376 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10377 | thermalMitigationResult = |
| 10378 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10379 | break; |
| 10380 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10381 | thermalMitigationResult = |
| 10382 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10383 | break; |
| 10384 | } |
| 10385 | } else { |
| 10386 | thermalMitigationResult = |
| 10387 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10388 | break; |
| 10389 | } |
| 10390 | |
| 10391 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10392 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10393 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10394 | thermalMitigationResult = |
| 10395 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10396 | break; |
| 10397 | } |
| 10398 | thermalMitigationResult = |
| 10399 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10400 | break; |
| 10401 | default: |
| 10402 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10403 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10404 | } |
| 10405 | } catch (IllegalArgumentException e) { |
| 10406 | throw e; |
| 10407 | } catch (Exception e) { |
| 10408 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10409 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10410 | } finally { |
| 10411 | Binder.restoreCallingIdentity(identity); |
| 10412 | } |
| 10413 | |
| 10414 | if (DBG) { |
| 10415 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10416 | + thermalMitigationResult); |
| 10417 | } |
| 10418 | |
| 10419 | return thermalMitigationResult; |
| 10420 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10421 | |
| 10422 | /** |
| 10423 | * Set the GbaService Package Name that Telephony will bind to. |
| 10424 | * |
| 10425 | * @param subId The sim that the GbaService is associated with. |
| 10426 | * @param packageName The name of the package to be replaced with. |
| 10427 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10428 | */ |
| 10429 | @Override |
| 10430 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10431 | enforceModifyPermission(); |
| 10432 | |
| 10433 | final long identity = Binder.clearCallingIdentity(); |
| 10434 | try { |
| 10435 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10436 | } finally { |
| 10437 | Binder.restoreCallingIdentity(identity); |
| 10438 | } |
| 10439 | } |
| 10440 | |
| 10441 | /** |
| 10442 | * Return the package name of the currently bound GbaService. |
| 10443 | * |
| 10444 | * @param subId The sim that the GbaService is associated with. |
| 10445 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10446 | */ |
| 10447 | @Override |
| 10448 | public String getBoundGbaService(int subId) { |
| 10449 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10450 | |
| 10451 | final long identity = Binder.clearCallingIdentity(); |
| 10452 | try { |
| 10453 | return getGbaManager(subId).getServicePackage(); |
| 10454 | } finally { |
| 10455 | Binder.restoreCallingIdentity(identity); |
| 10456 | } |
| 10457 | } |
| 10458 | |
| 10459 | /** |
| 10460 | * Set the release time for telephony to unbind GbaService. |
| 10461 | * |
| 10462 | * @param subId The sim that the GbaService is associated with. |
| 10463 | * @param interval The release time to unbind GbaService by millisecond. |
| 10464 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10465 | */ |
| 10466 | @Override |
| 10467 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10468 | enforceModifyPermission(); |
| 10469 | |
| 10470 | final long identity = Binder.clearCallingIdentity(); |
| 10471 | try { |
| 10472 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10473 | } finally { |
| 10474 | Binder.restoreCallingIdentity(identity); |
| 10475 | } |
| 10476 | } |
| 10477 | |
| 10478 | /** |
| 10479 | * Return the release time for telephony to unbind GbaService. |
| 10480 | * |
| 10481 | * @param subId The sim that the GbaService is associated with. |
| 10482 | * @return The release time to unbind GbaService by millisecond. |
| 10483 | */ |
| 10484 | @Override |
| 10485 | public int getGbaReleaseTime(int subId) { |
| 10486 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10487 | |
| 10488 | final long identity = Binder.clearCallingIdentity(); |
| 10489 | try { |
| 10490 | return getGbaManager(subId).getReleaseTime(); |
| 10491 | } finally { |
| 10492 | Binder.restoreCallingIdentity(identity); |
| 10493 | } |
| 10494 | } |
| 10495 | |
| 10496 | private GbaManager getGbaManager(int subId) { |
| 10497 | GbaManager instance = GbaManager.getInstance(subId); |
| 10498 | if (instance == null) { |
| 10499 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10500 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10501 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10502 | } |
| 10503 | return instance; |
| 10504 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10505 | |
| 10506 | /** |
| 10507 | * indicate whether the device and the carrier can support |
| 10508 | * RCS VoLTE single registration. |
| 10509 | */ |
| 10510 | @Override |
| 10511 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10512 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10513 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10514 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10515 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10516 | |
| 10517 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10518 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10519 | } |
| 10520 | |
| 10521 | final long identity = Binder.clearCallingIdentity(); |
| 10522 | try { |
| 10523 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10524 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10525 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10526 | if (isCapable != null) { |
| 10527 | return isCapable; |
| 10528 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10529 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10531 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10532 | } finally { |
| 10533 | Binder.restoreCallingIdentity(identity); |
| 10534 | } |
| 10535 | } |
| 10536 | |
| 10537 | /** |
| 10538 | * Register RCS provisioning callback. |
| 10539 | */ |
| 10540 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10541 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10542 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10543 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10544 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10545 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10546 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10547 | |
| 10548 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10549 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10550 | } |
| 10551 | if (!isImsAvailableOnDevice()) { |
| 10552 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10553 | "IMS not available on device."); |
| 10554 | } |
| 10555 | |
| 10556 | final long identity = Binder.clearCallingIdentity(); |
| 10557 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10558 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10559 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10560 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10561 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10562 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10563 | } finally { |
| 10564 | Binder.restoreCallingIdentity(identity); |
| 10565 | } |
| 10566 | } |
| 10567 | |
| 10568 | /** |
| 10569 | * Unregister RCS provisioning callback. |
| 10570 | */ |
| 10571 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10572 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10573 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10574 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10575 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10576 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10577 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10578 | |
| 10579 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10580 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10581 | } |
| 10582 | if (!isImsAvailableOnDevice()) { |
| 10583 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10584 | "IMS not available on device."); |
| 10585 | } |
| 10586 | |
| 10587 | final long identity = Binder.clearCallingIdentity(); |
| 10588 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10589 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10590 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10591 | } finally { |
| 10592 | Binder.restoreCallingIdentity(identity); |
| 10593 | } |
| 10594 | } |
| 10595 | |
| 10596 | /** |
| 10597 | * trigger RCS reconfiguration. |
| 10598 | */ |
| 10599 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10600 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10601 | "triggerRcsReconfiguration", |
| 10602 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10603 | |
| 10604 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10605 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10606 | } |
| 10607 | if (!isImsAvailableOnDevice()) { |
| 10608 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10609 | "IMS not available on device."); |
| 10610 | } |
| 10611 | |
| 10612 | final long identity = Binder.clearCallingIdentity(); |
| 10613 | try { |
| 10614 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10615 | } finally { |
| 10616 | Binder.restoreCallingIdentity(identity); |
| 10617 | } |
| 10618 | } |
| 10619 | |
| 10620 | /** |
| 10621 | * Provide the client configuration parameters of the RCS application. |
| 10622 | */ |
| 10623 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10624 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10625 | "setRcsClientConfiguration", |
| 10626 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10627 | |
| 10628 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10629 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10630 | } |
| 10631 | if (!isImsAvailableOnDevice()) { |
| 10632 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10633 | "IMS not available on device."); |
| 10634 | } |
| 10635 | |
| 10636 | final long identity = Binder.clearCallingIdentity(); |
| 10637 | |
| 10638 | try { |
| 10639 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10640 | if (configBinder == null) { |
| 10641 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10642 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10643 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10644 | } else { |
| 10645 | configBinder.setRcsClientConfiguration(rcc); |
| 10646 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10647 | |
| 10648 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10649 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10650 | } catch (RemoteException e) { |
| 10651 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10652 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10653 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10654 | } finally { |
| 10655 | Binder.restoreCallingIdentity(identity); |
| 10656 | } |
| 10657 | } |
| 10658 | |
| 10659 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10660 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10661 | */ |
| 10662 | @Override |
| 10663 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10664 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10665 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10666 | |
| 10667 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10668 | } |
| 10669 | |
| 10670 | /** |
| 10671 | * Gets the test mode for RCS VoLTE single registration. |
| 10672 | */ |
| 10673 | @Override |
| 10674 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10675 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10676 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10677 | |
| 10678 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10679 | } |
| 10680 | |
| 10681 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10682 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10683 | */ |
| 10684 | @Override |
| 10685 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10686 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10687 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10688 | enforceModifyPermission(); |
| 10689 | |
| 10690 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10691 | : Boolean.parseBoolean(enabledStr); |
| 10692 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10693 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10694 | } |
| 10695 | |
| 10696 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10697 | * Sends a device to device communication message. Only usable via shell. |
| 10698 | * @param message message to send. |
| 10699 | * @param value message value. |
| 10700 | */ |
| 10701 | @Override |
| 10702 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10703 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10704 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10705 | enforceModifyPermission(); |
| 10706 | |
| 10707 | final long identity = Binder.clearCallingIdentity(); |
| 10708 | try { |
| 10709 | TelephonyConnectionService service = |
| 10710 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10711 | if (service == null) { |
| 10712 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10713 | return; |
| 10714 | } |
| 10715 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10716 | } finally { |
| 10717 | Binder.restoreCallingIdentity(identity); |
| 10718 | } |
| 10719 | } |
| 10720 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10721 | /** |
| 10722 | * Sets the specified device to device transport active. |
| 10723 | * @param transport The transport to set active. |
| 10724 | */ |
| 10725 | @Override |
| 10726 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10727 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10728 | "setActiveDeviceToDeviceTransport"); |
| 10729 | enforceModifyPermission(); |
| 10730 | |
| 10731 | final long identity = Binder.clearCallingIdentity(); |
| 10732 | try { |
| 10733 | TelephonyConnectionService service = |
| 10734 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10735 | if (service == null) { |
| 10736 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10737 | return; |
| 10738 | } |
| 10739 | service.setActiveDeviceToDeviceTransport(transport); |
| 10740 | } finally { |
| 10741 | Binder.restoreCallingIdentity(identity); |
| 10742 | } |
| 10743 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10744 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10745 | @Override |
| 10746 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10747 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10748 | "setDeviceToDeviceForceEnabled"); |
| 10749 | |
| 10750 | final long identity = Binder.clearCallingIdentity(); |
| 10751 | try { |
| 10752 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10753 | p -> { |
| 10754 | Phone thePhone = p.getImsPhone(); |
| 10755 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10756 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10757 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10758 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10759 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10760 | (ImsPhoneCallTracker) tracker; |
| 10761 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10762 | } |
| 10763 | } |
| 10764 | } |
| 10765 | ); |
| 10766 | } finally { |
| 10767 | Binder.restoreCallingIdentity(identity); |
| 10768 | } |
| 10769 | } |
| 10770 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10771 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10772 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10773 | */ |
| 10774 | @Override |
| 10775 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10776 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10777 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10778 | } |
| 10779 | |
| 10780 | /** |
| 10781 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10782 | */ |
| 10783 | @Override |
| 10784 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10785 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10786 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10787 | enforceModifyPermission(); |
| 10788 | |
| 10789 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10790 | : Boolean.parseBoolean(enabledStr); |
| 10791 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10792 | subId, enabled); |
| 10793 | } |
| 10794 | |
| 10795 | /** |
| 10796 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10797 | */ |
| 10798 | @Override |
| 10799 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10800 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10801 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10802 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10803 | |
| 10804 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10805 | * Overrides the ims feature validation result |
| 10806 | */ |
| 10807 | @Override |
| 10808 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10809 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10810 | "setImsFeatureValidationOverride"); |
| 10811 | |
| 10812 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10813 | : Boolean.parseBoolean(enabledStr); |
| 10814 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10815 | subId, enabled); |
| 10816 | } |
| 10817 | |
| 10818 | /** |
| 10819 | * Gets the ims feature validation override value |
| 10820 | */ |
| 10821 | @Override |
| 10822 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10823 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10824 | "getImsFeatureValidationOverride"); |
| 10825 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10826 | } |
| 10827 | |
| 10828 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10829 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10830 | * their mobile plan. |
| 10831 | */ |
| 10832 | @Override |
| 10833 | public String getMobileProvisioningUrl() { |
| 10834 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10835 | final long identity = Binder.clearCallingIdentity(); |
| 10836 | try { |
| 10837 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10838 | } finally { |
| 10839 | Binder.restoreCallingIdentity(identity); |
| 10840 | } |
| 10841 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10842 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10843 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10844 | * Get the EAB contact from the EAB database. |
| 10845 | */ |
| 10846 | @Override |
| 10847 | public String getContactFromEab(String contact) { |
| 10848 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10849 | enforceModifyPermission(); |
| 10850 | final long identity = Binder.clearCallingIdentity(); |
| 10851 | try { |
| 10852 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10853 | } finally { |
| 10854 | Binder.restoreCallingIdentity(identity); |
| 10855 | } |
| 10856 | } |
| 10857 | |
| 10858 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10859 | * Get the EAB capability from the EAB database. |
| 10860 | */ |
| 10861 | @Override |
| 10862 | public String getCapabilityFromEab(String contact) { |
| 10863 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10864 | enforceModifyPermission(); |
| 10865 | final long identity = Binder.clearCallingIdentity(); |
| 10866 | try { |
| 10867 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10868 | } finally { |
| 10869 | Binder.restoreCallingIdentity(identity); |
| 10870 | } |
| 10871 | } |
| 10872 | |
| 10873 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10874 | * Remove the EAB contacts from the EAB database. |
| 10875 | */ |
| 10876 | @Override |
| 10877 | public int removeContactFromEab(int subId, String contacts) { |
| 10878 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10879 | enforceModifyPermission(); |
| 10880 | final long identity = Binder.clearCallingIdentity(); |
| 10881 | try { |
| 10882 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10883 | } finally { |
| 10884 | Binder.restoreCallingIdentity(identity); |
| 10885 | } |
| 10886 | } |
| 10887 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10888 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10889 | public boolean getDeviceUceEnabled() { |
| 10890 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10891 | final long identity = Binder.clearCallingIdentity(); |
| 10892 | try { |
| 10893 | return mApp.getDeviceUceEnabled(); |
| 10894 | } finally { |
| 10895 | Binder.restoreCallingIdentity(identity); |
| 10896 | } |
| 10897 | } |
| 10898 | |
| 10899 | @Override |
| 10900 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10901 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10902 | final long identity = Binder.clearCallingIdentity(); |
| 10903 | try { |
| 10904 | mApp.setDeviceUceEnabled(isEnabled); |
| 10905 | } finally { |
| 10906 | Binder.restoreCallingIdentity(identity); |
| 10907 | } |
| 10908 | } |
| 10909 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10910 | /** |
| 10911 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10912 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10913 | */ |
| 10914 | // Used for SHELL command only right now. |
| 10915 | @Override |
| 10916 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10917 | List<String> featureTags) { |
| 10918 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10919 | "addUceRegistrationOverrideShell"); |
| 10920 | final long identity = Binder.clearCallingIdentity(); |
| 10921 | try { |
| 10922 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10923 | new ArraySet<>(featureTags)); |
| 10924 | } catch (ImsException e) { |
| 10925 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10926 | } finally { |
| 10927 | Binder.restoreCallingIdentity(identity); |
| 10928 | } |
| 10929 | } |
| 10930 | |
| 10931 | /** |
| 10932 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10933 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10934 | */ |
| 10935 | // Used for SHELL command only right now. |
| 10936 | @Override |
| 10937 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10938 | List<String> featureTags) { |
| 10939 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10940 | "removeUceRegistrationOverrideShell"); |
| 10941 | final long identity = Binder.clearCallingIdentity(); |
| 10942 | try { |
| 10943 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10944 | new ArraySet<>(featureTags)); |
| 10945 | } catch (ImsException e) { |
| 10946 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10947 | } finally { |
| 10948 | Binder.restoreCallingIdentity(identity); |
| 10949 | } |
| 10950 | } |
| 10951 | |
| 10952 | /** |
| 10953 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10954 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10955 | */ |
| 10956 | // Used for SHELL command only right now. |
| 10957 | @Override |
| 10958 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10959 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10960 | "clearUceRegistrationOverrideShell"); |
| 10961 | final long identity = Binder.clearCallingIdentity(); |
| 10962 | try { |
| 10963 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10964 | } catch (ImsException e) { |
| 10965 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10966 | } finally { |
| 10967 | Binder.restoreCallingIdentity(identity); |
| 10968 | } |
| 10969 | } |
| 10970 | |
| 10971 | /** |
| 10972 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10973 | */ |
| 10974 | // Used for SHELL command only right now. |
| 10975 | @Override |
| 10976 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10977 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10978 | "getLatestRcsContactUceCapabilityShell"); |
| 10979 | final long identity = Binder.clearCallingIdentity(); |
| 10980 | try { |
| 10981 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10982 | } catch (ImsException e) { |
| 10983 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10984 | } finally { |
| 10985 | Binder.restoreCallingIdentity(identity); |
| 10986 | } |
| 10987 | } |
| 10988 | |
| 10989 | /** |
| 10990 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10991 | * device does not have an active PUBLISH. |
| 10992 | */ |
| 10993 | // Used for SHELL command only right now. |
| 10994 | @Override |
| 10995 | public String getLastUcePidfXmlShell(int subId) { |
| 10996 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10997 | final long identity = Binder.clearCallingIdentity(); |
| 10998 | try { |
| 10999 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11000 | } catch (ImsException e) { |
| 11001 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11002 | } finally { |
| 11003 | Binder.restoreCallingIdentity(identity); |
| 11004 | } |
| 11005 | } |
| 11006 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11007 | /** |
| 11008 | * Remove UCE requests cannot be sent to the network status. |
| 11009 | */ |
| 11010 | // Used for SHELL command only right now. |
| 11011 | @Override |
| 11012 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11013 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11014 | final long identity = Binder.clearCallingIdentity(); |
| 11015 | try { |
| 11016 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11017 | } catch (ImsException e) { |
| 11018 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11019 | } finally { |
| 11020 | Binder.restoreCallingIdentity(identity); |
| 11021 | } |
| 11022 | } |
| 11023 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11024 | /** |
| 11025 | * Remove UCE requests cannot be sent to the network status. |
| 11026 | */ |
| 11027 | // Used for SHELL command only. |
| 11028 | @Override |
| 11029 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11030 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11031 | final long identity = Binder.clearCallingIdentity(); |
| 11032 | try { |
| 11033 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11034 | } catch (ImsException e) { |
| 11035 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11036 | } finally { |
| 11037 | Binder.restoreCallingIdentity(identity); |
| 11038 | } |
| 11039 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11040 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11041 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11042 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11043 | String callingPackage) { |
| 11044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11045 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11046 | |
| 11047 | final int callingUid = Binder.getCallingUid(); |
| 11048 | // Verify that tha callingPackage belongs to the calling UID |
| 11049 | mApp.getSystemService(AppOpsManager.class) |
| 11050 | .checkPackage(callingUid, callingPackage); |
| 11051 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11052 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11053 | |
| 11054 | final long identity = Binder.clearCallingIdentity(); |
| 11055 | try { |
| 11056 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11057 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11058 | |
| 11059 | if (result instanceof IllegalStateException) { |
| 11060 | throw (IllegalStateException) result; |
| 11061 | } |
| 11062 | } finally { |
| 11063 | Binder.restoreCallingIdentity(identity); |
| 11064 | } |
| 11065 | } |
| 11066 | |
| 11067 | @Override |
| 11068 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11069 | String callingPackage) { |
| 11070 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11071 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11072 | |
| 11073 | final int callingUid = Binder.getCallingUid(); |
| 11074 | // Verify that tha callingPackage belongs to the calling UID |
| 11075 | mApp.getSystemService(AppOpsManager.class) |
| 11076 | .checkPackage(callingUid, callingPackage); |
| 11077 | |
| 11078 | final long identity = Binder.clearCallingIdentity(); |
| 11079 | try { |
| 11080 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11081 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11082 | |
| 11083 | if (result instanceof IllegalStateException) { |
| 11084 | throw (IllegalStateException) result; |
| 11085 | } |
| 11086 | } finally { |
| 11087 | Binder.restoreCallingIdentity(identity); |
| 11088 | } |
| 11089 | } |
| 11090 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11091 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11092 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11093 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11094 | // phone/system process do not have further restriction on request |
| 11095 | return; |
| 11096 | } |
| 11097 | |
| 11098 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11099 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11100 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11101 | context.enforceCallingOrSelfPermission( |
| 11102 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11103 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11104 | } |
| 11105 | |
| 11106 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11107 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11108 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11109 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11110 | || info.isEnabled()) { |
| 11111 | throw new IllegalArgumentException( |
| 11112 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11113 | } |
| 11114 | |
| 11115 | // Thresholds length for each RAN need in range. This has been validated in |
| 11116 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11117 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11118 | final int[] thresholds = info.getThresholds(); |
| 11119 | Objects.requireNonNull(thresholds); |
| 11120 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11121 | || thresholds.length |
| 11122 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11123 | throw new IllegalArgumentException( |
| 11124 | "thresholds length is out of range: " + thresholds.length); |
| 11125 | } |
| 11126 | } |
| 11127 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11128 | |
| 11129 | /** |
| 11130 | * Gets the current phone capability. |
| 11131 | * |
| 11132 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11133 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11134 | * It's used to evaluate possible phone config change, for example from single |
| 11135 | * SIM device to multi-SIM device. |
| 11136 | */ |
| 11137 | @Override |
| 11138 | public PhoneCapability getPhoneCapability() { |
| 11139 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11140 | final long identity = Binder.clearCallingIdentity(); |
| 11141 | try { |
| 11142 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11143 | } finally { |
| 11144 | Binder.restoreCallingIdentity(identity); |
| 11145 | } |
| 11146 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11147 | |
| 11148 | /** |
| 11149 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11150 | * required to be done shortly after the API is invoked. |
| 11151 | */ |
| 11152 | @Override |
| 11153 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11154 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11155 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11156 | enforceRebootPermission(); |
| 11157 | |
| 11158 | final long identity = Binder.clearCallingIdentity(); |
| 11159 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11160 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11161 | } finally { |
| 11162 | Binder.restoreCallingIdentity(identity); |
| 11163 | } |
| 11164 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11165 | |
| 11166 | /** |
| 11167 | * Request to get the current slicing configuration including URSP rules and |
| 11168 | * NSSAIs (configured, allowed and rejected). |
| 11169 | * |
| 11170 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11171 | */ |
| 11172 | @Override |
| 11173 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11174 | TelephonyPermissions |
| 11175 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11176 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11177 | |
| 11178 | final long identity = Binder.clearCallingIdentity(); |
| 11179 | try { |
| 11180 | Phone phone = getDefaultPhone(); |
| 11181 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11182 | } finally { |
| 11183 | Binder.restoreCallingIdentity(identity); |
| 11184 | } |
| 11185 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11186 | |
| 11187 | /** |
| 11188 | * Register an IMS connection state callback |
| 11189 | */ |
| 11190 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11191 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11192 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11193 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11194 | // ImsMmTelManager |
| 11195 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11196 | TelephonyPermissions |
| 11197 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11198 | mApp, subId, "registerImsStateCallback"); |
| 11199 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11200 | // ImsRcsManager or SipDelegateManager |
| 11201 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11202 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11203 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11204 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11205 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11206 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11207 | } |
| 11208 | |
| 11209 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11210 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11211 | "IMS not available on device."); |
| 11212 | } |
| 11213 | |
| 11214 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11215 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11216 | } |
| 11217 | |
| 11218 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11219 | if (controller == null) { |
| 11220 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11221 | "IMS not available on device."); |
| 11222 | } |
| 11223 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11224 | if (callingPackage == null) { |
| 11225 | callingPackage = getCurrentPackageName(); |
| 11226 | } |
| 11227 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11228 | final long token = Binder.clearCallingIdentity(); |
| 11229 | try { |
| 11230 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11231 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11232 | } catch (ImsException e) { |
| 11233 | throw new ServiceSpecificException(e.getCode()); |
| 11234 | } finally { |
| 11235 | Binder.restoreCallingIdentity(token); |
| 11236 | } |
| 11237 | } |
| 11238 | |
| 11239 | /** |
| 11240 | * Unregister an IMS connection state callback |
| 11241 | */ |
| 11242 | @Override |
| 11243 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11244 | final long token = Binder.clearCallingIdentity(); |
| 11245 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11246 | if (controller == null) { |
| 11247 | return; |
| 11248 | } |
| 11249 | try { |
| 11250 | controller.unregisterImsStateCallback(cb); |
| 11251 | } finally { |
| 11252 | Binder.restoreCallingIdentity(token); |
| 11253 | } |
| 11254 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11255 | |
| 11256 | /** |
| 11257 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11258 | * |
| 11259 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11260 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11261 | * SecurityException. |
| 11262 | * If there is current registered network this value will be same as the registered cell |
| 11263 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11264 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11265 | * it will be cleared and null will be returned. |
| 11266 | * |
| 11267 | */ |
| 11268 | @Override |
| 11269 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11270 | String callingFeatureId) { |
| 11271 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11272 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11273 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11274 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11275 | .setCallingPackage(callingPackage) |
| 11276 | .setCallingFeatureId(callingFeatureId) |
| 11277 | .setCallingPid(Binder.getCallingPid()) |
| 11278 | .setCallingUid(Binder.getCallingUid()) |
| 11279 | .setMethod("getLastKnownCellIdentity") |
| 11280 | .setLogAsInfo(true) |
| 11281 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11282 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11283 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11284 | .build()); |
| 11285 | |
| 11286 | boolean hasFinePermission = |
| 11287 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11288 | if (!hasFinePermission |
| 11289 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11290 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11291 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11292 | } |
| 11293 | |
| 11294 | final long identity = Binder.clearCallingIdentity(); |
| 11295 | try { |
| 11296 | Phone phone = getPhone(subId); |
| 11297 | if (phone == null) return null; |
| 11298 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11299 | if (sst == null) return null; |
| 11300 | return sst.getLastKnownCellIdentity(); |
| 11301 | } finally { |
| 11302 | Binder.restoreCallingIdentity(identity); |
| 11303 | } |
| 11304 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11305 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11306 | /** |
| 11307 | * Sets the modem service class Name that Telephony will bind to. |
| 11308 | * |
| 11309 | * @param serviceName The class name of the modem service. |
| 11310 | * @return true if the operation is succeed, otherwise false. |
| 11311 | */ |
| 11312 | public boolean setModemService(String serviceName) { |
| 11313 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11314 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11315 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11316 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11317 | "setModemService"); |
| 11318 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11319 | } |
| 11320 | |
| 11321 | /** |
| 11322 | * Return the class name of the currently bounded modem service. |
| 11323 | * |
| 11324 | * @return the class name of the modem service. |
| 11325 | */ |
| 11326 | public String getModemService() { |
| 11327 | String result; |
| 11328 | Log.d(LOG_TAG, "getModemService"); |
| 11329 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11330 | TelephonyPermissions |
| 11331 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11332 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11333 | "getModemService"); |
| 11334 | result = mPhoneConfigurationManager.getModemService(); |
| 11335 | Log.d(LOG_TAG, "result = " + result); |
| 11336 | return result; |
| 11337 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11338 | |
| 11339 | @Override |
| 11340 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11341 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11342 | mApp.enforceCallingOrSelfPermission( |
| 11343 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11344 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11345 | |
| 11346 | final long identity = Binder.clearCallingIdentity(); |
| 11347 | try { |
| 11348 | Phone phone = getPhone(subId); |
| 11349 | if (phone == null) return; |
| 11350 | phone.setVoiceServiceStateOverride(hasService); |
| 11351 | } finally { |
| 11352 | Binder.restoreCallingIdentity(identity); |
| 11353 | } |
| 11354 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11355 | |
| 11356 | /** |
| 11357 | * set removable eSIM as default eUICC. |
| 11358 | * |
| 11359 | * @hide |
| 11360 | */ |
| 11361 | @Override |
| 11362 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11363 | enforceModifyPermission(); |
| 11364 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11365 | |
| 11366 | final long identity = Binder.clearCallingIdentity(); |
| 11367 | try { |
| 11368 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11369 | } finally { |
| 11370 | Binder.restoreCallingIdentity(identity); |
| 11371 | } |
| 11372 | } |
| 11373 | |
| 11374 | /** |
| 11375 | * Returns whether the removable eSIM is default eUICC or not. |
| 11376 | * |
| 11377 | * @hide |
| 11378 | */ |
| 11379 | @Override |
| 11380 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11381 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11382 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11383 | |
| 11384 | final long identity = Binder.clearCallingIdentity(); |
| 11385 | try { |
| 11386 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11387 | } finally { |
| 11388 | Binder.restoreCallingIdentity(identity); |
| 11389 | } |
| 11390 | } |
| 11391 | |
| 11392 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11393 | } |