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; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 36 | import android.compat.annotation.ChangeId; |
| 37 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 38 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 39 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 40 | import android.content.Context; |
| 41 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 42 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 43 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 44 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.net.Uri; |
| 46 | import android.os.AsyncResult; |
| 47 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 48 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
| 50 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 51 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 52 | import android.os.Looper; |
| 53 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 54 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 55 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 56 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 57 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 58 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 59 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 60 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 61 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 62 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 64 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 65 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 66 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 67 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 68 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 69 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 70 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 71 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 73 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 74 | import android.telephony.AccessNetworkConstants; |
| 75 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 76 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 77 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 78 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 79 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 80 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 81 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 82 | import android.telephony.CellIdentityCdma; |
| 83 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 85 | import android.telephony.CellInfoGsm; |
| 86 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 87 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 88 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 89 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 90 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 91 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 92 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 93 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 94 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 95 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 97 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 98 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 100 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 102 | import android.telephony.SignalStrengthUpdateRequest; |
| 103 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 105 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 106 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 108 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 109 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 110 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 111 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 112 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 114 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 115 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 116 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 117 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 118 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 119 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 120 | import android.telephony.gba.GbaAuthRequest; |
| 121 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 122 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 125 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 126 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 134 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 135 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 136 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 138 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 140 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 141 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 143 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 144 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 145 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 146 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 147 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 148 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 164 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 180 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 186 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 187 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 189 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 190 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 191 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 192 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 193 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 194 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 195 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 207 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 208 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 209 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 210 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 211 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 212 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 213 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 214 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 215 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 216 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 218 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 219 | import com.android.services.telephony.TelecomAccountRegistry; |
| 220 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 221 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 222 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 223 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 224 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 225 | import java.io.IOException; |
| 226 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 227 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 228 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 229 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 230 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 231 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 232 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 233 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 234 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 235 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 236 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 237 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 238 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 239 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 240 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 241 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 242 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Implementation of the ITelephony interface. |
| 246 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 247 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 248 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 249 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 250 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 251 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 252 | |
| 253 | // Message codes used with mMainThreadHandler |
| 254 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 255 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 256 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 257 | private static final int CMD_OPEN_CHANNEL = 9; |
| 258 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 259 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 260 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 261 | private static final int CMD_NV_READ_ITEM = 13; |
| 262 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 263 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 264 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 265 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 266 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 267 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 268 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 269 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 270 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 271 | private static final int CMD_SEND_ENVELOPE = 25; |
| 272 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 273 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 274 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 275 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 276 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 277 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 278 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 279 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 280 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 281 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 282 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 283 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 284 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 285 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 286 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 287 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 288 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 289 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 290 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 291 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 292 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 293 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 294 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 295 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 296 | private static final int CMD_SWITCH_SLOTS = 50; |
| 297 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 298 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 299 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 300 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 301 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 302 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 303 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 304 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 305 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 306 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 307 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 308 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 309 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 310 | private static final int CMD_MODEM_REBOOT = 64; |
| 311 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 312 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 313 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 314 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 315 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 317 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 318 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 319 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 320 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 321 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 322 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 323 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 324 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 325 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 326 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 327 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 328 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 329 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 330 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 331 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 332 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 333 | private static final int CMD_GET_CALL_WAITING = 87; |
| 334 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 335 | private static final int CMD_SET_CALL_WAITING = 89; |
| 336 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 337 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 338 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 339 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 340 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 341 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 342 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 343 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 344 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 345 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 346 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 347 | private static final int CMD_SET_SIM_POWER = 101; |
| 348 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 349 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 350 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 351 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 352 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 353 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 354 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 355 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 356 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 357 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 358 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 359 | private static final int CMD_ENABLE_VONR = 113; |
| 360 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 361 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 362 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 363 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 364 | // Parameters of select command. |
| 365 | private static final int SELECT_COMMAND = 0xA4; |
| 366 | private static final int SELECT_P1 = 0x04; |
| 367 | private static final int SELECT_P2 = 0; |
| 368 | private static final int SELECT_P3 = 0x10; |
| 369 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | /** The singleton instance. */ |
| 371 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 372 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 374 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 376 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 377 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 378 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 379 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 380 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 381 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 382 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 383 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 384 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 386 | /** User Activity */ |
| 387 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 388 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 389 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 390 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 391 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 392 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 393 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 394 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 395 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 396 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 397 | // String to store multi SIM allowed |
| 398 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 399 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 400 | // The AID of ISD-R. |
| 401 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 402 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 403 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 404 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 405 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 406 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 407 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 408 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 409 | 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] | 410 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 411 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 412 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 413 | */ |
| 414 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 415 | "reset_network_erase_modem_config_enabled"; |
| 416 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 417 | 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] | 418 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 419 | /** |
| 420 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 421 | * one ICCID active at the same time. |
| 422 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 423 | * |
| 424 | * @hide |
| 425 | */ |
| 426 | @ChangeId |
| 427 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 428 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 429 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 430 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 431 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 432 | * operation fails. |
| 433 | */ |
| 434 | @ChangeId |
| 435 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 436 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 437 | |
| 438 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 439 | * A request object to use for transmitting data to an ICC. |
| 440 | */ |
| 441 | private static final class IccAPDUArgument { |
| 442 | public int channel, cla, command, p1, p2, p3; |
| 443 | public String data; |
| 444 | |
| 445 | public IccAPDUArgument(int channel, int cla, int command, |
| 446 | int p1, int p2, int p3, String data) { |
| 447 | this.channel = channel; |
| 448 | this.cla = cla; |
| 449 | this.command = command; |
| 450 | this.p1 = p1; |
| 451 | this.p2 = p2; |
| 452 | this.p3 = p3; |
| 453 | this.data = data; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 458 | * A request object to use for transmitting data to an ICC. |
| 459 | */ |
| 460 | private static final class ManualNetworkSelectionArgument { |
| 461 | public OperatorInfo operatorInfo; |
| 462 | public boolean persistSelection; |
| 463 | |
| 464 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 465 | this.operatorInfo = operatorInfo; |
| 466 | this.persistSelection = persistSelection; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 472 | * request after sending. The main thread will notify the request when it is complete. |
| 473 | */ |
| 474 | private static final class MainThreadRequest { |
| 475 | /** The argument to use for the request */ |
| 476 | public Object argument; |
| 477 | /** The result of the request that is run on the main thread */ |
| 478 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 479 | // The subscriber id that this request applies to. Defaults to |
| 480 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 481 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 482 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 483 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 484 | public Phone phone; |
| 485 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 486 | public WorkSource workSource; |
| 487 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | public MainThreadRequest(Object argument) { |
| 489 | this.argument = argument; |
| 490 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 491 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 492 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 493 | this.argument = argument; |
| 494 | if (phone != null) { |
| 495 | this.phone = phone; |
| 496 | } |
| 497 | this.workSource = workSource; |
| 498 | } |
| 499 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 500 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 501 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 502 | if (subId != null) { |
| 503 | this.subId = subId; |
| 504 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 505 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 506 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 509 | private static final class IncomingThirdPartyCallArgs { |
| 510 | public final ComponentName component; |
| 511 | public final String callId; |
| 512 | public final String callerDisplayName; |
| 513 | |
| 514 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 515 | String callerDisplayName) { |
| 516 | this.component = component; |
| 517 | this.callId = callId; |
| 518 | this.callerDisplayName = callerDisplayName; |
| 519 | } |
| 520 | } |
| 521 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | /** |
| 523 | * A handler that processes messages on the main thread in the phone process. Since many |
| 524 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 525 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 526 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 527 | * on, which will be notified when the operation completes and will contain the result of the |
| 528 | * request. |
| 529 | * |
| 530 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 531 | * note that request.result must be set to something non-null for the calling thread to |
| 532 | * unblock. |
| 533 | */ |
| 534 | private final class MainThreadHandler extends Handler { |
| 535 | @Override |
| 536 | public void handleMessage(Message msg) { |
| 537 | MainThreadRequest request; |
| 538 | Message onCompleted; |
| 539 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 540 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 542 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 543 | |
| 544 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | case CMD_HANDLE_USSD_REQUEST: { |
| 546 | request = (MainThreadRequest) msg.obj; |
| 547 | final Phone phone = getPhoneFromRequest(request); |
| 548 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 549 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 551 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 552 | if (!isUssdApiAllowed(request.subId)) { |
| 553 | // Carrier does not support use of this API, return failure. |
| 554 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 555 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 556 | Bundle returnData = new Bundle(); |
| 557 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 558 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 559 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 560 | request.result = true; |
| 561 | notifyRequester(request); |
| 562 | return; |
| 563 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 564 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 565 | try { |
| 566 | request.result = phone != null |
| 567 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 568 | } catch (CallStateException cse) { |
| 569 | request.result = false; |
| 570 | } |
| 571 | // Wake up the requesting thread |
| 572 | notifyRequester(request); |
| 573 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 576 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 577 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 578 | final Phone phone = getPhoneFromRequest(request); |
| 579 | request.result = phone != null ? |
| 580 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 581 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 582 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 583 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 584 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 585 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 586 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 588 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 589 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 590 | uiccPort = getUiccPortFromRequest(request); |
| 591 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 592 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 593 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 594 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 597 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 598 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 599 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 600 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 601 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 602 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | break; |
| 604 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 605 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 606 | ar = (AsyncResult) msg.obj; |
| 607 | request = (MainThreadRequest) ar.userObj; |
| 608 | if (ar.exception == null && ar.result != null) { |
| 609 | request.result = ar.result; |
| 610 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 611 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | if (ar.result == null) { |
| 613 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 614 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 615 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 616 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | } else { |
| 618 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 619 | } |
| 620 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | break; |
| 623 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 625 | request = (MainThreadRequest) msg.obj; |
| 626 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 627 | uiccPort = getUiccPortFromRequest(request); |
| 628 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 630 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 631 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 632 | } else { |
| 633 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 634 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 635 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 636 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 637 | iccArgument.p2, |
| 638 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | } |
| 640 | break; |
| 641 | |
| 642 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 643 | ar = (AsyncResult) msg.obj; |
| 644 | request = (MainThreadRequest) ar.userObj; |
| 645 | if (ar.exception == null && ar.result != null) { |
| 646 | request.result = ar.result; |
| 647 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 648 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 649 | if (ar.result == null) { |
| 650 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 651 | } else if (ar.exception instanceof CommandException) { |
| 652 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 653 | ar.exception); |
| 654 | } else { |
| 655 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 656 | } |
| 657 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 658 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | break; |
| 660 | |
| 661 | case CMD_EXCHANGE_SIM_IO: |
| 662 | request = (MainThreadRequest) msg.obj; |
| 663 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 664 | uiccPort = getUiccPortFromRequest(request); |
| 665 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 667 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 669 | } else { |
| 670 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 671 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 672 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 673 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 674 | iccArgument.data, onCompleted); |
| 675 | } |
| 676 | break; |
| 677 | |
| 678 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 679 | ar = (AsyncResult) msg.obj; |
| 680 | request = (MainThreadRequest) ar.userObj; |
| 681 | if (ar.exception == null && ar.result != null) { |
| 682 | request.result = ar.result; |
| 683 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 684 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 686 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 689 | case CMD_SEND_ENVELOPE: |
| 690 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 691 | uiccPort = getUiccPortFromRequest(request); |
| 692 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 693 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 694 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 695 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 696 | } else { |
| 697 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 698 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 699 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_SEND_ENVELOPE_DONE: |
| 703 | ar = (AsyncResult) msg.obj; |
| 704 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 705 | if (ar.exception == null && ar.result != null) { |
| 706 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 707 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 708 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 709 | if (ar.result == null) { |
| 710 | loge("sendEnvelopeWithStatus: Empty response"); |
| 711 | } else if (ar.exception instanceof CommandException) { |
| 712 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 713 | ar.exception); |
| 714 | } else { |
| 715 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 716 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 717 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 721 | case CMD_OPEN_CHANNEL: |
| 722 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 723 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 724 | IccLogicalChannelRequest openChannelRequest = |
| 725 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 726 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 728 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 729 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 730 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 731 | } else { |
| 732 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 733 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 734 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 735 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case EVENT_OPEN_CHANNEL_DONE: |
| 739 | ar = (AsyncResult) msg.obj; |
| 740 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 742 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 743 | int[] result = (int[]) ar.result; |
| 744 | int channelId = result[0]; |
| 745 | byte[] selectResponse = null; |
| 746 | if (result.length > 1) { |
| 747 | selectResponse = new byte[result.length - 1]; |
| 748 | for (int i = 1; i < result.length; ++i) { |
| 749 | selectResponse[i - 1] = (byte) result[i]; |
| 750 | } |
| 751 | } |
| 752 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 753 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 754 | |
| 755 | uiccPort = getUiccPortFromRequest(request); |
| 756 | IccLogicalChannelRequest channelRequest = |
| 757 | (IccLogicalChannelRequest) request.argument; |
| 758 | channelRequest.channel = channelId; |
| 759 | uiccPort.onLogicalChannelOpened(channelRequest); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | if (ar.result == null) { |
| 762 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 764 | if (ar.exception != null) { |
| 765 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 766 | } |
| 767 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 768 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 769 | if (ar.exception instanceof CommandException) { |
| 770 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 771 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 772 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 773 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 774 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 775 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 779 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 780 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 781 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 782 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 783 | break; |
| 784 | |
| 785 | case CMD_CLOSE_CHANNEL: |
| 786 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 787 | uiccPort = getUiccPortFromRequest(request); |
| 788 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 789 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 790 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 791 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 793 | } else { |
| 794 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 795 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 796 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 797 | break; |
| 798 | |
| 799 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 800 | ar = (AsyncResult) msg.obj; |
| 801 | request = (MainThreadRequest) ar.userObj; |
| 802 | if (ar.exception == null) { |
| 803 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 804 | uiccPort = getUiccPortFromRequest(request); |
| 805 | final int channelId = (Integer) request.argument; |
| 806 | uiccPort.onLogicalChannelClosed(channelId); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 807 | } else { |
| 808 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 809 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 810 | if (ar.exception instanceof CommandException) { |
| 811 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 812 | CommandException.Error error = |
| 813 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 814 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 815 | // should only throw exceptions from the binder threads. |
| 816 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 817 | "iccCloseLogicalChannel: invalid argument "); |
| 818 | } |
| 819 | } else { |
| 820 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 821 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 822 | request.result = (exception != null) ? exception : |
| 823 | new IllegalStateException( |
| 824 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 825 | } |
| 826 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case CMD_NV_READ_ITEM: |
| 830 | request = (MainThreadRequest) msg.obj; |
| 831 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 832 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 833 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 837 | ar = (AsyncResult) msg.obj; |
| 838 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 839 | if (ar.exception == null && ar.result != null) { |
| 840 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 842 | request.result = ""; |
| 843 | if (ar.result == null) { |
| 844 | loge("nvReadItem: Empty response"); |
| 845 | } else if (ar.exception instanceof CommandException) { |
| 846 | loge("nvReadItem: CommandException: " + |
| 847 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 849 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 852 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 853 | break; |
| 854 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 855 | case CMD_NV_WRITE_ITEM: |
| 856 | request = (MainThreadRequest) msg.obj; |
| 857 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 858 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 859 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 860 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case EVENT_NV_WRITE_ITEM_DONE: |
| 864 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 865 | break; |
| 866 | |
| 867 | case CMD_NV_WRITE_CDMA_PRL: |
| 868 | request = (MainThreadRequest) msg.obj; |
| 869 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 870 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 874 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 875 | break; |
| 876 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 877 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 878 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 879 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 880 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 881 | break; |
| 882 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 883 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 884 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | break; |
| 886 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 887 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 888 | request = (MainThreadRequest) msg.obj; |
| 889 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 890 | request); |
| 891 | Phone phone = getPhoneFromRequest(request); |
| 892 | if (phone != null) { |
| 893 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 894 | } else { |
| 895 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 896 | request.result = false; |
| 897 | notifyRequester(request); |
| 898 | } |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 903 | ar = (AsyncResult) msg.obj; |
| 904 | request = (MainThreadRequest) ar.userObj; |
| 905 | if (ar.exception == null && ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
| 908 | // request.result must be set to something non-null |
| 909 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 910 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 911 | request.result = ar.result; |
| 912 | } else { |
| 913 | request.result = false; |
| 914 | } |
| 915 | if (ar.result == null) { |
| 916 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 917 | } else if (ar.exception instanceof CommandException) { |
| 918 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 919 | + ar.exception); |
| 920 | } else { |
| 921 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 922 | } |
| 923 | } |
| 924 | notifyRequester(request); |
| 925 | break; |
| 926 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 927 | case CMD_IS_VONR_ENABLED: { |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 930 | request); |
| 931 | Phone phone = getPhoneFromRequest(request); |
| 932 | if (phone != null) { |
| 933 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 934 | } else { |
| 935 | loge("isVoNrEnabled: No phone object"); |
| 936 | request.result = false; |
| 937 | notifyRequester(request); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | case EVENT_IS_VONR_ENABLED_DONE: |
| 943 | ar = (AsyncResult) msg.obj; |
| 944 | request = (MainThreadRequest) ar.userObj; |
| 945 | if (ar.exception == null && ar.result != null) { |
| 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | // request.result must be set to something non-null |
| 949 | // for the calling thread to unblock |
| 950 | if (ar.result != null) { |
| 951 | request.result = ar.result; |
| 952 | } else { |
| 953 | request.result = false; |
| 954 | } |
| 955 | if (ar.result == null) { |
| 956 | loge("isVoNrEnabled: Empty response"); |
| 957 | } else if (ar.exception instanceof CommandException) { |
| 958 | loge("isVoNrEnabled: CommandException: " |
| 959 | + ar.exception); |
| 960 | } else { |
| 961 | loge("isVoNrEnabled: Unknown exception"); |
| 962 | } |
| 963 | } |
| 964 | notifyRequester(request); |
| 965 | break; |
| 966 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 967 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 968 | request = (MainThreadRequest) msg.obj; |
| 969 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 970 | Phone phone = getPhoneFromRequest(request); |
| 971 | if (phone != null) { |
| 972 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 973 | request.workSource); |
| 974 | } else { |
| 975 | loge("enableNrDualConnectivity: No phone object"); |
| 976 | request.result = |
| 977 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 978 | notifyRequester(request); |
| 979 | } |
| 980 | break; |
| 981 | } |
| 982 | |
| 983 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | if (ar.exception == null) { |
| 987 | request.result = |
| 988 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 989 | } else { |
| 990 | request.result = |
| 991 | TelephonyManager |
| 992 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 993 | if (ar.exception instanceof CommandException) { |
| 994 | CommandException.Error error = |
| 995 | ((CommandException) (ar.exception)).getCommandError(); |
| 996 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 997 | request.result = |
| 998 | TelephonyManager |
| 999 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1000 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1001 | request.result = |
| 1002 | TelephonyManager |
| 1003 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1004 | } |
| 1005 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1006 | + ar.exception); |
| 1007 | } else { |
| 1008 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1009 | } |
| 1010 | } |
| 1011 | notifyRequester(request); |
| 1012 | break; |
| 1013 | } |
| 1014 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1015 | case CMD_ENABLE_VONR: { |
| 1016 | request = (MainThreadRequest) msg.obj; |
| 1017 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1018 | Phone phone = getPhoneFromRequest(request); |
| 1019 | if (phone != null) { |
| 1020 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1021 | request.workSource); |
| 1022 | } else { |
| 1023 | loge("setVoNrEnabled: No phone object"); |
| 1024 | request.result = |
| 1025 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1026 | notifyRequester(request); |
| 1027 | } |
| 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | case EVENT_ENABLE_VONR_DONE: { |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
| 1034 | if (ar.exception == null) { |
| 1035 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1036 | } else { |
| 1037 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1038 | if (ar.exception instanceof CommandException) { |
| 1039 | CommandException.Error error = |
| 1040 | ((CommandException) (ar.exception)).getCommandError(); |
| 1041 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1042 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1043 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1044 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1045 | } else { |
| 1046 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1047 | } |
| 1048 | loge("setVoNrEnabled" + ": CommandException: " |
| 1049 | + ar.exception); |
| 1050 | } else { |
| 1051 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1052 | } |
| 1053 | } |
| 1054 | notifyRequester(request); |
| 1055 | break; |
| 1056 | } |
| 1057 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1058 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1059 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1060 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1061 | request); |
| 1062 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1063 | break; |
| 1064 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1065 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null && ar.result != null) { |
| 1069 | request.result = ar.result; // Integer |
| 1070 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1071 | // request.result must be set to something non-null |
| 1072 | // for the calling thread to unblock |
| 1073 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1074 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1075 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1076 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1077 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1078 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1079 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1080 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1083 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1084 | break; |
| 1085 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1086 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1087 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1088 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1089 | request); |
| 1090 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1091 | (Pair<Integer, Long>) request.argument; |
| 1092 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1093 | reasonWithNetworkTypes.first, |
| 1094 | reasonWithNetworkTypes.second, |
| 1095 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1096 | break; |
| 1097 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1098 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1099 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1100 | break; |
| 1101 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1102 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1103 | request = (MainThreadRequest)msg.obj; |
| 1104 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1105 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | |
| 1108 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1109 | ar = (AsyncResult)msg.obj; |
| 1110 | request = (MainThreadRequest)ar.userObj; |
| 1111 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1112 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1113 | break; |
| 1114 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1115 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1116 | request = (MainThreadRequest) msg.obj; |
| 1117 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1118 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1119 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1120 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1124 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1125 | break; |
| 1126 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1127 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1128 | request = (MainThreadRequest) msg.obj; |
| 1129 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1130 | request); |
| 1131 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1132 | break; |
| 1133 | |
| 1134 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1135 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1136 | break; |
| 1137 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1138 | case CMD_PERFORM_NETWORK_SCAN: |
| 1139 | request = (MainThreadRequest) msg.obj; |
| 1140 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1141 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1142 | break; |
| 1143 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1144 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | request = (MainThreadRequest) msg.obj; |
| 1146 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1147 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1148 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1149 | request.argument; |
| 1150 | int callForwardingReason = args.first; |
| 1151 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | } |
| 1154 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | ar = (AsyncResult) msg.obj; |
| 1156 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1158 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1159 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1161 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1163 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1164 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1165 | // any service for voice call. |
| 1166 | if ((callForwardInfo.serviceClass |
| 1167 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1168 | callForwardingInfo = new CallForwardingInfo( |
| 1169 | callForwardInfo.status |
| 1170 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | callForwardInfo.reason, |
| 1172 | callForwardInfo.number, |
| 1173 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | // Didn't find a call forward info for voice call. |
| 1178 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1179 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1180 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1181 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1182 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1183 | } else { |
| 1184 | if (ar.result == null) { |
| 1185 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1186 | } |
| 1187 | if (ar.exception != null) { |
| 1188 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1189 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1190 | int errorCode = TelephonyManager |
| 1191 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | if (ar.exception instanceof CommandException) { |
| 1193 | CommandException.Error error = |
| 1194 | ((CommandException) (ar.exception)).getCommandError(); |
| 1195 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1196 | errorCode = TelephonyManager |
| 1197 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1198 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1199 | errorCode = TelephonyManager |
| 1200 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | } |
| 1202 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1208 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1214 | request.argument).first; |
| 1215 | request.phone.setCallForwardingOption( |
| 1216 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1217 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | callForwardingInfoToSet.getReason(), |
| 1220 | callForwardingInfoToSet.getNumber(), |
| 1221 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1222 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | ar = (AsyncResult) msg.obj; |
| 1227 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | Consumer<Integer> callback = |
| 1229 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1230 | request.argument).second; |
| 1231 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1233 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1234 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | if (ar.exception instanceof CommandException) { |
| 1236 | CommandException.Error error = |
| 1237 | ((CommandException) (ar.exception)).getCommandError(); |
| 1238 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1240 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1242 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1243 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | callback.accept(errorCode); |
| 1247 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | request = (MainThreadRequest) msg.obj; |
| 1255 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1256 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1264 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1265 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1266 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | // Service Class is a bit mask per 3gpp 27.007. |
| 1268 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1269 | if (callForwardResults.length > 1 |
| 1270 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1272 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1274 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1276 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | } |
| 1278 | } else { |
| 1279 | if (ar.result == null) { |
| 1280 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1281 | } |
| 1282 | if (ar.exception != null) { |
| 1283 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1284 | } |
| 1285 | if (ar.exception instanceof CommandException) { |
| 1286 | CommandException.Error error = |
| 1287 | ((CommandException) (ar.exception)).getCommandError(); |
| 1288 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1289 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1290 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1291 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1292 | callWaitingStatus = |
| 1293 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1297 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1298 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1299 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1300 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1302 | request = (MainThreadRequest) msg.obj; |
| 1303 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1305 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1306 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1307 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1308 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1310 | ar = (AsyncResult) msg.obj; |
| 1311 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1312 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1313 | Consumer<Integer> callback = |
| 1314 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1315 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1316 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1317 | if (ar.exception instanceof CommandException) { |
| 1318 | CommandException.Error error = |
| 1319 | ((CommandException) (ar.exception)).getCommandError(); |
| 1320 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1321 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1322 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1323 | callback.accept( |
| 1324 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1325 | } else { |
| 1326 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1327 | } |
| 1328 | } else { |
| 1329 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1330 | } |
| 1331 | } else { |
| 1332 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1333 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1334 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1336 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1337 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1338 | ar = (AsyncResult) msg.obj; |
| 1339 | request = (MainThreadRequest) ar.userObj; |
| 1340 | CellNetworkScanResult cellScanResult; |
| 1341 | if (ar.exception == null && ar.result != null) { |
| 1342 | cellScanResult = new CellNetworkScanResult( |
| 1343 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1344 | (List<OperatorInfo>) ar.result); |
| 1345 | } else { |
| 1346 | if (ar.result == null) { |
| 1347 | loge("getCellNetworkScanResults: Empty response"); |
| 1348 | } |
| 1349 | if (ar.exception != null) { |
| 1350 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1351 | } |
| 1352 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1353 | if (ar.exception instanceof CommandException) { |
| 1354 | CommandException.Error error = |
| 1355 | ((CommandException) (ar.exception)).getCommandError(); |
| 1356 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1357 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1358 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1359 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1360 | } |
| 1361 | } |
| 1362 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1363 | } |
| 1364 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1365 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1366 | break; |
| 1367 | |
| 1368 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1369 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1370 | ManualNetworkSelectionArgument selArg = |
| 1371 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1372 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1373 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1374 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1375 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1376 | break; |
| 1377 | |
| 1378 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1379 | ar = (AsyncResult) msg.obj; |
| 1380 | request = (MainThreadRequest) ar.userObj; |
| 1381 | if (ar.exception == null) { |
| 1382 | request.result = true; |
| 1383 | } else { |
| 1384 | request.result = false; |
| 1385 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1386 | } |
| 1387 | notifyRequester(request); |
| 1388 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1389 | break; |
| 1390 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1391 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1392 | request = (MainThreadRequest) msg.obj; |
| 1393 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1394 | if (defaultPhone != null) { |
| 1395 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1396 | } else { |
| 1397 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1398 | Bundle bundle = new Bundle(); |
| 1399 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1400 | new ModemActivityInfo(0, 0, 0, |
| 1401 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1402 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1403 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1404 | break; |
| 1405 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1406 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1407 | ar = (AsyncResult) msg.obj; |
| 1408 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1409 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1410 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1411 | if (mLastModemActivityInfo == null) { |
| 1412 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1413 | mLastModemActivitySpecificInfo[0] = |
| 1414 | new ActivityStatsTechSpecificInfo( |
| 1415 | 0, |
| 1416 | 0, |
| 1417 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1418 | 0); |
| 1419 | mLastModemActivityInfo = |
| 1420 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1421 | } |
| 1422 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1423 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1424 | // Update the last modem activity info and the result of the request. |
| 1425 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1426 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1427 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1428 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1429 | mLastModemActivityInfo = |
| 1430 | new ModemActivityInfo( |
| 1431 | mLastModemActivityInfo.getTimestampMillis(), |
| 1432 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1433 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1434 | mLastModemActivitySpecificInfo); |
| 1435 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1436 | } else { |
| 1437 | if (ar.result == null) { |
| 1438 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1439 | error = TelephonyManager.ModemActivityInfoException |
| 1440 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1441 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1442 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1443 | error = TelephonyManager.ModemActivityInfoException |
| 1444 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1445 | } else { |
| 1446 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1447 | error = TelephonyManager.ModemActivityInfoException |
| 1448 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1449 | } |
| 1450 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1451 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1452 | if (mLastModemActivityInfo != null) { |
| 1453 | bundle.putParcelable( |
| 1454 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1455 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1456 | } else { |
| 1457 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1458 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1459 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1460 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1461 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1462 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1463 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1464 | case CMD_SET_ALLOWED_CARRIERS: |
| 1465 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1466 | CarrierRestrictionRules argument = |
| 1467 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1468 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1469 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | |
| 1472 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1473 | ar = (AsyncResult) msg.obj; |
| 1474 | request = (MainThreadRequest) ar.userObj; |
| 1475 | if (ar.exception == null && ar.result != null) { |
| 1476 | request.result = ar.result; |
| 1477 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1478 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1479 | if (ar.exception instanceof CommandException) { |
| 1480 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1481 | CommandException.Error error = |
| 1482 | ((CommandException) (ar.exception)).getCommandError(); |
| 1483 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1484 | request.result = |
| 1485 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1486 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1487 | } else { |
| 1488 | loge("setAllowedCarriers: Unknown exception"); |
| 1489 | } |
| 1490 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1491 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | |
| 1494 | case CMD_GET_ALLOWED_CARRIERS: |
| 1495 | request = (MainThreadRequest) msg.obj; |
| 1496 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1497 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1498 | break; |
| 1499 | |
| 1500 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1501 | ar = (AsyncResult) msg.obj; |
| 1502 | request = (MainThreadRequest) ar.userObj; |
| 1503 | if (ar.exception == null && ar.result != null) { |
| 1504 | request.result = ar.result; |
| 1505 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1506 | request.result = new IllegalStateException( |
| 1507 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1508 | if (ar.result == null) { |
| 1509 | loge("getAllowedCarriers: Empty response"); |
| 1510 | } else if (ar.exception instanceof CommandException) { |
| 1511 | loge("getAllowedCarriers: CommandException: " + |
| 1512 | ar.exception); |
| 1513 | } else { |
| 1514 | loge("getAllowedCarriers: Unknown exception"); |
| 1515 | } |
| 1516 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1517 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1518 | break; |
| 1519 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1520 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1521 | ar = (AsyncResult) msg.obj; |
| 1522 | request = (MainThreadRequest) ar.userObj; |
| 1523 | if (ar.exception == null && ar.result != null) { |
| 1524 | request.result = ar.result; |
| 1525 | } else { |
| 1526 | request.result = new IllegalArgumentException( |
| 1527 | "Failed to retrieve Forbidden Plmns"); |
| 1528 | if (ar.result == null) { |
| 1529 | loge("getForbiddenPlmns: Empty response"); |
| 1530 | } else { |
| 1531 | loge("getForbiddenPlmns: Unknown exception"); |
| 1532 | } |
| 1533 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1534 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1535 | break; |
| 1536 | |
| 1537 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1538 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1539 | uiccPort = getUiccPortFromRequest(request); |
| 1540 | if (uiccPort == null) { |
| 1541 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1542 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1543 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1544 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1545 | break; |
| 1546 | } |
| 1547 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1548 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1549 | if (uiccApp == null) { |
| 1550 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1551 | + appType); |
| 1552 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1553 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1554 | break; |
| 1555 | } else { |
| 1556 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1557 | + " specified type -- " + appType); |
| 1558 | } |
| 1559 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1560 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1561 | onCompleted); |
| 1562 | break; |
| 1563 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1564 | case CMD_SWITCH_SLOTS: |
| 1565 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1566 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1567 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1568 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1569 | break; |
| 1570 | |
| 1571 | case EVENT_SWITCH_SLOTS_DONE: |
| 1572 | ar = (AsyncResult) msg.obj; |
| 1573 | request = (MainThreadRequest) ar.userObj; |
| 1574 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1575 | notifyRequester(request); |
| 1576 | break; |
| 1577 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1578 | request = (MainThreadRequest) msg.obj; |
| 1579 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1580 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1581 | break; |
| 1582 | |
| 1583 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1584 | ar = (AsyncResult) msg.obj; |
| 1585 | request = (MainThreadRequest) ar.userObj; |
| 1586 | if (ar.exception != null) { |
| 1587 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1588 | } else { |
| 1589 | int mode = ((int[]) ar.result)[0]; |
| 1590 | if (mode == 0) { |
| 1591 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1592 | } else { |
| 1593 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1594 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1595 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1596 | notifyRequester(request); |
| 1597 | break; |
| 1598 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1599 | request = (MainThreadRequest) msg.obj; |
| 1600 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1601 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1602 | break; |
| 1603 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1604 | ar = (AsyncResult) msg.obj; |
| 1605 | request = (MainThreadRequest) ar.userObj; |
| 1606 | if (ar.exception != null) { |
| 1607 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1608 | } else { |
| 1609 | request.result = ((int[]) ar.result)[0]; |
| 1610 | } |
| 1611 | notifyRequester(request); |
| 1612 | break; |
| 1613 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1614 | request = (MainThreadRequest) msg.obj; |
| 1615 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1616 | int mode = (int) request.argument; |
| 1617 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1618 | break; |
| 1619 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1620 | ar = (AsyncResult) msg.obj; |
| 1621 | request = (MainThreadRequest) ar.userObj; |
| 1622 | request.result = ar.exception == null; |
| 1623 | notifyRequester(request); |
| 1624 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1625 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1626 | request = (MainThreadRequest) msg.obj; |
| 1627 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1628 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1629 | break; |
| 1630 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1631 | ar = (AsyncResult) msg.obj; |
| 1632 | request = (MainThreadRequest) ar.userObj; |
| 1633 | if (ar.exception != null) { |
| 1634 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1635 | } else { |
| 1636 | request.result = ((int[]) ar.result)[0]; |
| 1637 | } |
| 1638 | notifyRequester(request); |
| 1639 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1640 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1641 | request = (MainThreadRequest) msg.obj; |
| 1642 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1643 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1644 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1645 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1646 | break; |
| 1647 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1648 | ar = (AsyncResult) msg.obj; |
| 1649 | request = (MainThreadRequest) ar.userObj; |
| 1650 | request.result = ar.exception == null; |
| 1651 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1652 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1653 | case CMD_GET_ALL_CELL_INFO: |
| 1654 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1655 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1656 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1657 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1659 | ar = (AsyncResult) msg.obj; |
| 1660 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1661 | // If a timeout occurs, the response will be null |
| 1662 | request.result = (ar.exception == null && ar.result != null) |
| 1663 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1664 | synchronized (request) { |
| 1665 | request.notifyAll(); |
| 1666 | } |
| 1667 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1668 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1671 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1672 | break; |
| 1673 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1674 | ar = (AsyncResult) msg.obj; |
| 1675 | request = (MainThreadRequest) ar.userObj; |
| 1676 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1677 | try { |
| 1678 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1679 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1680 | cb.onError( |
| 1681 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1682 | ar.exception.getClass().getName(), |
| 1683 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1684 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1685 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1686 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1687 | } else { |
| 1688 | // use the result as returned |
| 1689 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1690 | } |
| 1691 | } catch (RemoteException re) { |
| 1692 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1693 | } |
| 1694 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1695 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1696 | request = (MainThreadRequest) msg.obj; |
| 1697 | WorkSource ws = (WorkSource) request.argument; |
| 1698 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1699 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1700 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1701 | } |
| 1702 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1703 | ar = (AsyncResult) msg.obj; |
| 1704 | request = (MainThreadRequest) ar.userObj; |
| 1705 | if (ar.exception == null) { |
| 1706 | request.result = ar.result; |
| 1707 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1708 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1709 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1710 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | synchronized (request) { |
| 1714 | request.notifyAll(); |
| 1715 | } |
| 1716 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1717 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1718 | case CMD_MODEM_REBOOT: |
| 1719 | request = (MainThreadRequest) msg.obj; |
| 1720 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1721 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1722 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1723 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1724 | handleNullReturnEvent(msg, "rebootModem"); |
| 1725 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1726 | case CMD_REQUEST_ENABLE_MODEM: |
| 1727 | request = (MainThreadRequest) msg.obj; |
| 1728 | boolean enable = (boolean) request.argument; |
| 1729 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1730 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1731 | PhoneConfigurationManager.getInstance() |
| 1732 | .enablePhone(request.phone, enable, onCompleted); |
| 1733 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1734 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1735 | ar = (AsyncResult) msg.obj; |
| 1736 | request = (MainThreadRequest) ar.userObj; |
| 1737 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1738 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1739 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1740 | if ((boolean) request.result) { |
| 1741 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1742 | updateModemStateMetrics(); |
| 1743 | } else { |
| 1744 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1745 | + ar.exception); |
| 1746 | } |
| 1747 | notifyRequester(request); |
| 1748 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1749 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1750 | case CMD_GET_MODEM_STATUS: |
| 1751 | request = (MainThreadRequest) msg.obj; |
| 1752 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1753 | PhoneConfigurationManager.getInstance() |
| 1754 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1755 | break; |
| 1756 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1757 | ar = (AsyncResult) msg.obj; |
| 1758 | request = (MainThreadRequest) ar.userObj; |
| 1759 | int id = request.phone.getPhoneId(); |
| 1760 | if (ar.exception == null && ar.result != null) { |
| 1761 | request.result = ar.result; |
| 1762 | //update the cache as modem status has changed |
| 1763 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1764 | (boolean) request.result); |
| 1765 | } else { |
| 1766 | // Return true if modem status cannot be retrieved. For most cases, |
| 1767 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1768 | // and disable modem are not supported. Modem is always on. |
| 1769 | // TODO: this should be fixed in R to support a third |
| 1770 | // status UNKNOWN b/131631629 |
| 1771 | request.result = true; |
| 1772 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1773 | + ar.exception); |
| 1774 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1775 | notifyRequester(request); |
| 1776 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1777 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1778 | request = (MainThreadRequest) msg.obj; |
| 1779 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1780 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1781 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1782 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1783 | break; |
| 1784 | } |
| 1785 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1786 | ar = (AsyncResult) msg.obj; |
| 1787 | request = (MainThreadRequest) ar.userObj; |
| 1788 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1789 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1790 | args.second.accept(ar.exception == null); |
| 1791 | notifyRequester(request); |
| 1792 | break; |
| 1793 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1794 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1795 | request = (MainThreadRequest) msg.obj; |
| 1796 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1797 | Phone phone = getPhoneFromRequest(request); |
| 1798 | if (phone != null) { |
| 1799 | phone.getSystemSelectionChannels(onCompleted); |
| 1800 | } else { |
| 1801 | loge("getSystemSelectionChannels: No phone object"); |
| 1802 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1803 | notifyRequester(request); |
| 1804 | } |
| 1805 | break; |
| 1806 | } |
| 1807 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1808 | ar = (AsyncResult) msg.obj; |
| 1809 | request = (MainThreadRequest) ar.userObj; |
| 1810 | if (ar.exception == null && ar.result != null) { |
| 1811 | request.result = ar.result; |
| 1812 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1813 | request.result = new IllegalStateException( |
| 1814 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1815 | if (ar.result == null) { |
| 1816 | loge("getSystemSelectionChannels: Empty response"); |
| 1817 | } else { |
| 1818 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1819 | } |
| 1820 | } |
| 1821 | notifyRequester(request); |
| 1822 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1823 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1824 | ar = (AsyncResult) msg.obj; |
| 1825 | request = (MainThreadRequest) ar.userObj; |
| 1826 | if (ar.exception == null && ar.result != null) { |
| 1827 | request.result = ar.result; |
| 1828 | } else { |
| 1829 | request.result = -1; |
| 1830 | loge("Failed to set Forbidden Plmns"); |
| 1831 | if (ar.result == null) { |
| 1832 | loge("setForbidenPlmns: Empty response"); |
| 1833 | } else if (ar.exception != null) { |
| 1834 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1835 | request.result = -1; |
| 1836 | } else { |
| 1837 | loge("setForbiddenPlmns: Unknown exception"); |
| 1838 | } |
| 1839 | } |
| 1840 | notifyRequester(request); |
| 1841 | break; |
| 1842 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1843 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1844 | uiccPort = getUiccPortFromRequest(request); |
| 1845 | if (uiccPort == null) { |
| 1846 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1847 | request.result = -1; |
| 1848 | notifyRequester(request); |
| 1849 | break; |
| 1850 | } |
| 1851 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1852 | (Pair<Integer, List<String>>) request.argument; |
| 1853 | appType = setFplmnsArgs.first; |
| 1854 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1855 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1856 | if (uiccApp == null) { |
| 1857 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1858 | request.result = -1; |
| 1859 | loge("Failed to get UICC App"); |
| 1860 | notifyRequester(request); |
| 1861 | } else { |
| 1862 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1863 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1864 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1865 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1866 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1867 | case CMD_ERASE_MODEM_CONFIG: |
| 1868 | request = (MainThreadRequest) msg.obj; |
| 1869 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1870 | defaultPhone.eraseModemConfig(onCompleted); |
| 1871 | break; |
| 1872 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1873 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1874 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1875 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1876 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1877 | request = (MainThreadRequest) msg.obj; |
| 1878 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1879 | notifyRequester(request); |
| 1880 | break; |
| 1881 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1882 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1883 | request = (MainThreadRequest) msg.obj; |
| 1884 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1885 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1886 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1887 | changed.first, changed.second, onCompleted); |
| 1888 | break; |
| 1889 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1890 | ar = (AsyncResult) msg.obj; |
| 1891 | request = (MainThreadRequest) ar.userObj; |
| 1892 | if (ar.exception == null) { |
| 1893 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1894 | // If the operation is successful, update the PIN storage |
| 1895 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1896 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1897 | UiccController.getInstance().getPinStorage() |
| 1898 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1899 | } else { |
| 1900 | request.result = msg.arg1; |
| 1901 | } |
| 1902 | notifyRequester(request); |
| 1903 | break; |
| 1904 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1905 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1906 | request = (MainThreadRequest) msg.obj; |
| 1907 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1908 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1909 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1910 | enabled.first, enabled.second, onCompleted); |
| 1911 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1912 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1913 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1914 | ar = (AsyncResult) msg.obj; |
| 1915 | request = (MainThreadRequest) ar.userObj; |
| 1916 | if (ar.exception == null) { |
| 1917 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1918 | // If the operation is successful, update the PIN storage |
| 1919 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1920 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1921 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1922 | UiccController.getInstance().getPinStorage() |
| 1923 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1924 | } else { |
| 1925 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1926 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1927 | } else { |
| 1928 | request.result = msg.arg1; |
| 1929 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1930 | |
| 1931 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1932 | notifyRequester(request); |
| 1933 | break; |
| 1934 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1935 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1936 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1937 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1938 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1939 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1940 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1941 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1942 | |
| 1943 | case CMD_SET_DATA_THROTTLING: { |
| 1944 | request = (MainThreadRequest) msg.obj; |
| 1945 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1946 | DataThrottlingRequest dataThrottlingRequest = |
| 1947 | (DataThrottlingRequest) request.argument; |
| 1948 | Phone phone = getPhoneFromRequest(request); |
| 1949 | if (phone != null) { |
| 1950 | phone.setDataThrottling(onCompleted, |
| 1951 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1952 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1953 | } else { |
| 1954 | loge("setDataThrottling: No phone object"); |
| 1955 | request.result = |
| 1956 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1957 | notifyRequester(request); |
| 1958 | } |
| 1959 | |
| 1960 | break; |
| 1961 | } |
| 1962 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1963 | ar = (AsyncResult) msg.obj; |
| 1964 | request = (MainThreadRequest) ar.userObj; |
| 1965 | |
| 1966 | if (ar.exception == null) { |
| 1967 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1968 | } else if (ar.exception instanceof CommandException) { |
| 1969 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1970 | CommandException.Error error = |
| 1971 | ((CommandException) (ar.exception)).getCommandError(); |
| 1972 | |
| 1973 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1974 | request.result = TelephonyManager |
| 1975 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1976 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1977 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1978 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1979 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1980 | } else { |
| 1981 | request.result = |
| 1982 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1983 | } |
| 1984 | } else { |
| 1985 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1986 | } |
| 1987 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1988 | notifyRequester(request); |
| 1989 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1990 | |
| 1991 | case CMD_SET_SIM_POWER: { |
| 1992 | request = (MainThreadRequest) msg.obj; |
| 1993 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1994 | request = (MainThreadRequest) msg.obj; |
| 1995 | int stateToSet = |
| 1996 | ((Pair<Integer, IIntegerConsumer>) |
| 1997 | request.argument).first; |
| 1998 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1999 | break; |
| 2000 | } |
| 2001 | case EVENT_SET_SIM_POWER_DONE: { |
| 2002 | ar = (AsyncResult) msg.obj; |
| 2003 | request = (MainThreadRequest) ar.userObj; |
| 2004 | IIntegerConsumer callback = |
| 2005 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2006 | if (ar.exception != null) { |
| 2007 | loge("setSimPower exception: " + ar.exception); |
| 2008 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2009 | .RESULT_ERROR_UNKNOWN; |
| 2010 | if (ar.exception instanceof CommandException) { |
| 2011 | CommandException.Error error = |
| 2012 | ((CommandException) (ar.exception)).getCommandError(); |
| 2013 | if (error == CommandException.Error.SIM_ERR) { |
| 2014 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2015 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2016 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2017 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2018 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2019 | } else { |
| 2020 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2021 | } |
| 2022 | } |
| 2023 | try { |
| 2024 | callback.accept(errorCode); |
| 2025 | } catch (RemoteException e) { |
| 2026 | // Ignore if the remote process is no longer available to call back. |
| 2027 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2028 | } |
| 2029 | } else { |
| 2030 | try { |
| 2031 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2032 | } catch (RemoteException e) { |
| 2033 | // Ignore if the remote process is no longer available to call back. |
| 2034 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2035 | } |
| 2036 | } |
| 2037 | break; |
| 2038 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2039 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2040 | request = (MainThreadRequest) msg.obj; |
| 2041 | |
| 2042 | final Phone phone = getPhoneFromRequest(request); |
| 2043 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2044 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2045 | notifyRequester(request); |
| 2046 | break; |
| 2047 | } |
| 2048 | |
| 2049 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2050 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2051 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2052 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2053 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2054 | request.subId, pair.first /*callingUid*/, |
| 2055 | pair.second /*request*/, onCompleted); |
| 2056 | break; |
| 2057 | } |
| 2058 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2059 | ar = (AsyncResult) msg.obj; |
| 2060 | request = (MainThreadRequest) ar.userObj; |
| 2061 | // request.result will be the exception of ar if present, true otherwise. |
| 2062 | // Be cautious not to leave result null which will wait() forever |
| 2063 | request.result = ar.exception != null ? ar.exception : true; |
| 2064 | notifyRequester(request); |
| 2065 | break; |
| 2066 | } |
| 2067 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2068 | request = (MainThreadRequest) msg.obj; |
| 2069 | |
| 2070 | Phone phone = getPhoneFromRequest(request); |
| 2071 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2072 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2073 | notifyRequester(request); |
| 2074 | break; |
| 2075 | } |
| 2076 | |
| 2077 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2078 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2079 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2080 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2081 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2082 | request.subId, pair.first /*callingUid*/, |
| 2083 | pair.second /*request*/, onCompleted); |
| 2084 | break; |
| 2085 | } |
| 2086 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2087 | ar = (AsyncResult) msg.obj; |
| 2088 | request = (MainThreadRequest) ar.userObj; |
| 2089 | request.result = ar.exception != null ? ar.exception : true; |
| 2090 | notifyRequester(request); |
| 2091 | break; |
| 2092 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2093 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2094 | case CMD_GET_SLICING_CONFIG: { |
| 2095 | request = (MainThreadRequest) msg.obj; |
| 2096 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2097 | request.phone.getSlicingConfig(onCompleted); |
| 2098 | break; |
| 2099 | } |
| 2100 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2101 | ar = (AsyncResult) msg.obj; |
| 2102 | request = (MainThreadRequest) ar.userObj; |
| 2103 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2104 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2105 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2106 | Bundle bundle = new Bundle(); |
| 2107 | int resultCode = 0; |
| 2108 | if (ar.exception != null) { |
| 2109 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2110 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2111 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2112 | } else if (ar.result == null) { |
| 2113 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2114 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2115 | } else { |
| 2116 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2117 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2118 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2119 | } |
| 2120 | |
| 2121 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2122 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2123 | } |
| 2124 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2125 | result.send(resultCode, bundle); |
| 2126 | notifyRequester(request); |
| 2127 | break; |
| 2128 | } |
| 2129 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2130 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2131 | request = (MainThreadRequest) msg.obj; |
| 2132 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2133 | UiccController.getInstance().getPinStorage() |
| 2134 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2135 | notifyRequester(request); |
| 2136 | break; |
| 2137 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | default: |
| 2139 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2140 | break; |
| 2141 | } |
| 2142 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2143 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2144 | private void notifyRequester(MainThreadRequest request) { |
| 2145 | synchronized (request) { |
| 2146 | request.notifyAll(); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2150 | private void handleNullReturnEvent(Message msg, String command) { |
| 2151 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2152 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2153 | if (ar.exception == null) { |
| 2154 | request.result = true; |
| 2155 | } else { |
| 2156 | request.result = false; |
| 2157 | if (ar.exception instanceof CommandException) { |
| 2158 | loge(command + ": CommandException: " + ar.exception); |
| 2159 | } else { |
| 2160 | loge(command + ": Unknown exception"); |
| 2161 | } |
| 2162 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2163 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2164 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * Posts the specified command to be executed on the main thread, |
| 2169 | * waits for the request to complete, and returns the result. |
| 2170 | * @see #sendRequestAsync |
| 2171 | */ |
| 2172 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2173 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2174 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | /** |
| 2178 | * Posts the specified command to be executed on the main thread, |
| 2179 | * waits for the request to complete, and returns the result. |
| 2180 | * @see #sendRequestAsync |
| 2181 | */ |
| 2182 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2183 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2184 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | /** |
| 2188 | * Posts the specified command to be executed on the main thread, |
| 2189 | * waits for the request to complete, and returns the result. |
| 2190 | * @see #sendRequestAsync |
| 2191 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2192 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2193 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2194 | } |
| 2195 | |
| 2196 | /** |
| 2197 | * Posts the specified command to be executed on the main thread, |
| 2198 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2199 | * if not timeout or null otherwise. |
| 2200 | * @see #sendRequestAsync |
| 2201 | */ |
| 2202 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2203 | long timeoutInMs) { |
| 2204 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * Posts the specified command to be executed on the main thread, |
| 2209 | * waits for the request to complete, and returns the result. |
| 2210 | * @see #sendRequestAsync |
| 2211 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2212 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2213 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | /** |
| 2217 | * Posts the specified command to be executed on the main thread, |
| 2218 | * waits for the request to complete, and returns the result. |
| 2219 | * @see #sendRequestAsync |
| 2220 | */ |
| 2221 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2222 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2223 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2227 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2228 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2229 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2230 | * @see #sendRequestAsync |
| 2231 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2232 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2233 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2235 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2236 | } |
| 2237 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2238 | MainThreadRequest request = null; |
| 2239 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2240 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2241 | } else if (phone != null) { |
| 2242 | request = new MainThreadRequest(argument, phone, workSource); |
| 2243 | } else { |
| 2244 | request = new MainThreadRequest(argument, subId, workSource); |
| 2245 | } |
| 2246 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2248 | msg.sendToTarget(); |
| 2249 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2250 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2251 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2252 | if (timeoutInMs >= 0) { |
| 2253 | // Wait for at least timeoutInMs before returning null request result |
| 2254 | long now = SystemClock.elapsedRealtime(); |
| 2255 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2256 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2257 | try { |
| 2258 | request.wait(deadline - now); |
| 2259 | } catch (InterruptedException e) { |
| 2260 | // Do nothing, go back and check if request is completed or timeout |
| 2261 | } finally { |
| 2262 | now = SystemClock.elapsedRealtime(); |
| 2263 | } |
| 2264 | } |
| 2265 | } else { |
| 2266 | // Wait for the request to complete |
| 2267 | while (request.result == null) { |
| 2268 | try { |
| 2269 | request.wait(); |
| 2270 | } catch (InterruptedException e) { |
| 2271 | // Do nothing, go back and wait until the request is complete |
| 2272 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2276 | if (request.result == null) { |
| 2277 | Log.wtf(LOG_TAG, |
| 2278 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2280 | return request.result; |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2285 | * Posts the specified command to be executed on the main thread, and |
| 2286 | * returns immediately. |
| 2287 | * @see #sendRequest |
| 2288 | */ |
| 2289 | private void sendRequestAsync(int command) { |
| 2290 | mMainThreadHandler.sendEmptyMessage(command); |
| 2291 | } |
| 2292 | |
| 2293 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2294 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2295 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2296 | */ |
| 2297 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2298 | sendRequestAsync(command, argument, null, null); |
| 2299 | } |
| 2300 | |
| 2301 | /** |
| 2302 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2303 | * @see {@link #sendRequest(int,Object)} |
| 2304 | */ |
| 2305 | private void sendRequestAsync( |
| 2306 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2307 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2308 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2309 | msg.sendToTarget(); |
| 2310 | } |
| 2311 | |
| 2312 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2314 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2315 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2316 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2317 | synchronized (PhoneInterfaceManager.class) { |
| 2318 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2319 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2320 | } else { |
| 2321 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2322 | } |
| 2323 | return sInstance; |
| 2324 | } |
| 2325 | } |
| 2326 | |
| 2327 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2328 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2329 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2331 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2332 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2334 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2335 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2336 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2337 | mTelephonySharedPreferences = |
| 2338 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2339 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2340 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2341 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2342 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2343 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2344 | publish(); |
| 2345 | } |
| 2346 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2347 | private Phone getDefaultPhone() { |
| 2348 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2349 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2350 | } |
| 2351 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2352 | private void publish() { |
| 2353 | if (DBG) log("publish: " + this); |
| 2354 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2355 | TelephonyFrameworkInitializer |
| 2356 | .getTelephonyServiceManager() |
| 2357 | .getTelephonyServiceRegisterer() |
| 2358 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2361 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2362 | if (request.phone != null) { |
| 2363 | return request.phone; |
| 2364 | } else { |
| 2365 | return getPhoneFromSubId(request.subId); |
| 2366 | } |
| 2367 | } |
| 2368 | |
| 2369 | private Phone getPhoneFromSubId(int subId) { |
| 2370 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2371 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2372 | } |
| 2373 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2374 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2375 | Phone phone = getPhoneFromRequest(request); |
| 2376 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2377 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2380 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2381 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2382 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2383 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2384 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2385 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2386 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2387 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2388 | } |
| 2389 | |
| 2390 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2391 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2392 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2395 | private boolean isImsAvailableOnDevice() { |
| 2396 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2397 | if (pm == null) { |
| 2398 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2399 | // so do not throw error and allow. |
| 2400 | return true; |
| 2401 | } |
| 2402 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2403 | } |
| 2404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2406 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2407 | } |
| 2408 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2409 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | if (DBG) log("dial: " + number); |
| 2411 | // No permission check needed here: This is just a wrapper around the |
| 2412 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2413 | // the UI before it does anything. |
| 2414 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | final long identity = Binder.clearCallingIdentity(); |
| 2416 | try { |
| 2417 | String url = createTelUrl(number); |
| 2418 | if (url == null) { |
| 2419 | return; |
| 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2422 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2423 | PhoneConstants.State state = mCM.getState(subId); |
| 2424 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2425 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2426 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2427 | mApp.startActivity(intent); |
| 2428 | } |
| 2429 | } finally { |
| 2430 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | } |
| 2432 | } |
| 2433 | |
| 2434 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2435 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2438 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | if (DBG) log("call: " + number); |
| 2440 | |
| 2441 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2442 | // need to do a permission check since we're calling startActivity() |
| 2443 | // from the context of the phone app. |
| 2444 | enforceCallPermission(); |
| 2445 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2446 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2447 | != AppOpsManager.MODE_ALLOWED) { |
| 2448 | return; |
| 2449 | } |
| 2450 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | final long identity = Binder.clearCallingIdentity(); |
| 2452 | try { |
| 2453 | String url = createTelUrl(number); |
| 2454 | if (url == null) { |
| 2455 | return; |
| 2456 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2458 | boolean isValid = false; |
| 2459 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2460 | if (slist != null) { |
| 2461 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2462 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2463 | isValid = true; |
| 2464 | break; |
| 2465 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2466 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2467 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | if (!isValid) { |
| 2469 | return; |
| 2470 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2472 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2473 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2474 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2475 | mApp.startActivity(intent); |
| 2476 | } finally { |
| 2477 | Binder.restoreCallingIdentity(identity); |
| 2478 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2481 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2482 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2483 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2484 | } |
| 2485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2486 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2487 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2488 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2489 | } |
| 2490 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2491 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2492 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | |
| 2494 | final long identity = Binder.clearCallingIdentity(); |
| 2495 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2496 | Phone phone = getPhone(subId); |
| 2497 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | checkSimPin.start(); |
| 2499 | return checkSimPin.unlockSim(null, pin); |
| 2500 | } finally { |
| 2501 | Binder.restoreCallingIdentity(identity); |
| 2502 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2505 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2506 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | |
| 2508 | final long identity = Binder.clearCallingIdentity(); |
| 2509 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2510 | Phone phone = getPhone(subId); |
| 2511 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2512 | checkSimPuk.start(); |
| 2513 | return checkSimPuk.unlockSim(puk, pin); |
| 2514 | } finally { |
| 2515 | Binder.restoreCallingIdentity(identity); |
| 2516 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2520 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | * a synchronous one. |
| 2522 | */ |
| 2523 | private static class UnlockSim extends Thread { |
| 2524 | |
| 2525 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2526 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2527 | |
| 2528 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2529 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2530 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2531 | |
| 2532 | // For replies from SimCard interface |
| 2533 | private Handler mHandler; |
| 2534 | |
| 2535 | // For async handler to identify request type |
| 2536 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2537 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2538 | UnlockSim(int phoneId, IccCard simCard) { |
| 2539 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2540 | mSimCard = simCard; |
| 2541 | } |
| 2542 | |
| 2543 | @Override |
| 2544 | public void run() { |
| 2545 | Looper.prepare(); |
| 2546 | synchronized (UnlockSim.this) { |
| 2547 | mHandler = new Handler() { |
| 2548 | @Override |
| 2549 | public void handleMessage(Message msg) { |
| 2550 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2551 | switch (msg.what) { |
| 2552 | case SUPPLY_PIN_COMPLETE: |
| 2553 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2554 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2555 | mRetryCount = msg.arg1; |
| 2556 | if (ar.exception != null) { |
| 2557 | if (ar.exception instanceof CommandException && |
| 2558 | ((CommandException)(ar.exception)).getCommandError() |
| 2559 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2560 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2561 | } //When UiccCardApp dispose,handle message and return exception |
| 2562 | else if (ar.exception instanceof CommandException && |
| 2563 | ((CommandException) (ar.exception)).getCommandError() |
| 2564 | == CommandException.Error.ABORTED) { |
| 2565 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2566 | } else { |
| 2567 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2568 | } |
| 2569 | } else { |
| 2570 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2571 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | mDone = true; |
| 2573 | UnlockSim.this.notifyAll(); |
| 2574 | } |
| 2575 | break; |
| 2576 | } |
| 2577 | } |
| 2578 | }; |
| 2579 | UnlockSim.this.notifyAll(); |
| 2580 | } |
| 2581 | Looper.loop(); |
| 2582 | } |
| 2583 | |
| 2584 | /* |
| 2585 | * Use PIN or PUK to unlock SIM card |
| 2586 | * |
| 2587 | * If PUK is null, unlock SIM card with PIN |
| 2588 | * |
| 2589 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2590 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2591 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2592 | |
| 2593 | while (mHandler == null) { |
| 2594 | try { |
| 2595 | wait(); |
| 2596 | } catch (InterruptedException e) { |
| 2597 | Thread.currentThread().interrupt(); |
| 2598 | } |
| 2599 | } |
| 2600 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2601 | |
| 2602 | if (puk == null) { |
| 2603 | mSimCard.supplyPin(pin, callback); |
| 2604 | } else { |
| 2605 | mSimCard.supplyPuk(puk, pin, callback); |
| 2606 | } |
| 2607 | |
| 2608 | while (!mDone) { |
| 2609 | try { |
| 2610 | Log.d(LOG_TAG, "wait for done"); |
| 2611 | wait(); |
| 2612 | } catch (InterruptedException e) { |
| 2613 | // Restore the interrupted status |
| 2614 | Thread.currentThread().interrupt(); |
| 2615 | } |
| 2616 | } |
| 2617 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2618 | int[] resultArray = new int[2]; |
| 2619 | resultArray[0] = mResult; |
| 2620 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2621 | |
| 2622 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2623 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2626 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2627 | } |
| 2628 | } |
| 2629 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2630 | /** |
| 2631 | * This method has been removed due to privacy and stability concerns. |
| 2632 | */ |
| 2633 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2635 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2636 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2637 | } |
| 2638 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2639 | @Override |
| 2640 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2641 | mApp.getSystemService(AppOpsManager.class) |
| 2642 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2643 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2644 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2645 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2646 | // Callers targeting S have no business invoking this method. |
| 2647 | return; |
| 2648 | } |
| 2649 | |
| 2650 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2651 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2652 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2653 | .setCallingPackage(callingPackage) |
| 2654 | .setCallingFeatureId(null) |
| 2655 | .setCallingPid(Binder.getCallingPid()) |
| 2656 | .setCallingUid(Binder.getCallingUid()) |
| 2657 | .setMethod("updateServiceLocation") |
| 2658 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2659 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2660 | .build()); |
| 2661 | // Apps that lack location permission have no business calling this method; |
| 2662 | // however, because no permission was declared in the public API, denials must |
| 2663 | // all be "soft". |
| 2664 | switch (locationResult) { |
| 2665 | case DENIED_HARD: /* fall through */ |
| 2666 | case DENIED_SOFT: |
| 2667 | return; |
| 2668 | } |
| 2669 | |
| 2670 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2673 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2675 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2676 | } |
| 2677 | } finally { |
| 2678 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2679 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2682 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2683 | @Override |
| 2684 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2685 | return isRadioOnWithFeature(callingPackage, null); |
| 2686 | } |
| 2687 | |
| 2688 | |
| 2689 | @Override |
| 2690 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2691 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2692 | callingFeatureId); |
| 2693 | } |
| 2694 | |
| 2695 | @Deprecated |
| 2696 | @Override |
| 2697 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2698 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2701 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2702 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2703 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2704 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2705 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2706 | return false; |
| 2707 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2708 | |
| 2709 | final long identity = Binder.clearCallingIdentity(); |
| 2710 | try { |
| 2711 | return isRadioOnForSubscriber(subId); |
| 2712 | } finally { |
| 2713 | Binder.restoreCallingIdentity(identity); |
| 2714 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2718 | final long identity = Binder.clearCallingIdentity(); |
| 2719 | try { |
| 2720 | final Phone phone = getPhone(subId); |
| 2721 | if (phone != null) { |
| 2722 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2723 | } else { |
| 2724 | return false; |
| 2725 | } |
| 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2732 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2733 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2734 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2735 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2737 | |
| 2738 | final long identity = Binder.clearCallingIdentity(); |
| 2739 | try { |
| 2740 | final Phone phone = getPhone(subId); |
| 2741 | if (phone != null) { |
| 2742 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2743 | } |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2746 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2750 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2753 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2754 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2755 | |
| 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
| 2758 | final Phone phone = getPhone(subId); |
| 2759 | if (phone == null) { |
| 2760 | return false; |
| 2761 | } |
| 2762 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2763 | toggleRadioOnOffForSubscriber(subId); |
| 2764 | } |
| 2765 | return true; |
| 2766 | } finally { |
| 2767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2770 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2771 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2772 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2773 | /* |
| 2774 | * If any of the Radios are available, it will need to be |
| 2775 | * shutdown. So return true if any Radio is available. |
| 2776 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2777 | final long identity = Binder.clearCallingIdentity(); |
| 2778 | try { |
| 2779 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2780 | Phone phone = PhoneFactory.getPhone(i); |
| 2781 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2782 | } |
| 2783 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2784 | return false; |
| 2785 | } finally { |
| 2786 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2787 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2790 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2791 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | enforceModifyPermission(); |
| 2793 | |
| 2794 | final long identity = Binder.clearCallingIdentity(); |
| 2795 | try { |
| 2796 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2797 | logv("Shutting down Phone " + i); |
| 2798 | shutdownRadioUsingPhoneId(i); |
| 2799 | } |
| 2800 | } finally { |
| 2801 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2806 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2807 | if (phone != null && phone.isRadioAvailable()) { |
| 2808 | phone.shutdownRadio(); |
| 2809 | } |
| 2810 | } |
| 2811 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2814 | |
| 2815 | final long identity = Binder.clearCallingIdentity(); |
| 2816 | try { |
| 2817 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2818 | if (defaultPhone != null) { |
| 2819 | defaultPhone.setRadioPower(turnOn); |
| 2820 | return true; |
| 2821 | } else { |
| 2822 | loge("There's no default phone."); |
| 2823 | return false; |
| 2824 | } |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2827 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2830 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2832 | |
| 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | final Phone phone = getPhone(subId); |
| 2836 | if (phone != null) { |
| 2837 | phone.setRadioPower(turnOn); |
| 2838 | return true; |
| 2839 | } else { |
| 2840 | return false; |
| 2841 | } |
| 2842 | } finally { |
| 2843 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2844 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2847 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2848 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | public boolean enableDataConnectivity() { |
| 2850 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2851 | |
| 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| 2854 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2855 | final Phone phone = getPhone(subId); |
| 2856 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2857 | if (phone.isUsingNewDataStack()) { |
| 2858 | phone.getDataSettingsManager().setDataEnabled( |
| 2859 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2860 | } else { |
| 2861 | phone.getDataEnabledSettings().setDataEnabled( |
| 2862 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2863 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | return true; |
| 2865 | } else { |
| 2866 | return false; |
| 2867 | } |
| 2868 | } finally { |
| 2869 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2870 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2873 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2874 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2875 | public boolean disableDataConnectivity() { |
| 2876 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2877 | |
| 2878 | final long identity = Binder.clearCallingIdentity(); |
| 2879 | try { |
| 2880 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2881 | final Phone phone = getPhone(subId); |
| 2882 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2883 | if (phone.isUsingNewDataStack()) { |
| 2884 | phone.getDataSettingsManager().setDataEnabled( |
| 2885 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2886 | } else { |
| 2887 | phone.getDataEnabledSettings().setDataEnabled( |
| 2888 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | return true; |
| 2891 | } else { |
| 2892 | return false; |
| 2893 | } |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2896 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2899 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2900 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | final long identity = Binder.clearCallingIdentity(); |
| 2902 | try { |
| 2903 | final Phone phone = getPhone(subId); |
| 2904 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2905 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2906 | } else { |
| 2907 | return false; |
| 2908 | } |
| 2909 | } finally { |
| 2910 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2911 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2915 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2918 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2919 | enforceCallPermission(); |
| 2920 | |
| 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
| 2923 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2924 | return; |
| 2925 | } |
| 2926 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2927 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2928 | } finally { |
| 2929 | Binder.restoreCallingIdentity(identity); |
| 2930 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2931 | }; |
| 2932 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2933 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | |
| 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2939 | return false; |
| 2940 | } |
| 2941 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2944 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2947 | /** |
| 2948 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2949 | * tag on getCallState Binder call. |
| 2950 | */ |
| 2951 | @Deprecated |
| 2952 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2954 | if (CompatChanges.isChangeEnabled( |
| 2955 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2956 | Binder.getCallingUid())) { |
| 2957 | // Do not allow this API to be called on API version 31+, it should only be |
| 2958 | // called on old apps using this Binder call directly. |
| 2959 | throw new SecurityException("This method can only be used for applications " |
| 2960 | + "targeting API version 30 or less."); |
| 2961 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2962 | final long identity = Binder.clearCallingIdentity(); |
| 2963 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2964 | Phone phone = getPhone(getDefaultSubscription()); |
| 2965 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2966 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2967 | } finally { |
| 2968 | Binder.restoreCallingIdentity(identity); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
| 2973 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2974 | if (CompatChanges.isChangeEnabled( |
| 2975 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2976 | Binder.getCallingUid())) { |
| 2977 | // Check READ_PHONE_STATE for API version 31+ |
| 2978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2979 | featureId, "getCallStateForSubscription")) { |
| 2980 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2981 | + "targeting API level 31+."); |
| 2982 | } |
| 2983 | } |
| 2984 | final long identity = Binder.clearCallingIdentity(); |
| 2985 | try { |
| 2986 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2988 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2989 | } finally { |
| 2990 | Binder.restoreCallingIdentity(identity); |
| 2991 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2994 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2995 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2996 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2997 | } |
| 2998 | |
| 2999 | @Override |
| 3000 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | final long identity = Binder.clearCallingIdentity(); |
| 3002 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3003 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3005 | if (phone.isUsingNewDataStack()) { |
| 3006 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3007 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3008 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3009 | } else { |
| 3010 | return PhoneConstantConversions.convertDataState( |
| 3011 | PhoneConstants.DataState.DISCONNECTED); |
| 3012 | } |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3018 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3019 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3020 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3021 | } |
| 3022 | |
| 3023 | @Override |
| 3024 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3027 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | if (phone != null) { |
| 3029 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 3030 | } else { |
| 3031 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3032 | } |
| 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3035 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3039 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3040 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3041 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3042 | |
| 3043 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3044 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3045 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3046 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3047 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3048 | .setCallingPid(Binder.getCallingPid()) |
| 3049 | .setCallingUid(Binder.getCallingUid()) |
| 3050 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3051 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3052 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3053 | .build()); |
| 3054 | switch (locationResult) { |
| 3055 | case DENIED_HARD: |
| 3056 | throw new SecurityException("Not allowed to access cell location"); |
| 3057 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3058 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3059 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3062 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3066 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3067 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
| 3070 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3073 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3074 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3075 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3076 | // registered cell info, so return a NULL country instead. |
| 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3079 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3080 | // Get default phone in this case. |
| 3081 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3082 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3083 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3084 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3085 | if (phone == null) return ""; |
| 3086 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3087 | if (sst == null) return ""; |
| 3088 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3089 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3090 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3091 | } finally { |
| 3092 | Binder.restoreCallingIdentity(identity); |
| 3093 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3096 | /** |
| 3097 | * This method was removed due to potential issues caused by performing partial |
| 3098 | * updates of service state, and lack of a credible use case. |
| 3099 | * |
| 3100 | * This has the ability to break the telephony implementation by disabling notification of |
| 3101 | * changes in device connectivity. DO NOT USE THIS! |
| 3102 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3103 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | public void enableLocationUpdates() { |
| 3105 | mApp.enforceCallingOrSelfPermission( |
| 3106 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3109 | /** |
| 3110 | * This method was removed due to potential issues caused by performing partial |
| 3111 | * updates of service state, and lack of a credible use case. |
| 3112 | * |
| 3113 | * This has the ability to break the telephony implementation by disabling notification of |
| 3114 | * changes in device connectivity. DO NOT USE THIS! |
| 3115 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3116 | @Override |
| 3117 | public void disableLocationUpdates() { |
| 3118 | mApp.enforceCallingOrSelfPermission( |
| 3119 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | @Override |
| 3123 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3124 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3125 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3126 | try { |
| 3127 | mApp.getSystemService(AppOpsManager.class) |
| 3128 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3129 | } catch (SecurityException e) { |
| 3130 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3131 | throw e; |
| 3132 | } |
| 3133 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3134 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3135 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3136 | throw new SecurityException( |
| 3137 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3138 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3139 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3140 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3141 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3142 | return null; |
| 3143 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3144 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3145 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3146 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3147 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3148 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3149 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3150 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3151 | for (CellInfo ci : info) { |
| 3152 | if (ci instanceof CellInfoGsm) { |
| 3153 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3154 | } else if (ci instanceof CellInfoWcdma) { |
| 3155 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3157 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3158 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3161 | private List<CellInfo> getCachedCellInfo() { |
| 3162 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3163 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3164 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3165 | if (info != null) cellInfos.addAll(info); |
| 3166 | } |
| 3167 | return cellInfos; |
| 3168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3169 | |
| 3170 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3171 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3172 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3173 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3174 | |
| 3175 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3176 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3177 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3178 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3179 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3180 | .setCallingPid(Binder.getCallingPid()) |
| 3181 | .setCallingUid(Binder.getCallingUid()) |
| 3182 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3183 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3184 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3185 | .build()); |
| 3186 | switch (locationResult) { |
| 3187 | case DENIED_HARD: |
| 3188 | throw new SecurityException("Not allowed to access cell info"); |
| 3189 | case DENIED_SOFT: |
| 3190 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3191 | } |
| 3192 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3193 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3194 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3195 | return getCachedCellInfo(); |
| 3196 | } |
| 3197 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3198 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3199 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
| 3202 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3203 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3204 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3205 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3206 | if (info != null) cellInfos.addAll(info); |
| 3207 | } |
| 3208 | return cellInfos; |
| 3209 | } finally { |
| 3210 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3214 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3215 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3216 | String callingFeatureId) { |
| 3217 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3218 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3222 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3223 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3224 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3225 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3226 | } |
| 3227 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3228 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3229 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3230 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3231 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3232 | |
| 3233 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3234 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3235 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3236 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3237 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3238 | .setCallingPid(Binder.getCallingPid()) |
| 3239 | .setCallingUid(Binder.getCallingUid()) |
| 3240 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3241 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3242 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3243 | .build()); |
| 3244 | switch (locationResult) { |
| 3245 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3246 | if (TelephonyPermissions |
| 3247 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3248 | // Safetynet logging for b/154934934 |
| 3249 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3250 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3251 | throw new SecurityException("Not allowed to access cell info"); |
| 3252 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3253 | if (TelephonyPermissions |
| 3254 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3255 | // Safetynet logging for b/154934934 |
| 3256 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3257 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3258 | try { |
| 3259 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3260 | } catch (RemoteException re) { |
| 3261 | // Drop without consequences |
| 3262 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3263 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3266 | |
| 3267 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3268 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3269 | |
| 3270 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3271 | } |
| 3272 | |
| 3273 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3274 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3275 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3276 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | |
| 3278 | final long identity = Binder.clearCallingIdentity(); |
| 3279 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3280 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
| 3283 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3286 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3287 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3288 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3289 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3290 | return null; |
| 3291 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3292 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3293 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3294 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3295 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3296 | return null; |
| 3297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3298 | |
| 3299 | final long identity = Binder.clearCallingIdentity(); |
| 3300 | try { |
| 3301 | return phone.getImei(); |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
| 3304 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
| 3307 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3308 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3309 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3310 | String tac = null; |
| 3311 | if (phone != null) { |
| 3312 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3313 | try { |
| 3314 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3315 | } catch (IndexOutOfBoundsException e) { |
| 3316 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3317 | return null; |
| 3318 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3319 | } |
| 3320 | return tac; |
| 3321 | } |
| 3322 | |
| 3323 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3324 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3325 | try { |
| 3326 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3327 | } catch (SecurityException se) { |
| 3328 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3329 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3330 | + Binder.getCallingUid()); |
| 3331 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3332 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3333 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3334 | return null; |
| 3335 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3336 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3337 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3338 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3339 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3340 | return null; |
| 3341 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3342 | |
| 3343 | final long identity = Binder.clearCallingIdentity(); |
| 3344 | try { |
| 3345 | return phone.getMeid(); |
| 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
| 3348 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3352 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3353 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3354 | String manufacturerCode = null; |
| 3355 | if (phone != null) { |
| 3356 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3357 | try { |
| 3358 | manufacturerCode = |
| 3359 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3360 | } catch (IndexOutOfBoundsException e) { |
| 3361 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3362 | return null; |
| 3363 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3364 | } |
| 3365 | return manufacturerCode; |
| 3366 | } |
| 3367 | |
| 3368 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3369 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3370 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3371 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3372 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3373 | return null; |
| 3374 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3375 | int subId = phone.getSubId(); |
| 3376 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3377 | mApp, subId, callingPackage, callingFeatureId, |
| 3378 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3379 | return null; |
| 3380 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3381 | |
| 3382 | final long identity = Binder.clearCallingIdentity(); |
| 3383 | try { |
| 3384 | return phone.getDeviceSvn(); |
| 3385 | } finally { |
| 3386 | Binder.restoreCallingIdentity(identity); |
| 3387 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3390 | @Override |
| 3391 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | final long identity = Binder.clearCallingIdentity(); |
| 3393 | try { |
| 3394 | final Phone phone = getPhone(subId); |
| 3395 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3396 | } finally { |
| 3397 | Binder.restoreCallingIdentity(identity); |
| 3398 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | @Override |
| 3402 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3403 | final long identity = Binder.clearCallingIdentity(); |
| 3404 | try { |
| 3405 | final Phone phone = getPhone(subId); |
| 3406 | return phone == null ? null : phone.getCarrierName(); |
| 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3410 | } |
| 3411 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3412 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3413 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3414 | final long identity = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | final Phone phone = getPhone(subId); |
| 3417 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3418 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3419 | } finally { |
| 3420 | Binder.restoreCallingIdentity(identity); |
| 3421 | } |
| 3422 | } |
| 3423 | |
| 3424 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3425 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3426 | final long identity = Binder.clearCallingIdentity(); |
| 3427 | try { |
| 3428 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3429 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3430 | } finally { |
| 3431 | Binder.restoreCallingIdentity(identity); |
| 3432 | } |
| 3433 | } |
| 3434 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3435 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3436 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3437 | if (!isSubscriptionMccMnc) { |
| 3438 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3439 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3440 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3441 | if (phone == null) { |
| 3442 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3443 | } |
| 3444 | final long identity = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3447 | } finally { |
| 3448 | Binder.restoreCallingIdentity(identity); |
| 3449 | } |
| 3450 | } |
| 3451 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3452 | // |
| 3453 | // Internal helper methods. |
| 3454 | // |
| 3455 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3456 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3457 | * Make sure the caller is the calling package itself |
| 3458 | * |
| 3459 | * @throws SecurityException if the caller is not the calling package |
| 3460 | */ |
| 3461 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3462 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3463 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3464 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3465 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3466 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3467 | } catch (PackageManager.NameNotFoundException e) { |
| 3468 | // packageUid is -1 |
| 3469 | } |
| 3470 | if (packageUid != callingUid) { |
| 3471 | throw new SecurityException(message + ": Package " + callingPackage |
| 3472 | + " does not belong to " + callingUid); |
| 3473 | } |
| 3474 | } |
| 3475 | |
| 3476 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3477 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3478 | * |
| 3479 | * @throws SecurityException if the caller does not have the required permission |
| 3480 | */ |
| 3481 | private void enforceModifyPermission() { |
| 3482 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3483 | } |
| 3484 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3485 | private void enforceActiveEmergencySessionPermission() { |
| 3486 | mApp.enforceCallingOrSelfPermission( |
| 3487 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3488 | } |
| 3489 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3490 | /** |
| 3491 | * Make sure the caller has the CALL_PHONE permission. |
| 3492 | * |
| 3493 | * @throws SecurityException if the caller does not have the required permission |
| 3494 | */ |
| 3495 | private void enforceCallPermission() { |
| 3496 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3497 | } |
| 3498 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3499 | private void enforceSettingsPermission() { |
| 3500 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3503 | private void enforceRebootPermission() { |
| 3504 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3505 | } |
| 3506 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3507 | private String createTelUrl(String number) { |
| 3508 | if (TextUtils.isEmpty(number)) { |
| 3509 | return null; |
| 3510 | } |
| 3511 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3512 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3515 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3516 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3517 | } |
| 3518 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3519 | private static void logv(String msg) { |
| 3520 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3521 | } |
| 3522 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3523 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3524 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3525 | } |
| 3526 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3527 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3528 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3529 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3532 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3533 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3534 | final long identity = Binder.clearCallingIdentity(); |
| 3535 | try { |
| 3536 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3537 | if (phone == null) { |
| 3538 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3539 | } else { |
| 3540 | return phone.getPhoneType(); |
| 3541 | } |
| 3542 | } finally { |
| 3543 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3544 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | /** |
| 3548 | * Returns the CDMA ERI icon index to display |
| 3549 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3550 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3551 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3552 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3553 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3556 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3557 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3558 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3559 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3560 | mApp, subId, callingPackage, callingFeatureId, |
| 3561 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3562 | return -1; |
| 3563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3564 | |
| 3565 | final long identity = Binder.clearCallingIdentity(); |
| 3566 | try { |
| 3567 | final Phone phone = getPhone(subId); |
| 3568 | if (phone != null) { |
| 3569 | return phone.getCdmaEriIconIndex(); |
| 3570 | } else { |
| 3571 | return -1; |
| 3572 | } |
| 3573 | } finally { |
| 3574 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3575 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | /** |
| 3579 | * Returns the CDMA ERI icon mode, |
| 3580 | * 0 - ON |
| 3581 | * 1 - FLASHING |
| 3582 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3583 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3584 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3585 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3586 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3589 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3590 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3591 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3592 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3593 | mApp, subId, callingPackage, callingFeatureId, |
| 3594 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3595 | return -1; |
| 3596 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3597 | |
| 3598 | final long identity = Binder.clearCallingIdentity(); |
| 3599 | try { |
| 3600 | final Phone phone = getPhone(subId); |
| 3601 | if (phone != null) { |
| 3602 | return phone.getCdmaEriIconMode(); |
| 3603 | } else { |
| 3604 | return -1; |
| 3605 | } |
| 3606 | } finally { |
| 3607 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3608 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | /** |
| 3612 | * Returns the CDMA ERI text, |
| 3613 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3614 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3615 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3616 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3617 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3620 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3621 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3622 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3623 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3624 | mApp, subId, callingPackage, callingFeatureId, |
| 3625 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3626 | return null; |
| 3627 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3628 | |
| 3629 | final long identity = Binder.clearCallingIdentity(); |
| 3630 | try { |
| 3631 | final Phone phone = getPhone(subId); |
| 3632 | if (phone != null) { |
| 3633 | return phone.getCdmaEriText(); |
| 3634 | } else { |
| 3635 | return null; |
| 3636 | } |
| 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3639 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3643 | * Returns the CDMA MDN. |
| 3644 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3645 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3646 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3648 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | |
| 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3653 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3654 | return phone.getLine1Number(); |
| 3655 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3656 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3657 | return null; |
| 3658 | } |
| 3659 | } finally { |
| 3660 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | /** |
| 3665 | * Returns the CDMA MIN. |
| 3666 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3667 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3668 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3670 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3671 | |
| 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | final Phone phone = getPhone(subId); |
| 3675 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3676 | return phone.getCdmaMin(); |
| 3677 | } else { |
| 3678 | return null; |
| 3679 | } |
| 3680 | } finally { |
| 3681 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3685 | @Override |
| 3686 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3687 | INumberVerificationCallback callback, String callingPackage) { |
| 3688 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3689 | != PERMISSION_GRANTED) { |
| 3690 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3691 | } |
| 3692 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3693 | |
| 3694 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3695 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3696 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3697 | + "calling package: " + callingPackage |
| 3698 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | if (range == null) { |
| 3702 | throw new NullPointerException("Range must be non-null"); |
| 3703 | } |
| 3704 | |
| 3705 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3706 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3707 | |
| 3708 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3709 | } |
| 3710 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3711 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3712 | * Returns true if CDMA provisioning needs to run. |
| 3713 | */ |
| 3714 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3715 | final long identity = Binder.clearCallingIdentity(); |
| 3716 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3717 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3718 | } finally { |
| 3719 | Binder.restoreCallingIdentity(identity); |
| 3720 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3724 | * Sets the voice mail number of a given subId. |
| 3725 | */ |
| 3726 | @Override |
| 3727 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3728 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3729 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3730 | |
| 3731 | final long identity = Binder.clearCallingIdentity(); |
| 3732 | try { |
| 3733 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3734 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3735 | return success; |
| 3736 | } finally { |
| 3737 | Binder.restoreCallingIdentity(identity); |
| 3738 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3739 | } |
| 3740 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3741 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3742 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3743 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3744 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3745 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3746 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3747 | throw new SecurityException("caller must be system dialer"); |
| 3748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3749 | |
| 3750 | final long identity = Binder.clearCallingIdentity(); |
| 3751 | try { |
| 3752 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3753 | if (phoneAccountHandle == null) { |
| 3754 | return null; |
| 3755 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3756 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3759 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3763 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3764 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3765 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3766 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3767 | mApp, subId, callingPackage, callingFeatureId, |
| 3768 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3769 | return null; |
| 3770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3771 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3772 | final long identity = Binder.clearCallingIdentity(); |
| 3773 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3774 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(identity); |
| 3777 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3781 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3782 | VisualVoicemailSmsFilterSettings settings) { |
| 3783 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3784 | |
| 3785 | final long identity = Binder.clearCallingIdentity(); |
| 3786 | try { |
| 3787 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3788 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3789 | } finally { |
| 3790 | Binder.restoreCallingIdentity(identity); |
| 3791 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3795 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3796 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | |
| 3798 | final long identity = Binder.clearCallingIdentity(); |
| 3799 | try { |
| 3800 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3801 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3802 | } finally { |
| 3803 | Binder.restoreCallingIdentity(identity); |
| 3804 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3808 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3809 | String callingPackage, int subId) { |
| 3810 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | |
| 3812 | final long identity = Binder.clearCallingIdentity(); |
| 3813 | try { |
| 3814 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3815 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3816 | } finally { |
| 3817 | Binder.restoreCallingIdentity(identity); |
| 3818 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3822 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3823 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | |
| 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3828 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(identity); |
| 3831 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3835 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3836 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3837 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3838 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3839 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3840 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3841 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3842 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3843 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3844 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3845 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3846 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3847 | * Sets the voice activation state of a given subId. |
| 3848 | */ |
| 3849 | @Override |
| 3850 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3851 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3852 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3853 | |
| 3854 | final long identity = Binder.clearCallingIdentity(); |
| 3855 | try { |
| 3856 | final Phone phone = getPhone(subId); |
| 3857 | if (phone != null) { |
| 3858 | phone.setVoiceActivationState(activationState); |
| 3859 | } else { |
| 3860 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3861 | } |
| 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * Sets the data activation state of a given subId. |
| 3869 | */ |
| 3870 | @Override |
| 3871 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3873 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3874 | |
| 3875 | final long identity = Binder.clearCallingIdentity(); |
| 3876 | try { |
| 3877 | final Phone phone = getPhone(subId); |
| 3878 | if (phone != null) { |
| 3879 | phone.setDataActivationState(activationState); |
| 3880 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3881 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3882 | } |
| 3883 | } finally { |
| 3884 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | /** |
| 3889 | * Returns the voice activation state of a given subId. |
| 3890 | */ |
| 3891 | @Override |
| 3892 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3894 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3895 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | if (phone != null) { |
| 3899 | return phone.getVoiceActivationState(); |
| 3900 | } else { |
| 3901 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3902 | } |
| 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | /** |
| 3909 | * Returns the data activation state of a given subId. |
| 3910 | */ |
| 3911 | @Override |
| 3912 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3914 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3915 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
| 3918 | if (phone != null) { |
| 3919 | return phone.getDataActivationState(); |
| 3920 | } else { |
| 3921 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3922 | } |
| 3923 | } finally { |
| 3924 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3929 | * Returns the unread count of voicemails for a subId |
| 3930 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3931 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3932 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3933 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3934 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3935 | mApp, subId, callingPackage, callingFeatureId, |
| 3936 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3937 | return 0; |
| 3938 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3939 | final long identity = Binder.clearCallingIdentity(); |
| 3940 | try { |
| 3941 | final Phone phone = getPhone(subId); |
| 3942 | if (phone != null) { |
| 3943 | return phone.getVoiceMessageCount(); |
| 3944 | } else { |
| 3945 | return 0; |
| 3946 | } |
| 3947 | } finally { |
| 3948 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3949 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3953 | * returns true, if the device is in a state where both voice and data |
| 3954 | * are supported simultaneously. This can change based on location or network condition. |
| 3955 | */ |
| 3956 | @Override |
| 3957 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3958 | final long identity = Binder.clearCallingIdentity(); |
| 3959 | try { |
| 3960 | final Phone phone = getPhone(subId); |
| 3961 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3962 | } finally { |
| 3963 | Binder.restoreCallingIdentity(identity); |
| 3964 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3968 | * Send the dialer code if called from the current default dialer or the caller has |
| 3969 | * carrier privilege. |
| 3970 | * @param inputCode The dialer code to send |
| 3971 | */ |
| 3972 | @Override |
| 3973 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3974 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3975 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3976 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3977 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3978 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3979 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3980 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3982 | |
| 3983 | final long identity = Binder.clearCallingIdentity(); |
| 3984 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3985 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(identity); |
| 3988 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3989 | } |
| 3990 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3991 | @Override |
| 3992 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3993 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3994 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3995 | mApp, subId, "getNetworkSelectionMode"); |
| 3996 | final long identity = Binder.clearCallingIdentity(); |
| 3997 | try { |
| 3998 | if (!isActiveSubscription(subId)) { |
| 3999 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4000 | } |
| 4001 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4004 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4008 | public boolean isInEmergencySmsMode() { |
| 4009 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4010 | final long identity = Binder.clearCallingIdentity(); |
| 4011 | try { |
| 4012 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4013 | if (phone.isInEmergencySmsMode()) { |
| 4014 | return true; |
| 4015 | } |
| 4016 | } |
| 4017 | } finally { |
| 4018 | Binder.restoreCallingIdentity(identity); |
| 4019 | } |
| 4020 | return false; |
| 4021 | } |
| 4022 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4023 | /** |
| 4024 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4025 | * @param subId The subscription to use to check the configuration. |
| 4026 | * @param c The callback that will be used to send the result. |
| 4027 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4028 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4029 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4030 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4031 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4032 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4033 | |
| 4034 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4035 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4036 | "IMS not available on device."); |
| 4037 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4038 | final long token = Binder.clearCallingIdentity(); |
| 4039 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4040 | int slotId = getSlotIndexOrException(subId); |
| 4041 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4042 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4043 | } catch (ImsException e) { |
| 4044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4045 | } finally { |
| 4046 | Binder.restoreCallingIdentity(token); |
| 4047 | } |
| 4048 | } |
| 4049 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4050 | /** |
| 4051 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4052 | * @param subId The subscription to use to check the configuration. |
| 4053 | * @param c The callback that will be used to send the result. |
| 4054 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4056 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4057 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4058 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4059 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4060 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4061 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4062 | final long token = Binder.clearCallingIdentity(); |
| 4063 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4064 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4065 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4066 | } catch (ImsException e) { |
| 4067 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4068 | + "is inactive, ignoring unregister."); |
| 4069 | // If the subscription is no longer active, just return, since the callback |
| 4070 | // will already have been removed internally. |
| 4071 | } finally { |
| 4072 | Binder.restoreCallingIdentity(token); |
| 4073 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4076 | /** |
| 4077 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4078 | */ |
| 4079 | @Override |
| 4080 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4081 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4082 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4083 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4084 | "IMS not available on device."); |
| 4085 | } |
| 4086 | final long token = Binder.clearCallingIdentity(); |
| 4087 | try { |
| 4088 | Phone phone = getPhone(subId); |
| 4089 | if (phone == null) { |
| 4090 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4091 | + subId + "'"); |
| 4092 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4093 | } |
| 4094 | phone.getImsRegistrationState(regState -> { |
| 4095 | try { |
| 4096 | consumer.accept((regState == null) |
| 4097 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4098 | } catch (RemoteException e) { |
| 4099 | // Ignore if the remote process is no longer available to call back. |
| 4100 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4101 | } |
| 4102 | }); |
| 4103 | } finally { |
| 4104 | Binder.restoreCallingIdentity(token); |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | /** |
| 4109 | * Get the transport type for the IMS service registration state. |
| 4110 | */ |
| 4111 | @Override |
| 4112 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
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, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4115 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4116 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4117 | "IMS not available on device."); |
| 4118 | } |
| 4119 | final long token = Binder.clearCallingIdentity(); |
| 4120 | try { |
| 4121 | Phone phone = getPhone(subId); |
| 4122 | if (phone == null) { |
| 4123 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4124 | + subId + "'"); |
| 4125 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4126 | } |
| 4127 | phone.getImsRegistrationTech(regTech -> { |
| 4128 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4129 | int regTechConverted = (regTech == null) |
| 4130 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4131 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4132 | regTechConverted); |
| 4133 | try { |
| 4134 | consumer.accept(regTechConverted); |
| 4135 | } catch (RemoteException e) { |
| 4136 | // Ignore if the remote process is no longer available to call back. |
| 4137 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4138 | } |
| 4139 | }); |
| 4140 | } finally { |
| 4141 | Binder.restoreCallingIdentity(token); |
| 4142 | } |
| 4143 | } |
| 4144 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4145 | /** |
| 4146 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4147 | * @param subId The subscription to use to check the configuration. |
| 4148 | * @param c The callback that will be used to send the result. |
| 4149 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4150 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4151 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4152 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4153 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4154 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4155 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4156 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4157 | "IMS not available on device."); |
| 4158 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4159 | final long token = Binder.clearCallingIdentity(); |
| 4160 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4161 | int slotId = getSlotIndexOrException(subId); |
| 4162 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4163 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4164 | } catch (ImsException e) { |
| 4165 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4166 | } finally { |
| 4167 | Binder.restoreCallingIdentity(token); |
| 4168 | } |
| 4169 | } |
| 4170 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4171 | /** |
| 4172 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4173 | * @param subId The subscription to use to check the configuration. |
| 4174 | * @param c The callback that will be used to send the result. |
| 4175 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4176 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4177 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4178 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4179 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4180 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4181 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4182 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4183 | |
| 4184 | final long token = Binder.clearCallingIdentity(); |
| 4185 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4186 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4187 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4188 | } catch (ImsException e) { |
| 4189 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4190 | + "is inactive, ignoring unregister."); |
| 4191 | // If the subscription is no longer active, just return, since the callback |
| 4192 | // will already have been removed internally. |
| 4193 | } finally { |
| 4194 | Binder.restoreCallingIdentity(token); |
| 4195 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | } |
| 4197 | |
| 4198 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4199 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4200 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | final long token = Binder.clearCallingIdentity(); |
| 4202 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4203 | int slotId = getSlotIndexOrException(subId); |
| 4204 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4205 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4206 | } catch (com.android.ims.ImsException e) { |
| 4207 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4208 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4209 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4210 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4211 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(token); |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4218 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4219 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4220 | final long token = Binder.clearCallingIdentity(); |
| 4221 | try { |
| 4222 | Phone phone = getPhone(subId); |
| 4223 | if (phone == null) return false; |
| 4224 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4225 | } catch (com.android.ims.ImsException e) { |
| 4226 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4227 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4228 | } finally { |
| 4229 | Binder.restoreCallingIdentity(token); |
| 4230 | } |
| 4231 | } |
| 4232 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4233 | /** |
| 4234 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4235 | * subscription. |
| 4236 | * @param subId The subscription to use to check the configuration. |
| 4237 | * @param callback The callback that will be used to send the result. |
| 4238 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4239 | * @param transportType The transport type of the MmTelFeature capability. |
| 4240 | */ |
| 4241 | @Override |
| 4242 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4243 | int transportType) { |
| 4244 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4245 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4246 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4247 | "IMS not available on device."); |
| 4248 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4249 | final long token = Binder.clearCallingIdentity(); |
| 4250 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4251 | int slotId = getSlotIndex(subId); |
| 4252 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4253 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4254 | + subId + "'"); |
| 4255 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4256 | } |
| 4257 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4258 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4259 | transportType, aBoolean -> { |
| 4260 | try { |
| 4261 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4262 | } catch (RemoteException e) { |
| 4263 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4264 | + "running. Ignore"); |
| 4265 | } |
| 4266 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4267 | } catch (ImsException e) { |
| 4268 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4269 | } finally { |
| 4270 | Binder.restoreCallingIdentity(token); |
| 4271 | } |
| 4272 | } |
| 4273 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4274 | /** |
| 4275 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4276 | * @param subId The subscription to use to check the configuration. |
| 4277 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4278 | @Override |
| 4279 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4280 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4281 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4282 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4283 | final long token = Binder.clearCallingIdentity(); |
| 4284 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4285 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4286 | // 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] | 4287 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4288 | } catch (ImsException e) { |
| 4289 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4290 | } finally { |
| 4291 | Binder.restoreCallingIdentity(token); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4296 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4297 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4298 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4299 | final long identity = Binder.clearCallingIdentity(); |
| 4300 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4301 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4302 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4303 | // 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] | 4304 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4305 | } catch (ImsException e) { |
| 4306 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4307 | } finally { |
| 4308 | Binder.restoreCallingIdentity(identity); |
| 4309 | } |
| 4310 | } |
| 4311 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4312 | /** |
| 4313 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4314 | * @param subId The subscription to use to check the configuration. |
| 4315 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4316 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4317 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4318 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4319 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4320 | final long identity = Binder.clearCallingIdentity(); |
| 4321 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4322 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4323 | // 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] | 4324 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4325 | } catch (ImsException e) { |
| 4326 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4327 | } finally { |
| 4328 | Binder.restoreCallingIdentity(identity); |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4333 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4335 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4336 | final long identity = Binder.clearCallingIdentity(); |
| 4337 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4338 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4339 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4340 | // 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] | 4341 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4342 | } catch (ImsException e) { |
| 4343 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4344 | } finally { |
| 4345 | Binder.restoreCallingIdentity(identity); |
| 4346 | } |
| 4347 | } |
| 4348 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4349 | /** |
| 4350 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4351 | * @param subId The subscription to use to check the configuration. |
| 4352 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4353 | @Override |
| 4354 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4355 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4356 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4359 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4360 | // 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] | 4361 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4362 | } catch (ImsException e) { |
| 4363 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4364 | } finally { |
| 4365 | Binder.restoreCallingIdentity(identity); |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4370 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4371 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4372 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4373 | final long identity = Binder.clearCallingIdentity(); |
| 4374 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4375 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4376 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4377 | // 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] | 4378 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4379 | } catch (ImsException e) { |
| 4380 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4381 | } finally { |
| 4382 | Binder.restoreCallingIdentity(identity); |
| 4383 | } |
| 4384 | } |
| 4385 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4386 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4387 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4388 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4389 | * @param subId The subscription to use to check the configuration. |
| 4390 | */ |
| 4391 | @Override |
| 4392 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4393 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4394 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4395 | final long identity = Binder.clearCallingIdentity(); |
| 4396 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4397 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4398 | // 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] | 4399 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4400 | } catch (ImsException e) { |
| 4401 | throw new ServiceSpecificException(e.getCode()); |
| 4402 | } finally { |
| 4403 | Binder.restoreCallingIdentity(identity); |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | /** |
| 4408 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4409 | * Requires MODIFY_PHONE_STATE permission. |
| 4410 | * @param subId The subscription to use to check the configuration. |
| 4411 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4412 | * false otherwise |
| 4413 | */ |
| 4414 | @Override |
| 4415 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4416 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4417 | "setCrossSimCallingEnabled"); |
| 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).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4424 | } catch (ImsException e) { |
| 4425 | throw new ServiceSpecificException(e.getCode()); |
| 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(identity); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 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 |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4436 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4437 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4438 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4439 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4440 | final long identity = Binder.clearCallingIdentity(); |
| 4441 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4442 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4443 | // This setting doesn't require an active ImsService connection, so do not verify. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4444 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4445 | } catch (ImsException e) { |
| 4446 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
| 4449 | } |
| 4450 | } |
| 4451 | |
| 4452 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4453 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4454 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4455 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4456 | final long identity = Binder.clearCallingIdentity(); |
| 4457 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4458 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4459 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4460 | // 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] | 4461 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4462 | } catch (ImsException e) { |
| 4463 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4464 | } finally { |
| 4465 | Binder.restoreCallingIdentity(identity); |
| 4466 | } |
| 4467 | } |
| 4468 | |
| 4469 | @Override |
| 4470 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4471 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4472 | "setVoWiFiNonPersistent"); |
| 4473 | final long identity = Binder.clearCallingIdentity(); |
| 4474 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4475 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4476 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4477 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4478 | } catch (ImsException e) { |
| 4479 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4480 | } finally { |
| 4481 | Binder.restoreCallingIdentity(identity); |
| 4482 | } |
| 4483 | } |
| 4484 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4485 | /** |
| 4486 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4487 | * @param subId The subscription to use to check the configuration. |
| 4488 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4489 | @Override |
| 4490 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4491 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4492 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4493 | final long identity = Binder.clearCallingIdentity(); |
| 4494 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4495 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4496 | // 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] | 4497 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4498 | } catch (ImsException e) { |
| 4499 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4500 | } finally { |
| 4501 | Binder.restoreCallingIdentity(identity); |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | @Override |
| 4506 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4507 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4508 | "setVoWiFiModeSetting"); |
| 4509 | final long identity = Binder.clearCallingIdentity(); |
| 4510 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4511 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4512 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4513 | // 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] | 4514 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4515 | } catch (ImsException e) { |
| 4516 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4517 | } finally { |
| 4518 | Binder.restoreCallingIdentity(identity); |
| 4519 | } |
| 4520 | } |
| 4521 | |
| 4522 | @Override |
| 4523 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4524 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4525 | final long identity = Binder.clearCallingIdentity(); |
| 4526 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4527 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4528 | // 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] | 4529 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4530 | } catch (ImsException e) { |
| 4531 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4532 | } finally { |
| 4533 | Binder.restoreCallingIdentity(identity); |
| 4534 | } |
| 4535 | } |
| 4536 | |
| 4537 | @Override |
| 4538 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4540 | "setVoWiFiRoamingModeSetting"); |
| 4541 | final long identity = Binder.clearCallingIdentity(); |
| 4542 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4543 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4544 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4545 | // 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] | 4546 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4547 | } catch (ImsException e) { |
| 4548 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4549 | } finally { |
| 4550 | Binder.restoreCallingIdentity(identity); |
| 4551 | } |
| 4552 | } |
| 4553 | |
| 4554 | @Override |
| 4555 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4556 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4557 | "setRttCapabilityEnabled"); |
| 4558 | final long identity = Binder.clearCallingIdentity(); |
| 4559 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4560 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4561 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4562 | // 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] | 4563 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4564 | } catch (ImsException e) { |
| 4565 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4566 | } finally { |
| 4567 | Binder.restoreCallingIdentity(identity); |
| 4568 | } |
| 4569 | } |
| 4570 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4571 | /** |
| 4572 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4573 | * @param subId The subscription to use to check the configuration. |
| 4574 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4575 | @Override |
| 4576 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4577 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4578 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4579 | final long identity = Binder.clearCallingIdentity(); |
| 4580 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4581 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4582 | // 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] | 4583 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4584 | } catch (ImsException e) { |
| 4585 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4586 | } finally { |
| 4587 | Binder.restoreCallingIdentity(identity); |
| 4588 | } |
| 4589 | } |
| 4590 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4591 | @Override |
| 4592 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4593 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4594 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4595 | final long identity = Binder.clearCallingIdentity(); |
| 4596 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4597 | if (!isImsAvailableOnDevice()) { |
| 4598 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4599 | "IMS not available on device."); |
| 4600 | } |
| 4601 | int slotId = getSlotIndexOrException(subId); |
| 4602 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4603 | ImsManager.getInstance(mApp, slotId) |
| 4604 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4605 | } catch (ImsException e) { |
| 4606 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4607 | } finally { |
| 4608 | Binder.restoreCallingIdentity(identity); |
| 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | @Override |
| 4613 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4614 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4615 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4616 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4617 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4618 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4619 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4620 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4621 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4622 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4623 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4624 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4625 | + "is inactive, ignoring unregister."); |
| 4626 | // If the subscription is no longer active, just return, since the callback will already |
| 4627 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4628 | } finally { |
| 4629 | Binder.restoreCallingIdentity(identity); |
| 4630 | } |
| 4631 | } |
| 4632 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4633 | @Override |
| 4634 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4635 | IFeatureProvisioningCallback callback) { |
| 4636 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4637 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4638 | |
| 4639 | final long identity = Binder.clearCallingIdentity(); |
| 4640 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4641 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4642 | } |
| 4643 | |
| 4644 | ImsProvisioningController.getInstance() |
| 4645 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4646 | |
| 4647 | Binder.restoreCallingIdentity(identity); |
| 4648 | } |
| 4649 | |
| 4650 | @Override |
| 4651 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4652 | IFeatureProvisioningCallback callback) { |
| 4653 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4654 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4655 | |
| 4656 | final long identity = Binder.clearCallingIdentity(); |
| 4657 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4658 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4659 | } |
| 4660 | |
| 4661 | ImsProvisioningController.getInstance() |
| 4662 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4663 | |
| 4664 | Binder.restoreCallingIdentity(identity); |
| 4665 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4666 | |
| 4667 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4669 | message); |
| 4670 | } |
| 4671 | |
| 4672 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4673 | boolean isMmtelCapability) { |
| 4674 | Phone phone = getPhone(subId); |
| 4675 | if (phone == null) { |
| 4676 | loge("phone instance null for subid " + subId); |
| 4677 | return false; |
| 4678 | } |
| 4679 | if (isMmtelCapability) { |
| 4680 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4681 | return false; |
| 4682 | } |
| 4683 | } else { |
| 4684 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4685 | return false; |
| 4686 | } |
| 4687 | } |
| 4688 | return true; |
| 4689 | } |
| 4690 | |
| 4691 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4692 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4693 | boolean isProvisioned) { |
| 4694 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4695 | |
| 4696 | final long identity = Binder.clearCallingIdentity(); |
| 4697 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4698 | ImsProvisioningController.getInstance() |
| 4699 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4700 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4701 | } finally { |
| 4702 | Binder.restoreCallingIdentity(identity); |
| 4703 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | |
| 4707 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4708 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4709 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4710 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4711 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4712 | final long identity = Binder.clearCallingIdentity(); |
| 4713 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4714 | return ImsProvisioningController.getInstance() |
| 4715 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4716 | } finally { |
| 4717 | Binder.restoreCallingIdentity(identity); |
| 4718 | } |
| 4719 | } |
| 4720 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4721 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4722 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4723 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4724 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4725 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4726 | final long identity = Binder.clearCallingIdentity(); |
| 4727 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4728 | ImsProvisioningController.getInstance() |
| 4729 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4730 | } finally { |
| 4731 | Binder.restoreCallingIdentity(identity); |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | @Override |
| 4736 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4737 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4738 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4739 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4742 | return ImsProvisioningController.getInstance() |
| 4743 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4744 | |
| 4745 | } finally { |
| 4746 | Binder.restoreCallingIdentity(identity); |
| 4747 | } |
| 4748 | } |
| 4749 | |
| 4750 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4751 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4752 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4753 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4754 | |
| 4755 | final long identity = Binder.clearCallingIdentity(); |
| 4756 | try { |
| 4757 | return ImsProvisioningController.getInstance() |
| 4758 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4759 | } finally { |
| 4760 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4761 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4765 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4766 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4767 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4768 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4769 | final long identity = Binder.clearCallingIdentity(); |
| 4770 | try { |
| 4771 | return ImsProvisioningController.getInstance() |
| 4772 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4773 | } finally { |
| 4774 | Binder.restoreCallingIdentity(identity); |
| 4775 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4776 | } |
| 4777 | |
| 4778 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4779 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4780 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4781 | } |
| 4782 | |
| 4783 | /** |
| 4784 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4785 | * carrier associated with the subscription id. |
| 4786 | */ |
| 4787 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4788 | int capability) { |
| 4789 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4790 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4791 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4792 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4793 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4794 | false); |
| 4795 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4796 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4797 | |
| 4798 | // First check to make sure that the capability requires provisioning. |
| 4799 | switch (capability) { |
| 4800 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4801 | // intentional fallthrough |
| 4802 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4803 | if (requireVoiceVtProvisioning) { |
| 4804 | // Voice and Video requires provisioning |
| 4805 | return true; |
| 4806 | } |
| 4807 | break; |
| 4808 | } |
| 4809 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4810 | if (requireUtProvisioning) { |
| 4811 | // UT requires provisioning |
| 4812 | return true; |
| 4813 | } |
| 4814 | break; |
| 4815 | } |
| 4816 | } |
| 4817 | return false; |
| 4818 | } |
| 4819 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4820 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4821 | int capability) { |
| 4822 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4823 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4824 | |
| 4825 | boolean requireRcsProvisioning = c.getBoolean( |
| 4826 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4827 | |
| 4828 | // First check to make sure that the capability requires provisioning. |
| 4829 | switch (capability) { |
| 4830 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4831 | // intentional fallthrough |
| 4832 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4833 | if (requireRcsProvisioning) { |
| 4834 | // OPTION or PRESENCE requires provisioning |
| 4835 | return true; |
| 4836 | } |
| 4837 | break; |
| 4838 | } |
| 4839 | } |
| 4840 | return false; |
| 4841 | } |
| 4842 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4843 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4844 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4845 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4846 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4847 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4848 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4849 | mApp, subId, "getImsProvisioningInt"); |
| 4850 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4854 | int slotId = getSlotIndex(subId); |
| 4855 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4856 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4857 | + subId + "' for key:" + key); |
| 4858 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4859 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4860 | |
| 4861 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4862 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4863 | return retVal; |
| 4864 | } |
| 4865 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4866 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4867 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4868 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4869 | + subId + "' for key:" + key); |
| 4870 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
| 4874 | } |
| 4875 | |
| 4876 | @Override |
| 4877 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4878 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4879 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4880 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4881 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4882 | mApp, subId, "getImsProvisioningString"); |
| 4883 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4884 | final long identity = Binder.clearCallingIdentity(); |
| 4885 | try { |
| 4886 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4887 | int slotId = getSlotIndex(subId); |
| 4888 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4889 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4890 | + subId + "' for key:" + key); |
| 4891 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4892 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4893 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4894 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4895 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4896 | + subId + "' for key:" + key); |
| 4897 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(identity); |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | @Override |
| 4904 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4905 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4906 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4907 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4908 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4909 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4910 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4911 | final long identity = Binder.clearCallingIdentity(); |
| 4912 | try { |
| 4913 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4914 | int slotId = getSlotIndex(subId); |
| 4915 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4916 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4917 | + subId + "' for key:" + key); |
| 4918 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4919 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4920 | |
| 4921 | int retVal = ImsProvisioningController.getInstance() |
| 4922 | .setProvisioningValue(subId, key, value); |
| 4923 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4924 | return retVal; |
| 4925 | } |
| 4926 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4927 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4928 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4929 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4930 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4931 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | @Override |
| 4938 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4939 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4940 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4941 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4942 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4943 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
| 4946 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4947 | int slotId = getSlotIndex(subId); |
| 4948 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4949 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4950 | + subId + "' for key:" + key); |
| 4951 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4952 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4953 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4954 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4955 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4956 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4957 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4958 | } finally { |
| 4959 | Binder.restoreCallingIdentity(identity); |
| 4960 | } |
| 4961 | } |
| 4962 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4963 | /** |
| 4964 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4965 | * for the given slot ID or no ImsResolver instance has been created. |
| 4966 | * @param slotId The slot ID that the IMS service is created for. |
| 4967 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4968 | */ |
| 4969 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4970 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4971 | ImsFeature.FEATURE_MMTEL)) { |
| 4972 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4973 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4974 | } |
| 4975 | } |
| 4976 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4977 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4978 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4979 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4980 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4981 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4982 | } |
| 4983 | return slotId; |
| 4984 | } |
| 4985 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4986 | private int getSlotIndex(int subId) { |
| 4987 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4988 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4989 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4990 | } |
| 4991 | return slotId; |
| 4992 | } |
| 4993 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4994 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4995 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4996 | */ |
| 4997 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4998 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4999 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5000 | try { |
| 5001 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5002 | } catch (SecurityException se) { |
| 5003 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5004 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5005 | + Binder.getCallingUid()); |
| 5006 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5007 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5008 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5009 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5010 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5011 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5012 | mApp, subId, callingPackage, callingFeatureId, |
| 5013 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5014 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5015 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5016 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | final long identity = Binder.clearCallingIdentity(); |
| 5018 | try { |
| 5019 | final Phone phone = getPhone(subId); |
| 5020 | if (phone != null) { |
| 5021 | return phone.getServiceState().getDataNetworkType(); |
| 5022 | } else { |
| 5023 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5024 | } |
| 5025 | } finally { |
| 5026 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | /** |
| 5031 | * Returns the data network type |
| 5032 | */ |
| 5033 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5034 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5035 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5036 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | /** |
| 5040 | * Returns the data network type for a subId |
| 5041 | */ |
| 5042 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5043 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5044 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5045 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5046 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5047 | mApp, functionName)) { |
| 5048 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5049 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5050 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5051 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5054 | final long identity = Binder.clearCallingIdentity(); |
| 5055 | try { |
| 5056 | final Phone phone = getPhone(subId); |
| 5057 | if (phone != null) { |
| 5058 | return phone.getServiceState().getDataNetworkType(); |
| 5059 | } else { |
| 5060 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5061 | } |
| 5062 | } finally { |
| 5063 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5064 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5065 | } |
| 5066 | |
| 5067 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5068 | * Returns the Voice network type for a subId |
| 5069 | */ |
| 5070 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5071 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5072 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5073 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5074 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5075 | mApp, functionName)) { |
| 5076 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5077 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5078 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5079 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5080 | } |
| 5081 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5082 | final long identity = Binder.clearCallingIdentity(); |
| 5083 | try { |
| 5084 | final Phone phone = getPhone(subId); |
| 5085 | if (phone != null) { |
| 5086 | return phone.getServiceState().getVoiceNetworkType(); |
| 5087 | } else { |
| 5088 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5089 | } |
| 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | /** |
| 5096 | * @return true if a ICC card is present |
| 5097 | */ |
| 5098 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5099 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5100 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5101 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5105 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5106 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5107 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5108 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5109 | final long identity = Binder.clearCallingIdentity(); |
| 5110 | try { |
| 5111 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5112 | if (phone != null) { |
| 5113 | return phone.getIccCard().hasIccCard(); |
| 5114 | } else { |
| 5115 | return false; |
| 5116 | } |
| 5117 | } finally { |
| 5118 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5119 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5120 | } |
| 5121 | |
| 5122 | /** |
| 5123 | * Return if the current radio is LTE on CDMA. This |
| 5124 | * is a tri-state return value as for a period of time |
| 5125 | * the mode may be unknown. |
| 5126 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5127 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5128 | * @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] | 5129 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5130 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5131 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5132 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5133 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5134 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5135 | } |
| 5136 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5137 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5138 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5139 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5140 | try { |
| 5141 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5142 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5143 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5144 | } |
| 5145 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
| 5148 | final Phone phone = getPhone(subId); |
| 5149 | if (phone == null) { |
| 5150 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5151 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5152 | return TelephonyProperties.lte_on_cdma_device() |
| 5153 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | } |
| 5155 | } finally { |
| 5156 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5157 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5158 | } |
| 5159 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5160 | /** |
| 5161 | * {@hide} |
| 5162 | * Returns Default subId, 0 in the case of single standby. |
| 5163 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5164 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5165 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5168 | private int getSlotForDefaultSubscription() { |
| 5169 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5170 | } |
| 5171 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5172 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5173 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5174 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5175 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5176 | private boolean isActiveSubscription(int subId) { |
| 5177 | return mSubscriptionController.isActiveSubId(subId); |
| 5178 | } |
| 5179 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5180 | /** |
| 5181 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5182 | */ |
| 5183 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | final long identity = Binder.clearCallingIdentity(); |
| 5185 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5186 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5187 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5188 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5189 | } finally { |
| 5190 | Binder.restoreCallingIdentity(identity); |
| 5191 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | /** |
| 5195 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5196 | */ |
| 5197 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | final long identity = Binder.clearCallingIdentity(); |
| 5199 | try { |
| 5200 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5201 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5203 | } finally { |
| 5204 | Binder.restoreCallingIdentity(identity); |
| 5205 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5206 | } |
| 5207 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5208 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5209 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5210 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5211 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5212 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5213 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5214 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5215 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5216 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5217 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5218 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5219 | } |
| 5220 | return PhoneFactory.getPhone(phoneId); |
| 5221 | } |
| 5222 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5223 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5224 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5225 | @NonNull IccLogicalChannelRequest request) { |
| 5226 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5227 | /*message=*/ "iccOpenLogicalChannel"); |
| 5228 | |
| 5229 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5230 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5231 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5232 | |
| 5233 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5234 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5235 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5236 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5237 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5238 | Phone phone; |
| 5239 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5241 | mApp, request.subId, message); |
| 5242 | phone = getPhoneFromSubId(request.subId); |
| 5243 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5244 | enforceModifyPermission(); |
| 5245 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5246 | } else { |
| 5247 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5248 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5249 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5253 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | final long identity = Binder.clearCallingIdentity(); |
| 5255 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5256 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5258 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5259 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5260 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5261 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | loge("The calling package is not allowed to access ISD-R."); |
| 5263 | throw new SecurityException( |
| 5264 | "The calling package is not allowed to access ISD-R."); |
| 5265 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5266 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5267 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5269 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5270 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | return response; |
| 5272 | } finally { |
| 5273 | Binder.restoreCallingIdentity(identity); |
| 5274 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5278 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5279 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5280 | /*message=*/"iccCloseLogicalChannel"); |
| 5281 | |
| 5282 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5283 | |
| 5284 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5285 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5286 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5287 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5288 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5289 | // before this feature is enabled, this API should only return false if |
| 5290 | // the operation fails instead of throwing runtime exception for |
| 5291 | // backward-compatibility. |
| 5292 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5293 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5296 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5297 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5299 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5300 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5301 | Boolean success = false; |
| 5302 | if (result instanceof RuntimeException) { |
| 5303 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5304 | if (shouldThrowExceptionOnFailure) { |
| 5305 | throw (RuntimeException) result; |
| 5306 | } else { |
| 5307 | return false; |
| 5308 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5309 | } else if (result instanceof Boolean) { |
| 5310 | success = (Boolean) result; |
| 5311 | } else { |
| 5312 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5313 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5314 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5315 | return success; |
| 5316 | } finally { |
| 5317 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5318 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5322 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5323 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5324 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5325 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5326 | if (DBG) { |
| 5327 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5328 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5329 | + p3 + " data=" + data); |
| 5330 | } |
| 5331 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5332 | command, p1, p2, p3, data); |
| 5333 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5334 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5335 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5336 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5337 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5338 | enforceModifyPermission(); |
| 5339 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5340 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5341 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5342 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5343 | } |
| 5344 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5345 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5346 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5350 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | final long identity = Binder.clearCallingIdentity(); |
| 5352 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5353 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | return ""; |
| 5355 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5356 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5358 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5359 | null /* workSource */); |
| 5360 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5361 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | // Append the returned status code to the end of the response payload. |
| 5363 | String s = Integer.toHexString( |
| 5364 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5365 | if (response.payload != null) { |
| 5366 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5367 | } |
| 5368 | return s; |
| 5369 | } finally { |
| 5370 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5371 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5372 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5373 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5374 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5375 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5376 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5377 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5378 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5380 | if (DBG) { |
| 5381 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5382 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5383 | } |
| 5384 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5385 | cla, command, p1, p2, p3, data); |
| 5386 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5387 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5388 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5389 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5390 | 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] | 5391 | enforceModifyPermission(); |
| 5392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5393 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5394 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5395 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5396 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5400 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5401 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5405 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5406 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | final long identity = Binder.clearCallingIdentity(); |
| 5408 | try { |
| 5409 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5410 | && TextUtils.equals(ISDR_AID, data)) { |
| 5411 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5412 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5413 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | if (bestComponent == null |
| 5415 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5416 | loge("The calling package is not allowed to select ISD-R."); |
| 5417 | throw new SecurityException( |
| 5418 | "The calling package is not allowed to select ISD-R."); |
| 5419 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5420 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5423 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5424 | null /* workSource */); |
| 5425 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5426 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | // Append the returned status code to the end of the response payload. |
| 5428 | String s = Integer.toHexString( |
| 5429 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5430 | if (response.payload != null) { |
| 5431 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5432 | } |
| 5433 | return s; |
| 5434 | } finally { |
| 5435 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5436 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5440 | 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] | 5441 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5443 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5445 | final long identity = Binder.clearCallingIdentity(); |
| 5446 | try { |
| 5447 | if (DBG) { |
| 5448 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5449 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5450 | } |
| 5451 | |
| 5452 | IccIoResult response = |
| 5453 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5454 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5455 | subId); |
| 5456 | |
| 5457 | if (DBG) { |
| 5458 | log("Exchange SIM_IO [R]" + response); |
| 5459 | } |
| 5460 | |
| 5461 | byte[] result = null; |
| 5462 | int length = 2; |
| 5463 | if (response.payload != null) { |
| 5464 | length = 2 + response.payload.length; |
| 5465 | result = new byte[length]; |
| 5466 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5467 | } else { |
| 5468 | result = new byte[length]; |
| 5469 | } |
| 5470 | |
| 5471 | result[length - 1] = (byte) response.sw2; |
| 5472 | result[length - 2] = (byte) response.sw1; |
| 5473 | return result; |
| 5474 | } finally { |
| 5475 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5476 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5479 | /** |
| 5480 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5481 | * on a particular subscription |
| 5482 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5483 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5484 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5485 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5486 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5487 | return null; |
| 5488 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5489 | |
| 5490 | final long identity = Binder.clearCallingIdentity(); |
| 5491 | try { |
| 5492 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5493 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5494 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5495 | return null; |
| 5496 | } |
| 5497 | Object response = sendRequest( |
| 5498 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5499 | if (response instanceof String[]) { |
| 5500 | return (String[]) response; |
| 5501 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5502 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5504 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5505 | } finally { |
| 5506 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5507 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5508 | } |
| 5509 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5510 | /** |
| 5511 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5512 | * subscription. |
| 5513 | * |
| 5514 | * @param subId the id of the subscription. |
| 5515 | * @param appType the uicc app type, must be USIM or SIM. |
| 5516 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5517 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5518 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5519 | * @return number of fplmns that is successfully written to the SIM. |
| 5520 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5521 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5522 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5524 | mApp, subId, "setForbiddenPlmns"); |
| 5525 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5526 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5527 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5528 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5529 | } |
| 5530 | if (fplmns == null) { |
| 5531 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5532 | } |
| 5533 | for (String fplmn : fplmns) { |
| 5534 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5535 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5536 | } |
| 5537 | } |
| 5538 | final long identity = Binder.clearCallingIdentity(); |
| 5539 | try { |
| 5540 | Object response = sendRequest( |
| 5541 | CMD_SET_FORBIDDEN_PLMNS, |
| 5542 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5543 | subId); |
| 5544 | return (int) response; |
| 5545 | } finally { |
| 5546 | Binder.restoreCallingIdentity(identity); |
| 5547 | } |
| 5548 | } |
| 5549 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5550 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5551 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5553 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5554 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5555 | final long identity = Binder.clearCallingIdentity(); |
| 5556 | try { |
| 5557 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5558 | if (response.payload == null) { |
| 5559 | return ""; |
| 5560 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5562 | // Append the returned status code to the end of the response payload. |
| 5563 | String s = Integer.toHexString( |
| 5564 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5565 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5566 | return s; |
| 5567 | } finally { |
| 5568 | Binder.restoreCallingIdentity(identity); |
| 5569 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5570 | } |
| 5571 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5572 | /** |
| 5573 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5574 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5575 | * |
| 5576 | * @param itemID the ID of the item to read |
| 5577 | * @return the NV item as a String, or null on error. |
| 5578 | */ |
| 5579 | @Override |
| 5580 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5581 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5583 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5584 | |
| 5585 | final long identity = Binder.clearCallingIdentity(); |
| 5586 | try { |
| 5587 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5588 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5590 | return value; |
| 5591 | } finally { |
| 5592 | Binder.restoreCallingIdentity(identity); |
| 5593 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5594 | } |
| 5595 | |
| 5596 | /** |
| 5597 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5598 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5599 | * |
| 5600 | * @param itemID the ID of the item to read |
| 5601 | * @param itemValue the value to write, as a String |
| 5602 | * @return true on success; false on any failure |
| 5603 | */ |
| 5604 | @Override |
| 5605 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5606 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5608 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | |
| 5610 | final long identity = Binder.clearCallingIdentity(); |
| 5611 | try { |
| 5612 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5613 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5614 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5615 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5616 | return success; |
| 5617 | } finally { |
| 5618 | Binder.restoreCallingIdentity(identity); |
| 5619 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | /** |
| 5623 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5624 | * Used for device configuration by some CDMA operators. |
| 5625 | * |
| 5626 | * @param preferredRoamingList byte array containing the new PRL |
| 5627 | * @return true on success; false on any failure |
| 5628 | */ |
| 5629 | @Override |
| 5630 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5632 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | |
| 5634 | final long identity = Binder.clearCallingIdentity(); |
| 5635 | try { |
| 5636 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5637 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5638 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5639 | return success; |
| 5640 | } finally { |
| 5641 | Binder.restoreCallingIdentity(identity); |
| 5642 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5643 | } |
| 5644 | |
| 5645 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5646 | * 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] | 5647 | * Used for device configuration by some CDMA operators. |
| 5648 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5649 | * @param slotIndex - device slot. |
| 5650 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5651 | * @return true on success; false on any failure |
| 5652 | */ |
| 5653 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5654 | public boolean resetModemConfig(int slotIndex) { |
| 5655 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5656 | if (phone != null) { |
| 5657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5658 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5659 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5660 | final long identity = Binder.clearCallingIdentity(); |
| 5661 | try { |
| 5662 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5663 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5664 | return success; |
| 5665 | } finally { |
| 5666 | Binder.restoreCallingIdentity(identity); |
| 5667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5668 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5669 | return false; |
| 5670 | } |
| 5671 | |
| 5672 | /** |
| 5673 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5674 | * |
| 5675 | * @param slotIndex - device slot. |
| 5676 | * |
| 5677 | * @return true on success; false on any failure |
| 5678 | */ |
| 5679 | @Override |
| 5680 | public boolean rebootModem(int slotIndex) { |
| 5681 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5682 | if (phone != null) { |
| 5683 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5684 | mApp, phone.getSubId(), "rebootModem"); |
| 5685 | |
| 5686 | final long identity = Binder.clearCallingIdentity(); |
| 5687 | try { |
| 5688 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5689 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5690 | return success; |
| 5691 | } finally { |
| 5692 | Binder.restoreCallingIdentity(identity); |
| 5693 | } |
| 5694 | } |
| 5695 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5696 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5697 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5698 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5699 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5700 | * {@link #disableIms(int)}. |
| 5701 | * @param slotIndex device slot. |
| 5702 | */ |
| 5703 | public void resetIms(int slotIndex) { |
| 5704 | enforceModifyPermission(); |
| 5705 | |
| 5706 | final long identity = Binder.clearCallingIdentity(); |
| 5707 | try { |
| 5708 | if (mImsResolver == null) { |
| 5709 | // may happen if the does not support IMS. |
| 5710 | return; |
| 5711 | } |
| 5712 | mImsResolver.disableIms(slotIndex); |
| 5713 | mImsResolver.enableIms(slotIndex); |
| 5714 | } finally { |
| 5715 | Binder.restoreCallingIdentity(identity); |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5720 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5721 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5722 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5723 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5724 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5725 | |
| 5726 | final long identity = Binder.clearCallingIdentity(); |
| 5727 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5728 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5729 | // may happen if the device does not support IMS. |
| 5730 | return; |
| 5731 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5732 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
| 5735 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5736 | } |
| 5737 | |
| 5738 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5739 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5740 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5741 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5742 | public void disableIms(int slotId) { |
| 5743 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5744 | |
| 5745 | final long identity = Binder.clearCallingIdentity(); |
| 5746 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5747 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5748 | // may happen if the device does not support IMS. |
| 5749 | return; |
| 5750 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5751 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
| 5754 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5755 | } |
| 5756 | |
| 5757 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5758 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5759 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5760 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5761 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5762 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | |
| 5765 | final long identity = Binder.clearCallingIdentity(); |
| 5766 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5767 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5768 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5769 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5770 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5771 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | } finally { |
| 5773 | Binder.restoreCallingIdentity(identity); |
| 5774 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5775 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5776 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5777 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5778 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5779 | @Override |
| 5780 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5781 | enforceModifyPermission(); |
| 5782 | |
| 5783 | final long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
| 5785 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5786 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
| 5789 | } |
| 5790 | } |
| 5791 | |
| 5792 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5793 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5794 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5795 | */ |
| 5796 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5797 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | |
| 5799 | final long identity = Binder.clearCallingIdentity(); |
| 5800 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5801 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5802 | // may happen if the device does not support IMS. |
| 5803 | return null; |
| 5804 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5805 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | } finally { |
| 5807 | Binder.restoreCallingIdentity(identity); |
| 5808 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5809 | } |
| 5810 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5811 | /** |
| 5812 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5813 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5814 | */ |
| 5815 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5816 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5817 | |
| 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5820 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5821 | // may happen if the device does not support IMS. |
| 5822 | return null; |
| 5823 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5824 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5825 | } finally { |
| 5826 | Binder.restoreCallingIdentity(identity); |
| 5827 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5828 | } |
| 5829 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5830 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5831 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5832 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5833 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5834 | * @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] | 5835 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5836 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5837 | * @param packageName The name of the package that the current configuration will be replaced |
| 5838 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5839 | * @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] | 5840 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5841 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5842 | int[] featureTypes, String packageName) { |
| 5843 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5844 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5846 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5847 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5848 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5849 | final long identity = Binder.clearCallingIdentity(); |
| 5850 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5851 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5852 | // may happen if the device does not support IMS. |
| 5853 | return false; |
| 5854 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5855 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5856 | for (int featureType : featureTypes) { |
| 5857 | featureConfig.put(featureType, packageName); |
| 5858 | } |
| 5859 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5860 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
| 5863 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5867 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5868 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5869 | * |
| 5870 | * This should only be used for testing. |
| 5871 | * |
| 5872 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5873 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5874 | */ |
| 5875 | @Override |
| 5876 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5877 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5878 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5879 | "clearCarrierImsServiceOverride"); |
| 5880 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5881 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5882 | "clearCarrierImsServiceOverride"); |
| 5883 | |
| 5884 | final long identity = Binder.clearCallingIdentity(); |
| 5885 | try { |
| 5886 | if (mImsResolver == null) { |
| 5887 | // may happen if the device does not support IMS. |
| 5888 | return false; |
| 5889 | } |
| 5890 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
| 5893 | } |
| 5894 | } |
| 5895 | |
| 5896 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5897 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5898 | * |
| 5899 | * @param slotId The slot that the ImsService is associated with. |
| 5900 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5901 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5902 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5903 | * @return the package name of the ImsService configuration. |
| 5904 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5905 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5906 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5907 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5908 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5909 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5910 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5911 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5913 | final long identity = Binder.clearCallingIdentity(); |
| 5914 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5915 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5916 | // may happen if the device does not support IMS. |
| 5917 | return ""; |
| 5918 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5919 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5920 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5921 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5922 | } finally { |
| 5923 | Binder.restoreCallingIdentity(identity); |
| 5924 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5925 | } |
| 5926 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5927 | /** |
| 5928 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5929 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5930 | * @param callback A callback with an integer containing the |
| 5931 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5932 | */ |
| 5933 | @Override |
| 5934 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5935 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5936 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5937 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5938 | "IMS not available on device."); |
| 5939 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5940 | final long token = Binder.clearCallingIdentity(); |
| 5941 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5942 | int slotId = getSlotIndex(subId); |
| 5943 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5944 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5945 | + subId + "'"); |
| 5946 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5947 | } |
| 5948 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5949 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5950 | try { |
| 5951 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5952 | } catch (RemoteException e) { |
| 5953 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5954 | + "Ignore"); |
| 5955 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5956 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5957 | } catch (ImsException e) { |
| 5958 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5959 | } finally { |
| 5960 | Binder.restoreCallingIdentity(token); |
| 5961 | } |
| 5962 | } |
| 5963 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5964 | /** |
| 5965 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5966 | */ |
| 5967 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5968 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5969 | |
| 5970 | final long identity = Binder.clearCallingIdentity(); |
| 5971 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5972 | // NOTE: Before S, this method only set the default phone. |
| 5973 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5974 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5975 | phone.setImsRegistrationState(registered); |
| 5976 | } |
| 5977 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5978 | } finally { |
| 5979 | Binder.restoreCallingIdentity(identity); |
| 5980 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5984 | * Set the network selection mode to automatic. |
| 5985 | * |
| 5986 | */ |
| 5987 | @Override |
| 5988 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5990 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | |
| 5992 | final long identity = Binder.clearCallingIdentity(); |
| 5993 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5994 | if (!isActiveSubscription(subId)) { |
| 5995 | return; |
| 5996 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5997 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5998 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5999 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | } finally { |
| 6001 | Binder.restoreCallingIdentity(identity); |
| 6002 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6003 | } |
| 6004 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6005 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6006 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6007 | * |
| 6008 | * @param subId the id of the subscription. |
| 6009 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6010 | * the operator to attach to. |
| 6011 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6012 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6013 | * normal network selection next time. |
| 6014 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6015 | */ |
| 6016 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6017 | public boolean setNetworkSelectionModeManual( |
| 6018 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6020 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6021 | |
| 6022 | if (!isActiveSubscription(subId)) { |
| 6023 | return false; |
| 6024 | } |
| 6025 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6028 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6029 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6030 | if (DBG) { |
| 6031 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6032 | + " operator: " + operatorInfo); |
| 6033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6035 | } finally { |
| 6036 | Binder.restoreCallingIdentity(identity); |
| 6037 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6038 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6039 | /** |
| 6040 | * Get the manual network selection |
| 6041 | * |
| 6042 | * @param subId the id of the subscription. |
| 6043 | * |
| 6044 | * @return the previously saved user selected PLMN |
| 6045 | */ |
| 6046 | @Override |
| 6047 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6048 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6049 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6050 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6051 | |
| 6052 | final long identity = Binder.clearCallingIdentity(); |
| 6053 | try { |
| 6054 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6055 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | final Phone phone = getPhone(subId); |
| 6059 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6060 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6061 | } |
| 6062 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6063 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6064 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6065 | } finally { |
| 6066 | Binder.restoreCallingIdentity(identity); |
| 6067 | } |
| 6068 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6069 | |
| 6070 | /** |
| 6071 | * Scans for available networks. |
| 6072 | */ |
| 6073 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6074 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6075 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6077 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6078 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6079 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6080 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6081 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6082 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6083 | .setCallingPid(Binder.getCallingPid()) |
| 6084 | .setCallingUid(Binder.getCallingUid()) |
| 6085 | .setMethod("getCellNetworkScanResults") |
| 6086 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6087 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6088 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6089 | .build()); |
| 6090 | switch (locationResult) { |
| 6091 | case DENIED_HARD: |
| 6092 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6093 | case DENIED_SOFT: |
| 6094 | return null; |
| 6095 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6097 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6098 | try { |
| 6099 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6100 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6101 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
| 6104 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6108 | * Get the call forwarding info, given the call forwarding reason. |
| 6109 | */ |
| 6110 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6111 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6112 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6113 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6114 | long identity = Binder.clearCallingIdentity(); |
| 6115 | try { |
| 6116 | if (DBG) { |
| 6117 | log("getCallForwarding: subId " + subId |
| 6118 | + " callForwardingReason" + callForwardingReason); |
| 6119 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6120 | |
| 6121 | Phone phone = getPhone(subId); |
| 6122 | if (phone == null) { |
| 6123 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6124 | callback.onError( |
| 6125 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6126 | } catch (RemoteException e) { |
| 6127 | // ignore |
| 6128 | } |
| 6129 | return; |
| 6130 | } |
| 6131 | |
| 6132 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6133 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6134 | @Override |
| 6135 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6136 | try { |
| 6137 | callback.onCallForwardingInfoAvailable(info); |
| 6138 | } catch (RemoteException e) { |
| 6139 | // ignore |
| 6140 | } |
| 6141 | } |
| 6142 | |
| 6143 | @Override |
| 6144 | public void onError(int error) { |
| 6145 | try { |
| 6146 | callback.onError(error); |
| 6147 | } catch (RemoteException e) { |
| 6148 | // ignore |
| 6149 | } |
| 6150 | } |
| 6151 | }); |
| 6152 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6153 | } finally { |
| 6154 | Binder.restoreCallingIdentity(identity); |
| 6155 | } |
| 6156 | } |
| 6157 | |
| 6158 | /** |
| 6159 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6160 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6161 | */ |
| 6162 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6163 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6164 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6165 | enforceModifyPermission(); |
| 6166 | long identity = Binder.clearCallingIdentity(); |
| 6167 | try { |
| 6168 | if (DBG) { |
| 6169 | log("setCallForwarding: subId " + subId |
| 6170 | + " callForwardingInfo" + callForwardingInfo); |
| 6171 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6172 | |
| 6173 | Phone phone = getPhone(subId); |
| 6174 | if (phone == null) { |
| 6175 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6176 | callback.accept( |
| 6177 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6178 | } catch (RemoteException e) { |
| 6179 | // ignore |
| 6180 | } |
| 6181 | return; |
| 6182 | } |
| 6183 | |
| 6184 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6185 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6186 | |
| 6187 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6188 | } finally { |
| 6189 | Binder.restoreCallingIdentity(identity); |
| 6190 | } |
| 6191 | } |
| 6192 | |
| 6193 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6194 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6195 | */ |
| 6196 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6197 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6198 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6199 | long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6201 | Phone phone = getPhone(subId); |
| 6202 | if (phone == null) { |
| 6203 | try { |
| 6204 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6205 | } catch (RemoteException e) { |
| 6206 | // ignore |
| 6207 | } |
| 6208 | return; |
| 6209 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6210 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6211 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6212 | boolean requireUssd = c.getBoolean( |
| 6213 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6214 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6215 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6216 | if (requireUssd) { |
| 6217 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6218 | getSubscriptionCarrierId(subId)); |
| 6219 | String newUssdCommand = ""; |
| 6220 | try { |
| 6221 | newUssdCommand = carrierXmlParser.getFeature( |
| 6222 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6223 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6224 | } catch (NullPointerException e) { |
| 6225 | loge("Failed to generate USSD number" + e); |
| 6226 | } |
| 6227 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6228 | mMainThreadHandler, callback, carrierXmlParser, |
| 6229 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6230 | final String ussdCommand = newUssdCommand; |
| 6231 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6232 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6233 | }); |
| 6234 | } else { |
| 6235 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6236 | callback::accept); |
| 6237 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6238 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6239 | } finally { |
| 6240 | Binder.restoreCallingIdentity(identity); |
| 6241 | } |
| 6242 | } |
| 6243 | |
| 6244 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6245 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6246 | */ |
| 6247 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6248 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6249 | enforceModifyPermission(); |
| 6250 | long identity = Binder.clearCallingIdentity(); |
| 6251 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6252 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6253 | |
| 6254 | Phone phone = getPhone(subId); |
| 6255 | if (phone == null) { |
| 6256 | try { |
| 6257 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6258 | } catch (RemoteException e) { |
| 6259 | // ignore |
| 6260 | } |
| 6261 | return; |
| 6262 | } |
| 6263 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6264 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6265 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6266 | boolean requireUssd = c.getBoolean( |
| 6267 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6268 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6269 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6270 | if (requireUssd) { |
| 6271 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6272 | getSubscriptionCarrierId(subId)); |
| 6273 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6274 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6275 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6276 | String newUssdCommand = ""; |
| 6277 | try { |
| 6278 | newUssdCommand = carrierXmlParser.getFeature( |
| 6279 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6280 | .makeCommand(ssAction, null); |
| 6281 | } catch (NullPointerException e) { |
| 6282 | loge("Failed to generate USSD number" + e); |
| 6283 | } |
| 6284 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6285 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6286 | final String ussdCommand = newUssdCommand; |
| 6287 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6288 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6289 | }); |
| 6290 | } else { |
| 6291 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6292 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6293 | |
| 6294 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6295 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6296 | } finally { |
| 6297 | Binder.restoreCallingIdentity(identity); |
| 6298 | } |
| 6299 | } |
| 6300 | |
| 6301 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6302 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6303 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6304 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6305 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6306 | * location related information which will be sent if the caller already possess |
| 6307 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6308 | * @param request contains the radio access networks with bands/channels to scan |
| 6309 | * @param messenger callback messenger for scan results or errors |
| 6310 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6311 | * @return the id of the requested scan which can be used to stop the scan. |
| 6312 | */ |
| 6313 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6314 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6315 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6316 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6318 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6319 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6320 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6321 | if (!renounceFineLocationAccess) { |
| 6322 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6323 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6324 | .setCallingPackage(callingPackage) |
| 6325 | .setCallingFeatureId(callingFeatureId) |
| 6326 | .setCallingPid(Binder.getCallingPid()) |
| 6327 | .setCallingUid(Binder.getCallingUid()) |
| 6328 | .setMethod("requestNetworkScan") |
| 6329 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6330 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6331 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6332 | .build()); |
| 6333 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6334 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6335 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6336 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6337 | if (e != null) { |
| 6338 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6339 | throw e; |
| 6340 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6341 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6342 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6343 | } |
| 6344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6346 | int callingUid = Binder.getCallingUid(); |
| 6347 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6348 | final long identity = Binder.clearCallingIdentity(); |
| 6349 | try { |
| 6350 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6351 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6352 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6353 | } finally { |
| 6354 | Binder.restoreCallingIdentity(identity); |
| 6355 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6356 | } |
| 6357 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6358 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6359 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6360 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6361 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6362 | boolean hasNetworkScanPermission = |
| 6363 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6364 | == PERMISSION_GRANTED; |
| 6365 | |
| 6366 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6367 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6368 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6372 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6373 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6374 | return new SecurityException("Specific channels must not be" |
| 6375 | + " scanned without location access."); |
| 6376 | } |
| 6377 | } |
| 6378 | } |
| 6379 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6380 | return null; |
| 6381 | } |
| 6382 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6383 | /** |
| 6384 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6385 | * |
| 6386 | * @param subId id of the subscription |
| 6387 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6388 | */ |
| 6389 | @Override |
| 6390 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6391 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6392 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6393 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6394 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6395 | final long identity = Binder.clearCallingIdentity(); |
| 6396 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6397 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6398 | } finally { |
| 6399 | Binder.restoreCallingIdentity(identity); |
| 6400 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6404 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6405 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6406 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6407 | */ |
| 6408 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6409 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6410 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6411 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6412 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6413 | |
| 6414 | final long identity = Binder.clearCallingIdentity(); |
| 6415 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6416 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6417 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6418 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6419 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6420 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | } finally { |
| 6422 | Binder.restoreCallingIdentity(identity); |
| 6423 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6427 | * Get the allowed network types for certain reason. |
| 6428 | * |
| 6429 | * @param subId the id of the subscription. |
| 6430 | * @param reason the reason the allowed network type change is taking place |
| 6431 | * @return the allowed network types. |
| 6432 | */ |
| 6433 | @Override |
| 6434 | public long getAllowedNetworkTypesForReason(int subId, |
| 6435 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6436 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6437 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6438 | final long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
| 6440 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
| 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6447 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6448 | * @param subId subscription id of the sim card |
| 6449 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6450 | * This can be passed following states |
| 6451 | * <ol> |
| 6452 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6453 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6454 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6455 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6456 | * </ol> |
| 6457 | * @return operation result. |
| 6458 | */ |
| 6459 | @Override |
| 6460 | public int setNrDualConnectivityState(int subId, |
| 6461 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6463 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6464 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6465 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6466 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6467 | } |
| 6468 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6469 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6470 | final long identity = Binder.clearCallingIdentity(); |
| 6471 | try { |
| 6472 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6473 | nrDualConnectivityState, subId, |
| 6474 | workSource); |
| 6475 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6476 | return result; |
| 6477 | } finally { |
| 6478 | Binder.restoreCallingIdentity(identity); |
| 6479 | } |
| 6480 | } |
| 6481 | |
| 6482 | /** |
| 6483 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6484 | * @return true if dual connectivity is enabled else false |
| 6485 | */ |
| 6486 | @Override |
| 6487 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6488 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6489 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6490 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6491 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6492 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6493 | return false; |
| 6494 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6495 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6496 | final long identity = Binder.clearCallingIdentity(); |
| 6497 | try { |
| 6498 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6499 | null, subId, workSource); |
| 6500 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6501 | return isEnabled; |
| 6502 | } finally { |
| 6503 | Binder.restoreCallingIdentity(identity); |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6508 | * Set the allowed network types of the device and |
| 6509 | * provide the reason triggering the allowed network change. |
| 6510 | * |
| 6511 | * @param subId the id of the subscription. |
| 6512 | * @param reason the reason the allowed network type change is taking place |
| 6513 | * @param allowedNetworkTypes the allowed network types. |
| 6514 | * @return true on success; false on any failure. |
| 6515 | */ |
| 6516 | @Override |
| 6517 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6518 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6519 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6521 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6522 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6523 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6524 | return false; |
| 6525 | } |
| 6526 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6527 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6528 | return false; |
| 6529 | } |
| 6530 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6531 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6532 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6533 | |
| 6534 | |
| 6535 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6536 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6537 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6538 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6539 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6540 | final long identity = Binder.clearCallingIdentity(); |
| 6541 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6542 | Boolean success = (Boolean) sendRequest( |
| 6543 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6544 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6545 | |
| 6546 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6547 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6548 | } finally { |
| 6549 | Binder.restoreCallingIdentity(identity); |
| 6550 | } |
| 6551 | } |
| 6552 | |
| 6553 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6554 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6555 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6556 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6557 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6558 | * @hide |
| 6559 | */ |
| 6560 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6561 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6562 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6563 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6564 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6565 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6566 | if (phone != null) { |
| 6567 | return phone.hasMatchedTetherApnSetting(); |
| 6568 | } else { |
| 6569 | return false; |
| 6570 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6571 | } finally { |
| 6572 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6573 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6577 | * Get the user enabled state of Mobile Data. |
| 6578 | * |
| 6579 | * TODO: remove and use isUserDataEnabled. |
| 6580 | * This can't be removed now because some vendor codes |
| 6581 | * calls through ITelephony directly while they should |
| 6582 | * use TelephonyManager. |
| 6583 | * |
| 6584 | * @return true on enabled |
| 6585 | */ |
| 6586 | @Override |
| 6587 | public boolean getDataEnabled(int subId) { |
| 6588 | return isUserDataEnabled(subId); |
| 6589 | } |
| 6590 | |
| 6591 | /** |
| 6592 | * Get whether mobile data is enabled per user setting. |
| 6593 | * |
| 6594 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6595 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6596 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6597 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6598 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6599 | * |
| 6600 | * @return {@code true} if data is enabled else {@code false} |
| 6601 | */ |
| 6602 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6603 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6604 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6605 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6606 | try { |
| 6607 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6608 | functionName); |
| 6609 | } catch (Exception e) { |
| 6610 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6611 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6612 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6614 | mApp, subId, functionName); |
| 6615 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6616 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | |
| 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
| 6620 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6621 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6622 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6623 | if (phone != null) { |
| 6624 | boolean retVal = phone.isUserDataEnabled(); |
| 6625 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6626 | return retVal; |
| 6627 | } else { |
| 6628 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6629 | return false; |
| 6630 | } |
| 6631 | } finally { |
| 6632 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6637 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6638 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6639 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6640 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6641 | * @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] | 6642 | */ |
| 6643 | @Override |
| 6644 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6645 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6646 | try { |
| 6647 | try { |
| 6648 | mApp.enforceCallingOrSelfPermission( |
| 6649 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6650 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6651 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6652 | try { |
| 6653 | mApp.enforceCallingOrSelfPermission( |
| 6654 | android.Manifest.permission.READ_PHONE_STATE, |
| 6655 | functionName); |
| 6656 | } catch (Exception e2) { |
| 6657 | mApp.enforceCallingOrSelfPermission( |
| 6658 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6659 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6660 | } |
| 6661 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6662 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6664 | |
| 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
| 6667 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6669 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6670 | boolean retVal; |
| 6671 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 2c094c5 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6672 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6673 | } else { |
| 6674 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6675 | } |
| 6676 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | return retVal; |
| 6678 | } else { |
| 6679 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6680 | return false; |
| 6681 | } |
| 6682 | } finally { |
| 6683 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6684 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6685 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6686 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6687 | /** |
| 6688 | * Check if data is enabled for a specific reason |
| 6689 | * @param subId Subscription index |
| 6690 | * @param reason the reason the data enable change is taking place |
| 6691 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6692 | */ |
| 6693 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6694 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6695 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6696 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6697 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6698 | try { |
| 6699 | mApp.enforceCallingOrSelfPermission( |
| 6700 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6701 | functionName); |
| 6702 | } catch (Exception e) { |
| 6703 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6704 | functionName); |
| 6705 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6706 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6707 | try { |
| 6708 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6709 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6710 | } catch (Exception e2) { |
| 6711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6712 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6713 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6714 | } |
| 6715 | |
| 6716 | |
| 6717 | final long identity = Binder.clearCallingIdentity(); |
| 6718 | try { |
| 6719 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6720 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6721 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6722 | + " reason=" + reason); |
| 6723 | } |
| 6724 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6725 | if (phone != null) { |
| 6726 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6727 | if (phone.isUsingNewDataStack()) { |
| 6728 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6729 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6730 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6731 | retVal = phone.isUserDataEnabled(); |
| 6732 | } else { |
| 6733 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6734 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6735 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6736 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6737 | return retVal; |
| 6738 | } else { |
| 6739 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6740 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6741 | + subId + " retVal=false"); |
| 6742 | } |
| 6743 | return false; |
| 6744 | } |
| 6745 | } finally { |
| 6746 | Binder.restoreCallingIdentity(identity); |
| 6747 | } |
| 6748 | } |
| 6749 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6750 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6751 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6752 | if (uid == Process.PHONE_UID) { |
| 6753 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6754 | // TODO (b/184954344): Check for system/phone UID at call site instead of here |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6755 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6756 | } |
| 6757 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6758 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6759 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6760 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6761 | || subController == null) return privilegeFromSim; |
| 6762 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6763 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6764 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6765 | |
| 6766 | final long identity = Binder.clearCallingIdentity(); |
| 6767 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6768 | int subId = phone.getSubId(); |
| 6769 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6770 | // A test override is in place for the privileges for this subId, so don't try to |
| 6771 | // read the subscription privileges. |
| 6772 | return privilegeFromSim; |
| 6773 | } |
| 6774 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6775 | SubscriptionManager subManager = (SubscriptionManager) |
| 6776 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6777 | for (String pkg : packages) { |
| 6778 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6779 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6780 | } |
| 6781 | } |
| 6782 | return privilegeFromSim; |
| 6783 | } finally { |
| 6784 | Binder.restoreCallingIdentity(identity); |
| 6785 | } |
| 6786 | } |
| 6787 | |
| 6788 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6789 | String pkgName) { |
| 6790 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6791 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6792 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6793 | || subController == null) return privilegeFromSim; |
| 6794 | |
| 6795 | final long identity = Binder.clearCallingIdentity(); |
| 6796 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6797 | int subId = phone.getSubId(); |
| 6798 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6799 | // A test override is in place for the privileges for this subId, so don't try to |
| 6800 | // read the subscription privileges. |
| 6801 | return privilegeFromSim; |
| 6802 | } |
| 6803 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6804 | SubscriptionManager subManager = (SubscriptionManager) |
| 6805 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6806 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6807 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6808 | } finally { |
| 6809 | Binder.restoreCallingIdentity(identity); |
| 6810 | } |
| 6811 | } |
| 6812 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6813 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6814 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6815 | // No permission needed; this only lets the caller inspect their own status. |
| 6816 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6817 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6818 | |
| 6819 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6820 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6821 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6822 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6823 | } |
| 6824 | |
| 6825 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6826 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6827 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6828 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6829 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6830 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6831 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6832 | if (cpt == null) { |
| 6833 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6834 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6835 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6836 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6837 | } |
| 6838 | |
| 6839 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6840 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6841 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6842 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6843 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6844 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6845 | Phone phone = getPhone(subId); |
| 6846 | if (phone == null) { |
| 6847 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6848 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6849 | } |
| 6850 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6851 | if (cpt == null) { |
| 6852 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6853 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6854 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6855 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | @Override |
| 6859 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6860 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6861 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6862 | } |
| 6863 | |
| 6864 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6865 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6866 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6867 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6868 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6869 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6870 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6871 | if (phone == null) { |
| 6872 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6873 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6874 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6875 | if (cpt == null) { |
| 6876 | continue; |
| 6877 | } |
| 6878 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6879 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6880 | break; |
| 6881 | } |
| 6882 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6883 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6884 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6885 | |
| 6886 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6887 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6888 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6889 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6890 | if (phone == null) { |
| 6891 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6892 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6893 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6894 | if (cpt == null) { |
| 6895 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6896 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6897 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6898 | } |
| 6899 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6900 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6901 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6902 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6903 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6904 | if (phone == null) { |
| 6905 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6906 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6907 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6908 | if (cpt == null) { |
| 6909 | return Collections.emptyList(); |
| 6910 | } |
| 6911 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6912 | } |
| 6913 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6914 | @Override |
| 6915 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6916 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6917 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6918 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6919 | try { |
| 6920 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6921 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6922 | } |
| 6923 | } finally { |
| 6924 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6925 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6926 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6927 | } |
| 6928 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6929 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6930 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6931 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6932 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6933 | return null; |
| 6934 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6935 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6936 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6937 | return null; |
| 6938 | } |
| 6939 | return iccId; |
| 6940 | } |
| 6941 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6942 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6943 | public void setCallComposerStatus(int subId, int status) { |
| 6944 | enforceModifyPermission(); |
| 6945 | |
| 6946 | final long identity = Binder.clearCallingIdentity(); |
| 6947 | try { |
| 6948 | Phone phone = getPhone(subId); |
| 6949 | if (phone != null) { |
| 6950 | Phone defaultPhone = phone.getImsPhone(); |
| 6951 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6952 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6953 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6954 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6955 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6956 | } |
| 6957 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6958 | } catch (ImsException e) { |
| 6959 | throw new ServiceSpecificException(e.getCode()); |
| 6960 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6961 | Binder.restoreCallingIdentity(identity); |
| 6962 | } |
| 6963 | } |
| 6964 | |
| 6965 | @Override |
| 6966 | public int getCallComposerStatus(int subId) { |
| 6967 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6968 | |
| 6969 | final long identity = Binder.clearCallingIdentity(); |
| 6970 | try { |
| 6971 | Phone phone = getPhone(subId); |
| 6972 | if (phone != null) { |
| 6973 | Phone defaultPhone = phone.getImsPhone(); |
| 6974 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6975 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6976 | return imsPhone.getCallComposerStatus(); |
| 6977 | } |
| 6978 | } |
| 6979 | } finally { |
| 6980 | Binder.restoreCallingIdentity(identity); |
| 6981 | } |
| 6982 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6983 | } |
| 6984 | |
| 6985 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6986 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6987 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6988 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6989 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6990 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | final long identity = Binder.clearCallingIdentity(); |
| 6992 | try { |
| 6993 | final String iccId = getIccId(subId); |
| 6994 | final Phone phone = getPhone(subId); |
| 6995 | if (phone == null) { |
| 6996 | return false; |
| 6997 | } |
| 6998 | final String subscriberId = phone.getSubscriberId(); |
| 6999 | |
| 7000 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7001 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | + subscriberId + " to " + number); |
| 7003 | } |
| 7004 | |
| 7005 | if (TextUtils.isEmpty(iccId)) { |
| 7006 | return false; |
| 7007 | } |
| 7008 | |
| 7009 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7010 | |
| 7011 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7012 | if (alphaTag == null) { |
| 7013 | editor.remove(alphaTagPrefKey); |
| 7014 | } else { |
| 7015 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7016 | } |
| 7017 | |
| 7018 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7019 | // track all merged IMSIs based on line number |
| 7020 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7021 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7022 | if (number == null) { |
| 7023 | editor.remove(numberPrefKey); |
| 7024 | editor.remove(subscriberPrefKey); |
| 7025 | } else { |
| 7026 | editor.putString(numberPrefKey, number); |
| 7027 | editor.putString(subscriberPrefKey, subscriberId); |
| 7028 | } |
| 7029 | |
| 7030 | editor.commit(); |
| 7031 | return true; |
| 7032 | } finally { |
| 7033 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7034 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7035 | } |
| 7036 | |
| 7037 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7038 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7039 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7040 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7041 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7042 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7043 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7044 | return null; |
| 7045 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7047 | final long identity = Binder.clearCallingIdentity(); |
| 7048 | try { |
| 7049 | String iccId = getIccId(subId); |
| 7050 | if (iccId != null) { |
| 7051 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7052 | if (DBG_MERGE) { |
| 7053 | log("getLine1NumberForDisplay returning " |
| 7054 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7055 | } |
| 7056 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7057 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7059 | return null; |
| 7060 | } finally { |
| 7061 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7062 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7066 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7067 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7069 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7070 | return null; |
| 7071 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7072 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | final long identity = Binder.clearCallingIdentity(); |
| 7074 | try { |
| 7075 | String iccId = getIccId(subId); |
| 7076 | if (iccId != null) { |
| 7077 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7078 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7079 | } |
| 7080 | return null; |
| 7081 | } finally { |
| 7082 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7083 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7084 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7085 | |
| 7086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7087 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7088 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7089 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7090 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7091 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7092 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7093 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7094 | return null; |
| 7095 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7096 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7097 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7098 | // the process, where TelephonyManager was instantiated. |
| 7099 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7100 | final long identity = Binder.clearCallingIdentity(); |
| 7101 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7102 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7103 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7104 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7105 | |
| 7106 | // Figure out what subscribers are currently active |
| 7107 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7108 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7109 | // Only consider subs which match the current subId |
| 7110 | // This logic can be simplified. See b/131189269 for progress. |
| 7111 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7112 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7113 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | |
| 7115 | // First pass, find a number override for an active subscriber |
| 7116 | String mergeNumber = null; |
| 7117 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7118 | for (String key : prefs.keySet()) { |
| 7119 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7120 | final String subscriberId = (String) prefs.get(key); |
| 7121 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7122 | final String iccId = key.substring( |
| 7123 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7124 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7125 | mergeNumber = (String) prefs.get(numberKey); |
| 7126 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7127 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | + " for active subscriber " + subscriberId); |
| 7129 | } |
| 7130 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7131 | break; |
| 7132 | } |
| 7133 | } |
| 7134 | } |
| 7135 | } |
| 7136 | |
| 7137 | // Shortcut when no active merged subscribers |
| 7138 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7139 | return null; |
| 7140 | } |
| 7141 | |
| 7142 | // Second pass, find all subscribers under that line override |
| 7143 | final ArraySet<String> result = new ArraySet<>(); |
| 7144 | for (String key : prefs.keySet()) { |
| 7145 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7146 | final String number = (String) prefs.get(key); |
| 7147 | if (mergeNumber.equals(number)) { |
| 7148 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7149 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7150 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7151 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7152 | result.add(subscriberId); |
| 7153 | } |
| 7154 | } |
| 7155 | } |
| 7156 | } |
| 7157 | |
| 7158 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7159 | Arrays.sort(resultArray); |
| 7160 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7161 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7163 | } |
| 7164 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7165 | } finally { |
| 7166 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7167 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7171 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7172 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7173 | |
| 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7177 | TelephonyManager.class); |
| 7178 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7179 | if (subscriberId == null) { |
| 7180 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7181 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7182 | + subId); |
| 7183 | } |
| 7184 | return null; |
| 7185 | } |
| 7186 | |
| 7187 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7188 | .getSubscriptionInfo(subId); |
| 7189 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7190 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7191 | if (groupUuid == null) { |
| 7192 | return new String[]{subscriberId}; |
| 7193 | } |
| 7194 | |
| 7195 | // Get all subscriberIds from the group. |
| 7196 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7197 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7198 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7199 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7200 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7201 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7202 | if (subscriberId != null) { |
| 7203 | mergedSubscriberIds.add(subscriberId); |
| 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7208 | } finally { |
| 7209 | Binder.restoreCallingIdentity(identity); |
| 7210 | |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7215 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7216 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7217 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7218 | |
| 7219 | final long identity = Binder.clearCallingIdentity(); |
| 7220 | try { |
| 7221 | final Phone phone = getPhone(subId); |
| 7222 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7223 | } finally { |
| 7224 | Binder.restoreCallingIdentity(identity); |
| 7225 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7226 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7227 | |
| 7228 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7229 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7230 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7231 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7232 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7233 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | |
| 7235 | final long identity = Binder.clearCallingIdentity(); |
| 7236 | try { |
| 7237 | final Phone phone = getPhone(subId); |
| 7238 | if (phone == null) { |
| 7239 | return false; |
| 7240 | } |
| 7241 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7242 | cdmaNonRoamingList); |
| 7243 | } finally { |
| 7244 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7245 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7249 | @Deprecated |
| 7250 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7251 | enforceModifyPermission(); |
| 7252 | |
| 7253 | int returnValue = 0; |
| 7254 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7255 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7256 | if(result.exception == null) { |
| 7257 | if (result.result != null) { |
| 7258 | byte[] responseData = (byte[])(result.result); |
| 7259 | if(responseData.length > oemResp.length) { |
| 7260 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7261 | responseData.length + "bytes. Buffer Size is " + |
| 7262 | oemResp.length + "bytes."); |
| 7263 | } |
| 7264 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7265 | returnValue = responseData.length; |
| 7266 | } |
| 7267 | } else { |
| 7268 | CommandException ex = (CommandException) result.exception; |
| 7269 | returnValue = ex.getCommandError().ordinal(); |
| 7270 | if(returnValue > 0) returnValue *= -1; |
| 7271 | } |
| 7272 | } catch (RuntimeException e) { |
| 7273 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7274 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7275 | if(returnValue > 0) returnValue *= -1; |
| 7276 | } |
| 7277 | |
| 7278 | return returnValue; |
| 7279 | } |
| 7280 | |
| 7281 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7282 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7283 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7284 | try { |
| 7285 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7286 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7287 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7288 | } catch (SecurityException e) { |
| 7289 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7290 | throw e; |
| 7291 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7292 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7293 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7294 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7298 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7299 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7300 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7301 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7302 | } finally { |
| 7303 | Binder.restoreCallingIdentity(identity); |
| 7304 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7305 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7306 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7307 | |
| 7308 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7309 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7310 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7311 | try { |
| 7312 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7313 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7314 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7315 | } |
| 7316 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7317 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7318 | } |
| 7319 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7320 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7321 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7322 | throw new SecurityException("App must be the dialer role holder to" |
| 7323 | + " upload a call composer pic"); |
| 7324 | } |
| 7325 | |
| 7326 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7327 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7328 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7329 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7330 | boolean readUntilEnd = false; |
| 7331 | int totalBytesRead = 0; |
| 7332 | byte[] buffer = new byte[16 * 1024]; |
| 7333 | while (true) { |
| 7334 | int numRead; |
| 7335 | try { |
| 7336 | numRead = input.read(buffer); |
| 7337 | } catch (IOException e) { |
| 7338 | try { |
| 7339 | fd.checkError(); |
| 7340 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7341 | null); |
| 7342 | } catch (IOException e1) { |
| 7343 | // This means that the other side closed explicitly with an error. If this |
| 7344 | // happens, log and ignore. |
| 7345 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7346 | } |
| 7347 | break; |
| 7348 | } |
| 7349 | if (numRead == -1) { |
| 7350 | readUntilEnd = true; |
| 7351 | break; |
| 7352 | } |
| 7353 | totalBytesRead += numRead; |
| 7354 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7355 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7356 | try { |
| 7357 | input.close(); |
| 7358 | } catch (IOException e) { |
| 7359 | // ignore |
| 7360 | } |
| 7361 | break; |
| 7362 | } |
| 7363 | output.write(buffer, 0, numRead); |
| 7364 | } |
| 7365 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7366 | // close is above, where the picture size is too big. |
| 7367 | |
| 7368 | try { |
| 7369 | fd.checkError(); |
| 7370 | } catch (IOException e) { |
| 7371 | loge("Remote end for call composer closed with an error: " + e); |
| 7372 | return; |
| 7373 | } |
| 7374 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7375 | if (!readUntilEnd) { |
| 7376 | loge("Did not finish reading entire image; aborting"); |
| 7377 | return; |
| 7378 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7379 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7380 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7381 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7382 | new CallComposerPictureTransfer.Factory() {}, |
| 7383 | imageData, |
| 7384 | (result) -> { |
| 7385 | if (result.first != null) { |
| 7386 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7387 | Bundle outputResult = new Bundle(); |
| 7388 | outputResult.putParcelable( |
| 7389 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7390 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7391 | outputResult); |
| 7392 | } else { |
| 7393 | callback.send(result.second, null); |
| 7394 | } |
| 7395 | } |
| 7396 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7397 | }); |
| 7398 | } |
| 7399 | |
| 7400 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7401 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7402 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7403 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7404 | |
| 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7407 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7408 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | } finally { |
| 7410 | Binder.restoreCallingIdentity(identity); |
| 7411 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7412 | } |
| 7413 | |
| 7414 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7415 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7416 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7417 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7418 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7419 | return false; |
| 7420 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7422 | final long identity = Binder.clearCallingIdentity(); |
| 7423 | try { |
| 7424 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7425 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7426 | // In the long run, we may instead need to check if there exists a connection service |
| 7427 | // which can support video calling. |
| 7428 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7429 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7430 | return imsManager.isVtEnabledByPlatform() |
| 7431 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7432 | && imsManager.isVtEnabledByUser(); |
| 7433 | } finally { |
| 7434 | Binder.restoreCallingIdentity(identity); |
| 7435 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7436 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7437 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7438 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7440 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7441 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7442 | mApp, subId, callingPackage, callingFeatureId, |
| 7443 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | return false; |
| 7445 | } |
| 7446 | |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
| 7449 | CarrierConfigManager configManager = |
| 7450 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7451 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
| 7455 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7456 | } |
| 7457 | |
| 7458 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7459 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7461 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7462 | return false; |
| 7463 | } |
| 7464 | |
| 7465 | final long identity = Binder.clearCallingIdentity(); |
| 7466 | try { |
| 7467 | CarrierConfigManager configManager = |
| 7468 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7469 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7471 | } finally { |
| 7472 | Binder.restoreCallingIdentity(identity); |
| 7473 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7474 | } |
| 7475 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7476 | @Override |
| 7477 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7478 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7479 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7480 | } |
| 7481 | |
| 7482 | @Override |
| 7483 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7486 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7490 | } |
| 7491 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7492 | /** |
| 7493 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7494 | * support for the feature and device firmware support. |
| 7495 | * |
| 7496 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7497 | */ |
| 7498 | @Override |
| 7499 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7501 | final Phone phone = getPhone(subscriptionId); |
| 7502 | if (phone == null) { |
| 7503 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7504 | return false; |
| 7505 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7507 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7508 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7509 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7510 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7511 | return isCarrierSupported && isDeviceSupported; |
| 7512 | } finally { |
| 7513 | Binder.restoreCallingIdentity(identity); |
| 7514 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7515 | } |
| 7516 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7517 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7518 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7519 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7520 | * 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] | 7521 | */ |
| 7522 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7523 | final long identity = Binder.clearCallingIdentity(); |
| 7524 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7525 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7526 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7527 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7528 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7529 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7530 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | } finally { |
| 7532 | Binder.restoreCallingIdentity(identity); |
| 7533 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7534 | } |
| 7535 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7536 | @Deprecated |
| 7537 | @Override |
| 7538 | public String getDeviceId(String callingPackage) { |
| 7539 | return getDeviceIdWithFeature(callingPackage, null); |
| 7540 | } |
| 7541 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7542 | /** |
| 7543 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7544 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7545 | * |
| 7546 | * <p>Requires Permission: |
| 7547 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7548 | */ |
| 7549 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7550 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7551 | try { |
| 7552 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7553 | } catch (SecurityException se) { |
| 7554 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7555 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7556 | + Binder.getCallingUid()); |
| 7557 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7558 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7559 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7560 | return null; |
| 7561 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7562 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7563 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7564 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7565 | return null; |
| 7566 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7567 | |
| 7568 | final long identity = Binder.clearCallingIdentity(); |
| 7569 | try { |
| 7570 | return phone.getDeviceId(); |
| 7571 | } finally { |
| 7572 | Binder.restoreCallingIdentity(identity); |
| 7573 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7574 | } |
| 7575 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7576 | /** |
| 7577 | * {@hide} |
| 7578 | * Returns the IMS Registration Status on a particular subid |
| 7579 | * |
| 7580 | * @param subId |
| 7581 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7582 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7583 | Phone phone = getPhone(subId); |
| 7584 | if (phone != null) { |
| 7585 | return phone.isImsRegistered(); |
| 7586 | } else { |
| 7587 | return false; |
| 7588 | } |
| 7589 | } |
| 7590 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7591 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7592 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7593 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7594 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7595 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7596 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7597 | } |
| 7598 | final long identity = Binder.clearCallingIdentity(); |
| 7599 | try { |
| 7600 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7601 | } finally { |
| 7602 | Binder.restoreCallingIdentity(identity); |
| 7603 | } |
| 7604 | } |
| 7605 | |
| 7606 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7607 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7608 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7609 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7610 | mApp, |
| 7611 | subscriptionId, |
| 7612 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7613 | final long identity = Binder.clearCallingIdentity(); |
| 7614 | try { |
| 7615 | Phone phone = getPhone(subscriptionId); |
| 7616 | if (phone == null) { |
| 7617 | return null; |
| 7618 | } |
| 7619 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7620 | } finally { |
| 7621 | Binder.restoreCallingIdentity(identity); |
| 7622 | } |
| 7623 | } |
| 7624 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7625 | /** |
| 7626 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7627 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7628 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7629 | final long identity = Binder.clearCallingIdentity(); |
| 7630 | try { |
| 7631 | Phone phone = getPhone(subId); |
| 7632 | if (phone != null) { |
| 7633 | return phone.isWifiCallingEnabled(); |
| 7634 | } else { |
| 7635 | return false; |
| 7636 | } |
| 7637 | } finally { |
| 7638 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7639 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7640 | } |
| 7641 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7642 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7643 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7644 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7645 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7646 | final long identity = Binder.clearCallingIdentity(); |
| 7647 | try { |
| 7648 | Phone phone = getPhone(subId); |
| 7649 | if (phone != null) { |
| 7650 | return phone.isVideoEnabled(); |
| 7651 | } else { |
| 7652 | return false; |
| 7653 | } |
| 7654 | } finally { |
| 7655 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7656 | } |
| 7657 | } |
| 7658 | |
| 7659 | /** |
| 7660 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7661 | * defined in {@link ImsRegistrationImplBase}. |
| 7662 | */ |
| 7663 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7664 | final long identity = Binder.clearCallingIdentity(); |
| 7665 | try { |
| 7666 | Phone phone = getPhone(subId); |
| 7667 | if (phone != null) { |
| 7668 | return phone.getImsRegistrationTech(); |
| 7669 | } else { |
| 7670 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7671 | } |
| 7672 | } finally { |
| 7673 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7674 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7675 | } |
| 7676 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7677 | @Override |
| 7678 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7679 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7680 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7681 | return; |
| 7682 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7683 | Phone defaultPhone = getDefaultPhone(); |
| 7684 | if (defaultPhone != null) { |
| 7685 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7686 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7687 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7688 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7689 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7690 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7691 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7692 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7693 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7694 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7695 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7696 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7697 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7698 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7699 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7700 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7701 | // There has been issues when Sms raw table somehow stores orphan |
| 7702 | // fragments. They lead to garbled message when new fragments come |
| 7703 | // in and combined with those stale ones. In case this happens again, |
| 7704 | // user can reset all network settings which will clean up this table. |
| 7705 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7706 | // Clean up IMS settings as well here. |
| 7707 | int slotId = getSlotIndex(subId); |
| 7708 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7709 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7710 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7711 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7712 | if (defaultPhone == null) { |
| 7713 | return; |
| 7714 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7715 | // Erase modem config if erase modem on network setting is enabled. |
| 7716 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7717 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7718 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7719 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7720 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7721 | |
| 7722 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7723 | } finally { |
| 7724 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7725 | } |
| 7726 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7727 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7728 | @VisibleForTesting |
| 7729 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7730 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7731 | return; |
| 7732 | } |
| 7733 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7734 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7735 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7736 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7737 | "user=" + defaultNetworkType); |
| 7738 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7739 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7740 | defaultNetworkType, null); |
| 7741 | } |
| 7742 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7743 | private void cleanUpSmsRawTable(Context context) { |
| 7744 | ContentResolver resolver = context.getContentResolver(); |
| 7745 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7746 | resolver.delete(uri, null, null); |
| 7747 | } |
| 7748 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7749 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7750 | public String getSimLocaleForSubscriber(int subId) { |
| 7751 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7752 | final Phone phone = getPhone(subId); |
| 7753 | if (phone == null) { |
| 7754 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7755 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7756 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7759 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7760 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7761 | if (info == null) { |
| 7762 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7763 | return null; |
| 7764 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7765 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7766 | // preferences (EF-PL and EF-LI)... |
| 7767 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7769 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7770 | if (localeFromDefaultSim != null) { |
| 7771 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7772 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7773 | + localeFromDefaultSim); |
| 7774 | return localeFromDefaultSim.toLanguageTag(); |
| 7775 | } else { |
| 7776 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7777 | } |
| 7778 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7779 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7781 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7782 | // the SIM and carrier preferences does not include a country we add the country |
| 7783 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7784 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7786 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7787 | return mccLocale.toLanguageTag(); |
| 7788 | } |
| 7789 | |
| 7790 | if (DBG) log("No locale found - returning null"); |
| 7791 | return null; |
| 7792 | } finally { |
| 7793 | Binder.restoreCallingIdentity(identity); |
| 7794 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7795 | } |
| 7796 | |
| 7797 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7798 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7799 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7800 | } |
| 7801 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | /** |
| 7803 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7804 | */ |
| 7805 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7806 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7807 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7808 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7809 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7810 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7811 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7812 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7813 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7814 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7815 | * representing the state of the modem. |
| 7816 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7817 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7818 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7819 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7820 | */ |
| 7821 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7822 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7823 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7824 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7825 | |
| 7826 | final long identity = Binder.clearCallingIdentity(); |
| 7827 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7828 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7831 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7832 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7833 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7834 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7835 | // less than total activity duration. |
| 7836 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7837 | if (info == null) { |
| 7838 | return false; |
| 7839 | } |
| 7840 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7841 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7842 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7843 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7844 | return (info.isValid() |
| 7845 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7846 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7847 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7848 | && (totalTxTimeMs <= activityDurationMs)); |
| 7849 | } |
| 7850 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7851 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7852 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7853 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7854 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7855 | |
| 7856 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7857 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7858 | } |
| 7859 | |
| 7860 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7861 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7862 | rat, |
| 7863 | freq, |
| 7864 | info.getReceiveTimeMillis(rat, freq) |
| 7865 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7866 | } |
| 7867 | |
| 7868 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7869 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7870 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7871 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7872 | |
| 7873 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7874 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7875 | } |
| 7876 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7877 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7878 | rat, |
| 7879 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7880 | } |
| 7881 | |
| 7882 | /** |
| 7883 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7884 | * @param info recent ModemActivityInfo |
| 7885 | */ |
| 7886 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7887 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7888 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7889 | boolean matched; |
| 7890 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7891 | matched = false; |
| 7892 | int rat = info.getSpecificInfoRat(i); |
| 7893 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7894 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7895 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7896 | //if it already exists |
| 7897 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7898 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7899 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7900 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7901 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7902 | updateLastModemActivityInfo(info, rat, freq); |
| 7903 | matched = true; |
| 7904 | } |
| 7905 | } else { |
| 7906 | updateLastModemActivityInfo(info, rat); |
| 7907 | matched = true; |
| 7908 | } |
| 7909 | } |
| 7910 | } |
| 7911 | |
| 7912 | if (!matched) { |
| 7913 | mDeltaSpecificInfo = |
| 7914 | new ActivityStatsTechSpecificInfo( |
| 7915 | rat, |
| 7916 | freq, |
| 7917 | info.getTransmitTimeMillis(rat, freq), |
| 7918 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7919 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7920 | } |
| 7921 | } |
| 7922 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7923 | mLastModemActivitySpecificInfo = |
| 7924 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7925 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7926 | |
| 7927 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7928 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7929 | info.getSleepTimeMillis() |
| 7930 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7931 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7932 | info.getIdleTimeMillis() |
| 7933 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7934 | } |
| 7935 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7936 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7937 | * Returns the service state information on specified subscription. |
| 7938 | */ |
| 7939 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7940 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7941 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7942 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7943 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7944 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7945 | return null; |
| 7946 | } |
| 7947 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7948 | boolean hasFinePermission = false; |
| 7949 | boolean hasCoarsePermission = false; |
| 7950 | if (!renounceFineLocationAccess) { |
| 7951 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7952 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7953 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7954 | .setCallingPackage(callingPackage) |
| 7955 | .setCallingFeatureId(callingFeatureId) |
| 7956 | .setCallingPid(Binder.getCallingPid()) |
| 7957 | .setCallingUid(Binder.getCallingUid()) |
| 7958 | .setMethod("getServiceStateForSubscriber") |
| 7959 | .setLogAsInfo(true) |
| 7960 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7961 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7962 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7963 | .build()); |
| 7964 | hasFinePermission = |
| 7965 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7966 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7967 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7968 | if (!renounceCoarseLocationAccess) { |
| 7969 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7970 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7971 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7972 | .setCallingPackage(callingPackage) |
| 7973 | .setCallingFeatureId(callingFeatureId) |
| 7974 | .setCallingPid(Binder.getCallingPid()) |
| 7975 | .setCallingUid(Binder.getCallingUid()) |
| 7976 | .setMethod("getServiceStateForSubscriber") |
| 7977 | .setLogAsInfo(true) |
| 7978 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7979 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7980 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7981 | .build()); |
| 7982 | hasCoarsePermission = |
| 7983 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7984 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7985 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7986 | final Phone phone = getPhone(subId); |
| 7987 | if (phone == null) { |
| 7988 | return null; |
| 7989 | } |
| 7990 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7991 | final long identity = Binder.clearCallingIdentity(); |
| 7992 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7993 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7994 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7995 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7996 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7997 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7998 | Rlog.d(LOG_TAG, |
| 7999 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8000 | return null; |
| 8001 | } |
| 8002 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8003 | ServiceState ss = phone.getServiceState(); |
| 8004 | |
| 8005 | // Scrub out the location info in ServiceState depending on what level of access |
| 8006 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8007 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8008 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8009 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8010 | } finally { |
| 8011 | Binder.restoreCallingIdentity(identity); |
| 8012 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8013 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8014 | |
| 8015 | /** |
| 8016 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8017 | * |
| 8018 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8019 | * voicemail ringtone. |
| 8020 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8021 | * PhoneAccount. |
| 8022 | */ |
| 8023 | @Override |
| 8024 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | final long identity = Binder.clearCallingIdentity(); |
| 8026 | try { |
| 8027 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8028 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8029 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8030 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8033 | } finally { |
| 8034 | Binder.restoreCallingIdentity(identity); |
| 8035 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8036 | } |
| 8037 | |
| 8038 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8039 | * Sets the per-account voicemail ringtone. |
| 8040 | * |
| 8041 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8042 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8043 | * |
| 8044 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8045 | * voicemail ringtone. |
| 8046 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8047 | * PhoneAccount. |
| 8048 | */ |
| 8049 | @Override |
| 8050 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8051 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8052 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8053 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8054 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8055 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8056 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8057 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8058 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8060 | |
| 8061 | final long identity = Binder.clearCallingIdentity(); |
| 8062 | try { |
| 8063 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8064 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8065 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8066 | } |
| 8067 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8068 | } finally { |
| 8069 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8070 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8071 | } |
| 8072 | |
| 8073 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8074 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8075 | * |
| 8076 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8077 | * voicemail vibration setting. |
| 8078 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8079 | */ |
| 8080 | @Override |
| 8081 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8082 | final long identity = Binder.clearCallingIdentity(); |
| 8083 | try { |
| 8084 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8085 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8086 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8089 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8090 | } finally { |
| 8091 | Binder.restoreCallingIdentity(identity); |
| 8092 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8093 | } |
| 8094 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8095 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8096 | * Sets the per-account voicemail vibration. |
| 8097 | * |
| 8098 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8099 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8100 | * |
| 8101 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8102 | * voicemail vibration setting. |
| 8103 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8104 | * specific PhoneAccount. |
| 8105 | */ |
| 8106 | @Override |
| 8107 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8108 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8109 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8110 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8111 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8112 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8114 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8115 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8116 | } |
| 8117 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | final long identity = Binder.clearCallingIdentity(); |
| 8119 | try { |
| 8120 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8121 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8122 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | } |
| 8124 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8127 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8131 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8132 | * |
| 8133 | * @throws SecurityException if the caller does not have the required permission |
| 8134 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8135 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8136 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8137 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8138 | } |
| 8139 | |
| 8140 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8141 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8142 | * permission. |
| 8143 | * |
| 8144 | * @throws SecurityException if the caller does not have the required permission |
| 8145 | */ |
| 8146 | private void enforceSendSmsPermission() { |
| 8147 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8148 | } |
| 8149 | |
| 8150 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8151 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8152 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8153 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8154 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8155 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8156 | final long identity = Binder.clearCallingIdentity(); |
| 8157 | try { |
| 8158 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8159 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8160 | if (componentName == null) { |
| 8161 | throw new SecurityException( |
| 8162 | "Caller not current active visual voicemail package[null]"); |
| 8163 | } |
| 8164 | String vvmPackage = componentName.getPackageName(); |
| 8165 | if (!callingPackage.equals(vvmPackage)) { |
| 8166 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8167 | + vvmPackage + "]"); |
| 8168 | } |
| 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8171 | } |
| 8172 | } |
| 8173 | |
| 8174 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8175 | * Return the application ID for the app type. |
| 8176 | * |
| 8177 | * @param subId the subscription ID that this request applies to. |
| 8178 | * @param appType the uicc app type. |
| 8179 | * @return Application ID for specificied app type, or null if no uicc. |
| 8180 | */ |
| 8181 | @Override |
| 8182 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8183 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8184 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8185 | |
| 8186 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8187 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8188 | if (phone == null) { |
| 8189 | return null; |
| 8190 | } |
| 8191 | String aid = null; |
| 8192 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8193 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8194 | .getApplicationByType(appType).getAid(); |
| 8195 | } catch (Exception e) { |
| 8196 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8197 | } |
| 8198 | return aid; |
| 8199 | } finally { |
| 8200 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8201 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8202 | } |
| 8203 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8204 | /** |
| 8205 | * Return the Electronic Serial Number. |
| 8206 | * |
| 8207 | * @param subId the subscription ID that this request applies to. |
| 8208 | * @return ESN or null if error. |
| 8209 | */ |
| 8210 | @Override |
| 8211 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8212 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8213 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8214 | |
| 8215 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8216 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8217 | if (phone == null) { |
| 8218 | return null; |
| 8219 | } |
| 8220 | String esn = null; |
| 8221 | try { |
| 8222 | esn = phone.getEsn(); |
| 8223 | } catch (Exception e) { |
| 8224 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8225 | } |
| 8226 | return esn; |
| 8227 | } finally { |
| 8228 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8229 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8230 | } |
| 8231 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8232 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8233 | * Return the Preferred Roaming List Version. |
| 8234 | * |
| 8235 | * @param subId the subscription ID that this request applies to. |
| 8236 | * @return PRLVersion or null if error. |
| 8237 | */ |
| 8238 | @Override |
| 8239 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8240 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8241 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8242 | |
| 8243 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8244 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8245 | if (phone == null) { |
| 8246 | return null; |
| 8247 | } |
| 8248 | String cdmaPrlVersion = null; |
| 8249 | try { |
| 8250 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8251 | } catch (Exception e) { |
| 8252 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8253 | } |
| 8254 | return cdmaPrlVersion; |
| 8255 | } finally { |
| 8256 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8257 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8258 | } |
| 8259 | |
| 8260 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8261 | * Get snapshot of Telephony histograms |
| 8262 | * @return List of Telephony histograms |
| 8263 | * @hide |
| 8264 | */ |
| 8265 | @Override |
| 8266 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8268 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | |
| 8270 | final long identity = Binder.clearCallingIdentity(); |
| 8271 | try { |
| 8272 | return RIL.getTelephonyRILTimingHistograms(); |
| 8273 | } finally { |
| 8274 | Binder.restoreCallingIdentity(identity); |
| 8275 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8276 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8277 | |
| 8278 | /** |
| 8279 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8280 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8281 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8282 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8283 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8284 | * @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] | 8285 | */ |
| 8286 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8287 | @TelephonyManager.SetCarrierRestrictionResult |
| 8288 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8289 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8290 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8291 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8292 | if (carrierRestrictionRules == null) { |
| 8293 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8294 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8296 | final long identity = Binder.clearCallingIdentity(); |
| 8297 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8298 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8299 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | } finally { |
| 8301 | Binder.restoreCallingIdentity(identity); |
| 8302 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8303 | } |
| 8304 | |
| 8305 | /** |
| 8306 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8307 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8308 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8309 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8310 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8311 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8312 | */ |
| 8313 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8314 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8315 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8316 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | |
| 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8320 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8321 | if (response instanceof CarrierRestrictionRules) { |
| 8322 | return (CarrierRestrictionRules) response; |
| 8323 | } |
| 8324 | // Response is an Exception of some kind, |
| 8325 | // which is signalled to the user as a NULL retval |
| 8326 | return null; |
| 8327 | } catch (Exception e) { |
| 8328 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8329 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | } finally { |
| 8331 | Binder.restoreCallingIdentity(identity); |
| 8332 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8333 | } |
| 8334 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8335 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8336 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8337 | * @param subId the subscription ID that this action applies to. |
| 8338 | * @param enabled control enable or disable radio. |
| 8339 | * {@hide} |
| 8340 | */ |
| 8341 | @Override |
| 8342 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8343 | enforceModifyPermission(); |
| 8344 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8345 | |
| 8346 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8347 | if (phone == null) { |
| 8348 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8349 | return; |
| 8350 | } |
| 8351 | try { |
| 8352 | phone.carrierActionSetRadioEnabled(enabled); |
| 8353 | } catch (Exception e) { |
| 8354 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8355 | } finally { |
| 8356 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8357 | } |
| 8358 | } |
| 8359 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8360 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8361 | * Enable or disable Voice over NR (VoNR) |
| 8362 | * @param subId the subscription ID that this action applies to. |
| 8363 | * @param enabled enable or disable VoNR. |
| 8364 | * @return operation result. |
| 8365 | */ |
| 8366 | @Override |
| 8367 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8368 | enforceModifyPermission(); |
| 8369 | final Phone phone = getPhone(subId); |
| 8370 | |
| 8371 | final long identity = Binder.clearCallingIdentity(); |
| 8372 | if (phone == null) { |
| 8373 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8374 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8375 | } |
| 8376 | |
| 8377 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8378 | try { |
| 8379 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8380 | workSource); |
| 8381 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8382 | |
| 8383 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8384 | if (DBG) { |
| 8385 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8386 | } |
| 8387 | SubscriptionManager.setSubscriptionProperty( |
| 8388 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8389 | (enabled ? "1" : "0")); |
| 8390 | } |
| 8391 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8392 | return result; |
| 8393 | } finally { |
| 8394 | Binder.restoreCallingIdentity(identity); |
| 8395 | } |
| 8396 | } |
| 8397 | |
| 8398 | /** |
| 8399 | * Is voice over NR enabled |
| 8400 | * @return true if VoNR is enabled else false |
| 8401 | */ |
| 8402 | @Override |
| 8403 | public boolean isVoNrEnabled(int subId) { |
| 8404 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8405 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8406 | final long identity = Binder.clearCallingIdentity(); |
| 8407 | try { |
| 8408 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8409 | null, subId, workSource); |
| 8410 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8411 | return isEnabled; |
| 8412 | } finally { |
| 8413 | Binder.restoreCallingIdentity(identity); |
| 8414 | } |
| 8415 | } |
| 8416 | |
| 8417 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8418 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8419 | * network status based on which carrier apps could apply actions accordingly, |
| 8420 | * enable/disable default url handler for example. |
| 8421 | * |
| 8422 | * @param subId the subscription ID that this action applies to. |
| 8423 | * @param report control start/stop reporting the default network status. |
| 8424 | * {@hide} |
| 8425 | */ |
| 8426 | @Override |
| 8427 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8428 | enforceModifyPermission(); |
| 8429 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8430 | |
| 8431 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8432 | if (phone == null) { |
| 8433 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8434 | return; |
| 8435 | } |
| 8436 | try { |
| 8437 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8438 | } catch (Exception e) { |
| 8439 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8440 | } finally { |
| 8441 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8442 | } |
| 8443 | } |
| 8444 | |
| 8445 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8446 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8447 | * @param subId the subscription ID that this action applies to. |
| 8448 | * {@hide} |
| 8449 | */ |
| 8450 | @Override |
| 8451 | public void carrierActionResetAll(int subId) { |
| 8452 | enforceModifyPermission(); |
| 8453 | final Phone phone = getPhone(subId); |
| 8454 | if (phone == null) { |
| 8455 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8456 | return; |
| 8457 | } |
| 8458 | try { |
| 8459 | phone.carrierActionResetAll(); |
| 8460 | } catch (Exception e) { |
| 8461 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8462 | } |
| 8463 | } |
| 8464 | |
| 8465 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8466 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8467 | * bug report is being generated. |
| 8468 | */ |
| 8469 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8470 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8471 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8472 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8473 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8474 | + Binder.getCallingPid() |
| 8475 | + ", uid=" + Binder.getCallingUid() |
| 8476 | + "without permission " |
| 8477 | + android.Manifest.permission.DUMP); |
| 8478 | return; |
| 8479 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8480 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8481 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8482 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8483 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8484 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8485 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8486 | @NonNull String[] args) { |
| 8487 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8488 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8489 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8490 | } |
| 8491 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8492 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8493 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8494 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8495 | * @param reason the reason the data enable change is taking place |
| 8496 | * @param enabled True if enabling the data, otherwise disabling. |
| 8497 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8498 | */ |
| 8499 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8500 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8501 | boolean enabled) { |
| 8502 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8503 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8504 | try { |
| 8505 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8506 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8507 | } catch (SecurityException se) { |
| 8508 | enforceModifyPermission(); |
| 8509 | } |
| 8510 | } else { |
| 8511 | enforceModifyPermission(); |
| 8512 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
| 8516 | Phone phone = getPhone(subId); |
| 8517 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8518 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8519 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8520 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8521 | if (phone.isUsingNewDataStack()) { |
| 8522 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8523 | } else { |
| 8524 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8525 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8526 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8527 | } |
| 8528 | } finally { |
| 8529 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8530 | } |
| 8531 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8532 | |
| 8533 | /** |
| 8534 | * Get Client request stats |
| 8535 | * @return List of Client Request Stats |
| 8536 | * @hide |
| 8537 | */ |
| 8538 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8539 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8540 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8542 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8543 | return null; |
| 8544 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8545 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8547 | final long identity = Binder.clearCallingIdentity(); |
| 8548 | try { |
| 8549 | if (phone != null) { |
| 8550 | return phone.getClientRequestStats(); |
| 8551 | } |
| 8552 | |
| 8553 | return null; |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8557 | } |
| 8558 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8559 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8560 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8561 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8562 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8563 | |
| 8564 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8565 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8566 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8567 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8568 | * @param state State of SIM (power down, power up, pass through) |
| 8569 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8570 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8571 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8572 | * |
| 8573 | **/ |
| 8574 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8575 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8576 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8577 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8578 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8579 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8581 | final long identity = Binder.clearCallingIdentity(); |
| 8582 | try { |
| 8583 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8584 | phone.setSimPowerState(state, null, workSource); |
| 8585 | } |
| 8586 | } finally { |
| 8587 | Binder.restoreCallingIdentity(identity); |
| 8588 | } |
| 8589 | } |
| 8590 | |
| 8591 | /** |
| 8592 | * Set SIM card power state. |
| 8593 | * |
| 8594 | * @param slotIndex SIM slot id. |
| 8595 | * @param state State of SIM (power down, power up, pass through) |
| 8596 | * @param callback callback to trigger after success or failure |
| 8597 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8598 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8599 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8600 | * |
| 8601 | **/ |
| 8602 | @Override |
| 8603 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8604 | IIntegerConsumer callback) { |
| 8605 | enforceModifyPermission(); |
| 8606 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8607 | |
| 8608 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8609 | |
| 8610 | final long identity = Binder.clearCallingIdentity(); |
| 8611 | try { |
| 8612 | if (phone != null) { |
| 8613 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8614 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8615 | } |
| 8616 | } finally { |
| 8617 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8618 | } |
| 8619 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8620 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8621 | private boolean isUssdApiAllowed(int subId) { |
| 8622 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8623 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8624 | if (configManager == null) { |
| 8625 | return false; |
| 8626 | } |
| 8627 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8628 | if (pb == null) { |
| 8629 | return false; |
| 8630 | } |
| 8631 | return pb.getBoolean( |
| 8632 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8633 | } |
| 8634 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8635 | /** |
| 8636 | * Check if phone is in emergency callback mode |
| 8637 | * @return true if phone is in emergency callback mode |
| 8638 | * @param subId sub id |
| 8639 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8640 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8641 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8642 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8643 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8644 | |
| 8645 | final long identity = Binder.clearCallingIdentity(); |
| 8646 | try { |
| 8647 | if (phone != null) { |
| 8648 | return phone.isInEcm(); |
| 8649 | } else { |
| 8650 | return false; |
| 8651 | } |
| 8652 | } finally { |
| 8653 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8654 | } |
| 8655 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8656 | |
| 8657 | /** |
| 8658 | * Get the current signal strength information for the given subscription. |
| 8659 | * Because this information is not updated when the device is in a low power state |
| 8660 | * it should not be relied-upon to be current. |
| 8661 | * @param subId Subscription index |
| 8662 | * @return the most recent cached signal strength info from the modem |
| 8663 | */ |
| 8664 | @Override |
| 8665 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8666 | final long identity = Binder.clearCallingIdentity(); |
| 8667 | try { |
| 8668 | Phone p = getPhone(subId); |
| 8669 | if (p == null) { |
| 8670 | return null; |
| 8671 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8672 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8673 | return p.getSignalStrength(); |
| 8674 | } finally { |
| 8675 | Binder.restoreCallingIdentity(identity); |
| 8676 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8677 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8678 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8679 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8680 | * Get the current modem radio state for the given slot. |
| 8681 | * @param slotIndex slot index. |
| 8682 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8683 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8684 | * @return the current radio power state from the modem |
| 8685 | */ |
| 8686 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8687 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8688 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8689 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8691 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8692 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8693 | } |
| 8694 | |
| 8695 | final long identity = Binder.clearCallingIdentity(); |
| 8696 | try { |
| 8697 | return phone.getRadioPowerState(); |
| 8698 | } finally { |
| 8699 | Binder.restoreCallingIdentity(identity); |
| 8700 | } |
| 8701 | } |
| 8702 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8703 | } |
| 8704 | |
| 8705 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8706 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8707 | * |
| 8708 | * <p>Requires one of the following permissions: |
| 8709 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8710 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8711 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8712 | * privileges. |
| 8713 | * |
| 8714 | * @param subId subscription id |
| 8715 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8716 | * {@code false}. |
| 8717 | */ |
| 8718 | @Override |
| 8719 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8720 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8721 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8722 | try { |
| 8723 | mApp.enforceCallingOrSelfPermission( |
| 8724 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8725 | functionName); |
| 8726 | } catch (Exception e) { |
| 8727 | mApp.enforceCallingOrSelfPermission( |
| 8728 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8729 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8730 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8731 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8732 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8733 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8734 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8735 | boolean isEnabled = false; |
| 8736 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8737 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8738 | Phone phone = getPhone(subId); |
| 8739 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8740 | } finally { |
| 8741 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8742 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8743 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8744 | } |
| 8745 | |
| 8746 | |
| 8747 | /** |
| 8748 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8749 | * |
| 8750 | * <p> Requires permission: |
| 8751 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8752 | * privileges. |
| 8753 | * |
| 8754 | * @param subId subscription id |
| 8755 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8756 | */ |
| 8757 | @Override |
| 8758 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8760 | mApp, subId, "setDataRoamingEnabled"); |
| 8761 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8762 | final long identity = Binder.clearCallingIdentity(); |
| 8763 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8764 | Phone phone = getPhone(subId); |
| 8765 | if (phone != null) { |
| 8766 | phone.setDataRoamingEnabled(isEnabled); |
| 8767 | } |
| 8768 | } finally { |
| 8769 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8770 | } |
| 8771 | } |
| 8772 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8773 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8774 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8775 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8776 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8777 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8778 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8779 | boolean isAllowed = true; |
| 8780 | final long identity = Binder.clearCallingIdentity(); |
| 8781 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8782 | Phone phone = getPhone(subId); |
| 8783 | if (phone != null) { |
| 8784 | isAllowed = phone.isCspPlmnEnabled(); |
| 8785 | } |
| 8786 | } finally { |
| 8787 | Binder.restoreCallingIdentity(identity); |
| 8788 | } |
| 8789 | return isAllowed; |
| 8790 | } |
| 8791 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8792 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8793 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8794 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8795 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8796 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8797 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8798 | if (phone == null) { |
| 8799 | return false; |
| 8800 | } |
| 8801 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8802 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8803 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8804 | } |
| 8805 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8806 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8807 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8808 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8809 | mApp.getSystemService(AppOpsManager.class) |
| 8810 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8811 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8812 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8813 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8814 | try { |
| 8815 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8816 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8817 | } catch (SecurityException e) { |
| 8818 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8819 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8820 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8821 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8822 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8823 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8824 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8825 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8826 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8827 | Binder.getCallingUid())) { |
| 8828 | isIccIdAccessRestricted = true; |
| 8829 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8830 | final long identity = Binder.clearCallingIdentity(); |
| 8831 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8832 | UiccController uiccController = UiccController.getInstance(); |
| 8833 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8834 | if (hasReadPermission) { |
| 8835 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8836 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8837 | |
| 8838 | // Remove private info if the caller doesn't have access |
| 8839 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8840 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8841 | //setting the value after compatibility check |
| 8842 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8843 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8844 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8845 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8846 | if (card == null) { |
| 8847 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8848 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8849 | continue; |
| 8850 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8851 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8852 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8853 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8854 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8855 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8856 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8857 | for (UiccPortInfo portInfo : portInfos) { |
| 8858 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8859 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8860 | if (port == null) { |
| 8861 | // assume no access if port is null |
| 8862 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8863 | continue; |
| 8864 | } |
| 8865 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8866 | uiccPortInfos.add(portInfo); |
| 8867 | } else { |
| 8868 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8869 | } |
| 8870 | } |
| 8871 | filteredInfos.add(new UiccCardInfo( |
| 8872 | cardInfo.isEuicc(), |
| 8873 | cardInfo.getCardId(), |
| 8874 | null, |
| 8875 | cardInfo.getPhysicalSlotIndex(), |
| 8876 | cardInfo.isRemovable(), |
| 8877 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8878 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8879 | } |
| 8880 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8881 | } finally { |
| 8882 | Binder.restoreCallingIdentity(identity); |
| 8883 | } |
| 8884 | } |
| 8885 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8886 | /** |
| 8887 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8888 | * generally private and require carrier privileges to view. |
| 8889 | * |
| 8890 | * @hide |
| 8891 | */ |
| 8892 | @NonNull |
| 8893 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8894 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8895 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8896 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8897 | } |
| 8898 | return new UiccCardInfo( |
| 8899 | cardInfo.isEuicc(), |
| 8900 | cardInfo.getCardId(), |
| 8901 | null, |
| 8902 | cardInfo.getPhysicalSlotIndex(), |
| 8903 | cardInfo.isRemovable(), |
| 8904 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8905 | portinfo |
| 8906 | ); |
| 8907 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8908 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8909 | /** |
| 8910 | * @hide |
| 8911 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8912 | * These values are generally private and require carrier privileges to view. |
| 8913 | */ |
| 8914 | @NonNull |
| 8915 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8916 | return new UiccPortInfo( |
| 8917 | UiccPortInfo.ICCID_REDACTED, |
| 8918 | portInfo.getPortIndex(), |
| 8919 | portInfo.getLogicalSlotIndex(), |
| 8920 | portInfo.isActive() |
| 8921 | ); |
| 8922 | } |
| 8923 | @Override |
| 8924 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8925 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8926 | mApp.getSystemService(AppOpsManager.class) |
| 8927 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8928 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8929 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8930 | |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame^] | 8931 | // This will make sure caller has the READ_PRIVILEGED_PHONE_STATE. Do not remove this as |
| 8932 | // we are reading iccId which is PII data. |
| 8933 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8934 | |
| 8935 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8936 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8937 | Binder.getCallingUid())) { |
| 8938 | isLogicalSlotAccessRestricted = true; |
| 8939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8940 | final long identity = Binder.clearCallingIdentity(); |
| 8941 | try { |
| 8942 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8943 | if (slots == null || slots.length == 0) { |
| 8944 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8945 | return null; |
| 8946 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8947 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8948 | for (int i = 0; i < slots.length; i++) { |
| 8949 | UiccSlot slot = slots[i]; |
| 8950 | if (slot == null) { |
| 8951 | continue; |
| 8952 | } |
| 8953 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8954 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8955 | UiccCard card = slot.getUiccCard(); |
| 8956 | if (card != null) { |
| 8957 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8958 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8959 | cardId = slot.getEid(); |
| 8960 | if (TextUtils.isEmpty(cardId)) { |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame^] | 8961 | // If cardId is null, use iccId of default port as cardId. |
| 8962 | cardId = slot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8963 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8964 | } |
| 8965 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8966 | if (cardId != null) { |
| 8967 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8968 | // if cardId is an EID, it's all digits so this is fine |
| 8969 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8970 | } |
| 8971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8972 | int cardState = 0; |
| 8973 | switch (slot.getCardState()) { |
| 8974 | case CARDSTATE_ABSENT: |
| 8975 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8976 | break; |
| 8977 | case CARDSTATE_PRESENT: |
| 8978 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8979 | break; |
| 8980 | case CARDSTATE_ERROR: |
| 8981 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8982 | break; |
| 8983 | case CARDSTATE_RESTRICTED: |
| 8984 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8985 | break; |
| 8986 | default: |
| 8987 | break; |
| 8988 | |
| 8989 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8990 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8991 | int[] portIndexes = slot.getPortList(); |
| 8992 | for (int portIdx : portIndexes) { |
| 8993 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
Aman Gupta | f3c90b3 | 2022-03-17 04:54:16 +0000 | [diff] [blame^] | 8994 | callingPackage, /* hasReadPermission= */ true)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 8995 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 8996 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8997 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8998 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8999 | slot.isEuicc(), |
| 9000 | cardId, |
| 9001 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9002 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9003 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9004 | //setting the value after compatibility check |
| 9005 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9006 | } |
| 9007 | return infos; |
| 9008 | } finally { |
| 9009 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9010 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9011 | } |
| 9012 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9013 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9014 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9015 | boolean hasReadPermission) { |
| 9016 | String iccId = slot.getIccId(portIndex); |
| 9017 | if (hasReadPermission) { // if has read permission |
| 9018 | return iccId; |
| 9019 | } else { |
| 9020 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9021 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9022 | // if no read permission, checking carrier privilege access |
| 9023 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9024 | return iccId; |
| 9025 | } |
| 9026 | } |
| 9027 | } |
| 9028 | // No read permission or carrier privilege access. |
| 9029 | return UiccPortInfo.ICCID_REDACTED; |
| 9030 | } |
| 9031 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9032 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9033 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9034 | public boolean switchSlots(int[] physicalSlots) { |
| 9035 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9036 | |
| 9037 | final long identity = Binder.clearCallingIdentity(); |
| 9038 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9039 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9040 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9041 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9042 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9043 | physicalSlots[i], i)); |
| 9044 | } |
| 9045 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9046 | } finally { |
| 9047 | Binder.restoreCallingIdentity(identity); |
| 9048 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9049 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9050 | |
| 9051 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9052 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9053 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9054 | enforceModifyPermission(); |
| 9055 | |
| 9056 | final long identity = Binder.clearCallingIdentity(); |
| 9057 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9058 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9059 | } finally { |
| 9060 | Binder.restoreCallingIdentity(identity); |
| 9061 | } |
| 9062 | } |
| 9063 | |
| 9064 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9065 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9066 | final long identity = Binder.clearCallingIdentity(); |
| 9067 | try { |
| 9068 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9069 | } finally { |
| 9070 | Binder.restoreCallingIdentity(identity); |
| 9071 | } |
| 9072 | } |
| 9073 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9074 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9075 | * A test API to reload the UICC profile. |
| 9076 | * |
| 9077 | * <p>Requires that the calling app has permission |
| 9078 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9079 | * @hide |
| 9080 | */ |
| 9081 | @Override |
| 9082 | public void refreshUiccProfile(int subId) { |
| 9083 | enforceModifyPermission(); |
| 9084 | |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
| 9086 | try { |
| 9087 | Phone phone = getPhone(subId); |
| 9088 | if (phone == null) { |
| 9089 | return; |
| 9090 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9091 | UiccPort uiccPort = phone.getUiccPort(); |
| 9092 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9093 | return; |
| 9094 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9095 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9096 | if (uiccProfile == null) { |
| 9097 | return; |
| 9098 | } |
| 9099 | uiccProfile.refresh(); |
| 9100 | } finally { |
| 9101 | Binder.restoreCallingIdentity(identity); |
| 9102 | } |
| 9103 | } |
| 9104 | |
| 9105 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9106 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9107 | */ |
| 9108 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9109 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9110 | } |
| 9111 | |
| 9112 | /** |
| 9113 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9114 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9115 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9116 | */ |
| 9117 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9118 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9119 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9120 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9121 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9122 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9123 | return isDataRoamingEnabled; |
| 9124 | } |
| 9125 | |
| 9126 | /** |
| 9127 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9128 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9129 | */ |
| 9130 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9131 | List<Integer> list = TelephonyProperties.default_network(); |
| 9132 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9133 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9134 | return list.get(phoneId); |
| 9135 | } |
| 9136 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9137 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9138 | |
| 9139 | @Override |
| 9140 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9141 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9142 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9143 | |
| 9144 | final long identity = Binder.clearCallingIdentity(); |
| 9145 | try { |
| 9146 | final Phone phone = getPhone(subId); |
| 9147 | if (phone == null) { |
| 9148 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9149 | return; |
| 9150 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9151 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9152 | if (cpt != null) { |
| 9153 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9154 | } |
| 9155 | // 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] | 9156 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9157 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9158 | if (carrierPrivilegeRules == null) { |
| 9159 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9160 | } else { |
| 9161 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9162 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9163 | } finally { |
| 9164 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9165 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9166 | } |
| 9167 | |
| 9168 | @Override |
| 9169 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9170 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9171 | |
| 9172 | final long identity = Binder.clearCallingIdentity(); |
| 9173 | try { |
| 9174 | final Phone phone = getPhone(subId); |
| 9175 | if (phone == null) { |
| 9176 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9177 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9178 | } |
| 9179 | return phone.getCarrierIdListVersion(); |
| 9180 | } finally { |
| 9181 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9182 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9183 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9184 | |
| 9185 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9186 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9187 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9188 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9189 | mApp, subId, callingPackage, callingFeatureId, |
| 9190 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9191 | return -1; |
| 9192 | } |
| 9193 | |
| 9194 | final long identity = Binder.clearCallingIdentity(); |
| 9195 | try { |
| 9196 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9197 | } finally { |
| 9198 | Binder.restoreCallingIdentity(identity); |
| 9199 | } |
| 9200 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9201 | |
| 9202 | @Override |
| 9203 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9204 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9205 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9206 | mApp, subId, "getCdmaRoamingMode"); |
| 9207 | |
| 9208 | final long identity = Binder.clearCallingIdentity(); |
| 9209 | try { |
| 9210 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9211 | } finally { |
| 9212 | Binder.restoreCallingIdentity(identity); |
| 9213 | } |
| 9214 | } |
| 9215 | |
| 9216 | @Override |
| 9217 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9219 | mApp, subId, "setCdmaRoamingMode"); |
| 9220 | |
| 9221 | final long identity = Binder.clearCallingIdentity(); |
| 9222 | try { |
| 9223 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9224 | } finally { |
| 9225 | Binder.restoreCallingIdentity(identity); |
| 9226 | } |
| 9227 | } |
| 9228 | |
| 9229 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9230 | public int getCdmaSubscriptionMode(int subId) { |
| 9231 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9232 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9233 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9234 | |
| 9235 | final long identity = Binder.clearCallingIdentity(); |
| 9236 | try { |
| 9237 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9238 | } finally { |
| 9239 | Binder.restoreCallingIdentity(identity); |
| 9240 | } |
| 9241 | } |
| 9242 | |
| 9243 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9244 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9246 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9247 | |
| 9248 | final long identity = Binder.clearCallingIdentity(); |
| 9249 | try { |
| 9250 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9251 | } finally { |
| 9252 | Binder.restoreCallingIdentity(identity); |
| 9253 | } |
| 9254 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9255 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9256 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9257 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9258 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9259 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9260 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9261 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9262 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9263 | } |
| 9264 | final long identity = Binder.clearCallingIdentity(); |
| 9265 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9266 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9267 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9268 | if (phone.getEmergencyNumberTracker() != null |
| 9269 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9270 | emergencyNumberListInternal.put( |
| 9271 | phone.getSubId(), |
| 9272 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9273 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9274 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9275 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9276 | } finally { |
| 9277 | Binder.restoreCallingIdentity(identity); |
| 9278 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9279 | } |
| 9280 | |
| 9281 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9282 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9283 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9284 | if (!exactMatch) { |
| 9285 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9286 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9287 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9288 | } |
| 9289 | final long identity = Binder.clearCallingIdentity(); |
| 9290 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9291 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9292 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9293 | && phone.getEmergencyNumberTracker() |
| 9294 | .isEmergencyNumber(number, exactMatch)) { |
| 9295 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9296 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9297 | } |
| 9298 | return false; |
| 9299 | } finally { |
| 9300 | Binder.restoreCallingIdentity(identity); |
| 9301 | } |
| 9302 | } |
| 9303 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9304 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9305 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9306 | */ |
| 9307 | @Override |
| 9308 | public void startEmergencyCallbackMode() { |
| 9309 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9310 | "startEmergencyCallbackMode"); |
| 9311 | enforceModifyPermission(); |
| 9312 | final long identity = Binder.clearCallingIdentity(); |
| 9313 | try { |
| 9314 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9315 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9316 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9317 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9318 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9319 | gsmCdmaPhone.obtainMessage( |
| 9320 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9321 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9322 | } |
| 9323 | } |
| 9324 | } finally { |
| 9325 | Binder.restoreCallingIdentity(identity); |
| 9326 | } |
| 9327 | } |
| 9328 | |
| 9329 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9330 | * Update emergency number list for test mode. |
| 9331 | */ |
| 9332 | @Override |
| 9333 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9334 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9335 | "updateEmergencyNumberListTestMode"); |
| 9336 | |
| 9337 | final long identity = Binder.clearCallingIdentity(); |
| 9338 | try { |
| 9339 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9340 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9341 | if (tracker != null) { |
| 9342 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9343 | } |
| 9344 | } |
| 9345 | } finally { |
| 9346 | Binder.restoreCallingIdentity(identity); |
| 9347 | } |
| 9348 | } |
| 9349 | |
| 9350 | /** |
| 9351 | * Get the full emergency number list for test mode. |
| 9352 | */ |
| 9353 | @Override |
| 9354 | public List<String> getEmergencyNumberListTestMode() { |
| 9355 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9356 | "getEmergencyNumberListTestMode"); |
| 9357 | |
| 9358 | final long identity = Binder.clearCallingIdentity(); |
| 9359 | try { |
| 9360 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9361 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9362 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9363 | if (tracker != null) { |
| 9364 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9365 | emergencyNumbers.add(num.getNumber()); |
| 9366 | } |
| 9367 | } |
| 9368 | } |
| 9369 | return new ArrayList<>(emergencyNumbers); |
| 9370 | } finally { |
| 9371 | Binder.restoreCallingIdentity(identity); |
| 9372 | } |
| 9373 | } |
| 9374 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9375 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9376 | public int getEmergencyNumberDbVersion(int subId) { |
| 9377 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9378 | |
| 9379 | final long identity = Binder.clearCallingIdentity(); |
| 9380 | try { |
| 9381 | final Phone phone = getPhone(subId); |
| 9382 | if (phone == null) { |
| 9383 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9384 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9385 | } |
| 9386 | return phone.getEmergencyNumberDbVersion(); |
| 9387 | } finally { |
| 9388 | Binder.restoreCallingIdentity(identity); |
| 9389 | } |
| 9390 | } |
| 9391 | |
| 9392 | @Override |
| 9393 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9394 | enforceModifyPermission(); |
| 9395 | |
| 9396 | final long identity = Binder.clearCallingIdentity(); |
| 9397 | try { |
| 9398 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9399 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9400 | if (tracker != null) { |
| 9401 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9402 | } |
| 9403 | } |
| 9404 | } finally { |
| 9405 | Binder.restoreCallingIdentity(identity); |
| 9406 | } |
| 9407 | } |
| 9408 | |
| 9409 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9410 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9411 | enforceActiveEmergencySessionPermission(); |
| 9412 | |
| 9413 | final long identity = Binder.clearCallingIdentity(); |
| 9414 | try { |
| 9415 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9416 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9417 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9418 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9419 | } |
| 9420 | } |
| 9421 | } finally { |
| 9422 | Binder.restoreCallingIdentity(identity); |
| 9423 | } |
| 9424 | } |
| 9425 | |
| 9426 | @Override |
| 9427 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9428 | enforceActiveEmergencySessionPermission(); |
| 9429 | |
| 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
| 9432 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9433 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9434 | if (tracker != null) { |
| 9435 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9436 | } |
| 9437 | } |
| 9438 | } finally { |
| 9439 | Binder.restoreCallingIdentity(identity); |
| 9440 | } |
| 9441 | } |
| 9442 | |
| 9443 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9444 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9445 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9446 | Phone phone = getPhone(subId); |
| 9447 | if (phone == null) { |
| 9448 | return null; |
| 9449 | } |
| 9450 | final long identity = Binder.clearCallingIdentity(); |
| 9451 | try { |
| 9452 | UiccProfile profile = UiccController.getInstance() |
| 9453 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9454 | if (profile != null) { |
| 9455 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9456 | } |
| 9457 | } finally { |
| 9458 | Binder.restoreCallingIdentity(identity); |
| 9459 | } |
| 9460 | return null; |
| 9461 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9462 | |
| 9463 | /** |
| 9464 | * Enable or disable a modem stack. |
| 9465 | */ |
| 9466 | @Override |
| 9467 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9468 | enforceModifyPermission(); |
| 9469 | |
| 9470 | final long identity = Binder.clearCallingIdentity(); |
| 9471 | try { |
| 9472 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9473 | if (phone == null) { |
| 9474 | return false; |
| 9475 | } else { |
| 9476 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9477 | } |
| 9478 | } finally { |
| 9479 | Binder.restoreCallingIdentity(identity); |
| 9480 | } |
| 9481 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9482 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9483 | /** |
| 9484 | * Whether a modem stack is enabled or not. |
| 9485 | */ |
| 9486 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9487 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9488 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9489 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9490 | if (phone == null) return false; |
| 9491 | |
| 9492 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9493 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9494 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9495 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9496 | } |
| 9497 | |
| 9498 | final long identity = Binder.clearCallingIdentity(); |
| 9499 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9500 | try { |
| 9501 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9502 | } catch (NoSuchElementException ex) { |
| 9503 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9504 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9505 | } finally { |
| 9506 | Binder.restoreCallingIdentity(identity); |
| 9507 | } |
| 9508 | } |
| 9509 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9510 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9511 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9512 | enforceModifyPermission(); |
| 9513 | |
| 9514 | final long identity = Binder.clearCallingIdentity(); |
| 9515 | try { |
| 9516 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9517 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9518 | .commit(); |
| 9519 | } finally { |
| 9520 | Binder.restoreCallingIdentity(identity); |
| 9521 | } |
| 9522 | } |
| 9523 | |
| 9524 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9525 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9526 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9528 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9529 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9530 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9531 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9532 | |
| 9533 | final long identity = Binder.clearCallingIdentity(); |
| 9534 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9535 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9536 | } finally { |
| 9537 | Binder.restoreCallingIdentity(identity); |
| 9538 | } |
| 9539 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9540 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9541 | @TelephonyManager.IsMultiSimSupportedResult |
| 9542 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9543 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9544 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9545 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9546 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9547 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9548 | } |
| 9549 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9550 | // supported by the modem, indicate that it is restricted. |
| 9551 | PhoneCapability staticCapability = |
| 9552 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9553 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9554 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9555 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9556 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9557 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9558 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9559 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9560 | } |
| 9561 | // Check if support of multiple SIMs is restricted by carrier |
| 9562 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9563 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9564 | } |
| 9565 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9566 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9567 | } |
| 9568 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9569 | /** |
| 9570 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9571 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9572 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9573 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9574 | * @param numOfSims number of active sims we want to switch to |
| 9575 | */ |
| 9576 | @Override |
| 9577 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9578 | if (numOfSims == 1) { |
| 9579 | enforceModifyPermission(); |
| 9580 | } else { |
| 9581 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9582 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9583 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9584 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9585 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9586 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9587 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9588 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9589 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9590 | return; |
| 9591 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9592 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9593 | } finally { |
| 9594 | Binder.restoreCallingIdentity(identity); |
| 9595 | } |
| 9596 | } |
| 9597 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9598 | @Override |
| 9599 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9600 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9601 | Phone phone = getPhone(subId); |
| 9602 | if (phone == null) { |
| 9603 | return false; |
| 9604 | } |
| 9605 | final long identity = Binder.clearCallingIdentity(); |
| 9606 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9607 | UiccPort uiccPort = phone.getUiccPort(); |
| 9608 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9609 | return false; |
| 9610 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9611 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9612 | if (uiccProfile == null) { |
| 9613 | return false; |
| 9614 | } |
| 9615 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9616 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9617 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9618 | } |
| 9619 | return false; |
| 9620 | } finally { |
| 9621 | Binder.restoreCallingIdentity(identity); |
| 9622 | } |
| 9623 | } |
| 9624 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9625 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9626 | * Get whether making changes to modem configurations will trigger reboot. |
| 9627 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9628 | */ |
| 9629 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9630 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9631 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9632 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9633 | mApp, subId, callingPackage, callingFeatureId, |
| 9634 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9635 | return false; |
| 9636 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9637 | final long identity = Binder.clearCallingIdentity(); |
| 9638 | try { |
| 9639 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9640 | } finally { |
| 9641 | Binder.restoreCallingIdentity(identity); |
| 9642 | } |
| 9643 | } |
| 9644 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9645 | private void updateModemStateMetrics() { |
| 9646 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9647 | // TODO: check the state for each modem if the api is ready. |
| 9648 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9649 | } |
| 9650 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9651 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9652 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9653 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9654 | // Verify that the callingPackage belongs to the calling UID |
| 9655 | mApp.getSystemService(AppOpsManager.class) |
| 9656 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9657 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9658 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9659 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9660 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9661 | if (slotInfos != null) { |
| 9662 | for (int i = 0; i < slotInfos.length; i++) { |
| 9663 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9664 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9665 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9666 | portInfo.getLogicalSlotIndex())); |
| 9667 | } |
| 9668 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9669 | } |
| 9670 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9671 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9672 | } finally { |
| 9673 | Binder.restoreCallingIdentity(identity); |
| 9674 | } |
| 9675 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9676 | |
| 9677 | /** |
| 9678 | * Get the IRadio HAL Version |
| 9679 | */ |
| 9680 | @Override |
| 9681 | public int getRadioHalVersion() { |
| 9682 | Phone phone = getDefaultPhone(); |
| 9683 | if (phone == null) return -1; |
| 9684 | HalVersion hv = phone.getHalVersion(); |
| 9685 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9686 | return hv.major * 100 + hv.minor; |
| 9687 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9688 | |
| 9689 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9690 | * Get the current calling package name. |
| 9691 | * @return the current calling package name |
| 9692 | */ |
| 9693 | @Override |
| 9694 | public String getCurrentPackageName() { |
| 9695 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9696 | } |
| 9697 | |
| 9698 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9699 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9700 | * corresponding network requests on a subId. |
| 9701 | * |
| 9702 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9703 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9704 | * 2) APN is un-metered for this subscription, or |
| 9705 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9706 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9707 | * |
| 9708 | * @return whether data is allowed for a apn type. |
| 9709 | * |
| 9710 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9711 | */ |
| 9712 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9713 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9714 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9715 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9716 | |
| 9717 | // Now that all security checks passes, perform the operation as ourselves. |
| 9718 | final long identity = Binder.clearCallingIdentity(); |
| 9719 | try { |
| 9720 | Phone phone = getPhone(subId); |
| 9721 | if (phone == null) return false; |
| 9722 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9723 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9724 | boolean isDataEnabled; |
| 9725 | if (phone.isUsingNewDataStack()) { |
| 9726 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9727 | } else { |
| 9728 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9729 | } |
| 9730 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9731 | } finally { |
| 9732 | Binder.restoreCallingIdentity(identity); |
| 9733 | } |
| 9734 | } |
| 9735 | |
| 9736 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9737 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9738 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9739 | |
| 9740 | // Now that all security checks passes, perform the operation as ourselves. |
| 9741 | final long identity = Binder.clearCallingIdentity(); |
| 9742 | try { |
| 9743 | Phone phone = getPhone(subId); |
| 9744 | if (phone == null) return true; // By default return true. |
| 9745 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9746 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9747 | } finally { |
| 9748 | Binder.restoreCallingIdentity(identity); |
| 9749 | } |
| 9750 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9751 | |
| 9752 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9753 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9754 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9755 | enforceModifyPermission(); |
| 9756 | long token = Binder.clearCallingIdentity(); |
| 9757 | try { |
| 9758 | Phone phone = getPhone(subscriptionId); |
| 9759 | if (phone == null) { |
| 9760 | try { |
| 9761 | if (resultCallback != null) { |
| 9762 | resultCallback.accept(false); |
| 9763 | } |
| 9764 | } catch (RemoteException e) { |
| 9765 | // ignore |
| 9766 | } |
| 9767 | return; |
| 9768 | } |
| 9769 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9770 | Pair.create(specifiers, (x) -> { |
| 9771 | try { |
| 9772 | if (resultCallback != null) { |
| 9773 | resultCallback.accept(x); |
| 9774 | } |
| 9775 | } catch (RemoteException e) { |
| 9776 | // ignore |
| 9777 | } |
| 9778 | }); |
| 9779 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9780 | } finally { |
| 9781 | Binder.restoreCallingIdentity(token); |
| 9782 | } |
| 9783 | } |
| 9784 | |
| 9785 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9786 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9787 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9788 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9789 | mApp, subId, "getSystemSelectionChannels"); |
| 9790 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9791 | final long identity = Binder.clearCallingIdentity(); |
| 9792 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9793 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9794 | if (result instanceof IllegalStateException) { |
| 9795 | throw (IllegalStateException) result; |
| 9796 | } |
| 9797 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9798 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9799 | return specifiers; |
| 9800 | } finally { |
| 9801 | Binder.restoreCallingIdentity(identity); |
| 9802 | } |
| 9803 | } |
| 9804 | |
| 9805 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9806 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9807 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9808 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9809 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9810 | if (iccRecords == null) { |
| 9811 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9812 | return false; |
| 9813 | } |
| 9814 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9815 | } |
| 9816 | |
| 9817 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9818 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9819 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9820 | if (callingPackage == null) { |
| 9821 | callingPackage = getCurrentPackageName(); |
| 9822 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9823 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9824 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9825 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9826 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9827 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9828 | } |
| 9829 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9830 | Intent intent = new Intent(); |
| 9831 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9832 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9833 | // Bring up choose default SMS subscription dialog right now |
| 9834 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9835 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9836 | mApp.startActivity(intent); |
| 9837 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9838 | |
| 9839 | @Override |
| 9840 | public String getMmsUAProfUrl(int subId) { |
| 9841 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9842 | final long identity = Binder.clearCallingIdentity(); |
| 9843 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9844 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9845 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9846 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9847 | return carrierUAProfUrl; |
| 9848 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9849 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9850 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9851 | } finally { |
| 9852 | Binder.restoreCallingIdentity(identity); |
| 9853 | } |
| 9854 | } |
| 9855 | |
| 9856 | @Override |
| 9857 | public String getMmsUserAgent(int subId) { |
| 9858 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9859 | final long identity = Binder.clearCallingIdentity(); |
| 9860 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9861 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9862 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9863 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9864 | return carrierUserAgent; |
| 9865 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9866 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9867 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9868 | } finally { |
| 9869 | Binder.restoreCallingIdentity(identity); |
| 9870 | } |
| 9871 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9872 | |
| 9873 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9874 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9875 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9876 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9877 | final long identity = Binder.clearCallingIdentity(); |
| 9878 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9879 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9880 | if (phone == null) return false; |
| 9881 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9882 | switch (policy) { |
| 9883 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9884 | if (phone.isUsingNewDataStack()) { |
| 9885 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9886 | } else { |
| 9887 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9888 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9889 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9890 | if (phone.isUsingNewDataStack()) { |
| 9891 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9892 | } else { |
| 9893 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9894 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9895 | default: |
| 9896 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9897 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9898 | } finally { |
| 9899 | Binder.restoreCallingIdentity(identity); |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9904 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9905 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9906 | enforceModifyPermission(); |
| 9907 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9908 | final long identity = Binder.clearCallingIdentity(); |
| 9909 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9910 | Phone phone = getPhone(subscriptionId); |
| 9911 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9912 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9913 | switch (policy) { |
| 9914 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9915 | if (phone.isUsingNewDataStack()) { |
| 9916 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9917 | } else { |
| 9918 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9919 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9920 | break; |
| 9921 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9922 | if (phone.isUsingNewDataStack()) { |
| 9923 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9924 | } else { |
| 9925 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9926 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9927 | break; |
| 9928 | default: |
| 9929 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9930 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9931 | } finally { |
| 9932 | Binder.restoreCallingIdentity(identity); |
| 9933 | } |
| 9934 | } |
| 9935 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9936 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9937 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9938 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9939 | * otherwise. |
| 9940 | */ |
| 9941 | @Override |
| 9942 | public void setCepEnabled(boolean isCepEnabled) { |
| 9943 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9944 | |
| 9945 | final long identity = Binder.clearCallingIdentity(); |
| 9946 | try { |
| 9947 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9948 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9949 | Phone defaultPhone = phone.getImsPhone(); |
| 9950 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9951 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9952 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9953 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9954 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9955 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9956 | + imsPhone.getMsisdn()); |
| 9957 | } |
| 9958 | } |
| 9959 | } finally { |
| 9960 | Binder.restoreCallingIdentity(identity); |
| 9961 | } |
| 9962 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9963 | |
| 9964 | /** |
| 9965 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9966 | * |
| 9967 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9968 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9969 | * before being read. |
| 9970 | */ |
| 9971 | @Override |
| 9972 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9973 | isCompressed) { |
| 9974 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9975 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9976 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9977 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9978 | } |
| 9979 | if (!isImsAvailableOnDevice()) { |
| 9980 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9981 | "IMS not available on device."); |
| 9982 | } |
| 9983 | |
| 9984 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9985 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9986 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9987 | } finally { |
| 9988 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9989 | } |
| 9990 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9991 | |
| 9992 | @Override |
| 9993 | public boolean isIccLockEnabled(int subId) { |
| 9994 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9995 | |
| 9996 | // Now that all security checks passes, perform the operation as ourselves. |
| 9997 | final long identity = Binder.clearCallingIdentity(); |
| 9998 | try { |
| 9999 | Phone phone = getPhone(subId); |
| 10000 | if (phone != null && phone.getIccCard() != null) { |
| 10001 | return phone.getIccCard().getIccLockEnabled(); |
| 10002 | } else { |
| 10003 | return false; |
| 10004 | } |
| 10005 | } finally { |
| 10006 | Binder.restoreCallingIdentity(identity); |
| 10007 | } |
| 10008 | } |
| 10009 | |
| 10010 | /** |
| 10011 | * Set the ICC pin lock enabled or disabled. |
| 10012 | * |
| 10013 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10014 | * three cases: |
| 10015 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10016 | * successfully. |
| 10017 | * - Positive number and zero for remaining password attempts. |
| 10018 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10019 | * |
| 10020 | */ |
| 10021 | @Override |
| 10022 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10023 | enforceModifyPermission(); |
| 10024 | |
| 10025 | Phone phone = getPhone(subId); |
| 10026 | if (phone == null) { |
| 10027 | return 0; |
| 10028 | } |
| 10029 | // Now that all security checks passes, perform the operation as ourselves. |
| 10030 | final long identity = Binder.clearCallingIdentity(); |
| 10031 | try { |
| 10032 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10033 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10034 | return attemptsRemaining; |
| 10035 | |
| 10036 | } catch (Exception e) { |
| 10037 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10038 | } finally { |
| 10039 | Binder.restoreCallingIdentity(identity); |
| 10040 | } |
| 10041 | return 0; |
| 10042 | } |
| 10043 | |
| 10044 | /** |
| 10045 | * Change the ICC password used in ICC pin lock. |
| 10046 | * |
| 10047 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10048 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10049 | * - Positive number and zero for remaining password attempts. |
| 10050 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10051 | * |
| 10052 | */ |
| 10053 | @Override |
| 10054 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10055 | enforceModifyPermission(); |
| 10056 | |
| 10057 | Phone phone = getPhone(subId); |
| 10058 | if (phone == null) { |
| 10059 | return 0; |
| 10060 | } |
| 10061 | // Now that all security checks passes, perform the operation as ourselves. |
| 10062 | final long identity = Binder.clearCallingIdentity(); |
| 10063 | try { |
| 10064 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10065 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10066 | return attemptsRemaining; |
| 10067 | |
| 10068 | } catch (Exception e) { |
| 10069 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10070 | } finally { |
| 10071 | Binder.restoreCallingIdentity(identity); |
| 10072 | } |
| 10073 | return 0; |
| 10074 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10075 | |
| 10076 | /** |
| 10077 | * Request for receiving user activity notification |
| 10078 | */ |
| 10079 | @Override |
| 10080 | public void requestUserActivityNotification() { |
| 10081 | if (!mNotifyUserActivity.get() |
| 10082 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10083 | mNotifyUserActivity.set(true); |
| 10084 | } |
| 10085 | } |
| 10086 | |
| 10087 | /** |
| 10088 | * Called when userActivity is signalled in the power manager. |
| 10089 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10090 | */ |
| 10091 | @Override |
| 10092 | public void userActivity() { |
| 10093 | // *************************************** |
| 10094 | // * Inherited from PhoneWindowManager * |
| 10095 | // *************************************** |
| 10096 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10097 | // WITH ITS LOCKS HELD. |
| 10098 | // |
| 10099 | // This code must be VERY careful about the locks |
| 10100 | // it acquires. |
| 10101 | // In fact, the current code acquires way too many, |
| 10102 | // and probably has lurking deadlocks. |
| 10103 | |
| 10104 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10105 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10106 | } |
| 10107 | |
| 10108 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10109 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10110 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10111 | } |
| 10112 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10113 | |
| 10114 | @Override |
| 10115 | public boolean canConnectTo5GInDsdsMode() { |
| 10116 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10117 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10118 | |
| 10119 | @Override |
| 10120 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10121 | String callingFeatureId) { |
| 10122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10123 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10124 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10125 | } |
| 10126 | |
| 10127 | Phone phone = getPhone(subId); |
| 10128 | if (phone == null) { |
| 10129 | throw new RuntimeException("phone is not available"); |
| 10130 | } |
| 10131 | // Now that all security checks passes, perform the operation as ourselves. |
| 10132 | final long identity = Binder.clearCallingIdentity(); |
| 10133 | try { |
| 10134 | return phone.getEquivalentHomePlmns(); |
| 10135 | } finally { |
| 10136 | Binder.restoreCallingIdentity(identity); |
| 10137 | } |
| 10138 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10139 | |
| 10140 | @Override |
| 10141 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10142 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10143 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10144 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10145 | if (radioInterfaceCapabilities == null) { |
| 10146 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10147 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10148 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10149 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10150 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10151 | @Override |
| 10152 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10153 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10154 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10155 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10156 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10157 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10158 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10159 | if (DBG) { |
| 10160 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10161 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10162 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10163 | } |
| 10164 | |
| 10165 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10166 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10167 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10168 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10169 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10170 | if (callback != null) { |
| 10171 | try { |
| 10172 | callback.onAuthenticationFailure( |
| 10173 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10174 | } catch (RemoteException exception) { |
| 10175 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10176 | } |
| 10177 | return; |
| 10178 | } |
| 10179 | } |
| 10180 | |
| 10181 | final long token = Binder.clearCallingIdentity(); |
| 10182 | try { |
| 10183 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10184 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10185 | forceBootStrapping, callback)); |
| 10186 | } finally { |
| 10187 | Binder.restoreCallingIdentity(token); |
| 10188 | } |
| 10189 | } |
| 10190 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10191 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10192 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10193 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10194 | * requested radio power state will actually be set. See {@link |
| 10195 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10196 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10197 | * @param enable {@code true} if trying to turn radio on. |
| 10198 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10199 | * false}. |
| 10200 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10201 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10202 | boolean isPhoneAvailable = false; |
| 10203 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10204 | Phone phone = PhoneFactory.getPhone(i); |
| 10205 | if (phone != null) { |
| 10206 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10207 | isPhoneAvailable = true; |
| 10208 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10209 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10210 | |
| 10211 | // return true if successfully informed the phone object about the thermal radio power |
| 10212 | // request. |
| 10213 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10214 | } |
| 10215 | |
| 10216 | private int handleDataThrottlingRequest(int subId, |
| 10217 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10218 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10219 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10220 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10221 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10222 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10223 | } |
| 10224 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10225 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10226 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10227 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10228 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10229 | } |
| 10230 | |
| 10231 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10232 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10233 | if (isDataThrottlingSupported) { |
| 10234 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10235 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10236 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10237 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10238 | } else if (thermalMitigationResult |
| 10239 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10240 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10241 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10242 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10243 | } |
| 10244 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10245 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10246 | |
| 10247 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10248 | } |
| 10249 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10250 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10251 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10252 | for (String pckg : context.getResources() |
| 10253 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10254 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10255 | } |
| 10256 | } |
| 10257 | |
| 10258 | return sThermalMitigationAllowlistedPackages; |
| 10259 | } |
| 10260 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10261 | private boolean isAnyPhoneInEmergencyState() { |
| 10262 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10263 | if (tm.isInEmergencyCall()) { |
| 10264 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10265 | return true; |
| 10266 | } |
| 10267 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10268 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10269 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10270 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10271 | + phone.isInEcm()); |
| 10272 | return true; |
| 10273 | } |
| 10274 | } |
| 10275 | |
| 10276 | return false; |
| 10277 | } |
| 10278 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10279 | /** |
| 10280 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10281 | * @param packageName name of package to be allowlisted |
| 10282 | * @param context |
| 10283 | */ |
| 10284 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10285 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10286 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10287 | } |
| 10288 | |
| 10289 | /** |
| 10290 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10291 | * @param packageName name of package to remove from allowlist |
| 10292 | * @param context |
| 10293 | */ |
| 10294 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10295 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10296 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10297 | } |
| 10298 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10299 | /** |
| 10300 | * Thermal mitigation request to control functionalities at modem. |
| 10301 | * |
| 10302 | * @param subId the id of the subscription. |
| 10303 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10304 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10305 | * |
| 10306 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10307 | */ |
| 10308 | @Override |
| 10309 | @ThermalMitigationResult |
| 10310 | public int sendThermalMitigationRequest( |
| 10311 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10312 | ThermalMitigationRequest thermalMitigationRequest, |
| 10313 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10314 | enforceModifyPermission(); |
| 10315 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10316 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10317 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10318 | .contains(callingPackage)) { |
| 10319 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10320 | + "calling package: " + callingPackage); |
| 10321 | } |
| 10322 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10323 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10324 | final long identity = Binder.clearCallingIdentity(); |
| 10325 | |
| 10326 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10327 | try { |
| 10328 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10329 | switch (thermalMitigationAction) { |
| 10330 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10331 | thermalMitigationResult = |
| 10332 | handleDataThrottlingRequest(subId, |
| 10333 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10334 | break; |
| 10335 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10336 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10337 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10338 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10339 | } |
| 10340 | |
| 10341 | // Ensure that radio is on. If not able to power on due to phone being |
| 10342 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10343 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10344 | thermalMitigationResult = |
| 10345 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10346 | break; |
| 10347 | } |
| 10348 | |
| 10349 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10350 | false); |
| 10351 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10352 | break; |
| 10353 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10354 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10355 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10356 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10357 | } |
| 10358 | |
| 10359 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10360 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10361 | Phone phone = getPhone(subId); |
| 10362 | if (phone == null) { |
| 10363 | thermalMitigationResult = |
| 10364 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10365 | break; |
| 10366 | } |
| 10367 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10368 | TelephonyConnectionService service = |
| 10369 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10370 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10371 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10372 | thermalMitigationResult = |
| 10373 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10374 | break; |
| 10375 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10376 | thermalMitigationResult = |
| 10377 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10378 | break; |
| 10379 | } |
| 10380 | } else { |
| 10381 | thermalMitigationResult = |
| 10382 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10383 | break; |
| 10384 | } |
| 10385 | |
| 10386 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10387 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10388 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10389 | thermalMitigationResult = |
| 10390 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10391 | break; |
| 10392 | } |
| 10393 | thermalMitigationResult = |
| 10394 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10395 | break; |
| 10396 | default: |
| 10397 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10398 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10399 | } |
| 10400 | } catch (IllegalArgumentException e) { |
| 10401 | throw e; |
| 10402 | } catch (Exception e) { |
| 10403 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10404 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10405 | } finally { |
| 10406 | Binder.restoreCallingIdentity(identity); |
| 10407 | } |
| 10408 | |
| 10409 | if (DBG) { |
| 10410 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10411 | + thermalMitigationResult); |
| 10412 | } |
| 10413 | |
| 10414 | return thermalMitigationResult; |
| 10415 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10416 | |
| 10417 | /** |
| 10418 | * Set the GbaService Package Name that Telephony will bind to. |
| 10419 | * |
| 10420 | * @param subId The sim that the GbaService is associated with. |
| 10421 | * @param packageName The name of the package to be replaced with. |
| 10422 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10423 | */ |
| 10424 | @Override |
| 10425 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10426 | enforceModifyPermission(); |
| 10427 | |
| 10428 | final long identity = Binder.clearCallingIdentity(); |
| 10429 | try { |
| 10430 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10431 | } finally { |
| 10432 | Binder.restoreCallingIdentity(identity); |
| 10433 | } |
| 10434 | } |
| 10435 | |
| 10436 | /** |
| 10437 | * Return the package name of the currently bound GbaService. |
| 10438 | * |
| 10439 | * @param subId The sim that the GbaService is associated with. |
| 10440 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10441 | */ |
| 10442 | @Override |
| 10443 | public String getBoundGbaService(int subId) { |
| 10444 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10445 | |
| 10446 | final long identity = Binder.clearCallingIdentity(); |
| 10447 | try { |
| 10448 | return getGbaManager(subId).getServicePackage(); |
| 10449 | } finally { |
| 10450 | Binder.restoreCallingIdentity(identity); |
| 10451 | } |
| 10452 | } |
| 10453 | |
| 10454 | /** |
| 10455 | * Set the release time for telephony to unbind GbaService. |
| 10456 | * |
| 10457 | * @param subId The sim that the GbaService is associated with. |
| 10458 | * @param interval The release time to unbind GbaService by millisecond. |
| 10459 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10460 | */ |
| 10461 | @Override |
| 10462 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10463 | enforceModifyPermission(); |
| 10464 | |
| 10465 | final long identity = Binder.clearCallingIdentity(); |
| 10466 | try { |
| 10467 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10468 | } finally { |
| 10469 | Binder.restoreCallingIdentity(identity); |
| 10470 | } |
| 10471 | } |
| 10472 | |
| 10473 | /** |
| 10474 | * Return the release time for telephony to unbind GbaService. |
| 10475 | * |
| 10476 | * @param subId The sim that the GbaService is associated with. |
| 10477 | * @return The release time to unbind GbaService by millisecond. |
| 10478 | */ |
| 10479 | @Override |
| 10480 | public int getGbaReleaseTime(int subId) { |
| 10481 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10482 | |
| 10483 | final long identity = Binder.clearCallingIdentity(); |
| 10484 | try { |
| 10485 | return getGbaManager(subId).getReleaseTime(); |
| 10486 | } finally { |
| 10487 | Binder.restoreCallingIdentity(identity); |
| 10488 | } |
| 10489 | } |
| 10490 | |
| 10491 | private GbaManager getGbaManager(int subId) { |
| 10492 | GbaManager instance = GbaManager.getInstance(subId); |
| 10493 | if (instance == null) { |
| 10494 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10495 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10496 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10497 | } |
| 10498 | return instance; |
| 10499 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10500 | |
| 10501 | /** |
| 10502 | * indicate whether the device and the carrier can support |
| 10503 | * RCS VoLTE single registration. |
| 10504 | */ |
| 10505 | @Override |
| 10506 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10507 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10508 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10509 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10510 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10511 | |
| 10512 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10513 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10514 | } |
| 10515 | |
| 10516 | final long identity = Binder.clearCallingIdentity(); |
| 10517 | try { |
| 10518 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10519 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10520 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10521 | if (isCapable != null) { |
| 10522 | return isCapable; |
| 10523 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10524 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10525 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10526 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10527 | } finally { |
| 10528 | Binder.restoreCallingIdentity(identity); |
| 10529 | } |
| 10530 | } |
| 10531 | |
| 10532 | /** |
| 10533 | * Register RCS provisioning callback. |
| 10534 | */ |
| 10535 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10536 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10537 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10538 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10539 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10540 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10541 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10542 | |
| 10543 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10544 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10545 | } |
| 10546 | if (!isImsAvailableOnDevice()) { |
| 10547 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10548 | "IMS not available on device."); |
| 10549 | } |
| 10550 | |
| 10551 | final long identity = Binder.clearCallingIdentity(); |
| 10552 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10553 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10554 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10556 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10557 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10558 | } finally { |
| 10559 | Binder.restoreCallingIdentity(identity); |
| 10560 | } |
| 10561 | } |
| 10562 | |
| 10563 | /** |
| 10564 | * Unregister RCS provisioning callback. |
| 10565 | */ |
| 10566 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10567 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10568 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10569 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10570 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10571 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10572 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10573 | |
| 10574 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10575 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10576 | } |
| 10577 | if (!isImsAvailableOnDevice()) { |
| 10578 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10579 | "IMS not available on device."); |
| 10580 | } |
| 10581 | |
| 10582 | final long identity = Binder.clearCallingIdentity(); |
| 10583 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10584 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10585 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10586 | } finally { |
| 10587 | Binder.restoreCallingIdentity(identity); |
| 10588 | } |
| 10589 | } |
| 10590 | |
| 10591 | /** |
| 10592 | * trigger RCS reconfiguration. |
| 10593 | */ |
| 10594 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10595 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10596 | "triggerRcsReconfiguration", |
| 10597 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10598 | |
| 10599 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10600 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10601 | } |
| 10602 | if (!isImsAvailableOnDevice()) { |
| 10603 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10604 | "IMS not available on device."); |
| 10605 | } |
| 10606 | |
| 10607 | final long identity = Binder.clearCallingIdentity(); |
| 10608 | try { |
| 10609 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10610 | } finally { |
| 10611 | Binder.restoreCallingIdentity(identity); |
| 10612 | } |
| 10613 | } |
| 10614 | |
| 10615 | /** |
| 10616 | * Provide the client configuration parameters of the RCS application. |
| 10617 | */ |
| 10618 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10619 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10620 | "setRcsClientConfiguration", |
| 10621 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10622 | |
| 10623 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10624 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10625 | } |
| 10626 | if (!isImsAvailableOnDevice()) { |
| 10627 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10628 | "IMS not available on device."); |
| 10629 | } |
| 10630 | |
| 10631 | final long identity = Binder.clearCallingIdentity(); |
| 10632 | |
| 10633 | try { |
| 10634 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10635 | if (configBinder == null) { |
| 10636 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10637 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10638 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10639 | } else { |
| 10640 | configBinder.setRcsClientConfiguration(rcc); |
| 10641 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10642 | |
| 10643 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10644 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10645 | } catch (RemoteException e) { |
| 10646 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10647 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10648 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10649 | } finally { |
| 10650 | Binder.restoreCallingIdentity(identity); |
| 10651 | } |
| 10652 | } |
| 10653 | |
| 10654 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10655 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10656 | */ |
| 10657 | @Override |
| 10658 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10659 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10660 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10661 | |
| 10662 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10663 | } |
| 10664 | |
| 10665 | /** |
| 10666 | * Gets the test mode for RCS VoLTE single registration. |
| 10667 | */ |
| 10668 | @Override |
| 10669 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10670 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10671 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10672 | |
| 10673 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10674 | } |
| 10675 | |
| 10676 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10677 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10678 | */ |
| 10679 | @Override |
| 10680 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10681 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10682 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10683 | enforceModifyPermission(); |
| 10684 | |
| 10685 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10686 | : Boolean.parseBoolean(enabledStr); |
| 10687 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10688 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10689 | } |
| 10690 | |
| 10691 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10692 | * Sends a device to device communication message. Only usable via shell. |
| 10693 | * @param message message to send. |
| 10694 | * @param value message value. |
| 10695 | */ |
| 10696 | @Override |
| 10697 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10698 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10699 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10700 | enforceModifyPermission(); |
| 10701 | |
| 10702 | final long identity = Binder.clearCallingIdentity(); |
| 10703 | try { |
| 10704 | TelephonyConnectionService service = |
| 10705 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10706 | if (service == null) { |
| 10707 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10708 | return; |
| 10709 | } |
| 10710 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10711 | } finally { |
| 10712 | Binder.restoreCallingIdentity(identity); |
| 10713 | } |
| 10714 | } |
| 10715 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10716 | /** |
| 10717 | * Sets the specified device to device transport active. |
| 10718 | * @param transport The transport to set active. |
| 10719 | */ |
| 10720 | @Override |
| 10721 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10722 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10723 | "setActiveDeviceToDeviceTransport"); |
| 10724 | enforceModifyPermission(); |
| 10725 | |
| 10726 | final long identity = Binder.clearCallingIdentity(); |
| 10727 | try { |
| 10728 | TelephonyConnectionService service = |
| 10729 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10730 | if (service == null) { |
| 10731 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10732 | return; |
| 10733 | } |
| 10734 | service.setActiveDeviceToDeviceTransport(transport); |
| 10735 | } finally { |
| 10736 | Binder.restoreCallingIdentity(identity); |
| 10737 | } |
| 10738 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10739 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10740 | @Override |
| 10741 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10742 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10743 | "setDeviceToDeviceForceEnabled"); |
| 10744 | |
| 10745 | final long identity = Binder.clearCallingIdentity(); |
| 10746 | try { |
| 10747 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10748 | p -> { |
| 10749 | Phone thePhone = p.getImsPhone(); |
| 10750 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10751 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10752 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10753 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10754 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10755 | (ImsPhoneCallTracker) tracker; |
| 10756 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10757 | } |
| 10758 | } |
| 10759 | } |
| 10760 | ); |
| 10761 | } finally { |
| 10762 | Binder.restoreCallingIdentity(identity); |
| 10763 | } |
| 10764 | } |
| 10765 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10766 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10767 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10768 | */ |
| 10769 | @Override |
| 10770 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10771 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10772 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10773 | } |
| 10774 | |
| 10775 | /** |
| 10776 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10777 | */ |
| 10778 | @Override |
| 10779 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10780 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10781 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10782 | enforceModifyPermission(); |
| 10783 | |
| 10784 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10785 | : Boolean.parseBoolean(enabledStr); |
| 10786 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10787 | subId, enabled); |
| 10788 | } |
| 10789 | |
| 10790 | /** |
| 10791 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10792 | */ |
| 10793 | @Override |
| 10794 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10795 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10796 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10797 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10798 | |
| 10799 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10800 | * Overrides the ims feature validation result |
| 10801 | */ |
| 10802 | @Override |
| 10803 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10804 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10805 | "setImsFeatureValidationOverride"); |
| 10806 | |
| 10807 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10808 | : Boolean.parseBoolean(enabledStr); |
| 10809 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10810 | subId, enabled); |
| 10811 | } |
| 10812 | |
| 10813 | /** |
| 10814 | * Gets the ims feature validation override value |
| 10815 | */ |
| 10816 | @Override |
| 10817 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10818 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10819 | "getImsFeatureValidationOverride"); |
| 10820 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10821 | } |
| 10822 | |
| 10823 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10824 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10825 | * their mobile plan. |
| 10826 | */ |
| 10827 | @Override |
| 10828 | public String getMobileProvisioningUrl() { |
| 10829 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10830 | final long identity = Binder.clearCallingIdentity(); |
| 10831 | try { |
| 10832 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10833 | } finally { |
| 10834 | Binder.restoreCallingIdentity(identity); |
| 10835 | } |
| 10836 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10837 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10838 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10839 | * Get the EAB contact from the EAB database. |
| 10840 | */ |
| 10841 | @Override |
| 10842 | public String getContactFromEab(String contact) { |
| 10843 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10844 | enforceModifyPermission(); |
| 10845 | final long identity = Binder.clearCallingIdentity(); |
| 10846 | try { |
| 10847 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10848 | } finally { |
| 10849 | Binder.restoreCallingIdentity(identity); |
| 10850 | } |
| 10851 | } |
| 10852 | |
| 10853 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10854 | * Get the EAB capability from the EAB database. |
| 10855 | */ |
| 10856 | @Override |
| 10857 | public String getCapabilityFromEab(String contact) { |
| 10858 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10859 | enforceModifyPermission(); |
| 10860 | final long identity = Binder.clearCallingIdentity(); |
| 10861 | try { |
| 10862 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10863 | } finally { |
| 10864 | Binder.restoreCallingIdentity(identity); |
| 10865 | } |
| 10866 | } |
| 10867 | |
| 10868 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10869 | * Remove the EAB contacts from the EAB database. |
| 10870 | */ |
| 10871 | @Override |
| 10872 | public int removeContactFromEab(int subId, String contacts) { |
| 10873 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10874 | enforceModifyPermission(); |
| 10875 | final long identity = Binder.clearCallingIdentity(); |
| 10876 | try { |
| 10877 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10878 | } finally { |
| 10879 | Binder.restoreCallingIdentity(identity); |
| 10880 | } |
| 10881 | } |
| 10882 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10883 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10884 | public boolean getDeviceUceEnabled() { |
| 10885 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10886 | final long identity = Binder.clearCallingIdentity(); |
| 10887 | try { |
| 10888 | return mApp.getDeviceUceEnabled(); |
| 10889 | } finally { |
| 10890 | Binder.restoreCallingIdentity(identity); |
| 10891 | } |
| 10892 | } |
| 10893 | |
| 10894 | @Override |
| 10895 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10896 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10897 | final long identity = Binder.clearCallingIdentity(); |
| 10898 | try { |
| 10899 | mApp.setDeviceUceEnabled(isEnabled); |
| 10900 | } finally { |
| 10901 | Binder.restoreCallingIdentity(identity); |
| 10902 | } |
| 10903 | } |
| 10904 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10905 | /** |
| 10906 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10907 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10908 | */ |
| 10909 | // Used for SHELL command only right now. |
| 10910 | @Override |
| 10911 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10912 | List<String> featureTags) { |
| 10913 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10914 | "addUceRegistrationOverrideShell"); |
| 10915 | final long identity = Binder.clearCallingIdentity(); |
| 10916 | try { |
| 10917 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10918 | new ArraySet<>(featureTags)); |
| 10919 | } catch (ImsException e) { |
| 10920 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10921 | } finally { |
| 10922 | Binder.restoreCallingIdentity(identity); |
| 10923 | } |
| 10924 | } |
| 10925 | |
| 10926 | /** |
| 10927 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10928 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10929 | */ |
| 10930 | // Used for SHELL command only right now. |
| 10931 | @Override |
| 10932 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10933 | List<String> featureTags) { |
| 10934 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10935 | "removeUceRegistrationOverrideShell"); |
| 10936 | final long identity = Binder.clearCallingIdentity(); |
| 10937 | try { |
| 10938 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10939 | new ArraySet<>(featureTags)); |
| 10940 | } catch (ImsException e) { |
| 10941 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10942 | } finally { |
| 10943 | Binder.restoreCallingIdentity(identity); |
| 10944 | } |
| 10945 | } |
| 10946 | |
| 10947 | /** |
| 10948 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10949 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10950 | */ |
| 10951 | // Used for SHELL command only right now. |
| 10952 | @Override |
| 10953 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10955 | "clearUceRegistrationOverrideShell"); |
| 10956 | final long identity = Binder.clearCallingIdentity(); |
| 10957 | try { |
| 10958 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10959 | } catch (ImsException e) { |
| 10960 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10961 | } finally { |
| 10962 | Binder.restoreCallingIdentity(identity); |
| 10963 | } |
| 10964 | } |
| 10965 | |
| 10966 | /** |
| 10967 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10968 | */ |
| 10969 | // Used for SHELL command only right now. |
| 10970 | @Override |
| 10971 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10972 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10973 | "getLatestRcsContactUceCapabilityShell"); |
| 10974 | final long identity = Binder.clearCallingIdentity(); |
| 10975 | try { |
| 10976 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10977 | } catch (ImsException e) { |
| 10978 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10979 | } finally { |
| 10980 | Binder.restoreCallingIdentity(identity); |
| 10981 | } |
| 10982 | } |
| 10983 | |
| 10984 | /** |
| 10985 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10986 | * device does not have an active PUBLISH. |
| 10987 | */ |
| 10988 | // Used for SHELL command only right now. |
| 10989 | @Override |
| 10990 | public String getLastUcePidfXmlShell(int subId) { |
| 10991 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10992 | final long identity = Binder.clearCallingIdentity(); |
| 10993 | try { |
| 10994 | return mApp.imsRcsController.getLastUcePidfXmlShell(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 | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11002 | /** |
| 11003 | * Remove UCE requests cannot be sent to the network status. |
| 11004 | */ |
| 11005 | // Used for SHELL command only right now. |
| 11006 | @Override |
| 11007 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11009 | final long identity = Binder.clearCallingIdentity(); |
| 11010 | try { |
| 11011 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11012 | } catch (ImsException e) { |
| 11013 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11014 | } finally { |
| 11015 | Binder.restoreCallingIdentity(identity); |
| 11016 | } |
| 11017 | } |
| 11018 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11019 | /** |
| 11020 | * Remove UCE requests cannot be sent to the network status. |
| 11021 | */ |
| 11022 | // Used for SHELL command only. |
| 11023 | @Override |
| 11024 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11025 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11026 | final long identity = Binder.clearCallingIdentity(); |
| 11027 | try { |
| 11028 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11029 | } catch (ImsException e) { |
| 11030 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11031 | } finally { |
| 11032 | Binder.restoreCallingIdentity(identity); |
| 11033 | } |
| 11034 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11035 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11036 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11037 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11038 | String callingPackage) { |
| 11039 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11040 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11041 | |
| 11042 | final int callingUid = Binder.getCallingUid(); |
| 11043 | // Verify that tha callingPackage belongs to the calling UID |
| 11044 | mApp.getSystemService(AppOpsManager.class) |
| 11045 | .checkPackage(callingUid, callingPackage); |
| 11046 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11047 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11048 | |
| 11049 | final long identity = Binder.clearCallingIdentity(); |
| 11050 | try { |
| 11051 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11052 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11053 | |
| 11054 | if (result instanceof IllegalStateException) { |
| 11055 | throw (IllegalStateException) result; |
| 11056 | } |
| 11057 | } finally { |
| 11058 | Binder.restoreCallingIdentity(identity); |
| 11059 | } |
| 11060 | } |
| 11061 | |
| 11062 | @Override |
| 11063 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11064 | String callingPackage) { |
| 11065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11066 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11067 | |
| 11068 | final int callingUid = Binder.getCallingUid(); |
| 11069 | // Verify that tha callingPackage belongs to the calling UID |
| 11070 | mApp.getSystemService(AppOpsManager.class) |
| 11071 | .checkPackage(callingUid, callingPackage); |
| 11072 | |
| 11073 | final long identity = Binder.clearCallingIdentity(); |
| 11074 | try { |
| 11075 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11076 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11077 | |
| 11078 | if (result instanceof IllegalStateException) { |
| 11079 | throw (IllegalStateException) result; |
| 11080 | } |
| 11081 | } finally { |
| 11082 | Binder.restoreCallingIdentity(identity); |
| 11083 | } |
| 11084 | } |
| 11085 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11086 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11087 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11088 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11089 | // phone/system process do not have further restriction on request |
| 11090 | return; |
| 11091 | } |
| 11092 | |
| 11093 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11094 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11095 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11096 | context.enforceCallingOrSelfPermission( |
| 11097 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11098 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11099 | } |
| 11100 | |
| 11101 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11102 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11103 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11104 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11105 | || info.isEnabled()) { |
| 11106 | throw new IllegalArgumentException( |
| 11107 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11108 | } |
| 11109 | |
| 11110 | // Thresholds length for each RAN need in range. This has been validated in |
| 11111 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11112 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11113 | final int[] thresholds = info.getThresholds(); |
| 11114 | Objects.requireNonNull(thresholds); |
| 11115 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11116 | || thresholds.length |
| 11117 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11118 | throw new IllegalArgumentException( |
| 11119 | "thresholds length is out of range: " + thresholds.length); |
| 11120 | } |
| 11121 | } |
| 11122 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11123 | |
| 11124 | /** |
| 11125 | * Gets the current phone capability. |
| 11126 | * |
| 11127 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11128 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11129 | * It's used to evaluate possible phone config change, for example from single |
| 11130 | * SIM device to multi-SIM device. |
| 11131 | */ |
| 11132 | @Override |
| 11133 | public PhoneCapability getPhoneCapability() { |
| 11134 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11135 | final long identity = Binder.clearCallingIdentity(); |
| 11136 | try { |
| 11137 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11138 | } finally { |
| 11139 | Binder.restoreCallingIdentity(identity); |
| 11140 | } |
| 11141 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11142 | |
| 11143 | /** |
| 11144 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11145 | * required to be done shortly after the API is invoked. |
| 11146 | */ |
| 11147 | @Override |
| 11148 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11149 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11150 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11151 | enforceRebootPermission(); |
| 11152 | |
| 11153 | final long identity = Binder.clearCallingIdentity(); |
| 11154 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11155 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11156 | } finally { |
| 11157 | Binder.restoreCallingIdentity(identity); |
| 11158 | } |
| 11159 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11160 | |
| 11161 | /** |
| 11162 | * Request to get the current slicing configuration including URSP rules and |
| 11163 | * NSSAIs (configured, allowed and rejected). |
| 11164 | * |
| 11165 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11166 | */ |
| 11167 | @Override |
| 11168 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11169 | TelephonyPermissions |
| 11170 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11171 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11172 | |
| 11173 | final long identity = Binder.clearCallingIdentity(); |
| 11174 | try { |
| 11175 | Phone phone = getDefaultPhone(); |
| 11176 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11177 | } finally { |
| 11178 | Binder.restoreCallingIdentity(identity); |
| 11179 | } |
| 11180 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11181 | |
| 11182 | /** |
| 11183 | * Register an IMS connection state callback |
| 11184 | */ |
| 11185 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11186 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11187 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11188 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11189 | // ImsMmTelManager |
| 11190 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11191 | TelephonyPermissions |
| 11192 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11193 | mApp, subId, "registerImsStateCallback"); |
| 11194 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11195 | // ImsRcsManager or SipDelegateManager |
| 11196 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11197 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11198 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11199 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11200 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11201 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11202 | } |
| 11203 | |
| 11204 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11205 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11206 | "IMS not available on device."); |
| 11207 | } |
| 11208 | |
| 11209 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11210 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11211 | } |
| 11212 | |
| 11213 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11214 | if (controller == null) { |
| 11215 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11216 | "IMS not available on device."); |
| 11217 | } |
| 11218 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11219 | if (callingPackage == null) { |
| 11220 | callingPackage = getCurrentPackageName(); |
| 11221 | } |
| 11222 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11223 | final long token = Binder.clearCallingIdentity(); |
| 11224 | try { |
| 11225 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11226 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11227 | } catch (ImsException e) { |
| 11228 | throw new ServiceSpecificException(e.getCode()); |
| 11229 | } finally { |
| 11230 | Binder.restoreCallingIdentity(token); |
| 11231 | } |
| 11232 | } |
| 11233 | |
| 11234 | /** |
| 11235 | * Unregister an IMS connection state callback |
| 11236 | */ |
| 11237 | @Override |
| 11238 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11239 | final long token = Binder.clearCallingIdentity(); |
| 11240 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11241 | if (controller == null) { |
| 11242 | return; |
| 11243 | } |
| 11244 | try { |
| 11245 | controller.unregisterImsStateCallback(cb); |
| 11246 | } finally { |
| 11247 | Binder.restoreCallingIdentity(token); |
| 11248 | } |
| 11249 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11250 | |
| 11251 | /** |
| 11252 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11253 | * |
| 11254 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11255 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11256 | * SecurityException. |
| 11257 | * If there is current registered network this value will be same as the registered cell |
| 11258 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11259 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11260 | * it will be cleared and null will be returned. |
| 11261 | * |
| 11262 | */ |
| 11263 | @Override |
| 11264 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11265 | String callingFeatureId) { |
| 11266 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11267 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11268 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11269 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11270 | .setCallingPackage(callingPackage) |
| 11271 | .setCallingFeatureId(callingFeatureId) |
| 11272 | .setCallingPid(Binder.getCallingPid()) |
| 11273 | .setCallingUid(Binder.getCallingUid()) |
| 11274 | .setMethod("getLastKnownCellIdentity") |
| 11275 | .setLogAsInfo(true) |
| 11276 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11277 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11278 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11279 | .build()); |
| 11280 | |
| 11281 | boolean hasFinePermission = |
| 11282 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11283 | if (!hasFinePermission |
| 11284 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11285 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11286 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11287 | } |
| 11288 | |
| 11289 | final long identity = Binder.clearCallingIdentity(); |
| 11290 | try { |
| 11291 | Phone phone = getPhone(subId); |
| 11292 | if (phone == null) return null; |
| 11293 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11294 | if (sst == null) return null; |
| 11295 | return sst.getLastKnownCellIdentity(); |
| 11296 | } finally { |
| 11297 | Binder.restoreCallingIdentity(identity); |
| 11298 | } |
| 11299 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11300 | |
| 11301 | @Override |
| 11302 | public boolean isUsingNewDataStack() { |
| 11303 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11304 | return getDefaultPhone().isUsingNewDataStack(); |
| 11305 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11306 | |
| 11307 | /** |
| 11308 | * Sets the modem service class Name that Telephony will bind to. |
| 11309 | * |
| 11310 | * @param serviceName The class name of the modem service. |
| 11311 | * @return true if the operation is succeed, otherwise false. |
| 11312 | */ |
| 11313 | public boolean setModemService(String serviceName) { |
| 11314 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11315 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11317 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11318 | "setModemService"); |
| 11319 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11320 | } |
| 11321 | |
| 11322 | /** |
| 11323 | * Return the class name of the currently bounded modem service. |
| 11324 | * |
| 11325 | * @return the class name of the modem service. |
| 11326 | */ |
| 11327 | public String getModemService() { |
| 11328 | String result; |
| 11329 | Log.d(LOG_TAG, "getModemService"); |
| 11330 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11331 | TelephonyPermissions |
| 11332 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11333 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11334 | "getModemService"); |
| 11335 | result = mPhoneConfigurationManager.getModemService(); |
| 11336 | Log.d(LOG_TAG, "result = " + result); |
| 11337 | return result; |
| 11338 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11339 | |
| 11340 | @Override |
| 11341 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11342 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11343 | mApp.enforceCallingOrSelfPermission( |
| 11344 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11345 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11346 | |
| 11347 | final long identity = Binder.clearCallingIdentity(); |
| 11348 | try { |
| 11349 | Phone phone = getPhone(subId); |
| 11350 | if (phone == null) return; |
| 11351 | phone.setVoiceServiceStateOverride(hasService); |
| 11352 | } finally { |
| 11353 | Binder.restoreCallingIdentity(identity); |
| 11354 | } |
| 11355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11356 | } |