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 | f86fb84 | 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 | f86fb84 | 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 | f86fb84 | 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 |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3356 | public void setCellInfoListRate(int rateInMillis) { |
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 { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3362 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(identity); |
| 3365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3366 | } |
| 3367 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3368 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3369 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3370 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3371 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3372 | return null; |
| 3373 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3374 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3375 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3376 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3377 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3378 | return null; |
| 3379 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | |
| 3381 | final long identity = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | return phone.getImei(); |
| 3384 | } finally { |
| 3385 | Binder.restoreCallingIdentity(identity); |
| 3386 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3387 | } |
| 3388 | |
| 3389 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3390 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3391 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3392 | String tac = null; |
| 3393 | if (phone != null) { |
| 3394 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3395 | try { |
| 3396 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3397 | } catch (IndexOutOfBoundsException e) { |
| 3398 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3399 | return null; |
| 3400 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3401 | } |
| 3402 | return tac; |
| 3403 | } |
| 3404 | |
| 3405 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3406 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3407 | try { |
| 3408 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3409 | } catch (SecurityException se) { |
| 3410 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3411 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3412 | + Binder.getCallingUid()); |
| 3413 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3414 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3415 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3416 | return null; |
| 3417 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3419 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3420 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3421 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3422 | return null; |
| 3423 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3424 | |
| 3425 | final long identity = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | return phone.getMeid(); |
| 3428 | } finally { |
| 3429 | Binder.restoreCallingIdentity(identity); |
| 3430 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3434 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3435 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3436 | String manufacturerCode = null; |
| 3437 | if (phone != null) { |
| 3438 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3439 | try { |
| 3440 | manufacturerCode = |
| 3441 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3442 | } catch (IndexOutOfBoundsException e) { |
| 3443 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3444 | return null; |
| 3445 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3446 | } |
| 3447 | return manufacturerCode; |
| 3448 | } |
| 3449 | |
| 3450 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3451 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3452 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3453 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3454 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3455 | return null; |
| 3456 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3457 | int subId = phone.getSubId(); |
| 3458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3459 | mApp, subId, callingPackage, callingFeatureId, |
| 3460 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3461 | return null; |
| 3462 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3463 | |
| 3464 | final long identity = Binder.clearCallingIdentity(); |
| 3465 | try { |
| 3466 | return phone.getDeviceSvn(); |
| 3467 | } finally { |
| 3468 | Binder.restoreCallingIdentity(identity); |
| 3469 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3470 | } |
| 3471 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3472 | @Override |
| 3473 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3474 | final long identity = Binder.clearCallingIdentity(); |
| 3475 | try { |
| 3476 | final Phone phone = getPhone(subId); |
| 3477 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | @Override |
| 3484 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3485 | final long identity = Binder.clearCallingIdentity(); |
| 3486 | try { |
| 3487 | final Phone phone = getPhone(subId); |
| 3488 | return phone == null ? null : phone.getCarrierName(); |
| 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(identity); |
| 3491 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3494 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3495 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3496 | final long identity = Binder.clearCallingIdentity(); |
| 3497 | try { |
| 3498 | final Phone phone = getPhone(subId); |
| 3499 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3500 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(identity); |
| 3503 | } |
| 3504 | } |
| 3505 | |
| 3506 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3507 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3508 | final long identity = Binder.clearCallingIdentity(); |
| 3509 | try { |
| 3510 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3511 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(identity); |
| 3514 | } |
| 3515 | } |
| 3516 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3517 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3518 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3519 | if (!isSubscriptionMccMnc) { |
| 3520 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3521 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3522 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3523 | if (phone == null) { |
| 3524 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3525 | } |
| 3526 | final long identity = Binder.clearCallingIdentity(); |
| 3527 | try { |
| 3528 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3529 | } finally { |
| 3530 | Binder.restoreCallingIdentity(identity); |
| 3531 | } |
| 3532 | } |
| 3533 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3534 | // |
| 3535 | // Internal helper methods. |
| 3536 | // |
| 3537 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3538 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3539 | * Make sure the caller is the calling package itself |
| 3540 | * |
| 3541 | * @throws SecurityException if the caller is not the calling package |
| 3542 | */ |
| 3543 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3544 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3545 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3546 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3547 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3548 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3549 | } catch (PackageManager.NameNotFoundException e) { |
| 3550 | // packageUid is -1 |
| 3551 | } |
| 3552 | if (packageUid != callingUid) { |
| 3553 | throw new SecurityException(message + ": Package " + callingPackage |
| 3554 | + " does not belong to " + callingUid); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3559 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3560 | * |
| 3561 | * @throws SecurityException if the caller does not have the required permission |
| 3562 | */ |
| 3563 | private void enforceModifyPermission() { |
| 3564 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3565 | } |
| 3566 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3567 | private void enforceActiveEmergencySessionPermission() { |
| 3568 | mApp.enforceCallingOrSelfPermission( |
| 3569 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3570 | } |
| 3571 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3572 | /** |
| 3573 | * Make sure the caller has the CALL_PHONE permission. |
| 3574 | * |
| 3575 | * @throws SecurityException if the caller does not have the required permission |
| 3576 | */ |
| 3577 | private void enforceCallPermission() { |
| 3578 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3579 | } |
| 3580 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3581 | private void enforceSettingsPermission() { |
| 3582 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3585 | private void enforceRebootPermission() { |
| 3586 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3587 | } |
| 3588 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3589 | private String createTelUrl(String number) { |
| 3590 | if (TextUtils.isEmpty(number)) { |
| 3591 | return null; |
| 3592 | } |
| 3593 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3594 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3597 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3598 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3599 | } |
| 3600 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3601 | private static void logv(String msg) { |
| 3602 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3603 | } |
| 3604 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3605 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3606 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3607 | } |
| 3608 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3609 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3610 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3611 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3614 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3615 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3619 | if (phone == null) { |
| 3620 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3621 | } else { |
| 3622 | return phone.getPhoneType(); |
| 3623 | } |
| 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3626 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | /** |
| 3630 | * Returns the CDMA ERI icon index to display |
| 3631 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3633 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3634 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3635 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3638 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3639 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3640 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3641 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3642 | mApp, subId, callingPackage, callingFeatureId, |
| 3643 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3644 | return -1; |
| 3645 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3646 | |
| 3647 | final long identity = Binder.clearCallingIdentity(); |
| 3648 | try { |
| 3649 | final Phone phone = getPhone(subId); |
| 3650 | if (phone != null) { |
| 3651 | return phone.getCdmaEriIconIndex(); |
| 3652 | } else { |
| 3653 | return -1; |
| 3654 | } |
| 3655 | } finally { |
| 3656 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3657 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /** |
| 3661 | * Returns the CDMA ERI icon mode, |
| 3662 | * 0 - ON |
| 3663 | * 1 - FLASHING |
| 3664 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3665 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3666 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3667 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3668 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3671 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3672 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3673 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3674 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3675 | mApp, subId, callingPackage, callingFeatureId, |
| 3676 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3677 | return -1; |
| 3678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3679 | |
| 3680 | final long identity = Binder.clearCallingIdentity(); |
| 3681 | try { |
| 3682 | final Phone phone = getPhone(subId); |
| 3683 | if (phone != null) { |
| 3684 | return phone.getCdmaEriIconMode(); |
| 3685 | } else { |
| 3686 | return -1; |
| 3687 | } |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | /** |
| 3694 | * Returns the CDMA ERI text, |
| 3695 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3697 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3698 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3699 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3703 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3704 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3706 | mApp, subId, callingPackage, callingFeatureId, |
| 3707 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3708 | return null; |
| 3709 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | |
| 3711 | final long identity = Binder.clearCallingIdentity(); |
| 3712 | try { |
| 3713 | final Phone phone = getPhone(subId); |
| 3714 | if (phone != null) { |
| 3715 | return phone.getCdmaEriText(); |
| 3716 | } else { |
| 3717 | return null; |
| 3718 | } |
| 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3725 | * Returns the CDMA MDN. |
| 3726 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3727 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3728 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3730 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3731 | |
| 3732 | final long identity = Binder.clearCallingIdentity(); |
| 3733 | try { |
| 3734 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3735 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3736 | return phone.getLine1Number(); |
| 3737 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3738 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3739 | return null; |
| 3740 | } |
| 3741 | } finally { |
| 3742 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | /** |
| 3747 | * Returns the CDMA MIN. |
| 3748 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3749 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3750 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3752 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3753 | |
| 3754 | final long identity = Binder.clearCallingIdentity(); |
| 3755 | try { |
| 3756 | final Phone phone = getPhone(subId); |
| 3757 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3758 | return phone.getCdmaMin(); |
| 3759 | } else { |
| 3760 | return null; |
| 3761 | } |
| 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3764 | } |
| 3765 | } |
| 3766 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3767 | @Override |
| 3768 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3769 | INumberVerificationCallback callback, String callingPackage) { |
| 3770 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3771 | != PERMISSION_GRANTED) { |
| 3772 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3773 | } |
| 3774 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3775 | |
| 3776 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3777 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3778 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3779 | + "calling package: " + callingPackage |
| 3780 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | if (range == null) { |
| 3784 | throw new NullPointerException("Range must be non-null"); |
| 3785 | } |
| 3786 | |
| 3787 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3788 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3789 | |
| 3790 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3791 | } |
| 3792 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3793 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3794 | * Returns true if CDMA provisioning needs to run. |
| 3795 | */ |
| 3796 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | final long identity = Binder.clearCallingIdentity(); |
| 3798 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3799 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3800 | } finally { |
| 3801 | Binder.restoreCallingIdentity(identity); |
| 3802 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3806 | * Sets the voice mail number of a given subId. |
| 3807 | */ |
| 3808 | @Override |
| 3809 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3810 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3811 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | |
| 3813 | final long identity = Binder.clearCallingIdentity(); |
| 3814 | try { |
| 3815 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3816 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3817 | return success; |
| 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
| 3820 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3821 | } |
| 3822 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3823 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3824 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3825 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3826 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3827 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3828 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3829 | throw new SecurityException("caller must be system dialer"); |
| 3830 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3831 | |
| 3832 | final long identity = Binder.clearCallingIdentity(); |
| 3833 | try { |
| 3834 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3835 | if (phoneAccountHandle == null) { |
| 3836 | return null; |
| 3837 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3838 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3839 | } finally { |
| 3840 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3841 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3845 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3846 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3847 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3848 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3849 | mApp, subId, callingPackage, callingFeatureId, |
| 3850 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3851 | return null; |
| 3852 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3856 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
| 3859 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3863 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3864 | VisualVoicemailSmsFilterSettings settings) { |
| 3865 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3866 | |
| 3867 | final long identity = Binder.clearCallingIdentity(); |
| 3868 | try { |
| 3869 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3870 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(identity); |
| 3873 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3877 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3878 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3879 | |
| 3880 | final long identity = Binder.clearCallingIdentity(); |
| 3881 | try { |
| 3882 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3883 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3884 | } finally { |
| 3885 | Binder.restoreCallingIdentity(identity); |
| 3886 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3890 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3891 | String callingPackage, int subId) { |
| 3892 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3893 | |
| 3894 | final long identity = Binder.clearCallingIdentity(); |
| 3895 | try { |
| 3896 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3897 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3898 | } finally { |
| 3899 | Binder.restoreCallingIdentity(identity); |
| 3900 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3904 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3905 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3906 | |
| 3907 | final long identity = Binder.clearCallingIdentity(); |
| 3908 | try { |
| 3909 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3910 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | } finally { |
| 3912 | Binder.restoreCallingIdentity(identity); |
| 3913 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3917 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3918 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3919 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3920 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3921 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3922 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3923 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3924 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3925 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3926 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3927 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3928 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3929 | * Sets the voice activation state of a given subId. |
| 3930 | */ |
| 3931 | @Override |
| 3932 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3933 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3934 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3935 | |
| 3936 | final long identity = Binder.clearCallingIdentity(); |
| 3937 | try { |
| 3938 | final Phone phone = getPhone(subId); |
| 3939 | if (phone != null) { |
| 3940 | phone.setVoiceActivationState(activationState); |
| 3941 | } else { |
| 3942 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3943 | } |
| 3944 | } finally { |
| 3945 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3946 | } |
| 3947 | } |
| 3948 | |
| 3949 | /** |
| 3950 | * Sets the data activation state of a given subId. |
| 3951 | */ |
| 3952 | @Override |
| 3953 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3954 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3955 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3956 | |
| 3957 | final long identity = Binder.clearCallingIdentity(); |
| 3958 | try { |
| 3959 | final Phone phone = getPhone(subId); |
| 3960 | if (phone != null) { |
| 3961 | phone.setDataActivationState(activationState); |
| 3962 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3963 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3964 | } |
| 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | /** |
| 3971 | * Returns the voice activation state of a given subId. |
| 3972 | */ |
| 3973 | @Override |
| 3974 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3975 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3976 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3977 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3978 | final long identity = Binder.clearCallingIdentity(); |
| 3979 | try { |
| 3980 | if (phone != null) { |
| 3981 | return phone.getVoiceActivationState(); |
| 3982 | } else { |
| 3983 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3984 | } |
| 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | /** |
| 3991 | * Returns the data activation state of a given subId. |
| 3992 | */ |
| 3993 | @Override |
| 3994 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3996 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3997 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3998 | final long identity = Binder.clearCallingIdentity(); |
| 3999 | try { |
| 4000 | if (phone != null) { |
| 4001 | return phone.getDataActivationState(); |
| 4002 | } else { |
| 4003 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 4004 | } |
| 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4011 | * Returns the unread count of voicemails for a subId |
| 4012 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4013 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4014 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 4015 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4017 | mApp, subId, callingPackage, callingFeatureId, |
| 4018 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 4019 | return 0; |
| 4020 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4021 | final long identity = Binder.clearCallingIdentity(); |
| 4022 | try { |
| 4023 | final Phone phone = getPhone(subId); |
| 4024 | if (phone != null) { |
| 4025 | return phone.getVoiceMessageCount(); |
| 4026 | } else { |
| 4027 | return 0; |
| 4028 | } |
| 4029 | } finally { |
| 4030 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4031 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4035 | * returns true, if the device is in a state where both voice and data |
| 4036 | * are supported simultaneously. This can change based on location or network condition. |
| 4037 | */ |
| 4038 | @Override |
| 4039 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
| 4042 | final Phone phone = getPhone(subId); |
| 4043 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 4044 | } finally { |
| 4045 | Binder.restoreCallingIdentity(identity); |
| 4046 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4050 | * Send the dialer code if called from the current default dialer or the caller has |
| 4051 | * carrier privilege. |
| 4052 | * @param inputCode The dialer code to send |
| 4053 | */ |
| 4054 | @Override |
| 4055 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4056 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4057 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 4058 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 4059 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4060 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 4061 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4062 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4063 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4064 | |
| 4065 | final long identity = Binder.clearCallingIdentity(); |
| 4066 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4067 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | } finally { |
| 4069 | Binder.restoreCallingIdentity(identity); |
| 4070 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 4071 | } |
| 4072 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4073 | @Override |
| 4074 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4075 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4076 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 4077 | mApp, subId, "getNetworkSelectionMode"); |
| 4078 | final long identity = Binder.clearCallingIdentity(); |
| 4079 | try { |
| 4080 | if (!isActiveSubscription(subId)) { |
| 4081 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4082 | } |
| 4083 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4084 | } finally { |
| 4085 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4086 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4087 | } |
| 4088 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4090 | public boolean isInEmergencySmsMode() { |
| 4091 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4092 | final long identity = Binder.clearCallingIdentity(); |
| 4093 | try { |
| 4094 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4095 | if (phone.isInEmergencySmsMode()) { |
| 4096 | return true; |
| 4097 | } |
| 4098 | } |
| 4099 | } finally { |
| 4100 | Binder.restoreCallingIdentity(identity); |
| 4101 | } |
| 4102 | return false; |
| 4103 | } |
| 4104 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4105 | /** |
| 4106 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4107 | * @param subId The subscription to use to check the configuration. |
| 4108 | * @param c The callback that will be used to send the result. |
| 4109 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4110 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4111 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4112 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4113 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4114 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4115 | |
| 4116 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4118 | "IMS not available on device."); |
| 4119 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4120 | final long token = Binder.clearCallingIdentity(); |
| 4121 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4122 | int slotId = getSlotIndexOrException(subId); |
| 4123 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4124 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4125 | } catch (ImsException e) { |
| 4126 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(token); |
| 4129 | } |
| 4130 | } |
| 4131 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4132 | /** |
| 4133 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4134 | * @param subId The subscription to use to check the configuration. |
| 4135 | * @param c The callback that will be used to send the result. |
| 4136 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4137 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4138 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4139 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4140 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4141 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4142 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4143 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4144 | final long token = Binder.clearCallingIdentity(); |
| 4145 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4146 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4147 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4148 | } catch (ImsException e) { |
| 4149 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4150 | + "is inactive, ignoring unregister."); |
| 4151 | // If the subscription is no longer active, just return, since the callback |
| 4152 | // will already have been removed internally. |
| 4153 | } finally { |
| 4154 | Binder.restoreCallingIdentity(token); |
| 4155 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4158 | /** |
| 4159 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4160 | */ |
| 4161 | @Override |
| 4162 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4163 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4164 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4165 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4166 | "IMS not available on device."); |
| 4167 | } |
| 4168 | final long token = Binder.clearCallingIdentity(); |
| 4169 | try { |
| 4170 | Phone phone = getPhone(subId); |
| 4171 | if (phone == null) { |
| 4172 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4173 | + subId + "'"); |
| 4174 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4175 | } |
| 4176 | phone.getImsRegistrationState(regState -> { |
| 4177 | try { |
| 4178 | consumer.accept((regState == null) |
| 4179 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4180 | } catch (RemoteException e) { |
| 4181 | // Ignore if the remote process is no longer available to call back. |
| 4182 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4183 | } |
| 4184 | }); |
| 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(token); |
| 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * Get the transport type for the IMS service registration state. |
| 4192 | */ |
| 4193 | @Override |
| 4194 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4195 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4196 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4197 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4198 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4199 | "IMS not available on device."); |
| 4200 | } |
| 4201 | final long token = Binder.clearCallingIdentity(); |
| 4202 | try { |
| 4203 | Phone phone = getPhone(subId); |
| 4204 | if (phone == null) { |
| 4205 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4206 | + subId + "'"); |
| 4207 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4208 | } |
| 4209 | phone.getImsRegistrationTech(regTech -> { |
| 4210 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4211 | int regTechConverted = (regTech == null) |
| 4212 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4213 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4214 | regTechConverted); |
| 4215 | try { |
| 4216 | consumer.accept(regTechConverted); |
| 4217 | } catch (RemoteException e) { |
| 4218 | // Ignore if the remote process is no longer available to call back. |
| 4219 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4220 | } |
| 4221 | }); |
| 4222 | } finally { |
| 4223 | Binder.restoreCallingIdentity(token); |
| 4224 | } |
| 4225 | } |
| 4226 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4227 | /** |
| 4228 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4229 | * @param subId The subscription to use to check the configuration. |
| 4230 | * @param c The callback that will be used to send the result. |
| 4231 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4232 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4233 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4234 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4235 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4236 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4237 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4238 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4239 | "IMS not available on device."); |
| 4240 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4241 | final long token = Binder.clearCallingIdentity(); |
| 4242 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4243 | int slotId = getSlotIndexOrException(subId); |
| 4244 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4245 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4246 | } catch (ImsException e) { |
| 4247 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4248 | } finally { |
| 4249 | Binder.restoreCallingIdentity(token); |
| 4250 | } |
| 4251 | } |
| 4252 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4253 | /** |
| 4254 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4255 | * @param subId The subscription to use to check the configuration. |
| 4256 | * @param c The callback that will be used to send the result. |
| 4257 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4258 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4259 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4260 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4261 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4262 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4263 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4264 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4265 | |
| 4266 | final long token = Binder.clearCallingIdentity(); |
| 4267 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4268 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4269 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4270 | } catch (ImsException e) { |
| 4271 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4272 | + "is inactive, ignoring unregister."); |
| 4273 | // If the subscription is no longer active, just return, since the callback |
| 4274 | // will already have been removed internally. |
| 4275 | } finally { |
| 4276 | Binder.restoreCallingIdentity(token); |
| 4277 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4281 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4282 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | final long token = Binder.clearCallingIdentity(); |
| 4284 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4285 | int slotId = getSlotIndexOrException(subId); |
| 4286 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4287 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4288 | } catch (com.android.ims.ImsException e) { |
| 4289 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4290 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4291 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4292 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4293 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | } finally { |
| 4295 | Binder.restoreCallingIdentity(token); |
| 4296 | } |
| 4297 | } |
| 4298 | |
| 4299 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4300 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4301 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4302 | final long token = Binder.clearCallingIdentity(); |
| 4303 | try { |
| 4304 | Phone phone = getPhone(subId); |
| 4305 | if (phone == null) return false; |
| 4306 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4307 | } catch (com.android.ims.ImsException e) { |
| 4308 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4309 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(token); |
| 4312 | } |
| 4313 | } |
| 4314 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4315 | /** |
| 4316 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4317 | * subscription. |
| 4318 | * @param subId The subscription to use to check the configuration. |
| 4319 | * @param callback The callback that will be used to send the result. |
| 4320 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4321 | * @param transportType The transport type of the MmTelFeature capability. |
| 4322 | */ |
| 4323 | @Override |
| 4324 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4325 | int transportType) { |
| 4326 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4327 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4328 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4329 | "IMS not available on device."); |
| 4330 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4331 | final long token = Binder.clearCallingIdentity(); |
| 4332 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4333 | int slotId = getSlotIndex(subId); |
| 4334 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4335 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4336 | + subId + "'"); |
| 4337 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4338 | } |
| 4339 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4340 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4341 | transportType, aBoolean -> { |
| 4342 | try { |
| 4343 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4344 | } catch (RemoteException e) { |
| 4345 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4346 | + "running. Ignore"); |
| 4347 | } |
| 4348 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4349 | } catch (ImsException e) { |
| 4350 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4351 | } finally { |
| 4352 | Binder.restoreCallingIdentity(token); |
| 4353 | } |
| 4354 | } |
| 4355 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4356 | /** |
| 4357 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4358 | * @param subId The subscription to use to check the configuration. |
| 4359 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4360 | @Override |
| 4361 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4362 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4363 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4364 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | final long token = Binder.clearCallingIdentity(); |
| 4366 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4367 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4368 | // 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] | 4369 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4370 | } catch (ImsException e) { |
| 4371 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4372 | } finally { |
| 4373 | Binder.restoreCallingIdentity(token); |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4378 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4380 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4381 | final long identity = Binder.clearCallingIdentity(); |
| 4382 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4383 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4384 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4385 | // 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] | 4386 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4387 | } catch (ImsException e) { |
| 4388 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4389 | } finally { |
| 4390 | Binder.restoreCallingIdentity(identity); |
| 4391 | } |
| 4392 | } |
| 4393 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4394 | /** |
| 4395 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4396 | * @param subId The subscription to use to check the configuration. |
| 4397 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4398 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4399 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4400 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4401 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4402 | final long identity = Binder.clearCallingIdentity(); |
| 4403 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4404 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4405 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4406 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4407 | } catch (ImsException e) { |
| 4408 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4409 | } finally { |
| 4410 | Binder.restoreCallingIdentity(identity); |
| 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4415 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4417 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4418 | final long identity = Binder.clearCallingIdentity(); |
| 4419 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4420 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4421 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4422 | // 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] | 4423 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4424 | } catch (ImsException e) { |
| 4425 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(identity); |
| 4428 | } |
| 4429 | } |
| 4430 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4431 | /** |
| 4432 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4433 | * @param subId The subscription to use to check the configuration. |
| 4434 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4435 | @Override |
| 4436 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4437 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4438 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4439 | final long identity = Binder.clearCallingIdentity(); |
| 4440 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4441 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4442 | // 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] | 4443 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4444 | } catch (ImsException e) { |
| 4445 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4446 | } finally { |
| 4447 | Binder.restoreCallingIdentity(identity); |
| 4448 | } |
| 4449 | } |
| 4450 | |
| 4451 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4452 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4454 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4457 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4458 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4459 | // 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] | 4460 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4461 | } catch (ImsException e) { |
| 4462 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4463 | } finally { |
| 4464 | Binder.restoreCallingIdentity(identity); |
| 4465 | } |
| 4466 | } |
| 4467 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4468 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4469 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4470 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4471 | * @param subId The subscription to use to check the configuration. |
| 4472 | */ |
| 4473 | @Override |
| 4474 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4475 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4476 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 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. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4481 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4482 | } catch (ImsException e) { |
| 4483 | throw new ServiceSpecificException(e.getCode()); |
| 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
| 4486 | } |
| 4487 | } |
| 4488 | |
| 4489 | /** |
| 4490 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4491 | * Requires MODIFY_PHONE_STATE permission. |
| 4492 | * @param subId The subscription to use to check the configuration. |
| 4493 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4494 | * false otherwise |
| 4495 | */ |
| 4496 | @Override |
| 4497 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4498 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4499 | "setCrossSimCallingEnabled"); |
| 4500 | final long identity = Binder.clearCallingIdentity(); |
| 4501 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4502 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4503 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4504 | // 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] | 4505 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4506 | } catch (ImsException e) { |
| 4507 | throw new ServiceSpecificException(e.getCode()); |
| 4508 | } finally { |
| 4509 | Binder.restoreCallingIdentity(identity); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4514 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4515 | * @param subId The subscription to use to check the configuration. |
| 4516 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4518 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4519 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4520 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4521 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4522 | final long identity = Binder.clearCallingIdentity(); |
| 4523 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4524 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4525 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4526 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4527 | } catch (ImsException e) { |
| 4528 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4529 | } finally { |
| 4530 | Binder.restoreCallingIdentity(identity); |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4535 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4536 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4537 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4538 | final long identity = Binder.clearCallingIdentity(); |
| 4539 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4540 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4541 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4542 | // new setting will be picked up when the ImsService comes up next if it isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4543 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4544 | } catch (ImsException e) { |
| 4545 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4546 | } finally { |
| 4547 | Binder.restoreCallingIdentity(identity); |
| 4548 | } |
| 4549 | } |
| 4550 | |
| 4551 | @Override |
| 4552 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4554 | "setVoWiFiNonPersistent"); |
| 4555 | final long identity = Binder.clearCallingIdentity(); |
| 4556 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4557 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4558 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4559 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4560 | } catch (ImsException e) { |
| 4561 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4562 | } finally { |
| 4563 | Binder.restoreCallingIdentity(identity); |
| 4564 | } |
| 4565 | } |
| 4566 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4567 | /** |
| 4568 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4569 | * @param subId The subscription to use to check the configuration. |
| 4570 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4571 | @Override |
| 4572 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4573 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4574 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4577 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4578 | // 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] | 4579 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4580 | } catch (ImsException e) { |
| 4581 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
| 4585 | } |
| 4586 | |
| 4587 | @Override |
| 4588 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4590 | "setVoWiFiModeSetting"); |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4593 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4594 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4595 | // 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] | 4596 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4597 | } catch (ImsException e) { |
| 4598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
| 4602 | } |
| 4603 | |
| 4604 | @Override |
| 4605 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4606 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4607 | final long identity = Binder.clearCallingIdentity(); |
| 4608 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4609 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4610 | // 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] | 4611 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4612 | } catch (ImsException e) { |
| 4613 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
| 4620 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4621 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4622 | "setVoWiFiRoamingModeSetting"); |
| 4623 | final long identity = Binder.clearCallingIdentity(); |
| 4624 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4625 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4626 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4627 | // 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] | 4628 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4629 | } catch (ImsException e) { |
| 4630 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4631 | } finally { |
| 4632 | Binder.restoreCallingIdentity(identity); |
| 4633 | } |
| 4634 | } |
| 4635 | |
| 4636 | @Override |
| 4637 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4639 | "setRttCapabilityEnabled"); |
| 4640 | final long identity = Binder.clearCallingIdentity(); |
| 4641 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4642 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4643 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4644 | // 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] | 4645 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4646 | } catch (ImsException e) { |
| 4647 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
| 4650 | } |
| 4651 | } |
| 4652 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4653 | /** |
| 4654 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4655 | * @param subId The subscription to use to check the configuration. |
| 4656 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4657 | @Override |
| 4658 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4659 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4660 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4661 | final long identity = Binder.clearCallingIdentity(); |
| 4662 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4663 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4664 | // 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] | 4665 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4666 | } catch (ImsException e) { |
| 4667 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4668 | } finally { |
| 4669 | Binder.restoreCallingIdentity(identity); |
| 4670 | } |
| 4671 | } |
| 4672 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4673 | @Override |
| 4674 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4675 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4676 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4679 | if (!isImsAvailableOnDevice()) { |
| 4680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4681 | "IMS not available on device."); |
| 4682 | } |
| 4683 | int slotId = getSlotIndexOrException(subId); |
| 4684 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4685 | ImsManager.getInstance(mApp, slotId) |
| 4686 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4687 | } catch (ImsException e) { |
| 4688 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4689 | } finally { |
| 4690 | Binder.restoreCallingIdentity(identity); |
| 4691 | } |
| 4692 | } |
| 4693 | |
| 4694 | @Override |
| 4695 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4696 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4697 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4698 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4699 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4700 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4701 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4702 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4703 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4704 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4705 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4706 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4707 | + "is inactive, ignoring unregister."); |
| 4708 | // If the subscription is no longer active, just return, since the callback will already |
| 4709 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
| 4713 | } |
| 4714 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4715 | @Override |
| 4716 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4717 | IFeatureProvisioningCallback callback) { |
| 4718 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4719 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4720 | |
| 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4723 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4724 | } |
| 4725 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4726 | try { |
| 4727 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4728 | if (controller == null) { |
| 4729 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4730 | "Device does not support IMS"); |
| 4731 | } |
| 4732 | controller.addFeatureProvisioningChangedCallback(subId, callback); |
| 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | @Override |
| 4739 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4740 | IFeatureProvisioningCallback callback) { |
| 4741 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4742 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4743 | |
| 4744 | final long identity = Binder.clearCallingIdentity(); |
| 4745 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4746 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4747 | } |
| 4748 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4749 | try { |
| 4750 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4751 | if (controller == null) { |
| 4752 | loge("unregisterFeatureProvisioningChangedCallback: Device does not support IMS"); |
| 4753 | return; |
| 4754 | } |
| 4755 | controller.removeFeatureProvisioningChangedCallback(subId, callback); |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
| 4758 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4759 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4760 | |
| 4761 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4763 | message); |
| 4764 | } |
| 4765 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4766 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4767 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4768 | boolean isProvisioned) { |
| 4769 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4770 | |
| 4771 | final long identity = Binder.clearCallingIdentity(); |
| 4772 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4773 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4774 | if (controller == null) { |
| 4775 | loge("setRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4776 | return; |
| 4777 | } |
| 4778 | controller.setRcsProvisioningStatusForCapability( |
| 4779 | subId, capability, tech, isProvisioned); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4780 | } finally { |
| 4781 | Binder.restoreCallingIdentity(identity); |
| 4782 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4787 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4788 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4789 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4790 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4791 | final long identity = Binder.clearCallingIdentity(); |
| 4792 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4793 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4794 | if (controller == null) { |
| 4795 | loge("getRcsProvisioningStatusForCapability: Device does not support IMS"); |
| 4796 | |
| 4797 | // device does not support IMS, this method will return true always. |
| 4798 | return true; |
| 4799 | } |
| 4800 | return controller.getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4801 | } finally { |
| 4802 | Binder.restoreCallingIdentity(identity); |
| 4803 | } |
| 4804 | } |
| 4805 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4806 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4807 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4808 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4809 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4810 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4811 | final long identity = Binder.clearCallingIdentity(); |
| 4812 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4813 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4814 | if (controller == null) { |
| 4815 | loge("setImsProvisioningStatusForCapability: Device does not support IMS"); |
| 4816 | return; |
| 4817 | } |
| 4818 | controller.setImsProvisioningStatusForCapability( |
| 4819 | subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4820 | } finally { |
| 4821 | Binder.restoreCallingIdentity(identity); |
| 4822 | } |
| 4823 | } |
| 4824 | |
| 4825 | @Override |
| 4826 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4827 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4828 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4829 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4830 | final long identity = Binder.clearCallingIdentity(); |
| 4831 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4832 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4833 | if (controller == null) { |
| 4834 | loge("getImsProvisioningStatusForCapability: Device does not support IMS"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4835 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4836 | // device does not support IMS, this method will return true always. |
| 4837 | return true; |
| 4838 | } |
| 4839 | return controller.getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4840 | } finally { |
| 4841 | Binder.restoreCallingIdentity(identity); |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4846 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4847 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4848 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4849 | |
| 4850 | final long identity = Binder.clearCallingIdentity(); |
| 4851 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4852 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4853 | if (controller == null) { |
| 4854 | loge("isProvisioningRequiredForCapability: Device does not support IMS"); |
| 4855 | |
| 4856 | // device does not support IMS, this method will return false |
| 4857 | return false; |
| 4858 | } |
| 4859 | return controller.isImsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4860 | } finally { |
| 4861 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4862 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4866 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4867 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4868 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4869 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4870 | final long identity = Binder.clearCallingIdentity(); |
| 4871 | try { |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4872 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4873 | if (controller == null) { |
| 4874 | loge("isRcsProvisioningRequiredForCapability: Device does not support IMS"); |
| 4875 | |
| 4876 | // device does not support IMS, this method will return false |
| 4877 | return false; |
| 4878 | } |
| 4879 | return controller.isRcsProvisioningRequiredForCapability(subId, capability, tech); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4880 | } finally { |
| 4881 | Binder.restoreCallingIdentity(identity); |
| 4882 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4883 | } |
| 4884 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4885 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4886 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4887 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4888 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4889 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4890 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4891 | mApp, subId, "getImsProvisioningInt"); |
| 4892 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4896 | int slotId = getSlotIndex(subId); |
| 4897 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4898 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4899 | + subId + "' for key:" + key); |
| 4900 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4901 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4902 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4903 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4904 | if (controller == null) { |
| 4905 | loge("getImsProvisioningInt: Device does not support IMS"); |
| 4906 | |
| 4907 | // device does not support IMS, this method will return CONFIG_RESULT_UNKNOWN. |
| 4908 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4909 | } |
| 4910 | int retVal = controller.getProvisioningValue(subId, key); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4911 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4912 | return retVal; |
| 4913 | } |
| 4914 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4915 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4916 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4917 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4918 | + subId + "' for key:" + key); |
| 4919 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | @Override |
| 4926 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4927 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4928 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4929 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4930 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4931 | mApp, subId, "getImsProvisioningString"); |
| 4932 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
| 4935 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4936 | int slotId = getSlotIndex(subId); |
| 4937 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4938 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4939 | + subId + "' for key:" + key); |
| 4940 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4941 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4942 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4943 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4944 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4945 | + subId + "' for key:" + key); |
| 4946 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4947 | } finally { |
| 4948 | Binder.restoreCallingIdentity(identity); |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | @Override |
| 4953 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4954 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4955 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4956 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4958 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4959 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4960 | final long identity = Binder.clearCallingIdentity(); |
| 4961 | try { |
| 4962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4963 | int slotId = getSlotIndex(subId); |
| 4964 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4965 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4966 | + subId + "' for key:" + key); |
| 4967 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4968 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4969 | |
joonhunshin | 91bc195 | 2022-04-29 08:47:15 +0000 | [diff] [blame] | 4970 | ImsProvisioningController controller = ImsProvisioningController.getInstance(); |
| 4971 | if (controller == null) { |
| 4972 | loge("setImsProvisioningInt: Device does not support IMS"); |
| 4973 | |
| 4974 | // device does not support IMS, this method will return CONFIG_RESULT_FAILED. |
| 4975 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4976 | } |
| 4977 | int retVal = controller.setProvisioningValue(subId, key, value); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4978 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4979 | return retVal; |
| 4980 | } |
| 4981 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4982 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4983 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4984 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4985 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4986 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | @Override |
| 4993 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4994 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4995 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4996 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4998 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4999 | final long identity = Binder.clearCallingIdentity(); |
| 5000 | try { |
| 5001 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5002 | int slotId = getSlotIndex(subId); |
| 5003 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5004 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 5005 | + subId + "' for key:" + key); |
| 5006 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 5007 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5008 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 5009 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5010 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 5011 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5012 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 5013 | } finally { |
| 5014 | Binder.restoreCallingIdentity(identity); |
| 5015 | } |
| 5016 | } |
| 5017 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5018 | /** |
| 5019 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 5020 | * for the given slot ID or no ImsResolver instance has been created. |
| 5021 | * @param slotId The slot ID that the IMS service is created for. |
| 5022 | * @throws ImsException If there is no ImsService configured for this slot. |
| 5023 | */ |
| 5024 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 5025 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 5026 | ImsFeature.FEATURE_MMTEL)) { |
| 5027 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 5028 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 5029 | } |
| 5030 | } |
| 5031 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5032 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5033 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5034 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 5035 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 5036 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 5037 | } |
| 5038 | return slotId; |
| 5039 | } |
| 5040 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 5041 | private int getSlotIndex(int subId) { |
| 5042 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 5043 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 5044 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 5045 | } |
| 5046 | return slotId; |
| 5047 | } |
| 5048 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5049 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5050 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5051 | */ |
| 5052 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5053 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5054 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5055 | try { |
| 5056 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5057 | } catch (SecurityException se) { |
| 5058 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5059 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5060 | + Binder.getCallingUid()); |
| 5061 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5062 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5063 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5064 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5065 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5066 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5067 | mApp, subId, callingPackage, callingFeatureId, |
| 5068 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5069 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5070 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5071 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | final long identity = Binder.clearCallingIdentity(); |
| 5073 | try { |
| 5074 | final Phone phone = getPhone(subId); |
| 5075 | if (phone != null) { |
| 5076 | return phone.getServiceState().getDataNetworkType(); |
| 5077 | } else { |
| 5078 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5079 | } |
| 5080 | } finally { |
| 5081 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5082 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5083 | } |
| 5084 | |
| 5085 | /** |
| 5086 | * Returns the data network type |
| 5087 | */ |
| 5088 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5089 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5090 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5091 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5092 | } |
| 5093 | |
| 5094 | /** |
| 5095 | * Returns the data network type for a subId |
| 5096 | */ |
| 5097 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5098 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5099 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5100 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5101 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5102 | mApp, functionName)) { |
| 5103 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5104 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5105 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5106 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5107 | } |
| 5108 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
| 5111 | final Phone phone = getPhone(subId); |
| 5112 | if (phone != null) { |
| 5113 | return phone.getServiceState().getDataNetworkType(); |
| 5114 | } else { |
| 5115 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5116 | } |
| 5117 | } finally { |
| 5118 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5119 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5123 | * Returns the Voice network type for a subId |
| 5124 | */ |
| 5125 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5126 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5127 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5128 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5129 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5130 | mApp, functionName)) { |
| 5131 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5132 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5133 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5134 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
| 5139 | final Phone phone = getPhone(subId); |
| 5140 | if (phone != null) { |
| 5141 | return phone.getServiceState().getVoiceNetworkType(); |
| 5142 | } else { |
| 5143 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5144 | } |
| 5145 | } finally { |
| 5146 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | /** |
| 5151 | * @return true if a ICC card is present |
| 5152 | */ |
| 5153 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5154 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5155 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5156 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5160 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5161 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5162 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5163 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
| 5166 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5167 | if (phone != null) { |
| 5168 | return phone.getIccCard().hasIccCard(); |
| 5169 | } else { |
| 5170 | return false; |
| 5171 | } |
| 5172 | } finally { |
| 5173 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5174 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5175 | } |
| 5176 | |
| 5177 | /** |
| 5178 | * Return if the current radio is LTE on CDMA. This |
| 5179 | * is a tri-state return value as for a period of time |
| 5180 | * the mode may be unknown. |
| 5181 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5182 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5183 | * @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] | 5184 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5185 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5186 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5187 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5188 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5189 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5190 | } |
| 5191 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5192 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5193 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5194 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5195 | try { |
| 5196 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5197 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5198 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5199 | } |
| 5200 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
| 5203 | final Phone phone = getPhone(subId); |
| 5204 | if (phone == null) { |
| 5205 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5206 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5207 | return TelephonyProperties.lte_on_cdma_device() |
| 5208 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5209 | } |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5212 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5215 | /** |
| 5216 | * {@hide} |
| 5217 | * Returns Default subId, 0 in the case of single standby. |
| 5218 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5219 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5220 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5221 | } |
| 5222 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5223 | private int getSlotForDefaultSubscription() { |
| 5224 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5225 | } |
| 5226 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5227 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5228 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5229 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5230 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5231 | private boolean isActiveSubscription(int subId) { |
| 5232 | return mSubscriptionController.isActiveSubId(subId); |
| 5233 | } |
| 5234 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5235 | /** |
| 5236 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5237 | */ |
| 5238 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5241 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5242 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5243 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5244 | } finally { |
| 5245 | Binder.restoreCallingIdentity(identity); |
| 5246 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5251 | */ |
| 5252 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
| 5255 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5256 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5261 | } |
| 5262 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5263 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5264 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5265 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5266 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5267 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5268 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5269 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5270 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5271 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5272 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5273 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5274 | } |
| 5275 | return PhoneFactory.getPhone(phoneId); |
| 5276 | } |
| 5277 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5278 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5279 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5280 | @NonNull IccLogicalChannelRequest request) { |
| 5281 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5282 | /*message=*/ "iccOpenLogicalChannel"); |
| 5283 | |
| 5284 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5285 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5286 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5287 | |
| 5288 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5289 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5290 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5291 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5292 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5293 | Phone phone; |
| 5294 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5295 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5296 | mApp, request.subId, message); |
| 5297 | phone = getPhoneFromSubId(request.subId); |
| 5298 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5299 | enforceModifyPermission(); |
| 5300 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5301 | } else { |
| 5302 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5303 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5304 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5308 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5309 | final long identity = Binder.clearCallingIdentity(); |
| 5310 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5311 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5313 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5314 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5315 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5316 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5317 | loge("The calling package is not allowed to access ISD-R."); |
| 5318 | throw new SecurityException( |
| 5319 | "The calling package is not allowed to access ISD-R."); |
| 5320 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5321 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5322 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5323 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5324 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5325 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5326 | return response; |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5330 | } |
| 5331 | |
| 5332 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5333 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5334 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5335 | /*message=*/"iccCloseLogicalChannel"); |
| 5336 | |
| 5337 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5338 | |
| 5339 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5340 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5341 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5342 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5343 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5344 | // before this feature is enabled, this API should only return false if |
| 5345 | // the operation fails instead of throwing runtime exception for |
| 5346 | // backward-compatibility. |
| 5347 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5348 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5349 | final long identity = Binder.clearCallingIdentity(); |
| 5350 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5351 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5352 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5354 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5355 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5356 | Boolean success = false; |
| 5357 | if (result instanceof RuntimeException) { |
| 5358 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5359 | if (shouldThrowExceptionOnFailure) { |
| 5360 | throw (RuntimeException) result; |
| 5361 | } else { |
| 5362 | return false; |
| 5363 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5364 | } else if (result instanceof Boolean) { |
| 5365 | success = (Boolean) result; |
| 5366 | } else { |
| 5367 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5368 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5369 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5370 | return success; |
| 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5373 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5377 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5378 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5379 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5380 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5381 | if (DBG) { |
| 5382 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5383 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5384 | + p3 + " data=" + data); |
| 5385 | } |
| 5386 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5387 | command, p1, p2, p3, data); |
| 5388 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5389 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5390 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5391 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5392 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5393 | enforceModifyPermission(); |
| 5394 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5395 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5396 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5397 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5398 | } |
| 5399 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5400 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5401 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5405 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5406 | final long identity = Binder.clearCallingIdentity(); |
| 5407 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5408 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5409 | return ""; |
| 5410 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5411 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5412 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5413 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5414 | null /* workSource */); |
| 5415 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | // Append the returned status code to the end of the response payload. |
| 5418 | String s = Integer.toHexString( |
| 5419 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5420 | if (response.payload != null) { |
| 5421 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5422 | } |
| 5423 | return s; |
| 5424 | } finally { |
| 5425 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5426 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5427 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5428 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5429 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5430 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5431 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5432 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5433 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5434 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5435 | if (DBG) { |
| 5436 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5437 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5438 | } |
| 5439 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5440 | cla, command, p1, p2, p3, data); |
| 5441 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5442 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5443 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5444 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5445 | 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] | 5446 | enforceModifyPermission(); |
| 5447 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5448 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5449 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5450 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5451 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5452 | } |
| 5453 | |
| 5454 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5455 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5456 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5457 | } |
| 5458 | |
| 5459 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5460 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5461 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5462 | final long identity = Binder.clearCallingIdentity(); |
| 5463 | try { |
| 5464 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5465 | && TextUtils.equals(ISDR_AID, data)) { |
| 5466 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5467 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5468 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | if (bestComponent == null |
| 5470 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5471 | loge("The calling package is not allowed to select ISD-R."); |
| 5472 | throw new SecurityException( |
| 5473 | "The calling package is not allowed to select ISD-R."); |
| 5474 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5475 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5478 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5479 | null /* workSource */); |
| 5480 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5481 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | // Append the returned status code to the end of the response payload. |
| 5483 | String s = Integer.toHexString( |
| 5484 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5485 | if (response.payload != null) { |
| 5486 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5487 | } |
| 5488 | return s; |
| 5489 | } finally { |
| 5490 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5491 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5492 | } |
| 5493 | |
| 5494 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5495 | 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] | 5496 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5498 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5500 | final long identity = Binder.clearCallingIdentity(); |
| 5501 | try { |
| 5502 | if (DBG) { |
| 5503 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5504 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5505 | } |
| 5506 | |
| 5507 | IccIoResult response = |
| 5508 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5509 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5510 | subId); |
| 5511 | |
| 5512 | if (DBG) { |
| 5513 | log("Exchange SIM_IO [R]" + response); |
| 5514 | } |
| 5515 | |
| 5516 | byte[] result = null; |
| 5517 | int length = 2; |
| 5518 | if (response.payload != null) { |
| 5519 | length = 2 + response.payload.length; |
| 5520 | result = new byte[length]; |
| 5521 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5522 | } else { |
| 5523 | result = new byte[length]; |
| 5524 | } |
| 5525 | |
| 5526 | result[length - 1] = (byte) response.sw2; |
| 5527 | result[length - 2] = (byte) response.sw1; |
| 5528 | return result; |
| 5529 | } finally { |
| 5530 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5531 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5532 | } |
| 5533 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5534 | /** |
| 5535 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5536 | * on a particular subscription |
| 5537 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5538 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5539 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5540 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5541 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5542 | return null; |
| 5543 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5544 | |
| 5545 | final long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
| 5547 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5548 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5549 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5550 | return null; |
| 5551 | } |
| 5552 | Object response = sendRequest( |
| 5553 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5554 | if (response instanceof String[]) { |
| 5555 | return (String[]) response; |
| 5556 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5557 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5558 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5559 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5560 | } finally { |
| 5561 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5562 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5563 | } |
| 5564 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5565 | /** |
| 5566 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5567 | * subscription. |
| 5568 | * |
| 5569 | * @param subId the id of the subscription. |
| 5570 | * @param appType the uicc app type, must be USIM or SIM. |
| 5571 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5572 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5573 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5574 | * @return number of fplmns that is successfully written to the SIM. |
| 5575 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5576 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5577 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5578 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5579 | mApp, subId, "setForbiddenPlmns"); |
| 5580 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5581 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5582 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5583 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5584 | } |
| 5585 | if (fplmns == null) { |
| 5586 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5587 | } |
| 5588 | for (String fplmn : fplmns) { |
| 5589 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5590 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5591 | } |
| 5592 | } |
| 5593 | final long identity = Binder.clearCallingIdentity(); |
| 5594 | try { |
| 5595 | Object response = sendRequest( |
| 5596 | CMD_SET_FORBIDDEN_PLMNS, |
| 5597 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5598 | subId); |
| 5599 | return (int) response; |
| 5600 | } finally { |
| 5601 | Binder.restoreCallingIdentity(identity); |
| 5602 | } |
| 5603 | } |
| 5604 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5605 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5606 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5608 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5609 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5613 | if (response.payload == null) { |
| 5614 | return ""; |
| 5615 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5616 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | // Append the returned status code to the end of the response payload. |
| 5618 | String s = Integer.toHexString( |
| 5619 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5620 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5621 | return s; |
| 5622 | } finally { |
| 5623 | Binder.restoreCallingIdentity(identity); |
| 5624 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5625 | } |
| 5626 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5627 | /** |
| 5628 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5629 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5630 | * |
| 5631 | * @param itemID the ID of the item to read |
| 5632 | * @return the NV item as a String, or null on error. |
| 5633 | */ |
| 5634 | @Override |
| 5635 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5636 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5637 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5638 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5639 | |
| 5640 | final long identity = Binder.clearCallingIdentity(); |
| 5641 | try { |
| 5642 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5643 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5645 | return value; |
| 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
| 5648 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5653 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5654 | * |
| 5655 | * @param itemID the ID of the item to read |
| 5656 | * @param itemValue the value to write, as a String |
| 5657 | * @return true on success; false on any failure |
| 5658 | */ |
| 5659 | @Override |
| 5660 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5661 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5662 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5663 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | |
| 5665 | final long identity = Binder.clearCallingIdentity(); |
| 5666 | try { |
| 5667 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5668 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5669 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5670 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5671 | return success; |
| 5672 | } finally { |
| 5673 | Binder.restoreCallingIdentity(identity); |
| 5674 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5675 | } |
| 5676 | |
| 5677 | /** |
| 5678 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5679 | * Used for device configuration by some CDMA operators. |
| 5680 | * |
| 5681 | * @param preferredRoamingList byte array containing the new PRL |
| 5682 | * @return true on success; false on any failure |
| 5683 | */ |
| 5684 | @Override |
| 5685 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5686 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5687 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | |
| 5689 | final long identity = Binder.clearCallingIdentity(); |
| 5690 | try { |
| 5691 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5692 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5693 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5694 | return success; |
| 5695 | } finally { |
| 5696 | Binder.restoreCallingIdentity(identity); |
| 5697 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5698 | } |
| 5699 | |
| 5700 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5701 | * 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] | 5702 | * Used for device configuration by some CDMA operators. |
| 5703 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5704 | * @param slotIndex - device slot. |
| 5705 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5706 | * @return true on success; false on any failure |
| 5707 | */ |
| 5708 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5709 | public boolean resetModemConfig(int slotIndex) { |
| 5710 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5711 | if (phone != null) { |
| 5712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5713 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5715 | final long identity = Binder.clearCallingIdentity(); |
| 5716 | try { |
| 5717 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5718 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5719 | return success; |
| 5720 | } finally { |
| 5721 | Binder.restoreCallingIdentity(identity); |
| 5722 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5723 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5724 | return false; |
| 5725 | } |
| 5726 | |
| 5727 | /** |
| 5728 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5729 | * |
| 5730 | * @param slotIndex - device slot. |
| 5731 | * |
| 5732 | * @return true on success; false on any failure |
| 5733 | */ |
| 5734 | @Override |
| 5735 | public boolean rebootModem(int slotIndex) { |
| 5736 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5737 | if (phone != null) { |
| 5738 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5739 | mApp, phone.getSubId(), "rebootModem"); |
| 5740 | |
| 5741 | final long identity = Binder.clearCallingIdentity(); |
| 5742 | try { |
| 5743 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5744 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5745 | return success; |
| 5746 | } finally { |
| 5747 | Binder.restoreCallingIdentity(identity); |
| 5748 | } |
| 5749 | } |
| 5750 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5751 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5752 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5753 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5754 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5755 | * {@link #disableIms(int)}. |
| 5756 | * @param slotIndex device slot. |
| 5757 | */ |
| 5758 | public void resetIms(int slotIndex) { |
| 5759 | enforceModifyPermission(); |
| 5760 | |
| 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
| 5763 | if (mImsResolver == null) { |
| 5764 | // may happen if the does not support IMS. |
| 5765 | return; |
| 5766 | } |
| 5767 | mImsResolver.disableIms(slotIndex); |
| 5768 | mImsResolver.enableIms(slotIndex); |
| 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
| 5772 | } |
| 5773 | |
| 5774 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5775 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5776 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5777 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5778 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5779 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
| 5781 | final long identity = Binder.clearCallingIdentity(); |
| 5782 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5783 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5784 | // may happen if the device does not support IMS. |
| 5785 | return; |
| 5786 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5787 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
| 5790 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5794 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5795 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5796 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5797 | public void disableIms(int slotId) { |
| 5798 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5802 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5803 | // may happen if the device does not support IMS. |
| 5804 | return; |
| 5805 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5806 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5810 | } |
| 5811 | |
| 5812 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5813 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5814 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5815 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5816 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5817 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | |
| 5820 | final long identity = Binder.clearCallingIdentity(); |
| 5821 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5822 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5823 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5824 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5825 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5826 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5827 | } finally { |
| 5828 | Binder.restoreCallingIdentity(identity); |
| 5829 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5830 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5831 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5832 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5833 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5834 | @Override |
| 5835 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5836 | enforceModifyPermission(); |
| 5837 | |
| 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
| 5840 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5841 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5848 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5849 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5850 | */ |
| 5851 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5852 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5853 | |
| 5854 | final long identity = Binder.clearCallingIdentity(); |
| 5855 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5856 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5857 | // may happen if the device does not support IMS. |
| 5858 | return null; |
| 5859 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5860 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
| 5863 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5864 | } |
| 5865 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5866 | /** |
| 5867 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5868 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5869 | */ |
| 5870 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5871 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5872 | |
| 5873 | final long identity = Binder.clearCallingIdentity(); |
| 5874 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5875 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5876 | // may happen if the device does not support IMS. |
| 5877 | return null; |
| 5878 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5879 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5880 | } finally { |
| 5881 | Binder.restoreCallingIdentity(identity); |
| 5882 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5885 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5886 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5887 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5888 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5889 | * @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] | 5890 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5891 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5892 | * @param packageName The name of the package that the current configuration will be replaced |
| 5893 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5894 | * @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] | 5895 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5896 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5897 | int[] featureTypes, String packageName) { |
| 5898 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5899 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5900 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5901 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5902 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5904 | final long identity = Binder.clearCallingIdentity(); |
| 5905 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5906 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5907 | // may happen if the device does not support IMS. |
| 5908 | return false; |
| 5909 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5910 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5911 | for (int featureType : featureTypes) { |
| 5912 | featureConfig.put(featureType, packageName); |
| 5913 | } |
| 5914 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5915 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5916 | } finally { |
| 5917 | Binder.restoreCallingIdentity(identity); |
| 5918 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5919 | } |
| 5920 | |
| 5921 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5922 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5923 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5924 | * |
| 5925 | * This should only be used for testing. |
| 5926 | * |
| 5927 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5928 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5929 | */ |
| 5930 | @Override |
| 5931 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5932 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5933 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5934 | "clearCarrierImsServiceOverride"); |
| 5935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5936 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5937 | "clearCarrierImsServiceOverride"); |
| 5938 | |
| 5939 | final long identity = Binder.clearCallingIdentity(); |
| 5940 | try { |
| 5941 | if (mImsResolver == null) { |
| 5942 | // may happen if the device does not support IMS. |
| 5943 | return false; |
| 5944 | } |
| 5945 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5946 | } finally { |
| 5947 | Binder.restoreCallingIdentity(identity); |
| 5948 | } |
| 5949 | } |
| 5950 | |
| 5951 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5952 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5953 | * |
| 5954 | * @param slotId The slot that the ImsService is associated with. |
| 5955 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5956 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5957 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5958 | * @return the package name of the ImsService configuration. |
| 5959 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5960 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5961 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5962 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5963 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5964 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5965 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5966 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5968 | final long identity = Binder.clearCallingIdentity(); |
| 5969 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5970 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5971 | // may happen if the device does not support IMS. |
| 5972 | return ""; |
| 5973 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5974 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5975 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5976 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5977 | } finally { |
| 5978 | Binder.restoreCallingIdentity(identity); |
| 5979 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5980 | } |
| 5981 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5982 | /** |
| 5983 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5984 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5985 | * @param callback A callback with an integer containing the |
| 5986 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5987 | */ |
| 5988 | @Override |
| 5989 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5990 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5991 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5992 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5993 | "IMS not available on device."); |
| 5994 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5995 | final long token = Binder.clearCallingIdentity(); |
| 5996 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5997 | int slotId = getSlotIndex(subId); |
| 5998 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5999 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 6000 | + subId + "'"); |
| 6001 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 6002 | } |
| 6003 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 6004 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 6005 | try { |
| 6006 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 6007 | } catch (RemoteException e) { |
| 6008 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 6009 | + "Ignore"); |
| 6010 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6011 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 6012 | } catch (ImsException e) { |
| 6013 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6014 | } finally { |
| 6015 | Binder.restoreCallingIdentity(token); |
| 6016 | } |
| 6017 | } |
| 6018 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6019 | /** |
| 6020 | * Sets the ims registration state on all valid {@link Phone}s. |
| 6021 | */ |
| 6022 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6023 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6024 | |
| 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 6027 | // NOTE: Before S, this method only set the default phone. |
| 6028 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 6029 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 6030 | phone.setImsRegistrationState(registered); |
| 6031 | } |
| 6032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6033 | } finally { |
| 6034 | Binder.restoreCallingIdentity(identity); |
| 6035 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 6036 | } |
| 6037 | |
| 6038 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6039 | * Set the network selection mode to automatic. |
| 6040 | * |
| 6041 | */ |
| 6042 | @Override |
| 6043 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6044 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6045 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | |
| 6047 | final long identity = Binder.clearCallingIdentity(); |
| 6048 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6049 | if (!isActiveSubscription(subId)) { |
| 6050 | return; |
| 6051 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6052 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6053 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6054 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6058 | } |
| 6059 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6060 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6061 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6062 | * |
| 6063 | * @param subId the id of the subscription. |
| 6064 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6065 | * the operator to attach to. |
| 6066 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6067 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6068 | * normal network selection next time. |
| 6069 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6070 | */ |
| 6071 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6072 | public boolean setNetworkSelectionModeManual( |
| 6073 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6074 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6075 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6076 | |
| 6077 | if (!isActiveSubscription(subId)) { |
| 6078 | return false; |
| 6079 | } |
| 6080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6081 | final long identity = Binder.clearCallingIdentity(); |
| 6082 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6083 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6085 | if (DBG) { |
| 6086 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6087 | + " operator: " + operatorInfo); |
| 6088 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6090 | } finally { |
| 6091 | Binder.restoreCallingIdentity(identity); |
| 6092 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6093 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6094 | /** |
| 6095 | * Get the manual network selection |
| 6096 | * |
| 6097 | * @param subId the id of the subscription. |
| 6098 | * |
| 6099 | * @return the previously saved user selected PLMN |
| 6100 | */ |
| 6101 | @Override |
| 6102 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6103 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6104 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6105 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6106 | |
| 6107 | final long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
| 6109 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6110 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | final Phone phone = getPhone(subId); |
| 6114 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6115 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6116 | } |
| 6117 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6118 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6119 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6120 | } finally { |
| 6121 | Binder.restoreCallingIdentity(identity); |
| 6122 | } |
| 6123 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6124 | |
| 6125 | /** |
| 6126 | * Scans for available networks. |
| 6127 | */ |
| 6128 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6129 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6130 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6131 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6132 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6133 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6134 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6135 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6136 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6137 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6138 | .setCallingPid(Binder.getCallingPid()) |
| 6139 | .setCallingUid(Binder.getCallingUid()) |
| 6140 | .setMethod("getCellNetworkScanResults") |
| 6141 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6142 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6143 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6144 | .build()); |
| 6145 | switch (locationResult) { |
| 6146 | case DENIED_HARD: |
| 6147 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6148 | case DENIED_SOFT: |
| 6149 | return null; |
| 6150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6152 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6153 | try { |
| 6154 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6155 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6156 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | } finally { |
| 6158 | Binder.restoreCallingIdentity(identity); |
| 6159 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6160 | } |
| 6161 | |
| 6162 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6163 | * Get the call forwarding info, given the call forwarding reason. |
| 6164 | */ |
| 6165 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6166 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6167 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6168 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6169 | long identity = Binder.clearCallingIdentity(); |
| 6170 | try { |
| 6171 | if (DBG) { |
| 6172 | log("getCallForwarding: subId " + subId |
| 6173 | + " callForwardingReason" + callForwardingReason); |
| 6174 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6175 | |
| 6176 | Phone phone = getPhone(subId); |
| 6177 | if (phone == null) { |
| 6178 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6179 | callback.onError( |
| 6180 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6181 | } catch (RemoteException e) { |
| 6182 | // ignore |
| 6183 | } |
| 6184 | return; |
| 6185 | } |
| 6186 | |
| 6187 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6188 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6189 | @Override |
| 6190 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6191 | try { |
| 6192 | callback.onCallForwardingInfoAvailable(info); |
| 6193 | } catch (RemoteException e) { |
| 6194 | // ignore |
| 6195 | } |
| 6196 | } |
| 6197 | |
| 6198 | @Override |
| 6199 | public void onError(int error) { |
| 6200 | try { |
| 6201 | callback.onError(error); |
| 6202 | } catch (RemoteException e) { |
| 6203 | // ignore |
| 6204 | } |
| 6205 | } |
| 6206 | }); |
| 6207 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6208 | } finally { |
| 6209 | Binder.restoreCallingIdentity(identity); |
| 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | /** |
| 6214 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6215 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6216 | */ |
| 6217 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6218 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6219 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6220 | enforceModifyPermission(); |
| 6221 | long identity = Binder.clearCallingIdentity(); |
| 6222 | try { |
| 6223 | if (DBG) { |
| 6224 | log("setCallForwarding: subId " + subId |
| 6225 | + " callForwardingInfo" + callForwardingInfo); |
| 6226 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6227 | |
| 6228 | Phone phone = getPhone(subId); |
| 6229 | if (phone == null) { |
| 6230 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6231 | callback.accept( |
| 6232 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6233 | } catch (RemoteException e) { |
| 6234 | // ignore |
| 6235 | } |
| 6236 | return; |
| 6237 | } |
| 6238 | |
| 6239 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6240 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6241 | |
| 6242 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6243 | } finally { |
| 6244 | Binder.restoreCallingIdentity(identity); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6249 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6250 | */ |
| 6251 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6252 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6253 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6254 | long identity = Binder.clearCallingIdentity(); |
| 6255 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6256 | Phone phone = getPhone(subId); |
| 6257 | if (phone == null) { |
| 6258 | try { |
| 6259 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6260 | } catch (RemoteException e) { |
| 6261 | // ignore |
| 6262 | } |
| 6263 | return; |
| 6264 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6265 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6266 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6267 | boolean requireUssd = c.getBoolean( |
| 6268 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6269 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6270 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6271 | if (requireUssd) { |
| 6272 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6273 | getSubscriptionCarrierId(subId)); |
| 6274 | String newUssdCommand = ""; |
| 6275 | try { |
| 6276 | newUssdCommand = carrierXmlParser.getFeature( |
| 6277 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6278 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6279 | } catch (NullPointerException e) { |
| 6280 | loge("Failed to generate USSD number" + e); |
| 6281 | } |
| 6282 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6283 | mMainThreadHandler, callback, carrierXmlParser, |
| 6284 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6285 | final String ussdCommand = newUssdCommand; |
| 6286 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6287 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6288 | }); |
| 6289 | } else { |
| 6290 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6291 | callback::accept); |
| 6292 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6293 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6294 | } finally { |
| 6295 | Binder.restoreCallingIdentity(identity); |
| 6296 | } |
| 6297 | } |
| 6298 | |
| 6299 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6300 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6301 | */ |
| 6302 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6303 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6304 | enforceModifyPermission(); |
| 6305 | long identity = Binder.clearCallingIdentity(); |
| 6306 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6307 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6308 | |
| 6309 | Phone phone = getPhone(subId); |
| 6310 | if (phone == null) { |
| 6311 | try { |
| 6312 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6313 | } catch (RemoteException e) { |
| 6314 | // ignore |
| 6315 | } |
| 6316 | return; |
| 6317 | } |
| 6318 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6319 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6320 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6321 | boolean requireUssd = c.getBoolean( |
| 6322 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6323 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6324 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6325 | if (requireUssd) { |
| 6326 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6327 | getSubscriptionCarrierId(subId)); |
| 6328 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6329 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6330 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6331 | String newUssdCommand = ""; |
| 6332 | try { |
| 6333 | newUssdCommand = carrierXmlParser.getFeature( |
| 6334 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6335 | .makeCommand(ssAction, null); |
| 6336 | } catch (NullPointerException e) { |
| 6337 | loge("Failed to generate USSD number" + e); |
| 6338 | } |
| 6339 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6340 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6341 | final String ussdCommand = newUssdCommand; |
| 6342 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6343 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6344 | }); |
| 6345 | } else { |
| 6346 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6347 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6348 | |
| 6349 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6350 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6351 | } finally { |
| 6352 | Binder.restoreCallingIdentity(identity); |
| 6353 | } |
| 6354 | } |
| 6355 | |
| 6356 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6357 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6358 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6359 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6360 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6361 | * location related information which will be sent if the caller already possess |
| 6362 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6363 | * @param request contains the radio access networks with bands/channels to scan |
| 6364 | * @param messenger callback messenger for scan results or errors |
| 6365 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6366 | * @return the id of the requested scan which can be used to stop the scan. |
| 6367 | */ |
| 6368 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6369 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6370 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6371 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6373 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6374 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6375 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6376 | if (!renounceFineLocationAccess) { |
| 6377 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6378 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6379 | .setCallingPackage(callingPackage) |
| 6380 | .setCallingFeatureId(callingFeatureId) |
| 6381 | .setCallingPid(Binder.getCallingPid()) |
| 6382 | .setCallingUid(Binder.getCallingUid()) |
| 6383 | .setMethod("requestNetworkScan") |
| 6384 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6385 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6386 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6387 | .build()); |
| 6388 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6389 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6390 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6391 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6392 | if (e != null) { |
| 6393 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6394 | throw e; |
| 6395 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6396 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6397 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6398 | } |
| 6399 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6400 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6401 | int callingUid = Binder.getCallingUid(); |
| 6402 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6403 | final long identity = Binder.clearCallingIdentity(); |
| 6404 | try { |
| 6405 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6406 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6407 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6408 | } finally { |
| 6409 | Binder.restoreCallingIdentity(identity); |
| 6410 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6411 | } |
| 6412 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6413 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6414 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6415 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6416 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6417 | boolean hasNetworkScanPermission = |
| 6418 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6419 | == PERMISSION_GRANTED; |
| 6420 | |
| 6421 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6422 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6423 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6427 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6428 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6429 | return new SecurityException("Specific channels must not be" |
| 6430 | + " scanned without location access."); |
| 6431 | } |
| 6432 | } |
| 6433 | } |
| 6434 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6435 | return null; |
| 6436 | } |
| 6437 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6438 | /** |
| 6439 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6440 | * |
| 6441 | * @param subId id of the subscription |
| 6442 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6443 | */ |
| 6444 | @Override |
| 6445 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6447 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6448 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6449 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6452 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
| 6455 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6456 | } |
| 6457 | |
| 6458 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6459 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6460 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6461 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6462 | */ |
| 6463 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6464 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6465 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6466 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6467 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6468 | |
| 6469 | final long identity = Binder.clearCallingIdentity(); |
| 6470 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6471 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6472 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6473 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6474 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6475 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6476 | } finally { |
| 6477 | Binder.restoreCallingIdentity(identity); |
| 6478 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6482 | * Get the allowed network types for certain reason. |
| 6483 | * |
| 6484 | * @param subId the id of the subscription. |
| 6485 | * @param reason the reason the allowed network type change is taking place |
| 6486 | * @return the allowed network types. |
| 6487 | */ |
| 6488 | @Override |
| 6489 | public long getAllowedNetworkTypesForReason(int subId, |
| 6490 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6491 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6492 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | try { |
| 6495 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6502 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6503 | * @param subId subscription id of the sim card |
| 6504 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6505 | * This can be passed following states |
| 6506 | * <ol> |
| 6507 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6508 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6509 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6510 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6511 | * </ol> |
| 6512 | * @return operation result. |
| 6513 | */ |
| 6514 | @Override |
| 6515 | public int setNrDualConnectivityState(int subId, |
| 6516 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6517 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6518 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6519 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6520 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6521 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6522 | } |
| 6523 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6524 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6525 | final long identity = Binder.clearCallingIdentity(); |
| 6526 | try { |
| 6527 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6528 | nrDualConnectivityState, subId, |
| 6529 | workSource); |
| 6530 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6531 | return result; |
| 6532 | } finally { |
| 6533 | Binder.restoreCallingIdentity(identity); |
| 6534 | } |
| 6535 | } |
| 6536 | |
| 6537 | /** |
| 6538 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6539 | * @return true if dual connectivity is enabled else false |
| 6540 | */ |
| 6541 | @Override |
| 6542 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6543 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6544 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6545 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6546 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6547 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6548 | return false; |
| 6549 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6550 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6554 | null, subId, workSource); |
| 6555 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6556 | return isEnabled; |
| 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
| 6559 | } |
| 6560 | } |
| 6561 | |
| 6562 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6563 | * Set the allowed network types of the device and |
| 6564 | * provide the reason triggering the allowed network change. |
| 6565 | * |
| 6566 | * @param subId the id of the subscription. |
| 6567 | * @param reason the reason the allowed network type change is taking place |
| 6568 | * @param allowedNetworkTypes the allowed network types. |
| 6569 | * @return true on success; false on any failure. |
| 6570 | */ |
| 6571 | @Override |
| 6572 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6573 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6574 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6576 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6577 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6578 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6579 | return false; |
| 6580 | } |
| 6581 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6582 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6583 | return false; |
| 6584 | } |
| 6585 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6586 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6587 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6588 | |
| 6589 | |
| 6590 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6591 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6592 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6593 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6594 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6595 | final long identity = Binder.clearCallingIdentity(); |
| 6596 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6597 | Boolean success = (Boolean) sendRequest( |
| 6598 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6599 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6600 | |
| 6601 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6602 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6603 | } finally { |
| 6604 | Binder.restoreCallingIdentity(identity); |
| 6605 | } |
| 6606 | } |
| 6607 | |
| 6608 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6609 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6610 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6611 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6612 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6613 | * @hide |
| 6614 | */ |
| 6615 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6616 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6617 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6619 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6620 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6621 | if (phone != null) { |
| 6622 | return phone.hasMatchedTetherApnSetting(); |
| 6623 | } else { |
| 6624 | return false; |
| 6625 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | } finally { |
| 6627 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6628 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6629 | } |
| 6630 | |
| 6631 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6632 | * Get the user enabled state of Mobile Data. |
| 6633 | * |
| 6634 | * TODO: remove and use isUserDataEnabled. |
| 6635 | * This can't be removed now because some vendor codes |
| 6636 | * calls through ITelephony directly while they should |
| 6637 | * use TelephonyManager. |
| 6638 | * |
| 6639 | * @return true on enabled |
| 6640 | */ |
| 6641 | @Override |
| 6642 | public boolean getDataEnabled(int subId) { |
| 6643 | return isUserDataEnabled(subId); |
| 6644 | } |
| 6645 | |
| 6646 | /** |
| 6647 | * Get whether mobile data is enabled per user setting. |
| 6648 | * |
| 6649 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6650 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6651 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6652 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6653 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6654 | * |
| 6655 | * @return {@code true} if data is enabled else {@code false} |
| 6656 | */ |
| 6657 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6658 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6659 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6660 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6661 | try { |
| 6662 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6663 | functionName); |
| 6664 | } catch (Exception e) { |
| 6665 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6666 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6667 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6669 | mApp, subId, functionName); |
| 6670 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6672 | |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
| 6675 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6676 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6677 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6678 | if (phone != null) { |
| 6679 | boolean retVal = phone.isUserDataEnabled(); |
| 6680 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6681 | return retVal; |
| 6682 | } else { |
| 6683 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6684 | return false; |
| 6685 | } |
| 6686 | } finally { |
| 6687 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6692 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6693 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6694 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6695 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6696 | * @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] | 6697 | */ |
| 6698 | @Override |
| 6699 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6700 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6701 | try { |
| 6702 | try { |
| 6703 | mApp.enforceCallingOrSelfPermission( |
| 6704 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6705 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6706 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6707 | try { |
| 6708 | mApp.enforceCallingOrSelfPermission( |
| 6709 | android.Manifest.permission.READ_PHONE_STATE, |
| 6710 | functionName); |
| 6711 | } catch (Exception e2) { |
| 6712 | mApp.enforceCallingOrSelfPermission( |
| 6713 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6714 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6715 | } |
| 6716 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6717 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6719 | |
| 6720 | final long identity = Binder.clearCallingIdentity(); |
| 6721 | try { |
| 6722 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6724 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6725 | boolean retVal; |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6726 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6727 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | return retVal; |
| 6729 | } else { |
| 6730 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6731 | return false; |
| 6732 | } |
| 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6735 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6736 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6737 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6738 | /** |
| 6739 | * Check if data is enabled for a specific reason |
| 6740 | * @param subId Subscription index |
| 6741 | * @param reason the reason the data enable change is taking place |
| 6742 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6743 | */ |
| 6744 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6745 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6746 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6747 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6748 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6749 | try { |
| 6750 | mApp.enforceCallingOrSelfPermission( |
| 6751 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6752 | functionName); |
| 6753 | } catch (Exception e) { |
| 6754 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6755 | functionName); |
| 6756 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6757 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6758 | try { |
| 6759 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6760 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6761 | } catch (Exception e2) { |
| 6762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6763 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6764 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
| 6767 | |
| 6768 | final long identity = Binder.clearCallingIdentity(); |
| 6769 | try { |
| 6770 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6771 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6772 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6773 | + " reason=" + reason); |
| 6774 | } |
| 6775 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6776 | if (phone != null) { |
| 6777 | boolean retVal; |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 6778 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6779 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6780 | return retVal; |
| 6781 | } else { |
| 6782 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6783 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6784 | + subId + " retVal=false"); |
| 6785 | } |
| 6786 | return false; |
| 6787 | } |
| 6788 | } finally { |
| 6789 | Binder.restoreCallingIdentity(identity); |
| 6790 | } |
| 6791 | } |
| 6792 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6793 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6794 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6795 | // No permission needed; this only lets the caller inspect their own status. |
| 6796 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6797 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6798 | |
| 6799 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6800 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6801 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6802 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6803 | } |
| 6804 | |
| 6805 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6806 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6807 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6808 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6809 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6810 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6811 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6812 | if (cpt == null) { |
| 6813 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6814 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6815 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6816 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6820 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6821 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6822 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6823 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6824 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6825 | Phone phone = getPhone(subId); |
| 6826 | if (phone == null) { |
| 6827 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6828 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6829 | } |
| 6830 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6831 | if (cpt == null) { |
| 6832 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6833 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6834 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6835 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6836 | } |
| 6837 | |
| 6838 | @Override |
| 6839 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6840 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6841 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6842 | } |
| 6843 | |
| 6844 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6845 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6846 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6847 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6848 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6849 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6850 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6851 | if (phone == null) { |
| 6852 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6853 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6854 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6855 | if (cpt == null) { |
| 6856 | continue; |
| 6857 | } |
| 6858 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6859 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6860 | break; |
| 6861 | } |
| 6862 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6863 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6864 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6865 | |
| 6866 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6867 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6868 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6869 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6870 | if (phone == null) { |
| 6871 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6872 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6873 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6874 | if (cpt == null) { |
| 6875 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6876 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6877 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6878 | } |
| 6879 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6880 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6881 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6882 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6883 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6884 | if (phone == null) { |
| 6885 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6886 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6887 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6888 | if (cpt == null) { |
| 6889 | return Collections.emptyList(); |
| 6890 | } |
| 6891 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6892 | } |
| 6893 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6894 | @Override |
| 6895 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6896 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6897 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6898 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6899 | try { |
| 6900 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6901 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6902 | } |
| 6903 | } finally { |
| 6904 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6905 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6906 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6907 | } |
| 6908 | |
Rambo Wang | 6812ffb | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6909 | @Override |
| 6910 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6911 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6912 | |
| 6913 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6914 | if (phone == null) { |
| 6915 | return null; |
| 6916 | } |
| 6917 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6918 | if (cpt == null) { |
| 6919 | return null; |
| 6920 | } |
| 6921 | return cpt.getCarrierServicePackageName(); |
| 6922 | } |
| 6923 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6924 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6925 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6926 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6927 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6928 | return null; |
| 6929 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6930 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6931 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6932 | return null; |
| 6933 | } |
| 6934 | return iccId; |
| 6935 | } |
| 6936 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6937 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6938 | public void setCallComposerStatus(int subId, int status) { |
| 6939 | enforceModifyPermission(); |
| 6940 | |
| 6941 | final long identity = Binder.clearCallingIdentity(); |
| 6942 | try { |
| 6943 | Phone phone = getPhone(subId); |
| 6944 | if (phone != null) { |
| 6945 | Phone defaultPhone = phone.getImsPhone(); |
| 6946 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6947 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6948 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6949 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6950 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6951 | } |
| 6952 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6953 | } catch (ImsException e) { |
| 6954 | throw new ServiceSpecificException(e.getCode()); |
| 6955 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6956 | Binder.restoreCallingIdentity(identity); |
| 6957 | } |
| 6958 | } |
| 6959 | |
| 6960 | @Override |
| 6961 | public int getCallComposerStatus(int subId) { |
| 6962 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6963 | |
| 6964 | final long identity = Binder.clearCallingIdentity(); |
| 6965 | try { |
| 6966 | Phone phone = getPhone(subId); |
| 6967 | if (phone != null) { |
| 6968 | Phone defaultPhone = phone.getImsPhone(); |
| 6969 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6970 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6971 | return imsPhone.getCallComposerStatus(); |
| 6972 | } |
| 6973 | } |
| 6974 | } finally { |
| 6975 | Binder.restoreCallingIdentity(identity); |
| 6976 | } |
| 6977 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6978 | } |
| 6979 | |
| 6980 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6981 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6982 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6983 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6984 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6986 | final long identity = Binder.clearCallingIdentity(); |
| 6987 | try { |
| 6988 | final String iccId = getIccId(subId); |
| 6989 | final Phone phone = getPhone(subId); |
| 6990 | if (phone == null) { |
| 6991 | return false; |
| 6992 | } |
| 6993 | final String subscriberId = phone.getSubscriberId(); |
| 6994 | |
| 6995 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6996 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6997 | + subscriberId + " to " + number); |
| 6998 | } |
| 6999 | |
| 7000 | if (TextUtils.isEmpty(iccId)) { |
| 7001 | return false; |
| 7002 | } |
| 7003 | |
| 7004 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7005 | |
| 7006 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7007 | if (alphaTag == null) { |
| 7008 | editor.remove(alphaTagPrefKey); |
| 7009 | } else { |
| 7010 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7011 | } |
| 7012 | |
| 7013 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7014 | // track all merged IMSIs based on line number |
| 7015 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7016 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7017 | if (number == null) { |
| 7018 | editor.remove(numberPrefKey); |
| 7019 | editor.remove(subscriberPrefKey); |
| 7020 | } else { |
| 7021 | editor.putString(numberPrefKey, number); |
| 7022 | editor.putString(subscriberPrefKey, subscriberId); |
| 7023 | } |
| 7024 | |
| 7025 | editor.commit(); |
| 7026 | return true; |
| 7027 | } finally { |
| 7028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7029 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7030 | } |
| 7031 | |
| 7032 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7033 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7034 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7035 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7036 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7037 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7038 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7039 | return null; |
| 7040 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7042 | final long identity = Binder.clearCallingIdentity(); |
| 7043 | try { |
| 7044 | String iccId = getIccId(subId); |
| 7045 | if (iccId != null) { |
| 7046 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7047 | if (DBG_MERGE) { |
| 7048 | log("getLine1NumberForDisplay returning " |
| 7049 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7050 | } |
| 7051 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7052 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7054 | return null; |
| 7055 | } finally { |
| 7056 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7057 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7061 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7062 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7063 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7064 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7065 | return null; |
| 7066 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | String iccId = getIccId(subId); |
| 7071 | if (iccId != null) { |
| 7072 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7073 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7074 | } |
| 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 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7080 | |
| 7081 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7082 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7083 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7084 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7085 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7086 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7087 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7088 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7089 | return null; |
| 7090 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7091 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7092 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7093 | // the process, where TelephonyManager was instantiated. |
| 7094 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7095 | final long identity = Binder.clearCallingIdentity(); |
| 7096 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7097 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7099 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7100 | |
| 7101 | // Figure out what subscribers are currently active |
| 7102 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7103 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7104 | // Only consider subs which match the current subId |
| 7105 | // This logic can be simplified. See b/131189269 for progress. |
| 7106 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7107 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7108 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | |
| 7110 | // First pass, find a number override for an active subscriber |
| 7111 | String mergeNumber = null; |
| 7112 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7113 | for (String key : prefs.keySet()) { |
| 7114 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7115 | final String subscriberId = (String) prefs.get(key); |
| 7116 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7117 | final String iccId = key.substring( |
| 7118 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7119 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7120 | mergeNumber = (String) prefs.get(numberKey); |
| 7121 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7122 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7123 | + " for active subscriber " + subscriberId); |
| 7124 | } |
| 7125 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7126 | break; |
| 7127 | } |
| 7128 | } |
| 7129 | } |
| 7130 | } |
| 7131 | |
| 7132 | // Shortcut when no active merged subscribers |
| 7133 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7134 | return null; |
| 7135 | } |
| 7136 | |
| 7137 | // Second pass, find all subscribers under that line override |
| 7138 | final ArraySet<String> result = new ArraySet<>(); |
| 7139 | for (String key : prefs.keySet()) { |
| 7140 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7141 | final String number = (String) prefs.get(key); |
| 7142 | if (mergeNumber.equals(number)) { |
| 7143 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7144 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7145 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7146 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7147 | result.add(subscriberId); |
| 7148 | } |
| 7149 | } |
| 7150 | } |
| 7151 | } |
| 7152 | |
| 7153 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7154 | Arrays.sort(resultArray); |
| 7155 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7156 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7158 | } |
| 7159 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7160 | } finally { |
| 7161 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7162 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7163 | } |
| 7164 | |
| 7165 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7166 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7167 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7168 | |
| 7169 | final long identity = Binder.clearCallingIdentity(); |
| 7170 | try { |
| 7171 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7172 | TelephonyManager.class); |
| 7173 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7174 | if (subscriberId == null) { |
| 7175 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7176 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7177 | + subId); |
| 7178 | } |
| 7179 | return null; |
| 7180 | } |
| 7181 | |
| 7182 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7183 | .getSubscriptionInfo(subId); |
| 7184 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7185 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7186 | if (groupUuid == null) { |
| 7187 | return new String[]{subscriberId}; |
| 7188 | } |
| 7189 | |
| 7190 | // Get all subscriberIds from the group. |
| 7191 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7192 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7193 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7194 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7195 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7196 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7197 | if (subscriberId != null) { |
| 7198 | mergedSubscriberIds.add(subscriberId); |
| 7199 | } |
| 7200 | } |
| 7201 | |
| 7202 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7203 | } finally { |
| 7204 | Binder.restoreCallingIdentity(identity); |
| 7205 | |
| 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7210 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7211 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7212 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | |
| 7214 | final long identity = Binder.clearCallingIdentity(); |
| 7215 | try { |
| 7216 | final Phone phone = getPhone(subId); |
| 7217 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7218 | } finally { |
| 7219 | Binder.restoreCallingIdentity(identity); |
| 7220 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7221 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7222 | |
| 7223 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7224 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7225 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7226 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7227 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7228 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7229 | |
| 7230 | final long identity = Binder.clearCallingIdentity(); |
| 7231 | try { |
| 7232 | final Phone phone = getPhone(subId); |
| 7233 | if (phone == null) { |
| 7234 | return false; |
| 7235 | } |
| 7236 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7237 | cdmaNonRoamingList); |
| 7238 | } finally { |
| 7239 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7240 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7244 | @Deprecated |
| 7245 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7246 | enforceModifyPermission(); |
| 7247 | |
| 7248 | int returnValue = 0; |
| 7249 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7250 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7251 | if(result.exception == null) { |
| 7252 | if (result.result != null) { |
| 7253 | byte[] responseData = (byte[])(result.result); |
| 7254 | if(responseData.length > oemResp.length) { |
| 7255 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7256 | responseData.length + "bytes. Buffer Size is " + |
| 7257 | oemResp.length + "bytes."); |
| 7258 | } |
| 7259 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7260 | returnValue = responseData.length; |
| 7261 | } |
| 7262 | } else { |
| 7263 | CommandException ex = (CommandException) result.exception; |
| 7264 | returnValue = ex.getCommandError().ordinal(); |
| 7265 | if(returnValue > 0) returnValue *= -1; |
| 7266 | } |
| 7267 | } catch (RuntimeException e) { |
| 7268 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7269 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7270 | if(returnValue > 0) returnValue *= -1; |
| 7271 | } |
| 7272 | |
| 7273 | return returnValue; |
| 7274 | } |
| 7275 | |
| 7276 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7277 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7278 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7279 | try { |
| 7280 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7281 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7282 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7283 | } catch (SecurityException e) { |
| 7284 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7285 | throw e; |
| 7286 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7287 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7288 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7289 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7290 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7293 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7294 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7295 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7296 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7297 | } finally { |
| 7298 | Binder.restoreCallingIdentity(identity); |
| 7299 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7300 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7301 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7302 | |
| 7303 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7304 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7305 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7306 | try { |
| 7307 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7308 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7309 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7310 | } |
| 7311 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7312 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7313 | } |
| 7314 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7315 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7316 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7317 | throw new SecurityException("App must be the dialer role holder to" |
| 7318 | + " upload a call composer pic"); |
| 7319 | } |
| 7320 | |
| 7321 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7322 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7323 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7324 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7325 | boolean readUntilEnd = false; |
| 7326 | int totalBytesRead = 0; |
| 7327 | byte[] buffer = new byte[16 * 1024]; |
| 7328 | while (true) { |
| 7329 | int numRead; |
| 7330 | try { |
| 7331 | numRead = input.read(buffer); |
| 7332 | } catch (IOException e) { |
| 7333 | try { |
| 7334 | fd.checkError(); |
| 7335 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7336 | null); |
| 7337 | } catch (IOException e1) { |
| 7338 | // This means that the other side closed explicitly with an error. If this |
| 7339 | // happens, log and ignore. |
| 7340 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7341 | } |
| 7342 | break; |
| 7343 | } |
| 7344 | if (numRead == -1) { |
| 7345 | readUntilEnd = true; |
| 7346 | break; |
| 7347 | } |
| 7348 | totalBytesRead += numRead; |
| 7349 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7350 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7351 | try { |
| 7352 | input.close(); |
| 7353 | } catch (IOException e) { |
| 7354 | // ignore |
| 7355 | } |
| 7356 | break; |
| 7357 | } |
| 7358 | output.write(buffer, 0, numRead); |
| 7359 | } |
| 7360 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7361 | // close is above, where the picture size is too big. |
| 7362 | |
| 7363 | try { |
| 7364 | fd.checkError(); |
| 7365 | } catch (IOException e) { |
| 7366 | loge("Remote end for call composer closed with an error: " + e); |
| 7367 | return; |
| 7368 | } |
| 7369 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7370 | if (!readUntilEnd) { |
| 7371 | loge("Did not finish reading entire image; aborting"); |
| 7372 | return; |
| 7373 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7374 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7375 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7376 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7377 | new CallComposerPictureTransfer.Factory() {}, |
| 7378 | imageData, |
| 7379 | (result) -> { |
| 7380 | if (result.first != null) { |
| 7381 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7382 | Bundle outputResult = new Bundle(); |
| 7383 | outputResult.putParcelable( |
| 7384 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7385 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7386 | outputResult); |
| 7387 | } else { |
| 7388 | callback.send(result.second, null); |
| 7389 | } |
| 7390 | } |
| 7391 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7392 | }); |
| 7393 | } |
| 7394 | |
| 7395 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7396 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7397 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7398 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7399 | |
| 7400 | final long identity = Binder.clearCallingIdentity(); |
| 7401 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7402 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7403 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | } finally { |
| 7405 | Binder.restoreCallingIdentity(identity); |
| 7406 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7407 | } |
| 7408 | |
| 7409 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7410 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7411 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7412 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7413 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7414 | return false; |
| 7415 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7420 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7421 | // In the long run, we may instead need to check if there exists a connection service |
| 7422 | // which can support video calling. |
| 7423 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7424 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7425 | return imsManager.isVtEnabledByPlatform() |
| 7426 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7427 | && imsManager.isVtEnabledByUser(); |
| 7428 | } finally { |
| 7429 | Binder.restoreCallingIdentity(identity); |
| 7430 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7431 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7432 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7433 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7434 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7435 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7437 | mApp, subId, callingPackage, callingFeatureId, |
| 7438 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | return false; |
| 7440 | } |
| 7441 | |
| 7442 | final long identity = Binder.clearCallingIdentity(); |
| 7443 | try { |
| 7444 | CarrierConfigManager configManager = |
| 7445 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7446 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7448 | } finally { |
| 7449 | Binder.restoreCallingIdentity(identity); |
| 7450 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7451 | } |
| 7452 | |
| 7453 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7454 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7455 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7456 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7457 | return false; |
| 7458 | } |
| 7459 | |
| 7460 | final long identity = Binder.clearCallingIdentity(); |
| 7461 | try { |
| 7462 | CarrierConfigManager configManager = |
| 7463 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7464 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7465 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7466 | } finally { |
| 7467 | Binder.restoreCallingIdentity(identity); |
| 7468 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7469 | } |
| 7470 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7471 | @Override |
| 7472 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7473 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7474 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | @Override |
| 7478 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | final long identity = Binder.clearCallingIdentity(); |
| 7480 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7481 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7482 | } finally { |
| 7483 | Binder.restoreCallingIdentity(identity); |
| 7484 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7485 | } |
| 7486 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7487 | /** |
| 7488 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7489 | * support for the feature and device firmware support. |
| 7490 | * |
| 7491 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7492 | */ |
| 7493 | @Override |
| 7494 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7496 | final Phone phone = getPhone(subscriptionId); |
| 7497 | if (phone == null) { |
| 7498 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7499 | return false; |
| 7500 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7502 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7503 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7504 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7505 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | return isCarrierSupported && isDeviceSupported; |
| 7507 | } finally { |
| 7508 | Binder.restoreCallingIdentity(identity); |
| 7509 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7512 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7513 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7514 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7515 | * 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] | 7516 | */ |
| 7517 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7518 | final long identity = Binder.clearCallingIdentity(); |
| 7519 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7520 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7521 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7522 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7523 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7524 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7525 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | } finally { |
| 7527 | Binder.restoreCallingIdentity(identity); |
| 7528 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7529 | } |
| 7530 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7531 | @Deprecated |
| 7532 | @Override |
| 7533 | public String getDeviceId(String callingPackage) { |
| 7534 | return getDeviceIdWithFeature(callingPackage, null); |
| 7535 | } |
| 7536 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7537 | /** |
| 7538 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7539 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7540 | * |
| 7541 | * <p>Requires Permission: |
| 7542 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7543 | */ |
| 7544 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7545 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7546 | try { |
| 7547 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7548 | } catch (SecurityException se) { |
| 7549 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7550 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7551 | + Binder.getCallingUid()); |
| 7552 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7553 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7554 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7555 | return null; |
| 7556 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7557 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7558 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7559 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7560 | return null; |
| 7561 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | |
| 7563 | final long identity = Binder.clearCallingIdentity(); |
| 7564 | try { |
| 7565 | return phone.getDeviceId(); |
| 7566 | } finally { |
| 7567 | Binder.restoreCallingIdentity(identity); |
| 7568 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7569 | } |
| 7570 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7571 | /** |
| 7572 | * {@hide} |
| 7573 | * Returns the IMS Registration Status on a particular subid |
| 7574 | * |
| 7575 | * @param subId |
| 7576 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7577 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7578 | Phone phone = getPhone(subId); |
| 7579 | if (phone != null) { |
| 7580 | return phone.isImsRegistered(); |
| 7581 | } else { |
| 7582 | return false; |
| 7583 | } |
| 7584 | } |
| 7585 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7586 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7587 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7588 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7589 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7590 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7591 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7592 | } |
| 7593 | final long identity = Binder.clearCallingIdentity(); |
| 7594 | try { |
| 7595 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7596 | } finally { |
| 7597 | Binder.restoreCallingIdentity(identity); |
| 7598 | } |
| 7599 | } |
| 7600 | |
| 7601 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7602 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7603 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7604 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7605 | mApp, |
| 7606 | subscriptionId, |
| 7607 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7608 | final long identity = Binder.clearCallingIdentity(); |
| 7609 | try { |
| 7610 | Phone phone = getPhone(subscriptionId); |
| 7611 | if (phone == null) { |
| 7612 | return null; |
| 7613 | } |
| 7614 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7615 | } finally { |
| 7616 | Binder.restoreCallingIdentity(identity); |
| 7617 | } |
| 7618 | } |
| 7619 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7620 | /** |
| 7621 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7622 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7623 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7624 | final long identity = Binder.clearCallingIdentity(); |
| 7625 | try { |
| 7626 | Phone phone = getPhone(subId); |
| 7627 | if (phone != null) { |
| 7628 | return phone.isWifiCallingEnabled(); |
| 7629 | } else { |
| 7630 | return false; |
| 7631 | } |
| 7632 | } finally { |
| 7633 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7634 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7635 | } |
| 7636 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7637 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7638 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7639 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7640 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7641 | final long identity = Binder.clearCallingIdentity(); |
| 7642 | try { |
| 7643 | Phone phone = getPhone(subId); |
| 7644 | if (phone != null) { |
| 7645 | return phone.isVideoEnabled(); |
| 7646 | } else { |
| 7647 | return false; |
| 7648 | } |
| 7649 | } finally { |
| 7650 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7651 | } |
| 7652 | } |
| 7653 | |
| 7654 | /** |
| 7655 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7656 | * defined in {@link ImsRegistrationImplBase}. |
| 7657 | */ |
| 7658 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7659 | final long identity = Binder.clearCallingIdentity(); |
| 7660 | try { |
| 7661 | Phone phone = getPhone(subId); |
| 7662 | if (phone != null) { |
| 7663 | return phone.getImsRegistrationTech(); |
| 7664 | } else { |
| 7665 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7666 | } |
| 7667 | } finally { |
| 7668 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7669 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7670 | } |
| 7671 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7672 | @Override |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7673 | public void factoryReset(int subId, String callingPackage) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7674 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7675 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7676 | return; |
| 7677 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7678 | Phone defaultPhone = getDefaultPhone(); |
| 7679 | if (defaultPhone != null) { |
| 7680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7681 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7682 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7683 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7684 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7685 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7686 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7687 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7688 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 7689 | getDefaultDataEnabled(), callingPackage); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7690 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7691 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7692 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7693 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7694 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7695 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7696 | // There has been issues when Sms raw table somehow stores orphan |
| 7697 | // fragments. They lead to garbled message when new fragments come |
| 7698 | // in and combined with those stale ones. In case this happens again, |
| 7699 | // user can reset all network settings which will clean up this table. |
| 7700 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7701 | // Clean up IMS settings as well here. |
| 7702 | int slotId = getSlotIndex(subId); |
| 7703 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7704 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7705 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7706 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7707 | if (defaultPhone == null) { |
| 7708 | return; |
| 7709 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7710 | // Erase modem config if erase modem on network setting is enabled. |
| 7711 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7712 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7713 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7714 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7715 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7716 | |
| 7717 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7718 | } finally { |
| 7719 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7720 | } |
| 7721 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7722 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7723 | @VisibleForTesting |
| 7724 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7725 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7726 | return; |
| 7727 | } |
| 7728 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7729 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7730 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7731 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7732 | "user=" + defaultNetworkType); |
| 7733 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7734 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7735 | defaultNetworkType, null); |
| 7736 | } |
| 7737 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7738 | private void cleanUpSmsRawTable(Context context) { |
| 7739 | ContentResolver resolver = context.getContentResolver(); |
| 7740 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7741 | resolver.delete(uri, null, null); |
| 7742 | } |
| 7743 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7744 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7745 | public String getSimLocaleForSubscriber(int subId) { |
| 7746 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7747 | final Phone phone = getPhone(subId); |
| 7748 | if (phone == null) { |
| 7749 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7750 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7751 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | final long identity = Binder.clearCallingIdentity(); |
| 7753 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7754 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7755 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7756 | if (info == null) { |
| 7757 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7758 | return null; |
| 7759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7760 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7761 | // preferences (EF-PL and EF-LI)... |
| 7762 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7763 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7764 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7765 | if (localeFromDefaultSim != null) { |
| 7766 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7767 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7768 | + localeFromDefaultSim); |
| 7769 | return localeFromDefaultSim.toLanguageTag(); |
| 7770 | } else { |
| 7771 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7772 | } |
| 7773 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7774 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7775 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7776 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7777 | // the SIM and carrier preferences does not include a country we add the country |
| 7778 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7779 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7781 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | return mccLocale.toLanguageTag(); |
| 7783 | } |
| 7784 | |
| 7785 | if (DBG) log("No locale found - returning null"); |
| 7786 | return null; |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7790 | } |
| 7791 | |
| 7792 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7793 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7794 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7795 | } |
| 7796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | /** |
| 7798 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7799 | */ |
| 7800 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7801 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7802 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7803 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7804 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7805 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7806 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7807 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7808 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7809 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7810 | * representing the state of the modem. |
| 7811 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7812 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7813 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7814 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7815 | */ |
| 7816 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7817 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7818 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7819 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | |
| 7821 | final long identity = Binder.clearCallingIdentity(); |
| 7822 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7823 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7826 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7827 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7828 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7829 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7830 | // less than total activity duration. |
| 7831 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7832 | if (info == null) { |
| 7833 | return false; |
| 7834 | } |
| 7835 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7836 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7837 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7838 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7839 | return (info.isValid() |
| 7840 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7841 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7842 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7843 | && (totalTxTimeMs <= activityDurationMs)); |
| 7844 | } |
| 7845 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7846 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7847 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7848 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7849 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7850 | |
| 7851 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7852 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7853 | } |
| 7854 | |
| 7855 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7856 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7857 | rat, |
| 7858 | freq, |
| 7859 | info.getReceiveTimeMillis(rat, freq) |
| 7860 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7861 | } |
| 7862 | |
| 7863 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7864 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7865 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7866 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7867 | |
| 7868 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7869 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7870 | } |
| 7871 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7872 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7873 | rat, |
| 7874 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7875 | } |
| 7876 | |
| 7877 | /** |
| 7878 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7879 | * @param info recent ModemActivityInfo |
| 7880 | */ |
| 7881 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7882 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7883 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7884 | boolean matched; |
| 7885 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7886 | matched = false; |
| 7887 | int rat = info.getSpecificInfoRat(i); |
| 7888 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7889 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7890 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7891 | //if it already exists |
| 7892 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7893 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7894 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7895 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7896 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7897 | updateLastModemActivityInfo(info, rat, freq); |
| 7898 | matched = true; |
| 7899 | } |
| 7900 | } else { |
| 7901 | updateLastModemActivityInfo(info, rat); |
| 7902 | matched = true; |
| 7903 | } |
| 7904 | } |
| 7905 | } |
| 7906 | |
| 7907 | if (!matched) { |
| 7908 | mDeltaSpecificInfo = |
| 7909 | new ActivityStatsTechSpecificInfo( |
| 7910 | rat, |
| 7911 | freq, |
| 7912 | info.getTransmitTimeMillis(rat, freq), |
| 7913 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7914 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7915 | } |
| 7916 | } |
| 7917 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7918 | mLastModemActivitySpecificInfo = |
| 7919 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7920 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7921 | |
| 7922 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7923 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7924 | info.getSleepTimeMillis() |
| 7925 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7926 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7927 | info.getIdleTimeMillis() |
| 7928 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7929 | } |
| 7930 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7931 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7932 | * Returns the service state information on specified subscription. |
| 7933 | */ |
| 7934 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7935 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7936 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7937 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7938 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7939 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7940 | return null; |
| 7941 | } |
| 7942 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7943 | boolean hasFinePermission = false; |
| 7944 | boolean hasCoarsePermission = false; |
| 7945 | if (!renounceFineLocationAccess) { |
| 7946 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7947 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7948 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7949 | .setCallingPackage(callingPackage) |
| 7950 | .setCallingFeatureId(callingFeatureId) |
| 7951 | .setCallingPid(Binder.getCallingPid()) |
| 7952 | .setCallingUid(Binder.getCallingUid()) |
| 7953 | .setMethod("getServiceStateForSubscriber") |
| 7954 | .setLogAsInfo(true) |
| 7955 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7956 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7957 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7958 | .build()); |
| 7959 | hasFinePermission = |
| 7960 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7961 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7962 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7963 | if (!renounceCoarseLocationAccess) { |
| 7964 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7965 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7966 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7967 | .setCallingPackage(callingPackage) |
| 7968 | .setCallingFeatureId(callingFeatureId) |
| 7969 | .setCallingPid(Binder.getCallingPid()) |
| 7970 | .setCallingUid(Binder.getCallingUid()) |
| 7971 | .setMethod("getServiceStateForSubscriber") |
| 7972 | .setLogAsInfo(true) |
| 7973 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7974 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7975 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7976 | .build()); |
| 7977 | hasCoarsePermission = |
| 7978 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7979 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7980 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7981 | final Phone phone = getPhone(subId); |
| 7982 | if (phone == null) { |
| 7983 | return null; |
| 7984 | } |
| 7985 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7986 | final long identity = Binder.clearCallingIdentity(); |
| 7987 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7988 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7989 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7990 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7991 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7992 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7993 | Rlog.d(LOG_TAG, |
| 7994 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7995 | return null; |
| 7996 | } |
| 7997 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7998 | ServiceState ss = phone.getServiceState(); |
| 7999 | |
| 8000 | // Scrub out the location info in ServiceState depending on what level of access |
| 8001 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8002 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8003 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8004 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8005 | } finally { |
| 8006 | Binder.restoreCallingIdentity(identity); |
| 8007 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8008 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8009 | |
| 8010 | /** |
| 8011 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8012 | * |
| 8013 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8014 | * voicemail ringtone. |
| 8015 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8016 | * PhoneAccount. |
| 8017 | */ |
| 8018 | @Override |
| 8019 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8020 | final long identity = Binder.clearCallingIdentity(); |
| 8021 | try { |
| 8022 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8023 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8024 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8027 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8028 | } finally { |
| 8029 | Binder.restoreCallingIdentity(identity); |
| 8030 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8031 | } |
| 8032 | |
| 8033 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8034 | * Sets the per-account voicemail ringtone. |
| 8035 | * |
| 8036 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8037 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8038 | * |
| 8039 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8040 | * voicemail ringtone. |
| 8041 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8042 | * PhoneAccount. |
| 8043 | */ |
| 8044 | @Override |
| 8045 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8046 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8047 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8048 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8049 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8050 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8051 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8052 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8053 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8054 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | |
| 8056 | final long identity = Binder.clearCallingIdentity(); |
| 8057 | try { |
| 8058 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8059 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8060 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8061 | } |
| 8062 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8063 | } finally { |
| 8064 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8065 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8066 | } |
| 8067 | |
| 8068 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8069 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8070 | * |
| 8071 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8072 | * voicemail vibration setting. |
| 8073 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8074 | */ |
| 8075 | @Override |
| 8076 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8077 | final long identity = Binder.clearCallingIdentity(); |
| 8078 | try { |
| 8079 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8080 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8081 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8083 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8085 | } finally { |
| 8086 | Binder.restoreCallingIdentity(identity); |
| 8087 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8088 | } |
| 8089 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8090 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8091 | * Sets the per-account voicemail vibration. |
| 8092 | * |
| 8093 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8094 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8095 | * |
| 8096 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8097 | * voicemail vibration setting. |
| 8098 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8099 | * specific PhoneAccount. |
| 8100 | */ |
| 8101 | @Override |
| 8102 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8103 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8104 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8105 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8106 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8107 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8109 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8110 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8111 | } |
| 8112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8113 | final long identity = Binder.clearCallingIdentity(); |
| 8114 | try { |
| 8115 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8116 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8117 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | } |
| 8119 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8120 | } finally { |
| 8121 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8122 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8123 | } |
| 8124 | |
| 8125 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8126 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8127 | * |
| 8128 | * @throws SecurityException if the caller does not have the required permission |
| 8129 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8130 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8131 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8132 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8133 | } |
| 8134 | |
| 8135 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8136 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8137 | * permission. |
| 8138 | * |
| 8139 | * @throws SecurityException if the caller does not have the required permission |
| 8140 | */ |
| 8141 | private void enforceSendSmsPermission() { |
| 8142 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8143 | } |
| 8144 | |
| 8145 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8146 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8147 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8148 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8149 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8150 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8151 | final long identity = Binder.clearCallingIdentity(); |
| 8152 | try { |
| 8153 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8154 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8155 | if (componentName == null) { |
| 8156 | throw new SecurityException( |
| 8157 | "Caller not current active visual voicemail package[null]"); |
| 8158 | } |
| 8159 | String vvmPackage = componentName.getPackageName(); |
| 8160 | if (!callingPackage.equals(vvmPackage)) { |
| 8161 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8162 | + vvmPackage + "]"); |
| 8163 | } |
| 8164 | } finally { |
| 8165 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8166 | } |
| 8167 | } |
| 8168 | |
| 8169 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8170 | * Return the application ID for the app type. |
| 8171 | * |
| 8172 | * @param subId the subscription ID that this request applies to. |
| 8173 | * @param appType the uicc app type. |
| 8174 | * @return Application ID for specificied app type, or null if no uicc. |
| 8175 | */ |
| 8176 | @Override |
| 8177 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8178 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8179 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8180 | |
| 8181 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8182 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8183 | if (phone == null) { |
| 8184 | return null; |
| 8185 | } |
| 8186 | String aid = null; |
| 8187 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8188 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | .getApplicationByType(appType).getAid(); |
| 8190 | } catch (Exception e) { |
| 8191 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8192 | } |
| 8193 | return aid; |
| 8194 | } finally { |
| 8195 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8196 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8197 | } |
| 8198 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8199 | /** |
| 8200 | * Return the Electronic Serial Number. |
| 8201 | * |
| 8202 | * @param subId the subscription ID that this request applies to. |
| 8203 | * @return ESN or null if error. |
| 8204 | */ |
| 8205 | @Override |
| 8206 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8207 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8208 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8209 | |
| 8210 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8211 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8212 | if (phone == null) { |
| 8213 | return null; |
| 8214 | } |
| 8215 | String esn = null; |
| 8216 | try { |
| 8217 | esn = phone.getEsn(); |
| 8218 | } catch (Exception e) { |
| 8219 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8220 | } |
| 8221 | return esn; |
| 8222 | } finally { |
| 8223 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8224 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8225 | } |
| 8226 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8227 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8228 | * Return the Preferred Roaming List Version. |
| 8229 | * |
| 8230 | * @param subId the subscription ID that this request applies to. |
| 8231 | * @return PRLVersion or null if error. |
| 8232 | */ |
| 8233 | @Override |
| 8234 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8235 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8236 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8237 | |
| 8238 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8239 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8240 | if (phone == null) { |
| 8241 | return null; |
| 8242 | } |
| 8243 | String cdmaPrlVersion = null; |
| 8244 | try { |
| 8245 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8246 | } catch (Exception e) { |
| 8247 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8248 | } |
| 8249 | return cdmaPrlVersion; |
| 8250 | } finally { |
| 8251 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8252 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8253 | } |
| 8254 | |
| 8255 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8256 | * Get snapshot of Telephony histograms |
| 8257 | * @return List of Telephony histograms |
| 8258 | * @hide |
| 8259 | */ |
| 8260 | @Override |
| 8261 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8263 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8264 | |
| 8265 | final long identity = Binder.clearCallingIdentity(); |
| 8266 | try { |
| 8267 | return RIL.getTelephonyRILTimingHistograms(); |
| 8268 | } finally { |
| 8269 | Binder.restoreCallingIdentity(identity); |
| 8270 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8271 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8272 | |
| 8273 | /** |
| 8274 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8275 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8276 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8277 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8278 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8279 | * @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] | 8280 | */ |
| 8281 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8282 | @TelephonyManager.SetCarrierRestrictionResult |
| 8283 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8284 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8285 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8286 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8287 | if (carrierRestrictionRules == null) { |
| 8288 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8289 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8290 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8291 | final long identity = Binder.clearCallingIdentity(); |
| 8292 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8293 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8294 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8295 | } finally { |
| 8296 | Binder.restoreCallingIdentity(identity); |
| 8297 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8298 | } |
| 8299 | |
| 8300 | /** |
| 8301 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8302 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8303 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8304 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8305 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8306 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8307 | */ |
| 8308 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8309 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8310 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8311 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8312 | |
| 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8315 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8316 | if (response instanceof CarrierRestrictionRules) { |
| 8317 | return (CarrierRestrictionRules) response; |
| 8318 | } |
| 8319 | // Response is an Exception of some kind, |
| 8320 | // which is signalled to the user as a NULL retval |
| 8321 | return null; |
| 8322 | } catch (Exception e) { |
| 8323 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8324 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8325 | } finally { |
| 8326 | Binder.restoreCallingIdentity(identity); |
| 8327 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8328 | } |
| 8329 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8330 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8331 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8332 | * @param subId the subscription ID that this action applies to. |
| 8333 | * @param enabled control enable or disable radio. |
| 8334 | * {@hide} |
| 8335 | */ |
| 8336 | @Override |
| 8337 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8338 | enforceModifyPermission(); |
| 8339 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8340 | |
| 8341 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8342 | if (phone == null) { |
| 8343 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8344 | return; |
| 8345 | } |
| 8346 | try { |
| 8347 | phone.carrierActionSetRadioEnabled(enabled); |
| 8348 | } catch (Exception e) { |
| 8349 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8350 | } finally { |
| 8351 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8352 | } |
| 8353 | } |
| 8354 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8355 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8356 | * Enable or disable Voice over NR (VoNR) |
| 8357 | * @param subId the subscription ID that this action applies to. |
| 8358 | * @param enabled enable or disable VoNR. |
| 8359 | * @return operation result. |
| 8360 | */ |
| 8361 | @Override |
| 8362 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8363 | enforceModifyPermission(); |
| 8364 | final Phone phone = getPhone(subId); |
| 8365 | |
| 8366 | final long identity = Binder.clearCallingIdentity(); |
| 8367 | if (phone == null) { |
| 8368 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8369 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8370 | } |
| 8371 | |
| 8372 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8373 | try { |
| 8374 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8375 | workSource); |
| 8376 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8377 | |
| 8378 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8379 | if (DBG) { |
| 8380 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8381 | } |
| 8382 | SubscriptionManager.setSubscriptionProperty( |
| 8383 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8384 | (enabled ? "1" : "0")); |
| 8385 | } |
| 8386 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8387 | return result; |
| 8388 | } finally { |
| 8389 | Binder.restoreCallingIdentity(identity); |
| 8390 | } |
| 8391 | } |
| 8392 | |
| 8393 | /** |
| 8394 | * Is voice over NR enabled |
| 8395 | * @return true if VoNR is enabled else false |
| 8396 | */ |
| 8397 | @Override |
| 8398 | public boolean isVoNrEnabled(int subId) { |
| 8399 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8400 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8401 | final long identity = Binder.clearCallingIdentity(); |
| 8402 | try { |
| 8403 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8404 | null, subId, workSource); |
| 8405 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8406 | return isEnabled; |
| 8407 | } finally { |
| 8408 | Binder.restoreCallingIdentity(identity); |
| 8409 | } |
| 8410 | } |
| 8411 | |
| 8412 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8413 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8414 | * network status based on which carrier apps could apply actions accordingly, |
| 8415 | * enable/disable default url handler for example. |
| 8416 | * |
| 8417 | * @param subId the subscription ID that this action applies to. |
| 8418 | * @param report control start/stop reporting the default network status. |
| 8419 | * {@hide} |
| 8420 | */ |
| 8421 | @Override |
| 8422 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8423 | enforceModifyPermission(); |
| 8424 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8425 | |
| 8426 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8427 | if (phone == null) { |
| 8428 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8429 | return; |
| 8430 | } |
| 8431 | try { |
| 8432 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8433 | } catch (Exception e) { |
| 8434 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8435 | } finally { |
| 8436 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8437 | } |
| 8438 | } |
| 8439 | |
| 8440 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8441 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8442 | * @param subId the subscription ID that this action applies to. |
| 8443 | * {@hide} |
| 8444 | */ |
| 8445 | @Override |
| 8446 | public void carrierActionResetAll(int subId) { |
| 8447 | enforceModifyPermission(); |
| 8448 | final Phone phone = getPhone(subId); |
| 8449 | if (phone == null) { |
| 8450 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8451 | return; |
| 8452 | } |
| 8453 | try { |
| 8454 | phone.carrierActionResetAll(); |
| 8455 | } catch (Exception e) { |
| 8456 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8461 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8462 | * bug report is being generated. |
| 8463 | */ |
| 8464 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8465 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8466 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8467 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8468 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8469 | + Binder.getCallingPid() |
| 8470 | + ", uid=" + Binder.getCallingUid() |
| 8471 | + "without permission " |
| 8472 | + android.Manifest.permission.DUMP); |
| 8473 | return; |
| 8474 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8475 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8476 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8477 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8478 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8479 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8480 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8481 | @NonNull String[] args) { |
| 8482 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8483 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8484 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8485 | } |
| 8486 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8487 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8488 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8489 | * @param subId Subscription index |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8490 | * @param reason The reason the data enable change is taking place. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8491 | * @param enabled True if enabling the data, otherwise disabling. |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8492 | * @param callingPackage The package that changed the data enabled state. |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8493 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8494 | */ |
| 8495 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8496 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 8497 | boolean enabled, String callingPackage) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8498 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8499 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8500 | try { |
| 8501 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8502 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8503 | } catch (SecurityException se) { |
| 8504 | enforceModifyPermission(); |
| 8505 | } |
| 8506 | } else { |
| 8507 | enforceModifyPermission(); |
| 8508 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8509 | |
| 8510 | final long identity = Binder.clearCallingIdentity(); |
| 8511 | try { |
| 8512 | Phone phone = getPhone(subId); |
| 8513 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8514 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8515 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8516 | } else { |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 8517 | phone.getDataSettingsManager().setDataEnabled( |
| 8518 | reason, enabled, callingPackage); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8520 | } |
| 8521 | } finally { |
| 8522 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8523 | } |
| 8524 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8525 | |
| 8526 | /** |
| 8527 | * Get Client request stats |
| 8528 | * @return List of Client Request Stats |
| 8529 | * @hide |
| 8530 | */ |
| 8531 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8532 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8533 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8534 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8535 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8536 | return null; |
| 8537 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8538 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8539 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8540 | final long identity = Binder.clearCallingIdentity(); |
| 8541 | try { |
| 8542 | if (phone != null) { |
| 8543 | return phone.getClientRequestStats(); |
| 8544 | } |
| 8545 | |
| 8546 | return null; |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
| 8549 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8550 | } |
| 8551 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8552 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8553 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame] | 8554 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8555 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8556 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8557 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8558 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8559 | // commands that plumb through the RIL as root, like so: |
| 8560 | // $ adb root |
| 8561 | // $ adb shell cmd phone ... |
| 8562 | packageName = "root"; |
| 8563 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8564 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8565 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8566 | |
| 8567 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8568 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8569 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8570 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8571 | * @param state State of SIM (power down, power up, pass through) |
| 8572 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8573 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8574 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8575 | * |
| 8576 | **/ |
| 8577 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8578 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8579 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8580 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8581 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8582 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8583 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8584 | final long identity = Binder.clearCallingIdentity(); |
| 8585 | try { |
| 8586 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8587 | phone.setSimPowerState(state, null, workSource); |
| 8588 | } |
| 8589 | } finally { |
| 8590 | Binder.restoreCallingIdentity(identity); |
| 8591 | } |
| 8592 | } |
| 8593 | |
| 8594 | /** |
| 8595 | * Set SIM card power state. |
| 8596 | * |
| 8597 | * @param slotIndex SIM slot id. |
| 8598 | * @param state State of SIM (power down, power up, pass through) |
| 8599 | * @param callback callback to trigger after success or failure |
| 8600 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8601 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8602 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8603 | * |
| 8604 | **/ |
| 8605 | @Override |
| 8606 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8607 | IIntegerConsumer callback) { |
| 8608 | enforceModifyPermission(); |
| 8609 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8610 | |
| 8611 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8612 | |
| 8613 | final long identity = Binder.clearCallingIdentity(); |
| 8614 | try { |
| 8615 | if (phone != null) { |
| 8616 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8617 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8618 | } |
| 8619 | } finally { |
| 8620 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8621 | } |
| 8622 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8623 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8624 | private boolean isUssdApiAllowed(int subId) { |
| 8625 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8626 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8627 | if (configManager == null) { |
| 8628 | return false; |
| 8629 | } |
| 8630 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8631 | if (pb == null) { |
| 8632 | return false; |
| 8633 | } |
| 8634 | return pb.getBoolean( |
| 8635 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8636 | } |
| 8637 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8638 | /** |
| 8639 | * Check if phone is in emergency callback mode |
| 8640 | * @return true if phone is in emergency callback mode |
| 8641 | * @param subId sub id |
| 8642 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8643 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8644 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8645 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8646 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8647 | |
| 8648 | final long identity = Binder.clearCallingIdentity(); |
| 8649 | try { |
| 8650 | if (phone != null) { |
| 8651 | return phone.isInEcm(); |
| 8652 | } else { |
| 8653 | return false; |
| 8654 | } |
| 8655 | } finally { |
| 8656 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8657 | } |
| 8658 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8659 | |
| 8660 | /** |
| 8661 | * Get the current signal strength information for the given subscription. |
| 8662 | * Because this information is not updated when the device is in a low power state |
| 8663 | * it should not be relied-upon to be current. |
| 8664 | * @param subId Subscription index |
| 8665 | * @return the most recent cached signal strength info from the modem |
| 8666 | */ |
| 8667 | @Override |
| 8668 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8669 | final long identity = Binder.clearCallingIdentity(); |
| 8670 | try { |
| 8671 | Phone p = getPhone(subId); |
| 8672 | if (p == null) { |
| 8673 | return null; |
| 8674 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8675 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8676 | return p.getSignalStrength(); |
| 8677 | } finally { |
| 8678 | Binder.restoreCallingIdentity(identity); |
| 8679 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8680 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8681 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8682 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8683 | * Get the current modem radio state for the given slot. |
| 8684 | * @param slotIndex slot index. |
| 8685 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8686 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8687 | * @return the current radio power state from the modem |
| 8688 | */ |
| 8689 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8690 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8691 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8692 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8693 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8694 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8695 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8696 | } |
| 8697 | |
| 8698 | final long identity = Binder.clearCallingIdentity(); |
| 8699 | try { |
| 8700 | return phone.getRadioPowerState(); |
| 8701 | } finally { |
| 8702 | Binder.restoreCallingIdentity(identity); |
| 8703 | } |
| 8704 | } |
| 8705 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8706 | } |
| 8707 | |
| 8708 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8709 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8710 | * |
| 8711 | * <p>Requires one of the following permissions: |
| 8712 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8713 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8714 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8715 | * privileges. |
| 8716 | * |
| 8717 | * @param subId subscription id |
| 8718 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8719 | * {@code false}. |
| 8720 | */ |
| 8721 | @Override |
| 8722 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8723 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8724 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8725 | try { |
| 8726 | mApp.enforceCallingOrSelfPermission( |
| 8727 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8728 | functionName); |
| 8729 | } catch (Exception e) { |
| 8730 | mApp.enforceCallingOrSelfPermission( |
| 8731 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8732 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8733 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8734 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8735 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8736 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8737 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8738 | boolean isEnabled = false; |
| 8739 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8740 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8741 | Phone phone = getPhone(subId); |
| 8742 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8743 | } finally { |
| 8744 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8745 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8746 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8747 | } |
| 8748 | |
| 8749 | |
| 8750 | /** |
| 8751 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8752 | * |
| 8753 | * <p> Requires permission: |
| 8754 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8755 | * privileges. |
| 8756 | * |
| 8757 | * @param subId subscription id |
| 8758 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8759 | */ |
| 8760 | @Override |
| 8761 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8763 | mApp, subId, "setDataRoamingEnabled"); |
| 8764 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8767 | Phone phone = getPhone(subId); |
| 8768 | if (phone != null) { |
| 8769 | phone.setDataRoamingEnabled(isEnabled); |
| 8770 | } |
| 8771 | } finally { |
| 8772 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8773 | } |
| 8774 | } |
| 8775 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8776 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8777 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8778 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8779 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8780 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8781 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8782 | boolean isAllowed = true; |
| 8783 | final long identity = Binder.clearCallingIdentity(); |
| 8784 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8785 | Phone phone = getPhone(subId); |
| 8786 | if (phone != null) { |
| 8787 | isAllowed = phone.isCspPlmnEnabled(); |
| 8788 | } |
| 8789 | } finally { |
| 8790 | Binder.restoreCallingIdentity(identity); |
| 8791 | } |
| 8792 | return isAllowed; |
| 8793 | } |
| 8794 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8795 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8796 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8797 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8798 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8799 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8800 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8801 | if (phone == null) { |
| 8802 | return false; |
| 8803 | } |
| 8804 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8805 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8806 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8807 | } |
| 8808 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8809 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8810 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8811 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8812 | mApp.getSystemService(AppOpsManager.class) |
| 8813 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8814 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8815 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8816 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8817 | try { |
| 8818 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8819 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8820 | } catch (SecurityException e) { |
| 8821 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8822 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8823 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8824 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8825 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8826 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8827 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8828 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8829 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8830 | Binder.getCallingUid())) { |
| 8831 | isIccIdAccessRestricted = true; |
| 8832 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8833 | final long identity = Binder.clearCallingIdentity(); |
| 8834 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8835 | UiccController uiccController = UiccController.getInstance(); |
| 8836 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8837 | if (hasReadPermission) { |
| 8838 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8839 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8840 | |
| 8841 | // Remove private info if the caller doesn't have access |
| 8842 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8843 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8844 | //setting the value after compatibility check |
| 8845 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8846 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8847 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8848 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8849 | if (card == null) { |
| 8850 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8851 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8852 | continue; |
| 8853 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8854 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8855 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8856 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8857 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8858 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8859 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8860 | for (UiccPortInfo portInfo : portInfos) { |
| 8861 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8862 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8863 | if (port == null) { |
| 8864 | // assume no access if port is null |
| 8865 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8866 | continue; |
| 8867 | } |
| 8868 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8869 | uiccPortInfos.add(portInfo); |
| 8870 | } else { |
| 8871 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8872 | } |
| 8873 | } |
| 8874 | filteredInfos.add(new UiccCardInfo( |
| 8875 | cardInfo.isEuicc(), |
| 8876 | cardInfo.getCardId(), |
| 8877 | null, |
| 8878 | cardInfo.getPhysicalSlotIndex(), |
| 8879 | cardInfo.isRemovable(), |
| 8880 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8881 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8882 | } |
| 8883 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8884 | } finally { |
| 8885 | Binder.restoreCallingIdentity(identity); |
| 8886 | } |
| 8887 | } |
| 8888 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8889 | /** |
| 8890 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8891 | * generally private and require carrier privileges to view. |
| 8892 | * |
| 8893 | * @hide |
| 8894 | */ |
| 8895 | @NonNull |
| 8896 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8897 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8898 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8899 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8900 | } |
| 8901 | return new UiccCardInfo( |
| 8902 | cardInfo.isEuicc(), |
| 8903 | cardInfo.getCardId(), |
| 8904 | null, |
| 8905 | cardInfo.getPhysicalSlotIndex(), |
| 8906 | cardInfo.isRemovable(), |
| 8907 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8908 | portinfo |
| 8909 | ); |
| 8910 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8911 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8912 | /** |
| 8913 | * @hide |
| 8914 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8915 | * These values are generally private and require carrier privileges to view. |
| 8916 | */ |
| 8917 | @NonNull |
| 8918 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8919 | return new UiccPortInfo( |
| 8920 | UiccPortInfo.ICCID_REDACTED, |
| 8921 | portInfo.getPortIndex(), |
| 8922 | portInfo.getLogicalSlotIndex(), |
| 8923 | portInfo.isActive() |
| 8924 | ); |
| 8925 | } |
| 8926 | @Override |
| 8927 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8928 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8929 | mApp.getSystemService(AppOpsManager.class) |
| 8930 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8931 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8932 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8933 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8934 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8935 | // we are reading iccId which is PII data. |
| 8936 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8937 | |
| 8938 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8939 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8940 | Binder.getCallingUid())) { |
| 8941 | isLogicalSlotAccessRestricted = true; |
| 8942 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8943 | final long identity = Binder.clearCallingIdentity(); |
| 8944 | try { |
| 8945 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8946 | if (slots == null || slots.length == 0) { |
| 8947 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8948 | return null; |
| 8949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8950 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8951 | for (int i = 0; i < slots.length; i++) { |
| 8952 | UiccSlot slot = slots[i]; |
| 8953 | if (slot == null) { |
| 8954 | continue; |
| 8955 | } |
| 8956 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8957 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8958 | UiccCard card = slot.getUiccCard(); |
| 8959 | if (card != null) { |
| 8960 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8961 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8962 | cardId = slot.getEid(); |
| 8963 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8964 | // If cardId is null, use iccId of default port as cardId. |
| 8965 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8966 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8967 | } |
| 8968 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8969 | if (cardId != null) { |
| 8970 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8971 | // if cardId is an EID, it's all digits so this is fine |
| 8972 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8973 | } |
| 8974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8975 | int cardState = 0; |
| 8976 | switch (slot.getCardState()) { |
| 8977 | case CARDSTATE_ABSENT: |
| 8978 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8979 | break; |
| 8980 | case CARDSTATE_PRESENT: |
| 8981 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8982 | break; |
| 8983 | case CARDSTATE_ERROR: |
| 8984 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8985 | break; |
| 8986 | case CARDSTATE_RESTRICTED: |
| 8987 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8988 | break; |
| 8989 | default: |
| 8990 | break; |
| 8991 | |
| 8992 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8993 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8994 | int[] portIndexes = slot.getPortList(); |
| 8995 | for (int portIdx : portIndexes) { |
| 8996 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame] | 8997 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 8998 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 8999 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9001 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9002 | slot.isEuicc(), |
| 9003 | cardId, |
| 9004 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9005 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9006 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9007 | //setting the value after compatibility check |
| 9008 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9009 | } |
| 9010 | return infos; |
| 9011 | } finally { |
| 9012 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9013 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9014 | } |
| 9015 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9016 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9017 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9018 | boolean hasReadPermission) { |
| 9019 | String iccId = slot.getIccId(portIndex); |
| 9020 | if (hasReadPermission) { // if has read permission |
| 9021 | return iccId; |
| 9022 | } else { |
| 9023 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9024 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9025 | // if no read permission, checking carrier privilege access |
| 9026 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9027 | return iccId; |
| 9028 | } |
| 9029 | } |
| 9030 | } |
| 9031 | // No read permission or carrier privilege access. |
| 9032 | return UiccPortInfo.ICCID_REDACTED; |
| 9033 | } |
| 9034 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9035 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9036 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9037 | public boolean switchSlots(int[] physicalSlots) { |
| 9038 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9039 | |
| 9040 | final long identity = Binder.clearCallingIdentity(); |
| 9041 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9042 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9043 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9044 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9045 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9046 | physicalSlots[i], i)); |
| 9047 | } |
| 9048 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9049 | } finally { |
| 9050 | Binder.restoreCallingIdentity(identity); |
| 9051 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9052 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9053 | |
| 9054 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9055 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9056 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9057 | enforceModifyPermission(); |
| 9058 | |
| 9059 | final long identity = Binder.clearCallingIdentity(); |
| 9060 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9061 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9062 | } finally { |
| 9063 | Binder.restoreCallingIdentity(identity); |
| 9064 | } |
| 9065 | } |
| 9066 | |
| 9067 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9068 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9069 | final long identity = Binder.clearCallingIdentity(); |
| 9070 | try { |
| 9071 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9072 | } finally { |
| 9073 | Binder.restoreCallingIdentity(identity); |
| 9074 | } |
| 9075 | } |
| 9076 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9077 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9078 | * A test API to reload the UICC profile. |
| 9079 | * |
| 9080 | * <p>Requires that the calling app has permission |
| 9081 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9082 | * @hide |
| 9083 | */ |
| 9084 | @Override |
| 9085 | public void refreshUiccProfile(int subId) { |
| 9086 | enforceModifyPermission(); |
| 9087 | |
| 9088 | final long identity = Binder.clearCallingIdentity(); |
| 9089 | try { |
| 9090 | Phone phone = getPhone(subId); |
| 9091 | if (phone == null) { |
| 9092 | return; |
| 9093 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9094 | UiccPort uiccPort = phone.getUiccPort(); |
| 9095 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9096 | return; |
| 9097 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9098 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9099 | if (uiccProfile == null) { |
| 9100 | return; |
| 9101 | } |
| 9102 | uiccProfile.refresh(); |
| 9103 | } finally { |
| 9104 | Binder.restoreCallingIdentity(identity); |
| 9105 | } |
| 9106 | } |
| 9107 | |
| 9108 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9109 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9110 | */ |
| 9111 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9112 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9113 | } |
| 9114 | |
| 9115 | /** |
| 9116 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9117 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9118 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9119 | */ |
| 9120 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9121 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9122 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9123 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9124 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9125 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9126 | return isDataRoamingEnabled; |
| 9127 | } |
| 9128 | |
| 9129 | /** |
| 9130 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9131 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9132 | */ |
| 9133 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9134 | List<Integer> list = TelephonyProperties.default_network(); |
| 9135 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9136 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9137 | return list.get(phoneId); |
| 9138 | } |
| 9139 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9140 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9141 | |
| 9142 | @Override |
| 9143 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9144 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9145 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9146 | |
| 9147 | final long identity = Binder.clearCallingIdentity(); |
| 9148 | try { |
| 9149 | final Phone phone = getPhone(subId); |
| 9150 | if (phone == null) { |
| 9151 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9152 | return; |
| 9153 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9154 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9155 | if (cpt != null) { |
| 9156 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9157 | } |
| 9158 | // 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] | 9159 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9160 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9161 | if (carrierPrivilegeRules == null) { |
| 9162 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9163 | } else { |
| 9164 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9166 | } finally { |
| 9167 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9168 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9169 | } |
| 9170 | |
| 9171 | @Override |
| 9172 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9173 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9174 | |
| 9175 | final long identity = Binder.clearCallingIdentity(); |
| 9176 | try { |
| 9177 | final Phone phone = getPhone(subId); |
| 9178 | if (phone == null) { |
| 9179 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9180 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9181 | } |
| 9182 | return phone.getCarrierIdListVersion(); |
| 9183 | } finally { |
| 9184 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9185 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9186 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9187 | |
| 9188 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9189 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9190 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9192 | mApp, subId, callingPackage, callingFeatureId, |
| 9193 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9194 | return -1; |
| 9195 | } |
| 9196 | |
| 9197 | final long identity = Binder.clearCallingIdentity(); |
| 9198 | try { |
| 9199 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9200 | } finally { |
| 9201 | Binder.restoreCallingIdentity(identity); |
| 9202 | } |
| 9203 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9204 | |
| 9205 | @Override |
| 9206 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9207 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9208 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9209 | mApp, subId, "getCdmaRoamingMode"); |
| 9210 | |
| 9211 | final long identity = Binder.clearCallingIdentity(); |
| 9212 | try { |
| 9213 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9214 | } finally { |
| 9215 | Binder.restoreCallingIdentity(identity); |
| 9216 | } |
| 9217 | } |
| 9218 | |
| 9219 | @Override |
| 9220 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9222 | mApp, subId, "setCdmaRoamingMode"); |
| 9223 | |
| 9224 | final long identity = Binder.clearCallingIdentity(); |
| 9225 | try { |
| 9226 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9227 | } finally { |
| 9228 | Binder.restoreCallingIdentity(identity); |
| 9229 | } |
| 9230 | } |
| 9231 | |
| 9232 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9233 | public int getCdmaSubscriptionMode(int subId) { |
| 9234 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9235 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9236 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9237 | |
| 9238 | final long identity = Binder.clearCallingIdentity(); |
| 9239 | try { |
| 9240 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9241 | } finally { |
| 9242 | Binder.restoreCallingIdentity(identity); |
| 9243 | } |
| 9244 | } |
| 9245 | |
| 9246 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9247 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9249 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9250 | |
| 9251 | final long identity = Binder.clearCallingIdentity(); |
| 9252 | try { |
| 9253 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9254 | } finally { |
| 9255 | Binder.restoreCallingIdentity(identity); |
| 9256 | } |
| 9257 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9258 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9259 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9260 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9261 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9262 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9263 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9264 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9265 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9266 | } |
| 9267 | final long identity = Binder.clearCallingIdentity(); |
| 9268 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9269 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9270 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9271 | if (phone.getEmergencyNumberTracker() != null |
| 9272 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9273 | emergencyNumberListInternal.put( |
| 9274 | phone.getSubId(), |
| 9275 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9276 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9277 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9278 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9279 | } finally { |
| 9280 | Binder.restoreCallingIdentity(identity); |
| 9281 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9282 | } |
| 9283 | |
| 9284 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9285 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9286 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9287 | if (!exactMatch) { |
| 9288 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9289 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9290 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9291 | } |
| 9292 | final long identity = Binder.clearCallingIdentity(); |
| 9293 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9294 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9295 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9296 | && phone.getEmergencyNumberTracker() |
| 9297 | .isEmergencyNumber(number, exactMatch)) { |
| 9298 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9299 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9300 | } |
| 9301 | return false; |
| 9302 | } finally { |
| 9303 | Binder.restoreCallingIdentity(identity); |
| 9304 | } |
| 9305 | } |
| 9306 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9307 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9308 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9309 | */ |
| 9310 | @Override |
| 9311 | public void startEmergencyCallbackMode() { |
| 9312 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9313 | "startEmergencyCallbackMode"); |
| 9314 | enforceModifyPermission(); |
| 9315 | final long identity = Binder.clearCallingIdentity(); |
| 9316 | try { |
| 9317 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9318 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9319 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9320 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9321 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9322 | gsmCdmaPhone.obtainMessage( |
| 9323 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9324 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9325 | } |
| 9326 | } |
| 9327 | } finally { |
| 9328 | Binder.restoreCallingIdentity(identity); |
| 9329 | } |
| 9330 | } |
| 9331 | |
| 9332 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9333 | * Update emergency number list for test mode. |
| 9334 | */ |
| 9335 | @Override |
| 9336 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9337 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9338 | "updateEmergencyNumberListTestMode"); |
| 9339 | |
| 9340 | final long identity = Binder.clearCallingIdentity(); |
| 9341 | try { |
| 9342 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9343 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9344 | if (tracker != null) { |
| 9345 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9346 | } |
| 9347 | } |
| 9348 | } finally { |
| 9349 | Binder.restoreCallingIdentity(identity); |
| 9350 | } |
| 9351 | } |
| 9352 | |
| 9353 | /** |
| 9354 | * Get the full emergency number list for test mode. |
| 9355 | */ |
| 9356 | @Override |
| 9357 | public List<String> getEmergencyNumberListTestMode() { |
| 9358 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9359 | "getEmergencyNumberListTestMode"); |
| 9360 | |
| 9361 | final long identity = Binder.clearCallingIdentity(); |
| 9362 | try { |
| 9363 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9364 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9365 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9366 | if (tracker != null) { |
| 9367 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9368 | emergencyNumbers.add(num.getNumber()); |
| 9369 | } |
| 9370 | } |
| 9371 | } |
| 9372 | return new ArrayList<>(emergencyNumbers); |
| 9373 | } finally { |
| 9374 | Binder.restoreCallingIdentity(identity); |
| 9375 | } |
| 9376 | } |
| 9377 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9378 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9379 | public int getEmergencyNumberDbVersion(int subId) { |
| 9380 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9381 | |
| 9382 | final long identity = Binder.clearCallingIdentity(); |
| 9383 | try { |
| 9384 | final Phone phone = getPhone(subId); |
| 9385 | if (phone == null) { |
| 9386 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9387 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9388 | } |
| 9389 | return phone.getEmergencyNumberDbVersion(); |
| 9390 | } finally { |
| 9391 | Binder.restoreCallingIdentity(identity); |
| 9392 | } |
| 9393 | } |
| 9394 | |
| 9395 | @Override |
| 9396 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9397 | enforceModifyPermission(); |
| 9398 | |
| 9399 | final long identity = Binder.clearCallingIdentity(); |
| 9400 | try { |
| 9401 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9402 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9403 | if (tracker != null) { |
| 9404 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9405 | } |
| 9406 | } |
| 9407 | } finally { |
| 9408 | Binder.restoreCallingIdentity(identity); |
| 9409 | } |
| 9410 | } |
| 9411 | |
| 9412 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9413 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9414 | enforceActiveEmergencySessionPermission(); |
| 9415 | |
| 9416 | final long identity = Binder.clearCallingIdentity(); |
| 9417 | try { |
| 9418 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9419 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9420 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9421 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9422 | } |
| 9423 | } |
| 9424 | } finally { |
| 9425 | Binder.restoreCallingIdentity(identity); |
| 9426 | } |
| 9427 | } |
| 9428 | |
| 9429 | @Override |
| 9430 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9431 | enforceActiveEmergencySessionPermission(); |
| 9432 | |
| 9433 | final long identity = Binder.clearCallingIdentity(); |
| 9434 | try { |
| 9435 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9436 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9437 | if (tracker != null) { |
| 9438 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9439 | } |
| 9440 | } |
| 9441 | } finally { |
| 9442 | Binder.restoreCallingIdentity(identity); |
| 9443 | } |
| 9444 | } |
| 9445 | |
| 9446 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9447 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9448 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9449 | Phone phone = getPhone(subId); |
| 9450 | if (phone == null) { |
| 9451 | return null; |
| 9452 | } |
| 9453 | final long identity = Binder.clearCallingIdentity(); |
| 9454 | try { |
| 9455 | UiccProfile profile = UiccController.getInstance() |
| 9456 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9457 | if (profile != null) { |
| 9458 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9459 | } |
| 9460 | } finally { |
| 9461 | Binder.restoreCallingIdentity(identity); |
| 9462 | } |
| 9463 | return null; |
| 9464 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9465 | |
| 9466 | /** |
| 9467 | * Enable or disable a modem stack. |
| 9468 | */ |
| 9469 | @Override |
| 9470 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9471 | enforceModifyPermission(); |
| 9472 | |
| 9473 | final long identity = Binder.clearCallingIdentity(); |
| 9474 | try { |
| 9475 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9476 | if (phone == null) { |
| 9477 | return false; |
| 9478 | } else { |
| 9479 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9480 | } |
| 9481 | } finally { |
| 9482 | Binder.restoreCallingIdentity(identity); |
| 9483 | } |
| 9484 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9485 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9486 | /** |
| 9487 | * Whether a modem stack is enabled or not. |
| 9488 | */ |
| 9489 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9490 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9491 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9492 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9493 | if (phone == null) return false; |
| 9494 | |
| 9495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9496 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9497 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9498 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9499 | } |
| 9500 | |
| 9501 | final long identity = Binder.clearCallingIdentity(); |
| 9502 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9503 | try { |
| 9504 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9505 | } catch (NoSuchElementException ex) { |
| 9506 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9507 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9508 | } finally { |
| 9509 | Binder.restoreCallingIdentity(identity); |
| 9510 | } |
| 9511 | } |
| 9512 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9513 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9514 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9515 | enforceModifyPermission(); |
| 9516 | |
| 9517 | final long identity = Binder.clearCallingIdentity(); |
| 9518 | try { |
| 9519 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9520 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9521 | .commit(); |
| 9522 | } finally { |
| 9523 | Binder.restoreCallingIdentity(identity); |
| 9524 | } |
| 9525 | } |
| 9526 | |
| 9527 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9528 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9529 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9530 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9531 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9532 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9533 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9534 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9535 | |
| 9536 | final long identity = Binder.clearCallingIdentity(); |
| 9537 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9538 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9539 | } finally { |
| 9540 | Binder.restoreCallingIdentity(identity); |
| 9541 | } |
| 9542 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9543 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9544 | @TelephonyManager.IsMultiSimSupportedResult |
| 9545 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9546 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9547 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9548 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9549 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9550 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9551 | } |
| 9552 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9553 | // supported by the modem, indicate that it is restricted. |
| 9554 | PhoneCapability staticCapability = |
| 9555 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9556 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9557 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9558 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9559 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9560 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9561 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9562 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9563 | } |
| 9564 | // Check if support of multiple SIMs is restricted by carrier |
| 9565 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9566 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9567 | } |
| 9568 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9569 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9570 | } |
| 9571 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9572 | /** |
| 9573 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9574 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9575 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9576 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9577 | * @param numOfSims number of active sims we want to switch to |
| 9578 | */ |
| 9579 | @Override |
| 9580 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9581 | if (numOfSims == 1) { |
| 9582 | enforceModifyPermission(); |
| 9583 | } else { |
| 9584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9585 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9586 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9587 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9588 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9589 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9590 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9591 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9592 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9593 | return; |
| 9594 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9595 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9596 | } finally { |
| 9597 | Binder.restoreCallingIdentity(identity); |
| 9598 | } |
| 9599 | } |
| 9600 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9601 | @Override |
| 9602 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9603 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9604 | Phone phone = getPhone(subId); |
| 9605 | if (phone == null) { |
| 9606 | return false; |
| 9607 | } |
| 9608 | final long identity = Binder.clearCallingIdentity(); |
| 9609 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9610 | UiccPort uiccPort = phone.getUiccPort(); |
| 9611 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9612 | return false; |
| 9613 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9614 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9615 | if (uiccProfile == null) { |
| 9616 | return false; |
| 9617 | } |
| 9618 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9619 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9620 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9621 | } |
| 9622 | return false; |
| 9623 | } finally { |
| 9624 | Binder.restoreCallingIdentity(identity); |
| 9625 | } |
| 9626 | } |
| 9627 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9628 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9629 | * Get whether making changes to modem configurations will trigger reboot. |
| 9630 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9631 | */ |
| 9632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9633 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9634 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9636 | mApp, subId, callingPackage, callingFeatureId, |
| 9637 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9638 | return false; |
| 9639 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9640 | final long identity = Binder.clearCallingIdentity(); |
| 9641 | try { |
| 9642 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9643 | } finally { |
| 9644 | Binder.restoreCallingIdentity(identity); |
| 9645 | } |
| 9646 | } |
| 9647 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9648 | private void updateModemStateMetrics() { |
| 9649 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9650 | // TODO: check the state for each modem if the api is ready. |
| 9651 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9652 | } |
| 9653 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9654 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9655 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9656 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9657 | // Verify that the callingPackage belongs to the calling UID |
| 9658 | mApp.getSystemService(AppOpsManager.class) |
| 9659 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9660 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9661 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9662 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9663 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9664 | if (slotInfos != null) { |
| 9665 | for (int i = 0; i < slotInfos.length; i++) { |
| 9666 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9667 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9668 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9669 | portInfo.getLogicalSlotIndex())); |
| 9670 | } |
| 9671 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9672 | } |
| 9673 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9674 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9675 | } finally { |
| 9676 | Binder.restoreCallingIdentity(identity); |
| 9677 | } |
| 9678 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9679 | |
| 9680 | /** |
| 9681 | * Get the IRadio HAL Version |
| 9682 | */ |
| 9683 | @Override |
| 9684 | public int getRadioHalVersion() { |
| 9685 | Phone phone = getDefaultPhone(); |
| 9686 | if (phone == null) return -1; |
| 9687 | HalVersion hv = phone.getHalVersion(); |
| 9688 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9689 | return hv.major * 100 + hv.minor; |
| 9690 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9691 | |
| 9692 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9693 | * Get the current calling package name. |
| 9694 | * @return the current calling package name |
| 9695 | */ |
| 9696 | @Override |
| 9697 | public String getCurrentPackageName() { |
| 9698 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9699 | } |
| 9700 | |
| 9701 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9702 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9703 | * corresponding network requests on a subId. |
| 9704 | * |
| 9705 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9706 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9707 | * 2) APN is un-metered for this subscription, or |
| 9708 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9709 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9710 | * |
| 9711 | * @return whether data is allowed for a apn type. |
| 9712 | * |
| 9713 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9714 | */ |
| 9715 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9716 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9717 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9718 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9719 | |
| 9720 | // Now that all security checks passes, perform the operation as ourselves. |
| 9721 | final long identity = Binder.clearCallingIdentity(); |
| 9722 | try { |
| 9723 | Phone phone = getPhone(subId); |
| 9724 | if (phone == null) return false; |
| 9725 | |
Jack Yu | 27422a5 | 2022-03-21 10:38:05 -0700 | [diff] [blame] | 9726 | boolean isMetered; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9727 | boolean isDataEnabled; |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9728 | isMetered = phone.getDataNetworkController().getDataConfigManager() |
| 9729 | .isMeteredCapability(DataUtils.apnTypeToNetworkCapability(apnType), |
| 9730 | phone.getServiceState().getDataRoaming()); |
| 9731 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9732 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9733 | } finally { |
| 9734 | Binder.restoreCallingIdentity(identity); |
| 9735 | } |
| 9736 | } |
| 9737 | |
| 9738 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9739 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9740 | enforceReadPrivilegedPermission("isApnMetered"); |
| 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 true; // By default return true. |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9747 | return phone.getDataNetworkController().getDataConfigManager().isMeteredCapability( |
| 9748 | DataUtils.apnTypeToNetworkCapability(apnType), |
| 9749 | phone.getServiceState().getDataRoaming()); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9750 | } finally { |
| 9751 | Binder.restoreCallingIdentity(identity); |
| 9752 | } |
| 9753 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9754 | |
| 9755 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9756 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9757 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9758 | enforceModifyPermission(); |
| 9759 | long token = Binder.clearCallingIdentity(); |
| 9760 | try { |
| 9761 | Phone phone = getPhone(subscriptionId); |
| 9762 | if (phone == null) { |
| 9763 | try { |
| 9764 | if (resultCallback != null) { |
| 9765 | resultCallback.accept(false); |
| 9766 | } |
| 9767 | } catch (RemoteException e) { |
| 9768 | // ignore |
| 9769 | } |
| 9770 | return; |
| 9771 | } |
| 9772 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9773 | Pair.create(specifiers, (x) -> { |
| 9774 | try { |
| 9775 | if (resultCallback != null) { |
| 9776 | resultCallback.accept(x); |
| 9777 | } |
| 9778 | } catch (RemoteException e) { |
| 9779 | // ignore |
| 9780 | } |
| 9781 | }); |
| 9782 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9783 | } finally { |
| 9784 | Binder.restoreCallingIdentity(token); |
| 9785 | } |
| 9786 | } |
| 9787 | |
| 9788 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9789 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9790 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9791 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9792 | mApp, subId, "getSystemSelectionChannels"); |
| 9793 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9794 | final long identity = Binder.clearCallingIdentity(); |
| 9795 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9796 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9797 | if (result instanceof IllegalStateException) { |
| 9798 | throw (IllegalStateException) result; |
| 9799 | } |
| 9800 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9801 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9802 | return specifiers; |
| 9803 | } finally { |
| 9804 | Binder.restoreCallingIdentity(identity); |
| 9805 | } |
| 9806 | } |
| 9807 | |
| 9808 | @Override |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9809 | public boolean isMvnoMatched(int slotIndex, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9810 | enforceReadPrivilegedPermission("isMvnoMatched"); |
Jack Yu | 8b766fc | 2022-03-21 09:42:33 -0700 | [diff] [blame] | 9811 | return UiccController.getInstance().mvnoMatches(slotIndex, mvnoType, mvnoMatchData); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9812 | } |
| 9813 | |
| 9814 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9815 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9816 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9817 | if (callingPackage == null) { |
| 9818 | callingPackage = getCurrentPackageName(); |
| 9819 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9820 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9821 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9822 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9823 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9824 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9825 | } |
| 9826 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9827 | Intent intent = new Intent(); |
| 9828 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9829 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9830 | // Bring up choose default SMS subscription dialog right now |
| 9831 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9832 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9833 | mApp.startActivity(intent); |
| 9834 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9835 | |
| 9836 | @Override |
| 9837 | public String getMmsUAProfUrl(int subId) { |
| 9838 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9839 | final long identity = Binder.clearCallingIdentity(); |
| 9840 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9841 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9842 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9843 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9844 | return carrierUAProfUrl; |
| 9845 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9846 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9847 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9848 | } finally { |
| 9849 | Binder.restoreCallingIdentity(identity); |
| 9850 | } |
| 9851 | } |
| 9852 | |
| 9853 | @Override |
| 9854 | public String getMmsUserAgent(int subId) { |
| 9855 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9856 | final long identity = Binder.clearCallingIdentity(); |
| 9857 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9858 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9859 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9860 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9861 | return carrierUserAgent; |
| 9862 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9863 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9864 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9865 | } finally { |
| 9866 | Binder.restoreCallingIdentity(identity); |
| 9867 | } |
| 9868 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9869 | |
| 9870 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9871 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9872 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9873 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9874 | final long identity = Binder.clearCallingIdentity(); |
| 9875 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9876 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9877 | if (phone == null) return false; |
| 9878 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9879 | switch (policy) { |
| 9880 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9881 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9882 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9883 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9884 | default: |
| 9885 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9886 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9887 | } finally { |
| 9888 | Binder.restoreCallingIdentity(identity); |
| 9889 | } |
| 9890 | } |
| 9891 | |
| 9892 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9893 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9894 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9895 | enforceModifyPermission(); |
| 9896 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9897 | final long identity = Binder.clearCallingIdentity(); |
| 9898 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9899 | Phone phone = getPhone(subscriptionId); |
| 9900 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9901 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9902 | switch (policy) { |
| 9903 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9904 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9905 | break; |
| 9906 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | f86fb84 | 2022-07-31 00:43:21 -0700 | [diff] [blame] | 9907 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9908 | break; |
| 9909 | default: |
| 9910 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9911 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9912 | } finally { |
| 9913 | Binder.restoreCallingIdentity(identity); |
| 9914 | } |
| 9915 | } |
| 9916 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9917 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9918 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9919 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9920 | * otherwise. |
| 9921 | */ |
| 9922 | @Override |
| 9923 | public void setCepEnabled(boolean isCepEnabled) { |
| 9924 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9925 | |
| 9926 | final long identity = Binder.clearCallingIdentity(); |
| 9927 | try { |
| 9928 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9929 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9930 | Phone defaultPhone = phone.getImsPhone(); |
| 9931 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9932 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9933 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9934 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9935 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9936 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9937 | + imsPhone.getMsisdn()); |
| 9938 | } |
| 9939 | } |
| 9940 | } finally { |
| 9941 | Binder.restoreCallingIdentity(identity); |
| 9942 | } |
| 9943 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9944 | |
| 9945 | /** |
| 9946 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9947 | * |
| 9948 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9949 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9950 | * before being read. |
| 9951 | */ |
| 9952 | @Override |
| 9953 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9954 | isCompressed) { |
| 9955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9956 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9957 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9958 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9959 | } |
| 9960 | if (!isImsAvailableOnDevice()) { |
| 9961 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9962 | "IMS not available on device."); |
| 9963 | } |
| 9964 | |
| 9965 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9966 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9967 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9968 | } finally { |
| 9969 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9970 | } |
| 9971 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9972 | |
| 9973 | @Override |
| 9974 | public boolean isIccLockEnabled(int subId) { |
| 9975 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9976 | |
| 9977 | // Now that all security checks passes, perform the operation as ourselves. |
| 9978 | final long identity = Binder.clearCallingIdentity(); |
| 9979 | try { |
| 9980 | Phone phone = getPhone(subId); |
| 9981 | if (phone != null && phone.getIccCard() != null) { |
| 9982 | return phone.getIccCard().getIccLockEnabled(); |
| 9983 | } else { |
| 9984 | return false; |
| 9985 | } |
| 9986 | } finally { |
| 9987 | Binder.restoreCallingIdentity(identity); |
| 9988 | } |
| 9989 | } |
| 9990 | |
| 9991 | /** |
| 9992 | * Set the ICC pin lock enabled or disabled. |
| 9993 | * |
| 9994 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9995 | * three cases: |
| 9996 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9997 | * successfully. |
| 9998 | * - Positive number and zero for remaining password attempts. |
| 9999 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10000 | * |
| 10001 | */ |
| 10002 | @Override |
| 10003 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10004 | enforceModifyPermission(); |
| 10005 | |
| 10006 | Phone phone = getPhone(subId); |
| 10007 | if (phone == null) { |
| 10008 | return 0; |
| 10009 | } |
| 10010 | // Now that all security checks passes, perform the operation as ourselves. |
| 10011 | final long identity = Binder.clearCallingIdentity(); |
| 10012 | try { |
| 10013 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10014 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10015 | return attemptsRemaining; |
| 10016 | |
| 10017 | } catch (Exception e) { |
| 10018 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10019 | } finally { |
| 10020 | Binder.restoreCallingIdentity(identity); |
| 10021 | } |
| 10022 | return 0; |
| 10023 | } |
| 10024 | |
| 10025 | /** |
| 10026 | * Change the ICC password used in ICC pin lock. |
| 10027 | * |
| 10028 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10029 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10030 | * - Positive number and zero for remaining password attempts. |
| 10031 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10032 | * |
| 10033 | */ |
| 10034 | @Override |
| 10035 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10036 | enforceModifyPermission(); |
| 10037 | |
| 10038 | Phone phone = getPhone(subId); |
| 10039 | if (phone == null) { |
| 10040 | return 0; |
| 10041 | } |
| 10042 | // Now that all security checks passes, perform the operation as ourselves. |
| 10043 | final long identity = Binder.clearCallingIdentity(); |
| 10044 | try { |
| 10045 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10046 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10047 | return attemptsRemaining; |
| 10048 | |
| 10049 | } catch (Exception e) { |
| 10050 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10051 | } finally { |
| 10052 | Binder.restoreCallingIdentity(identity); |
| 10053 | } |
| 10054 | return 0; |
| 10055 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10056 | |
| 10057 | /** |
| 10058 | * Request for receiving user activity notification |
| 10059 | */ |
| 10060 | @Override |
| 10061 | public void requestUserActivityNotification() { |
| 10062 | if (!mNotifyUserActivity.get() |
| 10063 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10064 | mNotifyUserActivity.set(true); |
| 10065 | } |
| 10066 | } |
| 10067 | |
| 10068 | /** |
| 10069 | * Called when userActivity is signalled in the power manager. |
| 10070 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10071 | */ |
| 10072 | @Override |
| 10073 | public void userActivity() { |
| 10074 | // *************************************** |
| 10075 | // * Inherited from PhoneWindowManager * |
| 10076 | // *************************************** |
| 10077 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10078 | // WITH ITS LOCKS HELD. |
| 10079 | // |
| 10080 | // This code must be VERY careful about the locks |
| 10081 | // it acquires. |
| 10082 | // In fact, the current code acquires way too many, |
| 10083 | // and probably has lurking deadlocks. |
| 10084 | |
| 10085 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10086 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10087 | } |
| 10088 | |
| 10089 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10090 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10091 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10092 | } |
| 10093 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10094 | |
| 10095 | @Override |
| 10096 | public boolean canConnectTo5GInDsdsMode() { |
| 10097 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10098 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10099 | |
| 10100 | @Override |
| 10101 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10102 | String callingFeatureId) { |
| 10103 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10104 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10105 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10106 | } |
| 10107 | |
| 10108 | Phone phone = getPhone(subId); |
| 10109 | if (phone == null) { |
| 10110 | throw new RuntimeException("phone is not available"); |
| 10111 | } |
| 10112 | // Now that all security checks passes, perform the operation as ourselves. |
| 10113 | final long identity = Binder.clearCallingIdentity(); |
| 10114 | try { |
| 10115 | return phone.getEquivalentHomePlmns(); |
| 10116 | } finally { |
| 10117 | Binder.restoreCallingIdentity(identity); |
| 10118 | } |
| 10119 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10120 | |
| 10121 | @Override |
| 10122 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10123 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10124 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10125 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10126 | if (radioInterfaceCapabilities == null) { |
| 10127 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10128 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10129 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10130 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10131 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10132 | @Override |
| 10133 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10134 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10135 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10136 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10137 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10138 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10139 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10140 | if (DBG) { |
| 10141 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10142 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10143 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10144 | } |
| 10145 | |
| 10146 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10147 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10148 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10149 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10150 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10151 | if (callback != null) { |
| 10152 | try { |
| 10153 | callback.onAuthenticationFailure( |
| 10154 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10155 | } catch (RemoteException exception) { |
| 10156 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10157 | } |
| 10158 | return; |
| 10159 | } |
| 10160 | } |
| 10161 | |
| 10162 | final long token = Binder.clearCallingIdentity(); |
| 10163 | try { |
| 10164 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10165 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10166 | forceBootStrapping, callback)); |
| 10167 | } finally { |
| 10168 | Binder.restoreCallingIdentity(token); |
| 10169 | } |
| 10170 | } |
| 10171 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10172 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10173 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10174 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10175 | * requested radio power state will actually be set. See {@link |
| 10176 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10177 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10178 | * @param enable {@code true} if trying to turn radio on. |
| 10179 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10180 | * false}. |
| 10181 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10182 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10183 | boolean isPhoneAvailable = false; |
| 10184 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10185 | Phone phone = PhoneFactory.getPhone(i); |
| 10186 | if (phone != null) { |
Thomas Nguyen | fd0572f | 2022-07-15 22:28:49 +0000 | [diff] [blame^] | 10187 | phone.setRadioPowerForReason(enable, TelephonyManager.RADIO_POWER_REASON_THERMAL); |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10188 | isPhoneAvailable = true; |
| 10189 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10190 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10191 | |
| 10192 | // return true if successfully informed the phone object about the thermal radio power |
| 10193 | // request. |
| 10194 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10195 | } |
| 10196 | |
| 10197 | private int handleDataThrottlingRequest(int subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10198 | DataThrottlingRequest dataThrottlingRequest, String callingPackage) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10199 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10200 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10201 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10202 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10203 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10204 | } |
| 10205 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10206 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10207 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10208 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10209 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10210 | } |
| 10211 | |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10212 | setDataEnabledForReason( |
| 10213 | subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10214 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10215 | if (isDataThrottlingSupported) { |
| 10216 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10217 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10218 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10219 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10220 | } else if (thermalMitigationResult |
| 10221 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10222 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10223 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10224 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10225 | } |
| 10226 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10227 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10228 | |
| 10229 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10230 | } |
| 10231 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10232 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10233 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10234 | for (String pckg : context.getResources() |
| 10235 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10236 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10237 | } |
| 10238 | } |
| 10239 | |
| 10240 | return sThermalMitigationAllowlistedPackages; |
| 10241 | } |
| 10242 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10243 | private boolean isAnyPhoneInEmergencyState() { |
| 10244 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10245 | if (tm.isInEmergencyCall()) { |
| 10246 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10247 | return true; |
| 10248 | } |
| 10249 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10250 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10251 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10252 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10253 | + phone.isInEcm()); |
| 10254 | return true; |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | return false; |
| 10259 | } |
| 10260 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10261 | /** |
| 10262 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10263 | * @param packageName name of package to be allowlisted |
| 10264 | * @param context |
| 10265 | */ |
| 10266 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10267 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10268 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10269 | } |
| 10270 | |
| 10271 | /** |
| 10272 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10273 | * @param packageName name of package to remove from allowlist |
| 10274 | * @param context |
| 10275 | */ |
| 10276 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10277 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10278 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10279 | } |
| 10280 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10281 | /** |
| 10282 | * Thermal mitigation request to control functionalities at modem. |
| 10283 | * |
| 10284 | * @param subId the id of the subscription. |
| 10285 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10286 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10287 | * |
| 10288 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10289 | */ |
| 10290 | @Override |
| 10291 | @ThermalMitigationResult |
| 10292 | public int sendThermalMitigationRequest( |
| 10293 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10294 | ThermalMitigationRequest thermalMitigationRequest, |
| 10295 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10296 | enforceModifyPermission(); |
| 10297 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10298 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10299 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10300 | .contains(callingPackage)) { |
| 10301 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10302 | + "calling package: " + callingPackage); |
| 10303 | } |
| 10304 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10305 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10306 | final long identity = Binder.clearCallingIdentity(); |
| 10307 | |
| 10308 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10309 | try { |
| 10310 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10311 | switch (thermalMitigationAction) { |
| 10312 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10313 | thermalMitigationResult = |
| 10314 | handleDataThrottlingRequest(subId, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10315 | thermalMitigationRequest.getDataThrottlingRequest(), |
| 10316 | callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10317 | break; |
| 10318 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10319 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10320 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10321 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10322 | } |
| 10323 | |
| 10324 | // Ensure that radio is on. If not able to power on due to phone being |
| 10325 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10326 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10327 | thermalMitigationResult = |
| 10328 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10329 | break; |
| 10330 | } |
| 10331 | |
| 10332 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
Sarah Chin | ecc78c4 | 2022-03-31 21:16:48 -0700 | [diff] [blame] | 10333 | false, callingPackage); |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10334 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10335 | break; |
| 10336 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10337 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10338 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10339 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10340 | } |
| 10341 | |
| 10342 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10343 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10344 | Phone phone = getPhone(subId); |
| 10345 | if (phone == null) { |
| 10346 | thermalMitigationResult = |
| 10347 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10348 | break; |
| 10349 | } |
| 10350 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10351 | TelephonyConnectionService service = |
| 10352 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10353 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10354 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10355 | thermalMitigationResult = |
| 10356 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10357 | break; |
| 10358 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10359 | thermalMitigationResult = |
| 10360 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10361 | break; |
| 10362 | } |
| 10363 | } else { |
| 10364 | thermalMitigationResult = |
| 10365 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10366 | break; |
| 10367 | } |
| 10368 | |
| 10369 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10370 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10371 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10372 | thermalMitigationResult = |
| 10373 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10374 | break; |
| 10375 | } |
| 10376 | thermalMitigationResult = |
| 10377 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10378 | break; |
| 10379 | default: |
| 10380 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10381 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10382 | } |
| 10383 | } catch (IllegalArgumentException e) { |
| 10384 | throw e; |
| 10385 | } catch (Exception e) { |
| 10386 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10387 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10388 | } finally { |
| 10389 | Binder.restoreCallingIdentity(identity); |
| 10390 | } |
| 10391 | |
| 10392 | if (DBG) { |
| 10393 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10394 | + thermalMitigationResult); |
| 10395 | } |
| 10396 | |
| 10397 | return thermalMitigationResult; |
| 10398 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10399 | |
| 10400 | /** |
| 10401 | * Set the GbaService Package Name that Telephony will bind to. |
| 10402 | * |
| 10403 | * @param subId The sim that the GbaService is associated with. |
| 10404 | * @param packageName The name of the package to be replaced with. |
| 10405 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10406 | */ |
| 10407 | @Override |
| 10408 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10409 | enforceModifyPermission(); |
| 10410 | |
| 10411 | final long identity = Binder.clearCallingIdentity(); |
| 10412 | try { |
| 10413 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10414 | } finally { |
| 10415 | Binder.restoreCallingIdentity(identity); |
| 10416 | } |
| 10417 | } |
| 10418 | |
| 10419 | /** |
| 10420 | * Return the package name of the currently bound GbaService. |
| 10421 | * |
| 10422 | * @param subId The sim that the GbaService is associated with. |
| 10423 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10424 | */ |
| 10425 | @Override |
| 10426 | public String getBoundGbaService(int subId) { |
| 10427 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10428 | |
| 10429 | final long identity = Binder.clearCallingIdentity(); |
| 10430 | try { |
| 10431 | return getGbaManager(subId).getServicePackage(); |
| 10432 | } finally { |
| 10433 | Binder.restoreCallingIdentity(identity); |
| 10434 | } |
| 10435 | } |
| 10436 | |
| 10437 | /** |
| 10438 | * Set the release time for telephony to unbind GbaService. |
| 10439 | * |
| 10440 | * @param subId The sim that the GbaService is associated with. |
| 10441 | * @param interval The release time to unbind GbaService by millisecond. |
| 10442 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10443 | */ |
| 10444 | @Override |
| 10445 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10446 | enforceModifyPermission(); |
| 10447 | |
| 10448 | final long identity = Binder.clearCallingIdentity(); |
| 10449 | try { |
| 10450 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10451 | } finally { |
| 10452 | Binder.restoreCallingIdentity(identity); |
| 10453 | } |
| 10454 | } |
| 10455 | |
| 10456 | /** |
| 10457 | * Return the release time for telephony to unbind GbaService. |
| 10458 | * |
| 10459 | * @param subId The sim that the GbaService is associated with. |
| 10460 | * @return The release time to unbind GbaService by millisecond. |
| 10461 | */ |
| 10462 | @Override |
| 10463 | public int getGbaReleaseTime(int subId) { |
| 10464 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10465 | |
| 10466 | final long identity = Binder.clearCallingIdentity(); |
| 10467 | try { |
| 10468 | return getGbaManager(subId).getReleaseTime(); |
| 10469 | } finally { |
| 10470 | Binder.restoreCallingIdentity(identity); |
| 10471 | } |
| 10472 | } |
| 10473 | |
| 10474 | private GbaManager getGbaManager(int subId) { |
| 10475 | GbaManager instance = GbaManager.getInstance(subId); |
| 10476 | if (instance == null) { |
| 10477 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10478 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10479 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10480 | } |
| 10481 | return instance; |
| 10482 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10483 | |
| 10484 | /** |
| 10485 | * indicate whether the device and the carrier can support |
| 10486 | * RCS VoLTE single registration. |
| 10487 | */ |
| 10488 | @Override |
| 10489 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10490 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10491 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10492 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10493 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10494 | |
| 10495 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10496 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10497 | } |
| 10498 | |
| 10499 | final long identity = Binder.clearCallingIdentity(); |
| 10500 | try { |
| 10501 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10502 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10503 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10504 | if (isCapable != null) { |
| 10505 | return isCapable; |
| 10506 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10507 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10508 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10509 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10510 | } finally { |
| 10511 | Binder.restoreCallingIdentity(identity); |
| 10512 | } |
| 10513 | } |
| 10514 | |
| 10515 | /** |
| 10516 | * Register RCS provisioning callback. |
| 10517 | */ |
| 10518 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10519 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10520 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10521 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10522 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10523 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10524 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10525 | |
| 10526 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10527 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10528 | } |
| 10529 | if (!isImsAvailableOnDevice()) { |
| 10530 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10531 | "IMS not available on device."); |
| 10532 | } |
| 10533 | |
| 10534 | final long identity = Binder.clearCallingIdentity(); |
| 10535 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10536 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10537 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10538 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10539 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10540 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10541 | } finally { |
| 10542 | Binder.restoreCallingIdentity(identity); |
| 10543 | } |
| 10544 | } |
| 10545 | |
| 10546 | /** |
| 10547 | * Unregister RCS provisioning callback. |
| 10548 | */ |
| 10549 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10550 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10551 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10552 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10553 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10554 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10555 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10556 | |
| 10557 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10558 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10559 | } |
| 10560 | if (!isImsAvailableOnDevice()) { |
| 10561 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10562 | "IMS not available on device."); |
| 10563 | } |
| 10564 | |
| 10565 | final long identity = Binder.clearCallingIdentity(); |
| 10566 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10567 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10568 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10569 | } finally { |
| 10570 | Binder.restoreCallingIdentity(identity); |
| 10571 | } |
| 10572 | } |
| 10573 | |
| 10574 | /** |
| 10575 | * trigger RCS reconfiguration. |
| 10576 | */ |
| 10577 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10578 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10579 | "triggerRcsReconfiguration", |
| 10580 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10581 | |
| 10582 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10583 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10584 | } |
| 10585 | if (!isImsAvailableOnDevice()) { |
| 10586 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10587 | "IMS not available on device."); |
| 10588 | } |
| 10589 | |
| 10590 | final long identity = Binder.clearCallingIdentity(); |
| 10591 | try { |
| 10592 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10593 | } finally { |
| 10594 | Binder.restoreCallingIdentity(identity); |
| 10595 | } |
| 10596 | } |
| 10597 | |
| 10598 | /** |
| 10599 | * Provide the client configuration parameters of the RCS application. |
| 10600 | */ |
| 10601 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10602 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10603 | "setRcsClientConfiguration", |
| 10604 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10605 | |
| 10606 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10607 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10608 | } |
| 10609 | if (!isImsAvailableOnDevice()) { |
| 10610 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10611 | "IMS not available on device."); |
| 10612 | } |
| 10613 | |
| 10614 | final long identity = Binder.clearCallingIdentity(); |
| 10615 | |
| 10616 | try { |
| 10617 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10618 | if (configBinder == null) { |
| 10619 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10620 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10621 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10622 | } else { |
| 10623 | configBinder.setRcsClientConfiguration(rcc); |
| 10624 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10625 | |
| 10626 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10627 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10628 | } catch (RemoteException e) { |
| 10629 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10630 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10631 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10632 | } finally { |
| 10633 | Binder.restoreCallingIdentity(identity); |
| 10634 | } |
| 10635 | } |
| 10636 | |
| 10637 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10638 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10639 | */ |
| 10640 | @Override |
| 10641 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10642 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10643 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10644 | |
| 10645 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10646 | } |
| 10647 | |
| 10648 | /** |
| 10649 | * Gets the test mode for RCS VoLTE single registration. |
| 10650 | */ |
| 10651 | @Override |
| 10652 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10653 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10654 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10655 | |
| 10656 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10657 | } |
| 10658 | |
| 10659 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10660 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10661 | */ |
| 10662 | @Override |
| 10663 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10664 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10665 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10666 | enforceModifyPermission(); |
| 10667 | |
| 10668 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10669 | : Boolean.parseBoolean(enabledStr); |
| 10670 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10671 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10672 | } |
| 10673 | |
| 10674 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10675 | * Sends a device to device communication message. Only usable via shell. |
| 10676 | * @param message message to send. |
| 10677 | * @param value message value. |
| 10678 | */ |
| 10679 | @Override |
| 10680 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10681 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10682 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10683 | enforceModifyPermission(); |
| 10684 | |
| 10685 | final long identity = Binder.clearCallingIdentity(); |
| 10686 | try { |
| 10687 | TelephonyConnectionService service = |
| 10688 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10689 | if (service == null) { |
| 10690 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10691 | return; |
| 10692 | } |
| 10693 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10694 | } finally { |
| 10695 | Binder.restoreCallingIdentity(identity); |
| 10696 | } |
| 10697 | } |
| 10698 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10699 | /** |
| 10700 | * Sets the specified device to device transport active. |
| 10701 | * @param transport The transport to set active. |
| 10702 | */ |
| 10703 | @Override |
| 10704 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10705 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10706 | "setActiveDeviceToDeviceTransport"); |
| 10707 | enforceModifyPermission(); |
| 10708 | |
| 10709 | final long identity = Binder.clearCallingIdentity(); |
| 10710 | try { |
| 10711 | TelephonyConnectionService service = |
| 10712 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10713 | if (service == null) { |
| 10714 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10715 | return; |
| 10716 | } |
| 10717 | service.setActiveDeviceToDeviceTransport(transport); |
| 10718 | } finally { |
| 10719 | Binder.restoreCallingIdentity(identity); |
| 10720 | } |
| 10721 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10722 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10723 | @Override |
| 10724 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10725 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10726 | "setDeviceToDeviceForceEnabled"); |
| 10727 | |
| 10728 | final long identity = Binder.clearCallingIdentity(); |
| 10729 | try { |
| 10730 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10731 | p -> { |
| 10732 | Phone thePhone = p.getImsPhone(); |
| 10733 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10734 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10735 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10736 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10737 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10738 | (ImsPhoneCallTracker) tracker; |
| 10739 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10740 | } |
| 10741 | } |
| 10742 | } |
| 10743 | ); |
| 10744 | } finally { |
| 10745 | Binder.restoreCallingIdentity(identity); |
| 10746 | } |
| 10747 | } |
| 10748 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10749 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10750 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10751 | */ |
| 10752 | @Override |
| 10753 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10754 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10755 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10756 | } |
| 10757 | |
| 10758 | /** |
| 10759 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10760 | */ |
| 10761 | @Override |
| 10762 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10763 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10764 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10765 | enforceModifyPermission(); |
| 10766 | |
| 10767 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10768 | : Boolean.parseBoolean(enabledStr); |
| 10769 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10770 | subId, enabled); |
| 10771 | } |
| 10772 | |
| 10773 | /** |
| 10774 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10775 | */ |
| 10776 | @Override |
| 10777 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10778 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10779 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10780 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10781 | |
| 10782 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10783 | * Overrides the ims feature validation result |
| 10784 | */ |
| 10785 | @Override |
| 10786 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10787 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10788 | "setImsFeatureValidationOverride"); |
| 10789 | |
| 10790 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10791 | : Boolean.parseBoolean(enabledStr); |
| 10792 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10793 | subId, enabled); |
| 10794 | } |
| 10795 | |
| 10796 | /** |
| 10797 | * Gets the ims feature validation override value |
| 10798 | */ |
| 10799 | @Override |
| 10800 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10801 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10802 | "getImsFeatureValidationOverride"); |
| 10803 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10804 | } |
| 10805 | |
| 10806 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10807 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10808 | * their mobile plan. |
| 10809 | */ |
| 10810 | @Override |
| 10811 | public String getMobileProvisioningUrl() { |
| 10812 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10813 | final long identity = Binder.clearCallingIdentity(); |
| 10814 | try { |
| 10815 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10816 | } finally { |
| 10817 | Binder.restoreCallingIdentity(identity); |
| 10818 | } |
| 10819 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10820 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10821 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10822 | * Get the EAB contact from the EAB database. |
| 10823 | */ |
| 10824 | @Override |
| 10825 | public String getContactFromEab(String contact) { |
| 10826 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10827 | enforceModifyPermission(); |
| 10828 | final long identity = Binder.clearCallingIdentity(); |
| 10829 | try { |
| 10830 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10831 | } finally { |
| 10832 | Binder.restoreCallingIdentity(identity); |
| 10833 | } |
| 10834 | } |
| 10835 | |
| 10836 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10837 | * Get the EAB capability from the EAB database. |
| 10838 | */ |
| 10839 | @Override |
| 10840 | public String getCapabilityFromEab(String contact) { |
| 10841 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10842 | enforceModifyPermission(); |
| 10843 | final long identity = Binder.clearCallingIdentity(); |
| 10844 | try { |
| 10845 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10846 | } finally { |
| 10847 | Binder.restoreCallingIdentity(identity); |
| 10848 | } |
| 10849 | } |
| 10850 | |
| 10851 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10852 | * Remove the EAB contacts from the EAB database. |
| 10853 | */ |
| 10854 | @Override |
| 10855 | public int removeContactFromEab(int subId, String contacts) { |
| 10856 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10857 | enforceModifyPermission(); |
| 10858 | final long identity = Binder.clearCallingIdentity(); |
| 10859 | try { |
| 10860 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10861 | } finally { |
| 10862 | Binder.restoreCallingIdentity(identity); |
| 10863 | } |
| 10864 | } |
| 10865 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10866 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10867 | public boolean getDeviceUceEnabled() { |
| 10868 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10869 | final long identity = Binder.clearCallingIdentity(); |
| 10870 | try { |
| 10871 | return mApp.getDeviceUceEnabled(); |
| 10872 | } finally { |
| 10873 | Binder.restoreCallingIdentity(identity); |
| 10874 | } |
| 10875 | } |
| 10876 | |
| 10877 | @Override |
| 10878 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10879 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10880 | final long identity = Binder.clearCallingIdentity(); |
| 10881 | try { |
| 10882 | mApp.setDeviceUceEnabled(isEnabled); |
| 10883 | } finally { |
| 10884 | Binder.restoreCallingIdentity(identity); |
| 10885 | } |
| 10886 | } |
| 10887 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10888 | /** |
| 10889 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10890 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10891 | */ |
| 10892 | // Used for SHELL command only right now. |
| 10893 | @Override |
| 10894 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10895 | List<String> featureTags) { |
| 10896 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10897 | "addUceRegistrationOverrideShell"); |
| 10898 | final long identity = Binder.clearCallingIdentity(); |
| 10899 | try { |
| 10900 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10901 | new ArraySet<>(featureTags)); |
| 10902 | } catch (ImsException e) { |
| 10903 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10904 | } finally { |
| 10905 | Binder.restoreCallingIdentity(identity); |
| 10906 | } |
| 10907 | } |
| 10908 | |
| 10909 | /** |
| 10910 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10911 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10912 | */ |
| 10913 | // Used for SHELL command only right now. |
| 10914 | @Override |
| 10915 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10916 | List<String> featureTags) { |
| 10917 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10918 | "removeUceRegistrationOverrideShell"); |
| 10919 | final long identity = Binder.clearCallingIdentity(); |
| 10920 | try { |
| 10921 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10922 | new ArraySet<>(featureTags)); |
| 10923 | } catch (ImsException e) { |
| 10924 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10925 | } finally { |
| 10926 | Binder.restoreCallingIdentity(identity); |
| 10927 | } |
| 10928 | } |
| 10929 | |
| 10930 | /** |
| 10931 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10932 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10933 | */ |
| 10934 | // Used for SHELL command only right now. |
| 10935 | @Override |
| 10936 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10937 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10938 | "clearUceRegistrationOverrideShell"); |
| 10939 | final long identity = Binder.clearCallingIdentity(); |
| 10940 | try { |
| 10941 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10942 | } catch (ImsException e) { |
| 10943 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10944 | } finally { |
| 10945 | Binder.restoreCallingIdentity(identity); |
| 10946 | } |
| 10947 | } |
| 10948 | |
| 10949 | /** |
| 10950 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10951 | */ |
| 10952 | // Used for SHELL command only right now. |
| 10953 | @Override |
| 10954 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10955 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10956 | "getLatestRcsContactUceCapabilityShell"); |
| 10957 | final long identity = Binder.clearCallingIdentity(); |
| 10958 | try { |
| 10959 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10960 | } catch (ImsException e) { |
| 10961 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10962 | } finally { |
| 10963 | Binder.restoreCallingIdentity(identity); |
| 10964 | } |
| 10965 | } |
| 10966 | |
| 10967 | /** |
| 10968 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10969 | * device does not have an active PUBLISH. |
| 10970 | */ |
| 10971 | // Used for SHELL command only right now. |
| 10972 | @Override |
| 10973 | public String getLastUcePidfXmlShell(int subId) { |
| 10974 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10975 | final long identity = Binder.clearCallingIdentity(); |
| 10976 | try { |
| 10977 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10978 | } catch (ImsException e) { |
| 10979 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10980 | } finally { |
| 10981 | Binder.restoreCallingIdentity(identity); |
| 10982 | } |
| 10983 | } |
| 10984 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10985 | /** |
| 10986 | * Remove UCE requests cannot be sent to the network status. |
| 10987 | */ |
| 10988 | // Used for SHELL command only right now. |
| 10989 | @Override |
| 10990 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10991 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10992 | final long identity = Binder.clearCallingIdentity(); |
| 10993 | try { |
| 10994 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10995 | } catch (ImsException e) { |
| 10996 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10997 | } finally { |
| 10998 | Binder.restoreCallingIdentity(identity); |
| 10999 | } |
| 11000 | } |
| 11001 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11002 | /** |
| 11003 | * Remove UCE requests cannot be sent to the network status. |
| 11004 | */ |
| 11005 | // Used for SHELL command only. |
| 11006 | @Override |
| 11007 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11009 | final long identity = Binder.clearCallingIdentity(); |
| 11010 | try { |
| 11011 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11012 | } catch (ImsException e) { |
| 11013 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11014 | } finally { |
| 11015 | Binder.restoreCallingIdentity(identity); |
| 11016 | } |
| 11017 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11018 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11019 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11020 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11021 | String callingPackage) { |
| 11022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11023 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11024 | |
| 11025 | final int callingUid = Binder.getCallingUid(); |
| 11026 | // Verify that tha callingPackage belongs to the calling UID |
| 11027 | mApp.getSystemService(AppOpsManager.class) |
| 11028 | .checkPackage(callingUid, callingPackage); |
| 11029 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11030 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11031 | |
| 11032 | final long identity = Binder.clearCallingIdentity(); |
| 11033 | try { |
| 11034 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11035 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11036 | |
| 11037 | if (result instanceof IllegalStateException) { |
| 11038 | throw (IllegalStateException) result; |
| 11039 | } |
| 11040 | } finally { |
| 11041 | Binder.restoreCallingIdentity(identity); |
| 11042 | } |
| 11043 | } |
| 11044 | |
| 11045 | @Override |
| 11046 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11047 | String callingPackage) { |
| 11048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11049 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11050 | |
| 11051 | final int callingUid = Binder.getCallingUid(); |
| 11052 | // Verify that tha callingPackage belongs to the calling UID |
| 11053 | mApp.getSystemService(AppOpsManager.class) |
| 11054 | .checkPackage(callingUid, callingPackage); |
| 11055 | |
| 11056 | final long identity = Binder.clearCallingIdentity(); |
| 11057 | try { |
| 11058 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11059 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11060 | |
| 11061 | if (result instanceof IllegalStateException) { |
| 11062 | throw (IllegalStateException) result; |
| 11063 | } |
| 11064 | } finally { |
| 11065 | Binder.restoreCallingIdentity(identity); |
| 11066 | } |
| 11067 | } |
| 11068 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11069 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11070 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11071 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11072 | // phone/system process do not have further restriction on request |
| 11073 | return; |
| 11074 | } |
| 11075 | |
| 11076 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11077 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11078 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11079 | context.enforceCallingOrSelfPermission( |
| 11080 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11081 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11082 | } |
| 11083 | |
| 11084 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11085 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11086 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11087 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11088 | || info.isEnabled()) { |
| 11089 | throw new IllegalArgumentException( |
| 11090 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11091 | } |
| 11092 | |
| 11093 | // Thresholds length for each RAN need in range. This has been validated in |
| 11094 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11095 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11096 | final int[] thresholds = info.getThresholds(); |
| 11097 | Objects.requireNonNull(thresholds); |
| 11098 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11099 | || thresholds.length |
| 11100 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11101 | throw new IllegalArgumentException( |
| 11102 | "thresholds length is out of range: " + thresholds.length); |
| 11103 | } |
| 11104 | } |
| 11105 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11106 | |
| 11107 | /** |
| 11108 | * Gets the current phone capability. |
| 11109 | * |
| 11110 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11111 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11112 | * It's used to evaluate possible phone config change, for example from single |
| 11113 | * SIM device to multi-SIM device. |
| 11114 | */ |
| 11115 | @Override |
| 11116 | public PhoneCapability getPhoneCapability() { |
| 11117 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11118 | final long identity = Binder.clearCallingIdentity(); |
| 11119 | try { |
| 11120 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11121 | } finally { |
| 11122 | Binder.restoreCallingIdentity(identity); |
| 11123 | } |
| 11124 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11125 | |
| 11126 | /** |
| 11127 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11128 | * required to be done shortly after the API is invoked. |
| 11129 | */ |
| 11130 | @Override |
| 11131 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11132 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11133 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11134 | enforceRebootPermission(); |
| 11135 | |
| 11136 | final long identity = Binder.clearCallingIdentity(); |
| 11137 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11138 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11139 | } finally { |
| 11140 | Binder.restoreCallingIdentity(identity); |
| 11141 | } |
| 11142 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11143 | |
| 11144 | /** |
| 11145 | * Request to get the current slicing configuration including URSP rules and |
| 11146 | * NSSAIs (configured, allowed and rejected). |
| 11147 | * |
| 11148 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11149 | */ |
| 11150 | @Override |
| 11151 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11152 | TelephonyPermissions |
| 11153 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11154 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11155 | |
| 11156 | final long identity = Binder.clearCallingIdentity(); |
| 11157 | try { |
| 11158 | Phone phone = getDefaultPhone(); |
| 11159 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11160 | } finally { |
| 11161 | Binder.restoreCallingIdentity(identity); |
| 11162 | } |
| 11163 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11164 | |
| 11165 | /** |
| 11166 | * Register an IMS connection state callback |
| 11167 | */ |
| 11168 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11169 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11170 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11171 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11172 | // ImsMmTelManager |
| 11173 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11174 | TelephonyPermissions |
| 11175 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11176 | mApp, subId, "registerImsStateCallback"); |
| 11177 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11178 | // ImsRcsManager or SipDelegateManager |
| 11179 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11180 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11181 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11182 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11183 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11184 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11185 | } |
| 11186 | |
| 11187 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11188 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11189 | "IMS not available on device."); |
| 11190 | } |
| 11191 | |
| 11192 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11193 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11194 | } |
| 11195 | |
| 11196 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11197 | if (controller == null) { |
| 11198 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11199 | "IMS not available on device."); |
| 11200 | } |
| 11201 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11202 | if (callingPackage == null) { |
| 11203 | callingPackage = getCurrentPackageName(); |
| 11204 | } |
| 11205 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11206 | final long token = Binder.clearCallingIdentity(); |
| 11207 | try { |
| 11208 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11209 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11210 | } catch (ImsException e) { |
| 11211 | throw new ServiceSpecificException(e.getCode()); |
| 11212 | } finally { |
| 11213 | Binder.restoreCallingIdentity(token); |
| 11214 | } |
| 11215 | } |
| 11216 | |
| 11217 | /** |
| 11218 | * Unregister an IMS connection state callback |
| 11219 | */ |
| 11220 | @Override |
| 11221 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11222 | final long token = Binder.clearCallingIdentity(); |
| 11223 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11224 | if (controller == null) { |
| 11225 | return; |
| 11226 | } |
| 11227 | try { |
| 11228 | controller.unregisterImsStateCallback(cb); |
| 11229 | } finally { |
| 11230 | Binder.restoreCallingIdentity(token); |
| 11231 | } |
| 11232 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11233 | |
| 11234 | /** |
| 11235 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11236 | * |
| 11237 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11238 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11239 | * SecurityException. |
| 11240 | * If there is current registered network this value will be same as the registered cell |
| 11241 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11242 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11243 | * it will be cleared and null will be returned. |
| 11244 | * |
| 11245 | */ |
| 11246 | @Override |
| 11247 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11248 | String callingFeatureId) { |
| 11249 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11250 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11251 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11252 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11253 | .setCallingPackage(callingPackage) |
| 11254 | .setCallingFeatureId(callingFeatureId) |
| 11255 | .setCallingPid(Binder.getCallingPid()) |
| 11256 | .setCallingUid(Binder.getCallingUid()) |
| 11257 | .setMethod("getLastKnownCellIdentity") |
| 11258 | .setLogAsInfo(true) |
| 11259 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11260 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11261 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11262 | .build()); |
| 11263 | |
| 11264 | boolean hasFinePermission = |
| 11265 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11266 | if (!hasFinePermission |
| 11267 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11268 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
Rambo Wang | 918993a | 2022-04-27 09:08:36 -0700 | [diff] [blame] | 11269 | + "and ACCESS_LAST_KNOWN_CELL_ID permission."); |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11270 | } |
| 11271 | |
| 11272 | final long identity = Binder.clearCallingIdentity(); |
| 11273 | try { |
| 11274 | Phone phone = getPhone(subId); |
| 11275 | if (phone == null) return null; |
| 11276 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11277 | if (sst == null) return null; |
| 11278 | return sst.getLastKnownCellIdentity(); |
| 11279 | } finally { |
| 11280 | Binder.restoreCallingIdentity(identity); |
| 11281 | } |
| 11282 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11283 | |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11284 | /** |
| 11285 | * Sets the modem service class Name that Telephony will bind to. |
| 11286 | * |
| 11287 | * @param serviceName The class name of the modem service. |
| 11288 | * @return true if the operation is succeed, otherwise false. |
| 11289 | */ |
| 11290 | public boolean setModemService(String serviceName) { |
| 11291 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11292 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11294 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11295 | "setModemService"); |
| 11296 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11297 | } |
| 11298 | |
| 11299 | /** |
| 11300 | * Return the class name of the currently bounded modem service. |
| 11301 | * |
| 11302 | * @return the class name of the modem service. |
| 11303 | */ |
| 11304 | public String getModemService() { |
| 11305 | String result; |
| 11306 | Log.d(LOG_TAG, "getModemService"); |
| 11307 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11308 | TelephonyPermissions |
| 11309 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11310 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11311 | "getModemService"); |
| 11312 | result = mPhoneConfigurationManager.getModemService(); |
| 11313 | Log.d(LOG_TAG, "result = " + result); |
| 11314 | return result; |
| 11315 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11316 | |
| 11317 | @Override |
| 11318 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11319 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11320 | mApp.enforceCallingOrSelfPermission( |
| 11321 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11322 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11323 | |
| 11324 | final long identity = Binder.clearCallingIdentity(); |
| 11325 | try { |
| 11326 | Phone phone = getPhone(subId); |
| 11327 | if (phone == null) return; |
| 11328 | phone.setVoiceServiceStateOverride(hasService); |
| 11329 | } finally { |
| 11330 | Binder.restoreCallingIdentity(identity); |
| 11331 | } |
| 11332 | } |
Muralidhar Reddy | 4e5a801 | 2022-05-11 14:49:00 +0000 | [diff] [blame] | 11333 | |
| 11334 | /** |
| 11335 | * set removable eSIM as default eUICC. |
| 11336 | * |
| 11337 | * @hide |
| 11338 | */ |
| 11339 | @Override |
| 11340 | public void setRemovableEsimAsDefaultEuicc(boolean isDefault, String callingPackage) { |
| 11341 | enforceModifyPermission(); |
| 11342 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11343 | |
| 11344 | final long identity = Binder.clearCallingIdentity(); |
| 11345 | try { |
| 11346 | UiccController.getInstance().setRemovableEsimAsDefaultEuicc(isDefault); |
| 11347 | } finally { |
| 11348 | Binder.restoreCallingIdentity(identity); |
| 11349 | } |
| 11350 | } |
| 11351 | |
| 11352 | /** |
| 11353 | * Returns whether the removable eSIM is default eUICC or not. |
| 11354 | * |
| 11355 | * @hide |
| 11356 | */ |
| 11357 | @Override |
| 11358 | public boolean isRemovableEsimDefaultEuicc(String callingPackage) { |
| 11359 | enforceReadPrivilegedPermission("isRemovableEsimDefaultEuicc"); |
| 11360 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11361 | |
| 11362 | final long identity = Binder.clearCallingIdentity(); |
| 11363 | try { |
| 11364 | return UiccController.getInstance().isRemovableEsimDefaultEuicc(); |
| 11365 | } finally { |
| 11366 | Binder.restoreCallingIdentity(identity); |
| 11367 | } |
| 11368 | } |
| 11369 | |
| 11370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11371 | } |