Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA; |
| 22 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 23 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 24 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 25 | import static com.android.internal.telephony.TelephonyStatsLog.RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 26 | |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 27 | import android.Manifest; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 29 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 30 | import android.annotation.Nullable; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame^] | 34 | import android.app.PropertyInvalidatedCache; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 35 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 36 | import android.app.role.RoleManager; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 37 | import android.compat.annotation.ChangeId; |
| 38 | import android.compat.annotation.EnabledSince; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 39 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 40 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 43 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 44 | import android.content.pm.ComponentInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 45 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.AsyncResult; |
| 48 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 49 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 50 | import android.os.Bundle; |
| 51 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 52 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 53 | import android.os.Looper; |
| 54 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 55 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 56 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 57 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 58 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 59 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 60 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 61 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 62 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 63 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 64 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 65 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 66 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 67 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 68 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 69 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 70 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 71 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 72 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 73 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 74 | import android.telecom.TelecomManager; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 75 | import android.telephony.AccessNetworkConstants; |
| 76 | import android.telephony.ActivityStatsTechSpecificInfo; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 77 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 78 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 79 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 80 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 81 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 82 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 83 | import android.telephony.CellIdentityCdma; |
| 84 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 85 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 86 | import android.telephony.CellInfoGsm; |
| 87 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 88 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 89 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 90 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 91 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 92 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 93 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 94 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 95 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 96 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 97 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 98 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 99 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 100 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 101 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 102 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 103 | import android.telephony.SignalStrengthUpdateRequest; |
| 104 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 105 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 106 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 107 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 108 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 109 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 110 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 111 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 112 | import android.telephony.UiccCardInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 113 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 114 | import android.telephony.UiccSlotInfo; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 115 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 116 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 117 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 118 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 119 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 120 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 121 | import android.telephony.gba.GbaAuthRequest; |
| 122 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 123 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 125 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 126 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 127 | import android.telephony.ims.RegistrationManager; |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 133 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 134 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 135 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 137 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 138 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 139 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 141 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 142 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 144 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 145 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 146 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 147 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 148 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 149 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 165 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.IccCard; |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 181 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 187 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 192 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 193 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 194 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 195 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 196 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 206 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 207 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 208 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 209 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 210 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 211 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 212 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 213 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 214 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 215 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 217 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 218 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 219 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 220 | import com.android.services.telephony.TelecomAccountRegistry; |
| 221 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 222 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 223 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 225 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 226 | import java.io.IOException; |
| 227 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 228 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 229 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 230 | import java.util.Arrays; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 231 | import java.util.Collection; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 232 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 233 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 234 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 235 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 236 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 237 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 238 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 239 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 240 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 241 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 242 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 243 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * Implementation of the ITelephony interface. |
| 247 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 248 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 249 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 250 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 251 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 252 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 253 | |
| 254 | // Message codes used with mMainThreadHandler |
| 255 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 256 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 257 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 258 | private static final int CMD_OPEN_CHANNEL = 9; |
| 259 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 260 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 261 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 262 | private static final int CMD_NV_READ_ITEM = 13; |
| 263 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 264 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 265 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 266 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 267 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 268 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 269 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 270 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 271 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 272 | private static final int CMD_SEND_ENVELOPE = 25; |
| 273 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 274 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 275 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 276 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 277 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 278 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 279 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 280 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 281 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 282 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 283 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 284 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 285 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 286 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 287 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 288 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 289 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 290 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 291 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 292 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 293 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 294 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 295 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 296 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 297 | private static final int CMD_SWITCH_SLOTS = 50; |
| 298 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 299 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 300 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 301 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 302 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 303 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 304 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 305 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 306 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 307 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 308 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 309 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 310 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 311 | private static final int CMD_MODEM_REBOOT = 64; |
| 312 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 313 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 314 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 315 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 316 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 317 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 318 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 319 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 320 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 321 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 322 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 323 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 324 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 325 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 326 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 327 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 328 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 329 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 330 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 331 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 332 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 333 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 334 | private static final int CMD_GET_CALL_WAITING = 87; |
| 335 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 336 | private static final int CMD_SET_CALL_WAITING = 89; |
| 337 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 338 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 339 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 340 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 341 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 342 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 343 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 344 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 345 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 347 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 348 | private static final int CMD_SET_SIM_POWER = 101; |
| 349 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 350 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 351 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 352 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 353 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 354 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 355 | 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] | 356 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 357 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 358 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 359 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 360 | private static final int CMD_ENABLE_VONR = 113; |
| 361 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 362 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 363 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 364 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 365 | // Parameters of select command. |
| 366 | private static final int SELECT_COMMAND = 0xA4; |
| 367 | private static final int SELECT_P1 = 0x04; |
| 368 | private static final int SELECT_P2 = 0; |
| 369 | private static final int SELECT_P3 = 0x10; |
| 370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | /** The singleton instance. */ |
| 372 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 373 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 374 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 375 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 376 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 377 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 378 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 380 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 381 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 382 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 383 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 384 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 385 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 387 | /** User Activity */ |
| 388 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 389 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 390 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 391 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 392 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 393 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 394 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 395 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 396 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 397 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 398 | // String to store multi SIM allowed |
| 399 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 400 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 401 | // The AID of ISD-R. |
| 402 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 403 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 404 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 405 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 406 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 407 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 408 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 409 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 410 | 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] | 411 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 412 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 413 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 414 | */ |
| 415 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 416 | "reset_network_erase_modem_config_enabled"; |
| 417 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 418 | 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] | 419 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 420 | /** |
| 421 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 422 | * one ICCID active at the same time. |
| 423 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 424 | * |
| 425 | * @hide |
| 426 | */ |
| 427 | @ChangeId |
| 428 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 429 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 430 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 431 | /** |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 432 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 433 | * operation fails. |
| 434 | */ |
| 435 | @ChangeId |
| 436 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 437 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 438 | |
| 439 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 440 | * A request object to use for transmitting data to an ICC. |
| 441 | */ |
| 442 | private static final class IccAPDUArgument { |
| 443 | public int channel, cla, command, p1, p2, p3; |
| 444 | public String data; |
| 445 | |
| 446 | public IccAPDUArgument(int channel, int cla, int command, |
| 447 | int p1, int p2, int p3, String data) { |
| 448 | this.channel = channel; |
| 449 | this.cla = cla; |
| 450 | this.command = command; |
| 451 | this.p1 = p1; |
| 452 | this.p2 = p2; |
| 453 | this.p3 = p3; |
| 454 | this.data = data; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 459 | * A request object to use for transmitting data to an ICC. |
| 460 | */ |
| 461 | private static final class ManualNetworkSelectionArgument { |
| 462 | public OperatorInfo operatorInfo; |
| 463 | public boolean persistSelection; |
| 464 | |
| 465 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 466 | this.operatorInfo = operatorInfo; |
| 467 | this.persistSelection = persistSelection; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 472 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 473 | * request after sending. The main thread will notify the request when it is complete. |
| 474 | */ |
| 475 | private static final class MainThreadRequest { |
| 476 | /** The argument to use for the request */ |
| 477 | public Object argument; |
| 478 | /** The result of the request that is run on the main thread */ |
| 479 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 480 | // The subscriber id that this request applies to. Defaults to |
| 481 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 482 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 484 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 485 | public Phone phone; |
| 486 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 487 | public WorkSource workSource; |
| 488 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 489 | public MainThreadRequest(Object argument) { |
| 490 | this.argument = argument; |
| 491 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 492 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 493 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 494 | this.argument = argument; |
| 495 | if (phone != null) { |
| 496 | this.phone = phone; |
| 497 | } |
| 498 | this.workSource = workSource; |
| 499 | } |
| 500 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 501 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 502 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 503 | if (subId != null) { |
| 504 | this.subId = subId; |
| 505 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 506 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 510 | private static final class IncomingThirdPartyCallArgs { |
| 511 | public final ComponentName component; |
| 512 | public final String callId; |
| 513 | public final String callerDisplayName; |
| 514 | |
| 515 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 516 | String callerDisplayName) { |
| 517 | this.component = component; |
| 518 | this.callId = callId; |
| 519 | this.callerDisplayName = callerDisplayName; |
| 520 | } |
| 521 | } |
| 522 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 523 | /** |
| 524 | * A handler that processes messages on the main thread in the phone process. Since many |
| 525 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 526 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 527 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 528 | * on, which will be notified when the operation completes and will contain the result of the |
| 529 | * request. |
| 530 | * |
| 531 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 532 | * note that request.result must be set to something non-null for the calling thread to |
| 533 | * unblock. |
| 534 | */ |
| 535 | private final class MainThreadHandler extends Handler { |
| 536 | @Override |
| 537 | public void handleMessage(Message msg) { |
| 538 | MainThreadRequest request; |
| 539 | Message onCompleted; |
| 540 | AsyncResult ar; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 541 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 543 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 544 | |
| 545 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 546 | case CMD_HANDLE_USSD_REQUEST: { |
| 547 | request = (MainThreadRequest) msg.obj; |
| 548 | final Phone phone = getPhoneFromRequest(request); |
| 549 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 550 | String ussdRequest = ussdObject.first; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 552 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 553 | if (!isUssdApiAllowed(request.subId)) { |
| 554 | // Carrier does not support use of this API, return failure. |
| 555 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 556 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 557 | Bundle returnData = new Bundle(); |
| 558 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 559 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 560 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | request.result = true; |
| 562 | notifyRequester(request); |
| 563 | return; |
| 564 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 565 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | try { |
| 567 | request.result = phone != null |
| 568 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 569 | } catch (CallStateException cse) { |
| 570 | request.result = false; |
| 571 | } |
| 572 | // Wake up the requesting thread |
| 573 | notifyRequester(request); |
| 574 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 577 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 578 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 579 | final Phone phone = getPhoneFromRequest(request); |
| 580 | request.result = phone != null ? |
| 581 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 582 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 586 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 587 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 589 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 591 | uiccPort = getUiccPortFromRequest(request); |
| 592 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | loge("iccTransmitApduLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 594 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 596 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 598 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 599 | uiccPort.iccTransmitApduLogicalChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 600 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 601 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
| 602 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 603 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 604 | break; |
| 605 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 606 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 607 | ar = (AsyncResult) msg.obj; |
| 608 | request = (MainThreadRequest) ar.userObj; |
| 609 | if (ar.exception == null && ar.result != null) { |
| 610 | request.result = ar.result; |
| 611 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 612 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 613 | if (ar.result == null) { |
| 614 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 615 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 617 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 618 | } else { |
| 619 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 620 | } |
| 621 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | break; |
| 624 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 625 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 626 | request = (MainThreadRequest) msg.obj; |
| 627 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 628 | uiccPort = getUiccPortFromRequest(request); |
| 629 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | loge("iccTransmitApduBasicChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 631 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | } else { |
| 634 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 635 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 636 | uiccPort.iccTransmitApduBasicChannel( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 637 | iccArgument.cla, iccArgument.command, iccArgument.p1, |
| 638 | iccArgument.p2, |
| 639 | iccArgument.p3, iccArgument.data, onCompleted); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | } |
| 641 | break; |
| 642 | |
| 643 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 644 | ar = (AsyncResult) msg.obj; |
| 645 | request = (MainThreadRequest) ar.userObj; |
| 646 | if (ar.exception == null && ar.result != null) { |
| 647 | request.result = ar.result; |
| 648 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 649 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | if (ar.result == null) { |
| 651 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 652 | } else if (ar.exception instanceof CommandException) { |
| 653 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 654 | ar.exception); |
| 655 | } else { |
| 656 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 657 | } |
| 658 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 659 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case CMD_EXCHANGE_SIM_IO: |
| 663 | request = (MainThreadRequest) msg.obj; |
| 664 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 665 | uiccPort = getUiccPortFromRequest(request); |
| 666 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | loge("iccExchangeSimIO: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 668 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 669 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | } else { |
| 671 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 672 | request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 673 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 675 | iccArgument.data, onCompleted); |
| 676 | } |
| 677 | break; |
| 678 | |
| 679 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 680 | ar = (AsyncResult) msg.obj; |
| 681 | request = (MainThreadRequest) ar.userObj; |
| 682 | if (ar.exception == null && ar.result != null) { |
| 683 | request.result = ar.result; |
| 684 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 685 | request.result = new IccIoResult(0x6f, 0, (byte[]) null); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 687 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | break; |
| 689 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 690 | case CMD_SEND_ENVELOPE: |
| 691 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 692 | uiccPort = getUiccPortFromRequest(request); |
| 693 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | loge("sendEnvelopeWithStatus: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 695 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 696 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 697 | } else { |
| 698 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 699 | uiccPort.sendEnvelopeWithStatus((String) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 700 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_SEND_ENVELOPE_DONE: |
| 704 | ar = (AsyncResult) msg.obj; |
| 705 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 706 | if (ar.exception == null && ar.result != null) { |
| 707 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 708 | } else { |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 709 | request.result = new IccIoResult(0x6F, 0, (byte[]) null); |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 710 | if (ar.result == null) { |
| 711 | loge("sendEnvelopeWithStatus: Empty response"); |
| 712 | } else if (ar.exception instanceof CommandException) { |
| 713 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 714 | ar.exception); |
| 715 | } else { |
| 716 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 717 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 718 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | case CMD_OPEN_CHANNEL: |
| 723 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 725 | IccLogicalChannelRequest openChannelRequest = |
| 726 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 727 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 728 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 729 | request.result = new IccOpenLogicalChannelResponse(-1, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 730 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 731 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 732 | } else { |
| 733 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 734 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 735 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 736 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_OPEN_CHANNEL_DONE: |
| 740 | ar = (AsyncResult) msg.obj; |
| 741 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 742 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 743 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 744 | int[] result = (int[]) ar.result; |
| 745 | int channelId = result[0]; |
| 746 | byte[] selectResponse = null; |
| 747 | if (result.length > 1) { |
| 748 | selectResponse = new byte[result.length - 1]; |
| 749 | for (int i = 1; i < result.length; ++i) { |
| 750 | selectResponse[i - 1] = (byte) result[i]; |
| 751 | } |
| 752 | } |
| 753 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 754 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 755 | |
| 756 | uiccPort = getUiccPortFromRequest(request); |
| 757 | IccLogicalChannelRequest channelRequest = |
| 758 | (IccLogicalChannelRequest) request.argument; |
| 759 | channelRequest.channel = channelId; |
| 760 | uiccPort.onLogicalChannelOpened(channelRequest); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 762 | if (ar.result == null) { |
| 763 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 764 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 765 | if (ar.exception != null) { |
| 766 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 767 | } |
| 768 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 769 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 770 | if (ar.exception instanceof CommandException) { |
| 771 | CommandException.Error error = |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 772 | ((CommandException) (ar.exception)).getCommandError(); |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 773 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 774 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 775 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 776 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | openChannelResp = new IccOpenLogicalChannelResponse( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 780 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 782 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 783 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 784 | break; |
| 785 | |
| 786 | case CMD_CLOSE_CHANNEL: |
| 787 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 788 | uiccPort = getUiccPortFromRequest(request); |
| 789 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 790 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 791 | request.result = new IllegalArgumentException( |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 792 | "iccCloseLogicalChannel: No UICC"); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 793 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 794 | } else { |
| 795 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 796 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 797 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 801 | ar = (AsyncResult) msg.obj; |
| 802 | request = (MainThreadRequest) ar.userObj; |
| 803 | if (ar.exception == null) { |
| 804 | request.result = true; |
Rambo Wang | 3b77c4c | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 805 | uiccPort = getUiccPortFromRequest(request); |
| 806 | final int channelId = (Integer) request.argument; |
| 807 | uiccPort.onLogicalChannelClosed(channelId); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 808 | } else { |
| 809 | request.result = false; |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 810 | Exception exception = null; |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 811 | if (ar.exception instanceof CommandException) { |
| 812 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 813 | CommandException.Error error = |
| 814 | ((CommandException) (ar.exception)).getCommandError(); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 815 | if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 816 | // should only throw exceptions from the binder threads. |
| 817 | exception = new IllegalArgumentException( |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 818 | "iccCloseLogicalChannel: invalid argument "); |
| 819 | } |
| 820 | } else { |
| 821 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 822 | } |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 823 | request.result = (exception != null) ? exception : |
| 824 | new IllegalStateException( |
| 825 | "exception from modem to close iccLogical Channel"); |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 826 | } |
| 827 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case CMD_NV_READ_ITEM: |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 833 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 834 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 835 | break; |
| 836 | |
| 837 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 838 | ar = (AsyncResult) msg.obj; |
| 839 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 840 | if (ar.exception == null && ar.result != null) { |
| 841 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 842 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 843 | request.result = ""; |
| 844 | if (ar.result == null) { |
| 845 | loge("nvReadItem: Empty response"); |
| 846 | } else if (ar.exception instanceof CommandException) { |
| 847 | loge("nvReadItem: CommandException: " + |
| 848 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 849 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 850 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 851 | } |
| 852 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 853 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 854 | break; |
| 855 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 856 | case CMD_NV_WRITE_ITEM: |
| 857 | request = (MainThreadRequest) msg.obj; |
| 858 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 859 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 860 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 861 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 862 | break; |
| 863 | |
| 864 | case EVENT_NV_WRITE_ITEM_DONE: |
| 865 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 866 | break; |
| 867 | |
| 868 | case CMD_NV_WRITE_CDMA_PRL: |
| 869 | request = (MainThreadRequest) msg.obj; |
| 870 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 871 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 875 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 876 | break; |
| 877 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 878 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 879 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 880 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 881 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 882 | break; |
| 883 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 884 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 885 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 886 | break; |
| 887 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 888 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 889 | request = (MainThreadRequest) msg.obj; |
| 890 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 891 | request); |
| 892 | Phone phone = getPhoneFromRequest(request); |
| 893 | if (phone != null) { |
| 894 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 895 | } else { |
| 896 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 897 | request.result = false; |
| 898 | notifyRequester(request); |
| 899 | } |
| 900 | break; |
| 901 | } |
| 902 | |
| 903 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 904 | ar = (AsyncResult) msg.obj; |
| 905 | request = (MainThreadRequest) ar.userObj; |
| 906 | if (ar.exception == null && ar.result != null) { |
| 907 | request.result = ar.result; |
| 908 | } else { |
| 909 | // request.result must be set to something non-null |
| 910 | // for the calling thread to unblock |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 911 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 912 | request.result = ar.result; |
| 913 | } else { |
| 914 | request.result = false; |
| 915 | } |
| 916 | if (ar.result == null) { |
| 917 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 918 | } else if (ar.exception instanceof CommandException) { |
| 919 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 920 | + ar.exception); |
| 921 | } else { |
| 922 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 923 | } |
| 924 | } |
| 925 | notifyRequester(request); |
| 926 | break; |
| 927 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 928 | case CMD_IS_VONR_ENABLED: { |
| 929 | request = (MainThreadRequest) msg.obj; |
| 930 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 931 | request); |
| 932 | Phone phone = getPhoneFromRequest(request); |
| 933 | if (phone != null) { |
| 934 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 935 | } else { |
| 936 | loge("isVoNrEnabled: No phone object"); |
| 937 | request.result = false; |
| 938 | notifyRequester(request); |
| 939 | } |
| 940 | break; |
| 941 | } |
| 942 | |
| 943 | case EVENT_IS_VONR_ENABLED_DONE: |
| 944 | ar = (AsyncResult) msg.obj; |
| 945 | request = (MainThreadRequest) ar.userObj; |
| 946 | if (ar.exception == null && ar.result != null) { |
| 947 | request.result = ar.result; |
| 948 | } else { |
| 949 | // request.result must be set to something non-null |
| 950 | // for the calling thread to unblock |
| 951 | if (ar.result != null) { |
| 952 | request.result = ar.result; |
| 953 | } else { |
| 954 | request.result = false; |
| 955 | } |
| 956 | if (ar.result == null) { |
| 957 | loge("isVoNrEnabled: Empty response"); |
| 958 | } else if (ar.exception instanceof CommandException) { |
| 959 | loge("isVoNrEnabled: CommandException: " |
| 960 | + ar.exception); |
| 961 | } else { |
| 962 | loge("isVoNrEnabled: Unknown exception"); |
| 963 | } |
| 964 | } |
| 965 | notifyRequester(request); |
| 966 | break; |
| 967 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 968 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 969 | request = (MainThreadRequest) msg.obj; |
| 970 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 971 | Phone phone = getPhoneFromRequest(request); |
| 972 | if (phone != null) { |
| 973 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 974 | request.workSource); |
| 975 | } else { |
| 976 | loge("enableNrDualConnectivity: No phone object"); |
| 977 | request.result = |
| 978 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 979 | notifyRequester(request); |
| 980 | } |
| 981 | break; |
| 982 | } |
| 983 | |
| 984 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 985 | ar = (AsyncResult) msg.obj; |
| 986 | request = (MainThreadRequest) ar.userObj; |
| 987 | if (ar.exception == null) { |
| 988 | request.result = |
| 989 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 990 | } else { |
| 991 | request.result = |
| 992 | TelephonyManager |
| 993 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 994 | if (ar.exception instanceof CommandException) { |
| 995 | CommandException.Error error = |
| 996 | ((CommandException) (ar.exception)).getCommandError(); |
| 997 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 998 | request.result = |
| 999 | TelephonyManager |
| 1000 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1001 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1002 | request.result = |
| 1003 | TelephonyManager |
| 1004 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1005 | } |
| 1006 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1007 | + ar.exception); |
| 1008 | } else { |
| 1009 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1010 | } |
| 1011 | } |
| 1012 | notifyRequester(request); |
| 1013 | break; |
| 1014 | } |
| 1015 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1016 | case CMD_ENABLE_VONR: { |
| 1017 | request = (MainThreadRequest) msg.obj; |
| 1018 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1019 | Phone phone = getPhoneFromRequest(request); |
| 1020 | if (phone != null) { |
| 1021 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1022 | request.workSource); |
| 1023 | } else { |
| 1024 | loge("setVoNrEnabled: No phone object"); |
| 1025 | request.result = |
| 1026 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1027 | notifyRequester(request); |
| 1028 | } |
| 1029 | break; |
| 1030 | } |
| 1031 | |
| 1032 | case EVENT_ENABLE_VONR_DONE: { |
| 1033 | ar = (AsyncResult) msg.obj; |
| 1034 | request = (MainThreadRequest) ar.userObj; |
| 1035 | if (ar.exception == null) { |
| 1036 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1037 | } else { |
| 1038 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1039 | if (ar.exception instanceof CommandException) { |
| 1040 | CommandException.Error error = |
| 1041 | ((CommandException) (ar.exception)).getCommandError(); |
| 1042 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1043 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1044 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1045 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1046 | } else { |
| 1047 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1048 | } |
| 1049 | loge("setVoNrEnabled" + ": CommandException: " |
| 1050 | + ar.exception); |
| 1051 | } else { |
| 1052 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1053 | } |
| 1054 | } |
| 1055 | notifyRequester(request); |
| 1056 | break; |
| 1057 | } |
| 1058 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1059 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1060 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1061 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1062 | request); |
| 1063 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1064 | break; |
| 1065 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1066 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
| 1069 | if (ar.exception == null && ar.result != null) { |
| 1070 | request.result = ar.result; // Integer |
| 1071 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1072 | // request.result must be set to something non-null |
| 1073 | // for the calling thread to unblock |
| 1074 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1075 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1076 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1077 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1078 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1079 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1080 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1081 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1084 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1085 | break; |
| 1086 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1087 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1088 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1089 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1090 | request); |
| 1091 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1092 | (Pair<Integer, Long>) request.argument; |
| 1093 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1094 | reasonWithNetworkTypes.first, |
| 1095 | reasonWithNetworkTypes.second, |
| 1096 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1097 | break; |
| 1098 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1099 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1100 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1101 | break; |
| 1102 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1103 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1104 | request = (MainThreadRequest)msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1106 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1107 | break; |
| 1108 | |
| 1109 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1110 | ar = (AsyncResult)msg.obj; |
| 1111 | request = (MainThreadRequest)ar.userObj; |
| 1112 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1113 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1114 | break; |
| 1115 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1116 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1117 | request = (MainThreadRequest) msg.obj; |
| 1118 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1119 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1120 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1121 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1122 | break; |
| 1123 | |
| 1124 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1125 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1126 | break; |
| 1127 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1128 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1129 | request = (MainThreadRequest) msg.obj; |
| 1130 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1131 | request); |
| 1132 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1133 | break; |
| 1134 | |
| 1135 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1136 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1137 | break; |
| 1138 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1139 | case CMD_PERFORM_NETWORK_SCAN: |
| 1140 | request = (MainThreadRequest) msg.obj; |
| 1141 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1142 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1143 | break; |
| 1144 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1145 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1146 | request = (MainThreadRequest) msg.obj; |
| 1147 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1148 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1149 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1150 | request.argument; |
| 1151 | int callForwardingReason = args.first; |
| 1152 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1153 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1154 | } |
| 1155 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1156 | ar = (AsyncResult) msg.obj; |
| 1157 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1158 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1159 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1160 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1161 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1162 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1163 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1164 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1165 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1166 | // any service for voice call. |
| 1167 | if ((callForwardInfo.serviceClass |
| 1168 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1169 | callForwardingInfo = new CallForwardingInfo( |
| 1170 | callForwardInfo.status |
| 1171 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1172 | callForwardInfo.reason, |
| 1173 | callForwardInfo.number, |
| 1174 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1175 | break; |
| 1176 | } |
| 1177 | } |
| 1178 | // Didn't find a call forward info for voice call. |
| 1179 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1180 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1181 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1182 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1183 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1184 | } else { |
| 1185 | if (ar.result == null) { |
| 1186 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1187 | } |
| 1188 | if (ar.exception != null) { |
| 1189 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1190 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1191 | int errorCode = TelephonyManager |
| 1192 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1193 | if (ar.exception instanceof CommandException) { |
| 1194 | CommandException.Error error = |
| 1195 | ((CommandException) (ar.exception)).getCommandError(); |
| 1196 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1197 | errorCode = TelephonyManager |
| 1198 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1199 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1200 | errorCode = TelephonyManager |
| 1201 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1202 | } |
| 1203 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1204 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1206 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1207 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1208 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1209 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1210 | request = (MainThreadRequest) msg.obj; |
| 1211 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1212 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1213 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1214 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1215 | request.argument).first; |
| 1216 | request.phone.setCallForwardingOption( |
| 1217 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1218 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1219 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1220 | callForwardingInfoToSet.getReason(), |
| 1221 | callForwardingInfoToSet.getNumber(), |
| 1222 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1223 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1224 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1225 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1226 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1227 | ar = (AsyncResult) msg.obj; |
| 1228 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1229 | Consumer<Integer> callback = |
| 1230 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1231 | request.argument).second; |
| 1232 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1233 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1234 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1235 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1236 | if (ar.exception instanceof CommandException) { |
| 1237 | CommandException.Error error = |
| 1238 | ((CommandException) (ar.exception)).getCommandError(); |
| 1239 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1240 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1241 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1242 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1243 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1244 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1245 | } |
| 1246 | } |
| 1247 | callback.accept(errorCode); |
| 1248 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1249 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1251 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1252 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1253 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1254 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1255 | request = (MainThreadRequest) msg.obj; |
| 1256 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1257 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1258 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1259 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1260 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1261 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1262 | ar = (AsyncResult) msg.obj; |
| 1263 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1264 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1265 | int callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1266 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1267 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1268 | // Service Class is a bit mask per 3gpp 27.007. |
| 1269 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1270 | if (callForwardResults.length > 1 |
| 1271 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1272 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1273 | callWaitingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1274 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1275 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1276 | } else { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1277 | callWaitingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1278 | } |
| 1279 | } else { |
| 1280 | if (ar.result == null) { |
| 1281 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1282 | } |
| 1283 | if (ar.exception != null) { |
| 1284 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1285 | } |
| 1286 | if (ar.exception instanceof CommandException) { |
| 1287 | CommandException.Error error = |
| 1288 | ((CommandException) (ar.exception)).getCommandError(); |
| 1289 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1290 | callWaitingStatus = |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1291 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1292 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1293 | callWaitingStatus = |
| 1294 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1298 | callback.accept(callWaitingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1300 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1301 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1302 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | request = (MainThreadRequest) msg.obj; |
| 1304 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1305 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1306 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1308 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1309 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1310 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1311 | ar = (AsyncResult) msg.obj; |
| 1312 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1313 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1314 | Consumer<Integer> callback = |
| 1315 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1316 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1317 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1318 | if (ar.exception instanceof CommandException) { |
| 1319 | CommandException.Error error = |
| 1320 | ((CommandException) (ar.exception)).getCommandError(); |
| 1321 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1322 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
SongFerngWang | ebda2c5 | 2022-01-11 15:28:38 +0800 | [diff] [blame] | 1323 | } else if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 1324 | callback.accept( |
| 1325 | TelephonyManager.CALL_WAITING_STATUS_FDN_CHECK_FAILURE); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1326 | } else { |
| 1327 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1328 | } |
| 1329 | } else { |
| 1330 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1331 | } |
| 1332 | } else { |
| 1333 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1334 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1335 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1336 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1337 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1338 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1339 | ar = (AsyncResult) msg.obj; |
| 1340 | request = (MainThreadRequest) ar.userObj; |
| 1341 | CellNetworkScanResult cellScanResult; |
| 1342 | if (ar.exception == null && ar.result != null) { |
| 1343 | cellScanResult = new CellNetworkScanResult( |
| 1344 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1345 | (List<OperatorInfo>) ar.result); |
| 1346 | } else { |
| 1347 | if (ar.result == null) { |
| 1348 | loge("getCellNetworkScanResults: Empty response"); |
| 1349 | } |
| 1350 | if (ar.exception != null) { |
| 1351 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1352 | } |
| 1353 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1354 | if (ar.exception instanceof CommandException) { |
| 1355 | CommandException.Error error = |
| 1356 | ((CommandException) (ar.exception)).getCommandError(); |
| 1357 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1358 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1359 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1360 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1361 | } |
| 1362 | } |
| 1363 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1364 | } |
| 1365 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1366 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1367 | break; |
| 1368 | |
| 1369 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1370 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1371 | ManualNetworkSelectionArgument selArg = |
| 1372 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1373 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1374 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1375 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1376 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1377 | break; |
| 1378 | |
| 1379 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
| 1382 | if (ar.exception == null) { |
| 1383 | request.result = true; |
| 1384 | } else { |
| 1385 | request.result = false; |
| 1386 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1387 | } |
| 1388 | notifyRequester(request); |
| 1389 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1390 | break; |
| 1391 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1392 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1393 | request = (MainThreadRequest) msg.obj; |
| 1394 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1395 | if (defaultPhone != null) { |
| 1396 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1397 | } else { |
| 1398 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1399 | Bundle bundle = new Bundle(); |
| 1400 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1401 | new ModemActivityInfo(0, 0, 0, |
| 1402 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1403 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1404 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1405 | break; |
| 1406 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1407 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1408 | ar = (AsyncResult) msg.obj; |
| 1409 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1410 | ResultReceiver result = (ResultReceiver) request.argument; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1411 | int error = 0; |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1412 | if (mLastModemActivityInfo == null) { |
| 1413 | mLastModemActivitySpecificInfo = new ActivityStatsTechSpecificInfo[1]; |
| 1414 | mLastModemActivitySpecificInfo[0] = |
| 1415 | new ActivityStatsTechSpecificInfo( |
| 1416 | 0, |
| 1417 | 0, |
| 1418 | new int[ModemActivityInfo.getNumTxPowerLevels()], |
| 1419 | 0); |
| 1420 | mLastModemActivityInfo = |
| 1421 | new ModemActivityInfo(0, 0, 0, mLastModemActivitySpecificInfo); |
| 1422 | } |
| 1423 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1424 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1425 | // Update the last modem activity info and the result of the request. |
| 1426 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1427 | if (isModemActivityInfoValid(info)) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1428 | mergeModemActivityInfo(info); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1429 | } |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1430 | mLastModemActivityInfo = |
| 1431 | new ModemActivityInfo( |
| 1432 | mLastModemActivityInfo.getTimestampMillis(), |
| 1433 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1434 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1435 | mLastModemActivitySpecificInfo); |
| 1436 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1437 | } else { |
| 1438 | if (ar.result == null) { |
| 1439 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1440 | error = TelephonyManager.ModemActivityInfoException |
| 1441 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1442 | } else if (ar.exception instanceof CommandException) { |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1443 | loge("queryModemActivityInfo: CommandException: " + ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1444 | error = TelephonyManager.ModemActivityInfoException |
| 1445 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1446 | } else { |
| 1447 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1448 | error = TelephonyManager.ModemActivityInfoException |
| 1449 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1450 | } |
| 1451 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1452 | Bundle bundle = new Bundle(); |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 1453 | if (mLastModemActivityInfo != null) { |
| 1454 | bundle.putParcelable( |
| 1455 | TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1456 | mLastModemActivityInfo); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1457 | } else { |
| 1458 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1459 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1460 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1461 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1462 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1463 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1464 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1465 | case CMD_SET_ALLOWED_CARRIERS: |
| 1466 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1467 | CarrierRestrictionRules argument = |
| 1468 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1469 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1470 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | |
| 1473 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1474 | ar = (AsyncResult) msg.obj; |
| 1475 | request = (MainThreadRequest) ar.userObj; |
| 1476 | if (ar.exception == null && ar.result != null) { |
| 1477 | request.result = ar.result; |
| 1478 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1479 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1480 | if (ar.exception instanceof CommandException) { |
| 1481 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1482 | CommandException.Error error = |
| 1483 | ((CommandException) (ar.exception)).getCommandError(); |
| 1484 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1485 | request.result = |
| 1486 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1487 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1488 | } else { |
| 1489 | loge("setAllowedCarriers: Unknown exception"); |
| 1490 | } |
| 1491 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1492 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1493 | break; |
| 1494 | |
| 1495 | case CMD_GET_ALLOWED_CARRIERS: |
| 1496 | request = (MainThreadRequest) msg.obj; |
| 1497 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1498 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1499 | break; |
| 1500 | |
| 1501 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1502 | ar = (AsyncResult) msg.obj; |
| 1503 | request = (MainThreadRequest) ar.userObj; |
| 1504 | if (ar.exception == null && ar.result != null) { |
| 1505 | request.result = ar.result; |
| 1506 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1507 | request.result = new IllegalStateException( |
| 1508 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1509 | if (ar.result == null) { |
| 1510 | loge("getAllowedCarriers: Empty response"); |
| 1511 | } else if (ar.exception instanceof CommandException) { |
| 1512 | loge("getAllowedCarriers: CommandException: " + |
| 1513 | ar.exception); |
| 1514 | } else { |
| 1515 | loge("getAllowedCarriers: Unknown exception"); |
| 1516 | } |
| 1517 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1518 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1519 | break; |
| 1520 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1521 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1522 | ar = (AsyncResult) msg.obj; |
| 1523 | request = (MainThreadRequest) ar.userObj; |
| 1524 | if (ar.exception == null && ar.result != null) { |
| 1525 | request.result = ar.result; |
| 1526 | } else { |
| 1527 | request.result = new IllegalArgumentException( |
| 1528 | "Failed to retrieve Forbidden Plmns"); |
| 1529 | if (ar.result == null) { |
| 1530 | loge("getForbiddenPlmns: Empty response"); |
| 1531 | } else { |
| 1532 | loge("getForbiddenPlmns: Unknown exception"); |
| 1533 | } |
| 1534 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1535 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1536 | break; |
| 1537 | |
| 1538 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1539 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1540 | uiccPort = getUiccPortFromRequest(request); |
| 1541 | if (uiccPort == null) { |
| 1542 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1543 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1544 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1545 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1546 | break; |
| 1547 | } |
| 1548 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1549 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1550 | if (uiccApp == null) { |
| 1551 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1552 | + appType); |
| 1553 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1554 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1555 | break; |
| 1556 | } else { |
| 1557 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1558 | + " specified type -- " + appType); |
| 1559 | } |
| 1560 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1561 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1562 | onCompleted); |
| 1563 | break; |
| 1564 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1565 | case CMD_SWITCH_SLOTS: |
| 1566 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1567 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1568 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1569 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1570 | break; |
| 1571 | |
| 1572 | case EVENT_SWITCH_SLOTS_DONE: |
| 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1576 | notifyRequester(request); |
| 1577 | break; |
| 1578 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1579 | request = (MainThreadRequest) msg.obj; |
| 1580 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1581 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1582 | break; |
| 1583 | |
| 1584 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1585 | ar = (AsyncResult) msg.obj; |
| 1586 | request = (MainThreadRequest) ar.userObj; |
| 1587 | if (ar.exception != null) { |
| 1588 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1589 | } else { |
| 1590 | int mode = ((int[]) ar.result)[0]; |
| 1591 | if (mode == 0) { |
| 1592 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1593 | } else { |
| 1594 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1595 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1596 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1597 | notifyRequester(request); |
| 1598 | break; |
| 1599 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1600 | request = (MainThreadRequest) msg.obj; |
| 1601 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1602 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1603 | break; |
| 1604 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1605 | ar = (AsyncResult) msg.obj; |
| 1606 | request = (MainThreadRequest) ar.userObj; |
| 1607 | if (ar.exception != null) { |
| 1608 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1609 | } else { |
| 1610 | request.result = ((int[]) ar.result)[0]; |
| 1611 | } |
| 1612 | notifyRequester(request); |
| 1613 | break; |
| 1614 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1615 | request = (MainThreadRequest) msg.obj; |
| 1616 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1617 | int mode = (int) request.argument; |
| 1618 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1619 | break; |
| 1620 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1621 | ar = (AsyncResult) msg.obj; |
| 1622 | request = (MainThreadRequest) ar.userObj; |
| 1623 | request.result = ar.exception == null; |
| 1624 | notifyRequester(request); |
| 1625 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1626 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1627 | request = (MainThreadRequest) msg.obj; |
| 1628 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1629 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1630 | break; |
| 1631 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1632 | ar = (AsyncResult) msg.obj; |
| 1633 | request = (MainThreadRequest) ar.userObj; |
| 1634 | if (ar.exception != null) { |
| 1635 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1636 | } else { |
| 1637 | request.result = ((int[]) ar.result)[0]; |
| 1638 | } |
| 1639 | notifyRequester(request); |
| 1640 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1641 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1642 | request = (MainThreadRequest) msg.obj; |
| 1643 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1644 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1645 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1646 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1647 | break; |
| 1648 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1649 | ar = (AsyncResult) msg.obj; |
| 1650 | request = (MainThreadRequest) ar.userObj; |
| 1651 | request.result = ar.exception == null; |
| 1652 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1653 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1654 | case CMD_GET_ALL_CELL_INFO: |
| 1655 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1656 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1657 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1658 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1659 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1660 | ar = (AsyncResult) msg.obj; |
| 1661 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1662 | // If a timeout occurs, the response will be null |
| 1663 | request.result = (ar.exception == null && ar.result != null) |
| 1664 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1665 | synchronized (request) { |
| 1666 | request.notifyAll(); |
| 1667 | } |
| 1668 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1669 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1670 | request = (MainThreadRequest) msg.obj; |
| 1671 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1672 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1673 | break; |
| 1674 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1675 | ar = (AsyncResult) msg.obj; |
| 1676 | request = (MainThreadRequest) ar.userObj; |
| 1677 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1678 | try { |
| 1679 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1680 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1681 | cb.onError( |
| 1682 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1683 | ar.exception.getClass().getName(), |
| 1684 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1685 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1686 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1687 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1688 | } else { |
| 1689 | // use the result as returned |
| 1690 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1691 | } |
| 1692 | } catch (RemoteException re) { |
| 1693 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1694 | } |
| 1695 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1696 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1697 | request = (MainThreadRequest) msg.obj; |
| 1698 | WorkSource ws = (WorkSource) request.argument; |
| 1699 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1700 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1701 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1702 | } |
| 1703 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1704 | ar = (AsyncResult) msg.obj; |
| 1705 | request = (MainThreadRequest) ar.userObj; |
| 1706 | if (ar.exception == null) { |
| 1707 | request.result = ar.result; |
| 1708 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1709 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1710 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1711 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | synchronized (request) { |
| 1715 | request.notifyAll(); |
| 1716 | } |
| 1717 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1718 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1719 | case CMD_MODEM_REBOOT: |
| 1720 | request = (MainThreadRequest) msg.obj; |
| 1721 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1722 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1723 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1724 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1725 | handleNullReturnEvent(msg, "rebootModem"); |
| 1726 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1727 | case CMD_REQUEST_ENABLE_MODEM: |
| 1728 | request = (MainThreadRequest) msg.obj; |
| 1729 | boolean enable = (boolean) request.argument; |
| 1730 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1731 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1732 | PhoneConfigurationManager.getInstance() |
| 1733 | .enablePhone(request.phone, enable, onCompleted); |
| 1734 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1735 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1736 | ar = (AsyncResult) msg.obj; |
| 1737 | request = (MainThreadRequest) ar.userObj; |
| 1738 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1739 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1740 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1741 | if ((boolean) request.result) { |
| 1742 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1743 | updateModemStateMetrics(); |
| 1744 | } else { |
| 1745 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1746 | + ar.exception); |
| 1747 | } |
| 1748 | notifyRequester(request); |
| 1749 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1750 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1751 | case CMD_GET_MODEM_STATUS: |
| 1752 | request = (MainThreadRequest) msg.obj; |
| 1753 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1754 | PhoneConfigurationManager.getInstance() |
| 1755 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1756 | break; |
| 1757 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1758 | ar = (AsyncResult) msg.obj; |
| 1759 | request = (MainThreadRequest) ar.userObj; |
| 1760 | int id = request.phone.getPhoneId(); |
| 1761 | if (ar.exception == null && ar.result != null) { |
| 1762 | request.result = ar.result; |
| 1763 | //update the cache as modem status has changed |
| 1764 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1765 | (boolean) request.result); |
| 1766 | } else { |
| 1767 | // Return true if modem status cannot be retrieved. For most cases, |
| 1768 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1769 | // and disable modem are not supported. Modem is always on. |
| 1770 | // TODO: this should be fixed in R to support a third |
| 1771 | // status UNKNOWN b/131631629 |
| 1772 | request.result = true; |
| 1773 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1774 | + ar.exception); |
| 1775 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1776 | notifyRequester(request); |
| 1777 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1778 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1779 | request = (MainThreadRequest) msg.obj; |
| 1780 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1781 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1782 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1783 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1784 | break; |
| 1785 | } |
| 1786 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1787 | ar = (AsyncResult) msg.obj; |
| 1788 | request = (MainThreadRequest) ar.userObj; |
| 1789 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1790 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1791 | args.second.accept(ar.exception == null); |
| 1792 | notifyRequester(request); |
| 1793 | break; |
| 1794 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1795 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1796 | request = (MainThreadRequest) msg.obj; |
| 1797 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1798 | Phone phone = getPhoneFromRequest(request); |
| 1799 | if (phone != null) { |
| 1800 | phone.getSystemSelectionChannels(onCompleted); |
| 1801 | } else { |
| 1802 | loge("getSystemSelectionChannels: No phone object"); |
| 1803 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1804 | notifyRequester(request); |
| 1805 | } |
| 1806 | break; |
| 1807 | } |
| 1808 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1809 | ar = (AsyncResult) msg.obj; |
| 1810 | request = (MainThreadRequest) ar.userObj; |
| 1811 | if (ar.exception == null && ar.result != null) { |
| 1812 | request.result = ar.result; |
| 1813 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1814 | request.result = new IllegalStateException( |
| 1815 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1816 | if (ar.result == null) { |
| 1817 | loge("getSystemSelectionChannels: Empty response"); |
| 1818 | } else { |
| 1819 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1820 | } |
| 1821 | } |
| 1822 | notifyRequester(request); |
| 1823 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1824 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1825 | ar = (AsyncResult) msg.obj; |
| 1826 | request = (MainThreadRequest) ar.userObj; |
| 1827 | if (ar.exception == null && ar.result != null) { |
| 1828 | request.result = ar.result; |
| 1829 | } else { |
| 1830 | request.result = -1; |
| 1831 | loge("Failed to set Forbidden Plmns"); |
| 1832 | if (ar.result == null) { |
| 1833 | loge("setForbidenPlmns: Empty response"); |
| 1834 | } else if (ar.exception != null) { |
| 1835 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1836 | request.result = -1; |
| 1837 | } else { |
| 1838 | loge("setForbiddenPlmns: Unknown exception"); |
| 1839 | } |
| 1840 | } |
| 1841 | notifyRequester(request); |
| 1842 | break; |
| 1843 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1844 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1845 | uiccPort = getUiccPortFromRequest(request); |
| 1846 | if (uiccPort == null) { |
| 1847 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1848 | request.result = -1; |
| 1849 | notifyRequester(request); |
| 1850 | break; |
| 1851 | } |
| 1852 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1853 | (Pair<Integer, List<String>>) request.argument; |
| 1854 | appType = setFplmnsArgs.first; |
| 1855 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1856 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1857 | if (uiccApp == null) { |
| 1858 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1859 | request.result = -1; |
| 1860 | loge("Failed to get UICC App"); |
| 1861 | notifyRequester(request); |
| 1862 | } else { |
| 1863 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1864 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1865 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1866 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1867 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1868 | case CMD_ERASE_MODEM_CONFIG: |
| 1869 | request = (MainThreadRequest) msg.obj; |
| 1870 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1871 | defaultPhone.eraseModemConfig(onCompleted); |
| 1872 | break; |
| 1873 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1874 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1875 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1876 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1877 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1878 | request = (MainThreadRequest) msg.obj; |
| 1879 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1880 | notifyRequester(request); |
| 1881 | break; |
| 1882 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1883 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1884 | request = (MainThreadRequest) msg.obj; |
| 1885 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1886 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1887 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1888 | changed.first, changed.second, onCompleted); |
| 1889 | break; |
| 1890 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1891 | ar = (AsyncResult) msg.obj; |
| 1892 | request = (MainThreadRequest) ar.userObj; |
| 1893 | if (ar.exception == null) { |
| 1894 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1895 | // If the operation is successful, update the PIN storage |
| 1896 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1897 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1898 | UiccController.getInstance().getPinStorage() |
| 1899 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1900 | } else { |
| 1901 | request.result = msg.arg1; |
| 1902 | } |
| 1903 | notifyRequester(request); |
| 1904 | break; |
| 1905 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1906 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1907 | request = (MainThreadRequest) msg.obj; |
| 1908 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1909 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1910 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1911 | enabled.first, enabled.second, onCompleted); |
| 1912 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1913 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1914 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1915 | ar = (AsyncResult) msg.obj; |
| 1916 | request = (MainThreadRequest) ar.userObj; |
| 1917 | if (ar.exception == null) { |
| 1918 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1919 | // If the operation is successful, update the PIN storage |
| 1920 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1921 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1922 | if (enabled.first) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1923 | UiccController.getInstance().getPinStorage() |
| 1924 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1925 | } else { |
| 1926 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1927 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1928 | } else { |
| 1929 | request.result = msg.arg1; |
| 1930 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1931 | |
| 1932 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1933 | notifyRequester(request); |
| 1934 | break; |
| 1935 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1936 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1937 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1938 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1939 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1940 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1941 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1942 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1943 | |
| 1944 | case CMD_SET_DATA_THROTTLING: { |
| 1945 | request = (MainThreadRequest) msg.obj; |
| 1946 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1947 | DataThrottlingRequest dataThrottlingRequest = |
| 1948 | (DataThrottlingRequest) request.argument; |
| 1949 | Phone phone = getPhoneFromRequest(request); |
| 1950 | if (phone != null) { |
| 1951 | phone.setDataThrottling(onCompleted, |
| 1952 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1953 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1954 | } else { |
| 1955 | loge("setDataThrottling: No phone object"); |
| 1956 | request.result = |
| 1957 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1958 | notifyRequester(request); |
| 1959 | } |
| 1960 | |
| 1961 | break; |
| 1962 | } |
| 1963 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1964 | ar = (AsyncResult) msg.obj; |
| 1965 | request = (MainThreadRequest) ar.userObj; |
| 1966 | |
| 1967 | if (ar.exception == null) { |
| 1968 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1969 | } else if (ar.exception instanceof CommandException) { |
| 1970 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1971 | CommandException.Error error = |
| 1972 | ((CommandException) (ar.exception)).getCommandError(); |
| 1973 | |
| 1974 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1975 | request.result = TelephonyManager |
| 1976 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1977 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1978 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1979 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1980 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1981 | } else { |
| 1982 | request.result = |
| 1983 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1984 | } |
| 1985 | } else { |
| 1986 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1987 | } |
| 1988 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1989 | notifyRequester(request); |
| 1990 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1991 | |
| 1992 | case CMD_SET_SIM_POWER: { |
| 1993 | request = (MainThreadRequest) msg.obj; |
| 1994 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1995 | request = (MainThreadRequest) msg.obj; |
| 1996 | int stateToSet = |
| 1997 | ((Pair<Integer, IIntegerConsumer>) |
| 1998 | request.argument).first; |
| 1999 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 2000 | break; |
| 2001 | } |
| 2002 | case EVENT_SET_SIM_POWER_DONE: { |
| 2003 | ar = (AsyncResult) msg.obj; |
| 2004 | request = (MainThreadRequest) ar.userObj; |
| 2005 | IIntegerConsumer callback = |
| 2006 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2007 | if (ar.exception != null) { |
| 2008 | loge("setSimPower exception: " + ar.exception); |
| 2009 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2010 | .RESULT_ERROR_UNKNOWN; |
| 2011 | if (ar.exception instanceof CommandException) { |
| 2012 | CommandException.Error error = |
| 2013 | ((CommandException) (ar.exception)).getCommandError(); |
| 2014 | if (error == CommandException.Error.SIM_ERR) { |
| 2015 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2016 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2017 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2018 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2019 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2020 | } else { |
| 2021 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2022 | } |
| 2023 | } |
| 2024 | try { |
| 2025 | callback.accept(errorCode); |
| 2026 | } catch (RemoteException e) { |
| 2027 | // Ignore if the remote process is no longer available to call back. |
| 2028 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2029 | } |
| 2030 | } else { |
| 2031 | try { |
| 2032 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2033 | } catch (RemoteException e) { |
| 2034 | // Ignore if the remote process is no longer available to call back. |
| 2035 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2036 | } |
| 2037 | } |
| 2038 | break; |
| 2039 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2040 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2041 | request = (MainThreadRequest) msg.obj; |
| 2042 | |
| 2043 | final Phone phone = getPhoneFromRequest(request); |
| 2044 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2045 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2046 | notifyRequester(request); |
| 2047 | break; |
| 2048 | } |
| 2049 | |
| 2050 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2051 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2052 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2053 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2054 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2055 | request.subId, pair.first /*callingUid*/, |
| 2056 | pair.second /*request*/, onCompleted); |
| 2057 | break; |
| 2058 | } |
| 2059 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2060 | ar = (AsyncResult) msg.obj; |
| 2061 | request = (MainThreadRequest) ar.userObj; |
| 2062 | // request.result will be the exception of ar if present, true otherwise. |
| 2063 | // Be cautious not to leave result null which will wait() forever |
| 2064 | request.result = ar.exception != null ? ar.exception : true; |
| 2065 | notifyRequester(request); |
| 2066 | break; |
| 2067 | } |
| 2068 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2069 | request = (MainThreadRequest) msg.obj; |
| 2070 | |
| 2071 | Phone phone = getPhoneFromRequest(request); |
| 2072 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2073 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2074 | notifyRequester(request); |
| 2075 | break; |
| 2076 | } |
| 2077 | |
| 2078 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2079 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2080 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2081 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2082 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2083 | request.subId, pair.first /*callingUid*/, |
| 2084 | pair.second /*request*/, onCompleted); |
| 2085 | break; |
| 2086 | } |
| 2087 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2088 | ar = (AsyncResult) msg.obj; |
| 2089 | request = (MainThreadRequest) ar.userObj; |
| 2090 | request.result = ar.exception != null ? ar.exception : true; |
| 2091 | notifyRequester(request); |
| 2092 | break; |
| 2093 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2094 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2095 | case CMD_GET_SLICING_CONFIG: { |
| 2096 | request = (MainThreadRequest) msg.obj; |
| 2097 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2098 | request.phone.getSlicingConfig(onCompleted); |
| 2099 | break; |
| 2100 | } |
| 2101 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2102 | ar = (AsyncResult) msg.obj; |
| 2103 | request = (MainThreadRequest) ar.userObj; |
| 2104 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2105 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2106 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2107 | Bundle bundle = new Bundle(); |
| 2108 | int resultCode = 0; |
| 2109 | if (ar.exception != null) { |
| 2110 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2111 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2112 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2113 | } else if (ar.result == null) { |
| 2114 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2115 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2116 | } else { |
| 2117 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2118 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2119 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2123 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2124 | } |
| 2125 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2126 | result.send(resultCode, bundle); |
| 2127 | notifyRequester(request); |
| 2128 | break; |
| 2129 | } |
| 2130 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2131 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2132 | request = (MainThreadRequest) msg.obj; |
| 2133 | request.result = |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 2134 | UiccController.getInstance().getPinStorage() |
| 2135 | .prepareUnattendedReboot(request.workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2136 | notifyRequester(request); |
| 2137 | break; |
| 2138 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2139 | default: |
| 2140 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2141 | break; |
| 2142 | } |
| 2143 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2144 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2145 | private void notifyRequester(MainThreadRequest request) { |
| 2146 | synchronized (request) { |
| 2147 | request.notifyAll(); |
| 2148 | } |
| 2149 | } |
| 2150 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2151 | private void handleNullReturnEvent(Message msg, String command) { |
| 2152 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2153 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2154 | if (ar.exception == null) { |
| 2155 | request.result = true; |
| 2156 | } else { |
| 2157 | request.result = false; |
| 2158 | if (ar.exception instanceof CommandException) { |
| 2159 | loge(command + ": CommandException: " + ar.exception); |
| 2160 | } else { |
| 2161 | loge(command + ": Unknown exception"); |
| 2162 | } |
| 2163 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2164 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | /** |
| 2169 | * Posts the specified command to be executed on the main thread, |
| 2170 | * waits for the request to complete, and returns the result. |
| 2171 | * @see #sendRequestAsync |
| 2172 | */ |
| 2173 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2174 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2175 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | /** |
| 2179 | * Posts the specified command to be executed on the main thread, |
| 2180 | * waits for the request to complete, and returns the result. |
| 2181 | * @see #sendRequestAsync |
| 2182 | */ |
| 2183 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2184 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2185 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | /** |
| 2189 | * Posts the specified command to be executed on the main thread, |
| 2190 | * waits for the request to complete, and returns the result. |
| 2191 | * @see #sendRequestAsync |
| 2192 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2193 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2194 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2195 | } |
| 2196 | |
| 2197 | /** |
| 2198 | * Posts the specified command to be executed on the main thread, |
| 2199 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2200 | * if not timeout or null otherwise. |
| 2201 | * @see #sendRequestAsync |
| 2202 | */ |
| 2203 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2204 | long timeoutInMs) { |
| 2205 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
| 2208 | /** |
| 2209 | * Posts the specified command to be executed on the main thread, |
| 2210 | * waits for the request to complete, and returns the result. |
| 2211 | * @see #sendRequestAsync |
| 2212 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2213 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2214 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | /** |
| 2218 | * Posts the specified command to be executed on the main thread, |
| 2219 | * waits for the request to complete, and returns the result. |
| 2220 | * @see #sendRequestAsync |
| 2221 | */ |
| 2222 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2223 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2224 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2228 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2229 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2230 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2231 | * @see #sendRequestAsync |
| 2232 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2233 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2234 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2236 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2237 | } |
| 2238 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2239 | MainThreadRequest request = null; |
| 2240 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2241 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2242 | } else if (phone != null) { |
| 2243 | request = new MainThreadRequest(argument, phone, workSource); |
| 2244 | } else { |
| 2245 | request = new MainThreadRequest(argument, subId, workSource); |
| 2246 | } |
| 2247 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2248 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2249 | msg.sendToTarget(); |
| 2250 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2251 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2252 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2253 | if (timeoutInMs >= 0) { |
| 2254 | // Wait for at least timeoutInMs before returning null request result |
| 2255 | long now = SystemClock.elapsedRealtime(); |
| 2256 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2257 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2258 | try { |
| 2259 | request.wait(deadline - now); |
| 2260 | } catch (InterruptedException e) { |
| 2261 | // Do nothing, go back and check if request is completed or timeout |
| 2262 | } finally { |
| 2263 | now = SystemClock.elapsedRealtime(); |
| 2264 | } |
| 2265 | } |
| 2266 | } else { |
| 2267 | // Wait for the request to complete |
| 2268 | while (request.result == null) { |
| 2269 | try { |
| 2270 | request.wait(); |
| 2271 | } catch (InterruptedException e) { |
| 2272 | // Do nothing, go back and wait until the request is complete |
| 2273 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | } |
| 2275 | } |
| 2276 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2277 | if (request.result == null) { |
| 2278 | Log.wtf(LOG_TAG, |
| 2279 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2280 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | return request.result; |
| 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2286 | * Posts the specified command to be executed on the main thread, and |
| 2287 | * returns immediately. |
| 2288 | * @see #sendRequest |
| 2289 | */ |
| 2290 | private void sendRequestAsync(int command) { |
| 2291 | mMainThreadHandler.sendEmptyMessage(command); |
| 2292 | } |
| 2293 | |
| 2294 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2295 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2296 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2297 | */ |
| 2298 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2299 | sendRequestAsync(command, argument, null, null); |
| 2300 | } |
| 2301 | |
| 2302 | /** |
| 2303 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2304 | * @see {@link #sendRequest(int,Object)} |
| 2305 | */ |
| 2306 | private void sendRequestAsync( |
| 2307 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2308 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2309 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2310 | msg.sendToTarget(); |
| 2311 | } |
| 2312 | |
| 2313 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2315 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2316 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2317 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | synchronized (PhoneInterfaceManager.class) { |
| 2319 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2320 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2321 | } else { |
| 2322 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2323 | } |
| 2324 | return sInstance; |
| 2325 | } |
| 2326 | } |
| 2327 | |
| 2328 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2329 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2331 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2332 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2333 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2334 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2335 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2337 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2338 | mTelephonySharedPreferences = |
| 2339 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2340 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2341 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2342 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2343 | mNotifyUserActivity = new AtomicBoolean(false); |
Tyler Gunn | 64144d9 | 2022-03-17 14:16:41 -0700 | [diff] [blame^] | 2344 | PropertyInvalidatedCache.invalidateCache(TelephonyManager.CACHE_KEY_PHONE_ACCOUNT_TO_SUBID); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2345 | publish(); |
| 2346 | } |
| 2347 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2348 | private Phone getDefaultPhone() { |
| 2349 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2350 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2351 | } |
| 2352 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | private void publish() { |
| 2354 | if (DBG) log("publish: " + this); |
| 2355 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2356 | TelephonyFrameworkInitializer |
| 2357 | .getTelephonyServiceManager() |
| 2358 | .getTelephonyServiceRegisterer() |
| 2359 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2362 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2363 | if (request.phone != null) { |
| 2364 | return request.phone; |
| 2365 | } else { |
| 2366 | return getPhoneFromSubId(request.subId); |
| 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | private Phone getPhoneFromSubId(int subId) { |
| 2371 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2372 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2375 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2376 | Phone phone = getPhoneFromRequest(request); |
| 2377 | return phone == null ? null : |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2378 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2379 | } |
| 2380 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2381 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2382 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2383 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2385 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2386 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2387 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2388 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2389 | } |
| 2390 | |
| 2391 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2392 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2393 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2394 | } |
| 2395 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2396 | private boolean isImsAvailableOnDevice() { |
| 2397 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2398 | if (pm == null) { |
| 2399 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2400 | // so do not throw error and allow. |
| 2401 | return true; |
| 2402 | } |
| 2403 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2404 | } |
| 2405 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2407 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2410 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | if (DBG) log("dial: " + number); |
| 2412 | // No permission check needed here: This is just a wrapper around the |
| 2413 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2414 | // the UI before it does anything. |
| 2415 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | final long identity = Binder.clearCallingIdentity(); |
| 2417 | try { |
| 2418 | String url = createTelUrl(number); |
| 2419 | if (url == null) { |
| 2420 | return; |
| 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2423 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2424 | PhoneConstants.State state = mCM.getState(subId); |
| 2425 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2426 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2427 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2428 | mApp.startActivity(intent); |
| 2429 | } |
| 2430 | } finally { |
| 2431 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2436 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2439 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | if (DBG) log("call: " + number); |
| 2441 | |
| 2442 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2443 | // need to do a permission check since we're calling startActivity() |
| 2444 | // from the context of the phone app. |
| 2445 | enforceCallPermission(); |
| 2446 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2447 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | != AppOpsManager.MODE_ALLOWED) { |
| 2449 | return; |
| 2450 | } |
| 2451 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 | final long identity = Binder.clearCallingIdentity(); |
| 2453 | try { |
| 2454 | String url = createTelUrl(number); |
| 2455 | if (url == null) { |
| 2456 | return; |
| 2457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | boolean isValid = false; |
| 2460 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2461 | if (slist != null) { |
| 2462 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2463 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2464 | isValid = true; |
| 2465 | break; |
| 2466 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2467 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2469 | if (!isValid) { |
| 2470 | return; |
| 2471 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2472 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2474 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2475 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2476 | mApp.startActivity(intent); |
| 2477 | } finally { |
| 2478 | Binder.restoreCallingIdentity(identity); |
| 2479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | } |
| 2481 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2482 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2483 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2484 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2485 | } |
| 2486 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2487 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2488 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2489 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2490 | } |
| 2491 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2492 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2494 | |
| 2495 | final long identity = Binder.clearCallingIdentity(); |
| 2496 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2497 | Phone phone = getPhone(subId); |
| 2498 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | checkSimPin.start(); |
| 2500 | return checkSimPin.unlockSim(null, pin); |
| 2501 | } finally { |
| 2502 | Binder.restoreCallingIdentity(identity); |
| 2503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2506 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2507 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2508 | |
| 2509 | final long identity = Binder.clearCallingIdentity(); |
| 2510 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2511 | Phone phone = getPhone(subId); |
| 2512 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2513 | checkSimPuk.start(); |
| 2514 | return checkSimPuk.unlockSim(puk, pin); |
| 2515 | } finally { |
| 2516 | Binder.restoreCallingIdentity(identity); |
| 2517 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2521 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | * a synchronous one. |
| 2523 | */ |
| 2524 | private static class UnlockSim extends Thread { |
| 2525 | |
| 2526 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2527 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2528 | |
| 2529 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2530 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2531 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | |
| 2533 | // For replies from SimCard interface |
| 2534 | private Handler mHandler; |
| 2535 | |
| 2536 | // For async handler to identify request type |
| 2537 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2538 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2539 | UnlockSim(int phoneId, IccCard simCard) { |
| 2540 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | mSimCard = simCard; |
| 2542 | } |
| 2543 | |
| 2544 | @Override |
| 2545 | public void run() { |
| 2546 | Looper.prepare(); |
| 2547 | synchronized (UnlockSim.this) { |
| 2548 | mHandler = new Handler() { |
| 2549 | @Override |
| 2550 | public void handleMessage(Message msg) { |
| 2551 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2552 | switch (msg.what) { |
| 2553 | case SUPPLY_PIN_COMPLETE: |
| 2554 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2555 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2556 | mRetryCount = msg.arg1; |
| 2557 | if (ar.exception != null) { |
| 2558 | if (ar.exception instanceof CommandException && |
| 2559 | ((CommandException)(ar.exception)).getCommandError() |
| 2560 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2561 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2562 | } //When UiccCardApp dispose,handle message and return exception |
| 2563 | else if (ar.exception instanceof CommandException && |
| 2564 | ((CommandException) (ar.exception)).getCommandError() |
| 2565 | == CommandException.Error.ABORTED) { |
| 2566 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2567 | } else { |
| 2568 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2569 | } |
| 2570 | } else { |
| 2571 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2572 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2573 | mDone = true; |
| 2574 | UnlockSim.this.notifyAll(); |
| 2575 | } |
| 2576 | break; |
| 2577 | } |
| 2578 | } |
| 2579 | }; |
| 2580 | UnlockSim.this.notifyAll(); |
| 2581 | } |
| 2582 | Looper.loop(); |
| 2583 | } |
| 2584 | |
| 2585 | /* |
| 2586 | * Use PIN or PUK to unlock SIM card |
| 2587 | * |
| 2588 | * If PUK is null, unlock SIM card with PIN |
| 2589 | * |
| 2590 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2591 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2592 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2593 | |
| 2594 | while (mHandler == null) { |
| 2595 | try { |
| 2596 | wait(); |
| 2597 | } catch (InterruptedException e) { |
| 2598 | Thread.currentThread().interrupt(); |
| 2599 | } |
| 2600 | } |
| 2601 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2602 | |
| 2603 | if (puk == null) { |
| 2604 | mSimCard.supplyPin(pin, callback); |
| 2605 | } else { |
| 2606 | mSimCard.supplyPuk(puk, pin, callback); |
| 2607 | } |
| 2608 | |
| 2609 | while (!mDone) { |
| 2610 | try { |
| 2611 | Log.d(LOG_TAG, "wait for done"); |
| 2612 | wait(); |
| 2613 | } catch (InterruptedException e) { |
| 2614 | // Restore the interrupted status |
| 2615 | Thread.currentThread().interrupt(); |
| 2616 | } |
| 2617 | } |
| 2618 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2619 | int[] resultArray = new int[2]; |
| 2620 | resultArray[0] = mResult; |
| 2621 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2622 | |
| 2623 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | 9c3bc76 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2624 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2627 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2631 | /** |
| 2632 | * This method has been removed due to privacy and stability concerns. |
| 2633 | */ |
| 2634 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2635 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2636 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2637 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2640 | @Override |
| 2641 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2642 | mApp.getSystemService(AppOpsManager.class) |
| 2643 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2644 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2645 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2646 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2647 | // Callers targeting S have no business invoking this method. |
| 2648 | return; |
| 2649 | } |
| 2650 | |
| 2651 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2652 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2653 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2654 | .setCallingPackage(callingPackage) |
| 2655 | .setCallingFeatureId(null) |
| 2656 | .setCallingPid(Binder.getCallingPid()) |
| 2657 | .setCallingUid(Binder.getCallingUid()) |
| 2658 | .setMethod("updateServiceLocation") |
| 2659 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2660 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2661 | .build()); |
| 2662 | // Apps that lack location permission have no business calling this method; |
| 2663 | // however, because no permission was declared in the public API, denials must |
| 2664 | // all be "soft". |
| 2665 | switch (locationResult) { |
| 2666 | case DENIED_HARD: /* fall through */ |
| 2667 | case DENIED_SOFT: |
| 2668 | return; |
| 2669 | } |
| 2670 | |
| 2671 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | final long identity = Binder.clearCallingIdentity(); |
| 2673 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2674 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2676 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | } |
| 2678 | } finally { |
| 2679 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2680 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2683 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2684 | @Override |
| 2685 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2686 | return isRadioOnWithFeature(callingPackage, null); |
| 2687 | } |
| 2688 | |
| 2689 | |
| 2690 | @Override |
| 2691 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2692 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2693 | callingFeatureId); |
| 2694 | } |
| 2695 | |
| 2696 | @Deprecated |
| 2697 | @Override |
| 2698 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2699 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2702 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2703 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2704 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2706 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2707 | return false; |
| 2708 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2709 | |
| 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
| 2712 | return isRadioOnForSubscriber(subId); |
| 2713 | } finally { |
| 2714 | Binder.restoreCallingIdentity(identity); |
| 2715 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2719 | final long identity = Binder.clearCallingIdentity(); |
| 2720 | try { |
| 2721 | final Phone phone = getPhone(subId); |
| 2722 | if (phone != null) { |
| 2723 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2724 | } else { |
| 2725 | return false; |
| 2726 | } |
| 2727 | } finally { |
| 2728 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2729 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2733 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2735 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2736 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | |
| 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
| 2741 | final Phone phone = getPhone(subId); |
| 2742 | if (phone != null) { |
| 2743 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2744 | } |
| 2745 | } finally { |
| 2746 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2747 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2751 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2754 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2755 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | |
| 2757 | final long identity = Binder.clearCallingIdentity(); |
| 2758 | try { |
| 2759 | final Phone phone = getPhone(subId); |
| 2760 | if (phone == null) { |
| 2761 | return false; |
| 2762 | } |
| 2763 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2764 | toggleRadioOnOffForSubscriber(subId); |
| 2765 | } |
| 2766 | return true; |
| 2767 | } finally { |
| 2768 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2769 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2771 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2772 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2773 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2774 | /* |
| 2775 | * If any of the Radios are available, it will need to be |
| 2776 | * shutdown. So return true if any Radio is available. |
| 2777 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2778 | final long identity = Binder.clearCallingIdentity(); |
| 2779 | try { |
| 2780 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2781 | Phone phone = PhoneFactory.getPhone(i); |
| 2782 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2783 | } |
| 2784 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2785 | return false; |
| 2786 | } finally { |
| 2787 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2788 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2791 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2792 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2793 | enforceModifyPermission(); |
| 2794 | |
| 2795 | final long identity = Binder.clearCallingIdentity(); |
| 2796 | try { |
| 2797 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2798 | logv("Shutting down Phone " + i); |
| 2799 | shutdownRadioUsingPhoneId(i); |
| 2800 | } |
| 2801 | } finally { |
| 2802 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2807 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2808 | if (phone != null && phone.isRadioAvailable()) { |
| 2809 | phone.shutdownRadio(); |
| 2810 | } |
| 2811 | } |
| 2812 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2814 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2815 | |
| 2816 | final long identity = Binder.clearCallingIdentity(); |
| 2817 | try { |
| 2818 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2819 | if (defaultPhone != null) { |
| 2820 | defaultPhone.setRadioPower(turnOn); |
| 2821 | return true; |
| 2822 | } else { |
| 2823 | loge("There's no default phone."); |
| 2824 | return false; |
| 2825 | } |
| 2826 | } finally { |
| 2827 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2828 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2829 | } |
| 2830 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2831 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2832 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2833 | |
| 2834 | final long identity = Binder.clearCallingIdentity(); |
| 2835 | try { |
| 2836 | final Phone phone = getPhone(subId); |
| 2837 | if (phone != null) { |
| 2838 | phone.setRadioPower(turnOn); |
| 2839 | return true; |
| 2840 | } else { |
| 2841 | return false; |
| 2842 | } |
| 2843 | } finally { |
| 2844 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2845 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2848 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2849 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | public boolean enableDataConnectivity() { |
| 2851 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2856 | final Phone phone = getPhone(subId); |
| 2857 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2858 | if (phone.isUsingNewDataStack()) { |
| 2859 | phone.getDataSettingsManager().setDataEnabled( |
| 2860 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2861 | } else { |
| 2862 | phone.getDataEnabledSettings().setDataEnabled( |
| 2863 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | return true; |
| 2866 | } else { |
| 2867 | return false; |
| 2868 | } |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2874 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2875 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2876 | public boolean disableDataConnectivity() { |
| 2877 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | |
| 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2882 | final Phone phone = getPhone(subId); |
| 2883 | if (phone != null) { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2884 | if (phone.isUsingNewDataStack()) { |
| 2885 | phone.getDataSettingsManager().setDataEnabled( |
| 2886 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2887 | } else { |
| 2888 | phone.getDataEnabledSettings().setDataEnabled( |
| 2889 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2890 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2891 | return true; |
| 2892 | } else { |
| 2893 | return false; |
| 2894 | } |
| 2895 | } finally { |
| 2896 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2897 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2898 | } |
| 2899 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2900 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2901 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2902 | final long identity = Binder.clearCallingIdentity(); |
| 2903 | try { |
| 2904 | final Phone phone = getPhone(subId); |
| 2905 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2906 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2907 | } else { |
| 2908 | return false; |
| 2909 | } |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2912 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2916 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2917 | } |
| 2918 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2919 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2920 | enforceCallPermission(); |
| 2921 | |
| 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2925 | return; |
| 2926 | } |
| 2927 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2928 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2929 | } finally { |
| 2930 | Binder.restoreCallingIdentity(identity); |
| 2931 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2932 | }; |
| 2933 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2934 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2935 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | |
| 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2940 | return false; |
| 2941 | } |
| 2942 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2945 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2946 | } |
| 2947 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2948 | /** |
| 2949 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2950 | * tag on getCallState Binder call. |
| 2951 | */ |
| 2952 | @Deprecated |
| 2953 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2954 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2955 | if (CompatChanges.isChangeEnabled( |
| 2956 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2957 | Binder.getCallingUid())) { |
| 2958 | // Do not allow this API to be called on API version 31+, it should only be |
| 2959 | // called on old apps using this Binder call directly. |
| 2960 | throw new SecurityException("This method can only be used for applications " |
| 2961 | + "targeting API version 30 or less."); |
| 2962 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2963 | final long identity = Binder.clearCallingIdentity(); |
| 2964 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2965 | Phone phone = getPhone(getDefaultSubscription()); |
| 2966 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2967 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2968 | } finally { |
| 2969 | Binder.restoreCallingIdentity(identity); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | @Override |
| 2974 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2975 | if (CompatChanges.isChangeEnabled( |
| 2976 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2977 | Binder.getCallingUid())) { |
| 2978 | // Check READ_PHONE_STATE for API version 31+ |
| 2979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2980 | featureId, "getCallStateForSubscription")) { |
| 2981 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2982 | + "targeting API level 31+."); |
| 2983 | } |
| 2984 | } |
| 2985 | final long identity = Binder.clearCallingIdentity(); |
| 2986 | try { |
| 2987 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2989 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2990 | } finally { |
| 2991 | Binder.restoreCallingIdentity(identity); |
| 2992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2993 | } |
| 2994 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2995 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2996 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2997 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2998 | } |
| 2999 | |
| 3000 | @Override |
| 3001 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3004 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3005 | if (phone != null) { |
Jack Yu | 2c45095 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3006 | if (phone.isUsingNewDataStack()) { |
| 3007 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3010 | } else { |
| 3011 | return PhoneConstantConversions.convertDataState( |
| 3012 | PhoneConstants.DataState.DISCONNECTED); |
| 3013 | } |
| 3014 | } finally { |
| 3015 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3016 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3017 | } |
| 3018 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3019 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3020 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3021 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3022 | } |
| 3023 | |
| 3024 | @Override |
| 3025 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | final long identity = Binder.clearCallingIdentity(); |
| 3027 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3028 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | if (phone != null) { |
| 3030 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 3031 | } else { |
| 3032 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3033 | } |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3036 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3040 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3041 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3042 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3043 | |
| 3044 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3045 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3046 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3047 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3048 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3049 | .setCallingPid(Binder.getCallingPid()) |
| 3050 | .setCallingUid(Binder.getCallingUid()) |
| 3051 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3052 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3053 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3054 | .build()); |
| 3055 | switch (locationResult) { |
| 3056 | case DENIED_HARD: |
| 3057 | throw new SecurityException("Not allowed to access cell location"); |
| 3058 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3059 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3060 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3063 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3064 | final long identity = Binder.clearCallingIdentity(); |
| 3065 | try { |
| 3066 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3067 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3068 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3072 | } |
| 3073 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3074 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3075 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3076 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3077 | // registered cell info, so return a NULL country instead. |
| 3078 | final long identity = Binder.clearCallingIdentity(); |
| 3079 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3080 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3081 | // Get default phone in this case. |
| 3082 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3083 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3084 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3085 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3086 | if (phone == null) return ""; |
| 3087 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3088 | if (sst == null) return ""; |
| 3089 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3090 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3091 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3095 | } |
| 3096 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3097 | /** |
| 3098 | * This method was removed due to potential issues caused by performing partial |
| 3099 | * updates of service state, and lack of a credible use case. |
| 3100 | * |
| 3101 | * This has the ability to break the telephony implementation by disabling notification of |
| 3102 | * changes in device connectivity. DO NOT USE THIS! |
| 3103 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3104 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3105 | public void enableLocationUpdates() { |
| 3106 | mApp.enforceCallingOrSelfPermission( |
| 3107 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3110 | /** |
| 3111 | * This method was removed due to potential issues caused by performing partial |
| 3112 | * updates of service state, and lack of a credible use case. |
| 3113 | * |
| 3114 | * This has the ability to break the telephony implementation by disabling notification of |
| 3115 | * changes in device connectivity. DO NOT USE THIS! |
| 3116 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3117 | @Override |
| 3118 | public void disableLocationUpdates() { |
| 3119 | mApp.enforceCallingOrSelfPermission( |
| 3120 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | @Override |
| 3124 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3125 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3126 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3127 | try { |
| 3128 | mApp.getSystemService(AppOpsManager.class) |
| 3129 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3130 | } catch (SecurityException e) { |
| 3131 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3132 | throw e; |
| 3133 | } |
| 3134 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3135 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3136 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3137 | throw new SecurityException( |
| 3138 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3139 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3140 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3141 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3142 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3143 | return null; |
| 3144 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3145 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3146 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3147 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3148 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3149 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3151 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3152 | for (CellInfo ci : info) { |
| 3153 | if (ci instanceof CellInfoGsm) { |
| 3154 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3155 | } else if (ci instanceof CellInfoWcdma) { |
| 3156 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3157 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3158 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3159 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3162 | private List<CellInfo> getCachedCellInfo() { |
| 3163 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3164 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3165 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3166 | if (info != null) cellInfos.addAll(info); |
| 3167 | } |
| 3168 | return cellInfos; |
| 3169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3170 | |
| 3171 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3172 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3173 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3174 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3175 | |
| 3176 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3177 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3178 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3179 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3180 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3181 | .setCallingPid(Binder.getCallingPid()) |
| 3182 | .setCallingUid(Binder.getCallingUid()) |
| 3183 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3184 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3185 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3186 | .build()); |
| 3187 | switch (locationResult) { |
| 3188 | case DENIED_HARD: |
| 3189 | throw new SecurityException("Not allowed to access cell info"); |
| 3190 | case DENIED_SOFT: |
| 3191 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3194 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3195 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3196 | return getCachedCellInfo(); |
| 3197 | } |
| 3198 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3199 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3200 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | final long identity = Binder.clearCallingIdentity(); |
| 3202 | try { |
| 3203 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3204 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3205 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3206 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3207 | if (info != null) cellInfos.addAll(info); |
| 3208 | } |
| 3209 | return cellInfos; |
| 3210 | } finally { |
| 3211 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3212 | } |
| 3213 | } |
| 3214 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3215 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3216 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3217 | String callingFeatureId) { |
| 3218 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3219 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3223 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3224 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3225 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3226 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3229 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3230 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3231 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3232 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3233 | |
| 3234 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3235 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3236 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3237 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3238 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3239 | .setCallingPid(Binder.getCallingPid()) |
| 3240 | .setCallingUid(Binder.getCallingUid()) |
| 3241 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3242 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3243 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3244 | .build()); |
| 3245 | switch (locationResult) { |
| 3246 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3247 | if (TelephonyPermissions |
| 3248 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3249 | // Safetynet logging for b/154934934 |
| 3250 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3251 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3252 | throw new SecurityException("Not allowed to access cell info"); |
| 3253 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3254 | if (TelephonyPermissions |
| 3255 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3256 | // Safetynet logging for b/154934934 |
| 3257 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3258 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3259 | try { |
| 3260 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3261 | } catch (RemoteException re) { |
| 3262 | // Drop without consequences |
| 3263 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3264 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3265 | } |
| 3266 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3267 | |
| 3268 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3269 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3270 | |
| 3271 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3272 | } |
| 3273 | |
| 3274 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3275 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3276 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3277 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3278 | |
| 3279 | final long identity = Binder.clearCallingIdentity(); |
| 3280 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3281 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
| 3284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3288 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3289 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3290 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3291 | return null; |
| 3292 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3293 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3294 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3295 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3296 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3297 | return null; |
| 3298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3299 | |
| 3300 | final long identity = Binder.clearCallingIdentity(); |
| 3301 | try { |
| 3302 | return phone.getImei(); |
| 3303 | } finally { |
| 3304 | Binder.restoreCallingIdentity(identity); |
| 3305 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3309 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3310 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3311 | String tac = null; |
| 3312 | if (phone != null) { |
| 3313 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3314 | try { |
| 3315 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3316 | } catch (IndexOutOfBoundsException e) { |
| 3317 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3318 | return null; |
| 3319 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3320 | } |
| 3321 | return tac; |
| 3322 | } |
| 3323 | |
| 3324 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3325 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3326 | try { |
| 3327 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3328 | } catch (SecurityException se) { |
| 3329 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3330 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3331 | + Binder.getCallingUid()); |
| 3332 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3333 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3334 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3335 | return null; |
| 3336 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3337 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3338 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3339 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3340 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3341 | return null; |
| 3342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | |
| 3344 | final long identity = Binder.clearCallingIdentity(); |
| 3345 | try { |
| 3346 | return phone.getMeid(); |
| 3347 | } finally { |
| 3348 | Binder.restoreCallingIdentity(identity); |
| 3349 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3353 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3354 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3355 | String manufacturerCode = null; |
| 3356 | if (phone != null) { |
| 3357 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3358 | try { |
| 3359 | manufacturerCode = |
| 3360 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3361 | } catch (IndexOutOfBoundsException e) { |
| 3362 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3363 | return null; |
| 3364 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3365 | } |
| 3366 | return manufacturerCode; |
| 3367 | } |
| 3368 | |
| 3369 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3370 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3371 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3372 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3373 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3374 | return null; |
| 3375 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3376 | int subId = phone.getSubId(); |
| 3377 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3378 | mApp, subId, callingPackage, callingFeatureId, |
| 3379 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3380 | return null; |
| 3381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3382 | |
| 3383 | final long identity = Binder.clearCallingIdentity(); |
| 3384 | try { |
| 3385 | return phone.getDeviceSvn(); |
| 3386 | } finally { |
| 3387 | Binder.restoreCallingIdentity(identity); |
| 3388 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3389 | } |
| 3390 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3391 | @Override |
| 3392 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
| 3395 | final Phone phone = getPhone(subId); |
| 3396 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3397 | } finally { |
| 3398 | Binder.restoreCallingIdentity(identity); |
| 3399 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | @Override |
| 3403 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3404 | final long identity = Binder.clearCallingIdentity(); |
| 3405 | try { |
| 3406 | final Phone phone = getPhone(subId); |
| 3407 | return phone == null ? null : phone.getCarrierName(); |
| 3408 | } finally { |
| 3409 | Binder.restoreCallingIdentity(identity); |
| 3410 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3411 | } |
| 3412 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3413 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3414 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3415 | final long identity = Binder.clearCallingIdentity(); |
| 3416 | try { |
| 3417 | final Phone phone = getPhone(subId); |
| 3418 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3419 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3420 | } finally { |
| 3421 | Binder.restoreCallingIdentity(identity); |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3426 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3427 | final long identity = Binder.clearCallingIdentity(); |
| 3428 | try { |
| 3429 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3430 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3431 | } finally { |
| 3432 | Binder.restoreCallingIdentity(identity); |
| 3433 | } |
| 3434 | } |
| 3435 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3436 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3437 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3438 | if (!isSubscriptionMccMnc) { |
| 3439 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3440 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3441 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3442 | if (phone == null) { |
| 3443 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3444 | } |
| 3445 | final long identity = Binder.clearCallingIdentity(); |
| 3446 | try { |
| 3447 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3448 | } finally { |
| 3449 | Binder.restoreCallingIdentity(identity); |
| 3450 | } |
| 3451 | } |
| 3452 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3453 | // |
| 3454 | // Internal helper methods. |
| 3455 | // |
| 3456 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3457 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3458 | * Make sure the caller is the calling package itself |
| 3459 | * |
| 3460 | * @throws SecurityException if the caller is not the calling package |
| 3461 | */ |
| 3462 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3463 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3464 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3465 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3466 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3467 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3468 | } catch (PackageManager.NameNotFoundException e) { |
| 3469 | // packageUid is -1 |
| 3470 | } |
| 3471 | if (packageUid != callingUid) { |
| 3472 | throw new SecurityException(message + ": Package " + callingPackage |
| 3473 | + " does not belong to " + callingUid); |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3478 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3479 | * |
| 3480 | * @throws SecurityException if the caller does not have the required permission |
| 3481 | */ |
| 3482 | private void enforceModifyPermission() { |
| 3483 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3484 | } |
| 3485 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3486 | private void enforceActiveEmergencySessionPermission() { |
| 3487 | mApp.enforceCallingOrSelfPermission( |
| 3488 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3489 | } |
| 3490 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3491 | /** |
| 3492 | * Make sure the caller has the CALL_PHONE permission. |
| 3493 | * |
| 3494 | * @throws SecurityException if the caller does not have the required permission |
| 3495 | */ |
| 3496 | private void enforceCallPermission() { |
| 3497 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3498 | } |
| 3499 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3500 | private void enforceSettingsPermission() { |
| 3501 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3504 | private void enforceRebootPermission() { |
| 3505 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3506 | } |
| 3507 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3508 | private String createTelUrl(String number) { |
| 3509 | if (TextUtils.isEmpty(number)) { |
| 3510 | return null; |
| 3511 | } |
| 3512 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3513 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3514 | } |
| 3515 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3516 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3517 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3518 | } |
| 3519 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3520 | private static void logv(String msg) { |
| 3521 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3522 | } |
| 3523 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3524 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3525 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3526 | } |
| 3527 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3528 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3529 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3530 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3531 | } |
| 3532 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3533 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3534 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3538 | if (phone == null) { |
| 3539 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3540 | } else { |
| 3541 | return phone.getPhoneType(); |
| 3542 | } |
| 3543 | } finally { |
| 3544 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3545 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | /** |
| 3549 | * Returns the CDMA ERI icon index to display |
| 3550 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3551 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3552 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3553 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3554 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3557 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3558 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3559 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3561 | mApp, subId, callingPackage, callingFeatureId, |
| 3562 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3563 | return -1; |
| 3564 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3565 | |
| 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
| 3568 | final Phone phone = getPhone(subId); |
| 3569 | if (phone != null) { |
| 3570 | return phone.getCdmaEriIconIndex(); |
| 3571 | } else { |
| 3572 | return -1; |
| 3573 | } |
| 3574 | } finally { |
| 3575 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3577 | } |
| 3578 | |
| 3579 | /** |
| 3580 | * Returns the CDMA ERI icon mode, |
| 3581 | * 0 - ON |
| 3582 | * 1 - FLASHING |
| 3583 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3585 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3586 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3587 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3588 | } |
| 3589 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3590 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3591 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3592 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3593 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3594 | mApp, subId, callingPackage, callingFeatureId, |
| 3595 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3596 | return -1; |
| 3597 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3598 | |
| 3599 | final long identity = Binder.clearCallingIdentity(); |
| 3600 | try { |
| 3601 | final Phone phone = getPhone(subId); |
| 3602 | if (phone != null) { |
| 3603 | return phone.getCdmaEriIconMode(); |
| 3604 | } else { |
| 3605 | return -1; |
| 3606 | } |
| 3607 | } finally { |
| 3608 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | /** |
| 3613 | * Returns the CDMA ERI text, |
| 3614 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3615 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3616 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3617 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3618 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3621 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3622 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3623 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3624 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3625 | mApp, subId, callingPackage, callingFeatureId, |
| 3626 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3627 | return null; |
| 3628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3629 | |
| 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
| 3632 | final Phone phone = getPhone(subId); |
| 3633 | if (phone != null) { |
| 3634 | return phone.getCdmaEriText(); |
| 3635 | } else { |
| 3636 | return null; |
| 3637 | } |
| 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3640 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3644 | * Returns the CDMA MDN. |
| 3645 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3646 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3647 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3648 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3649 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3650 | |
| 3651 | final long identity = Binder.clearCallingIdentity(); |
| 3652 | try { |
| 3653 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3654 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3655 | return phone.getLine1Number(); |
| 3656 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3657 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | return null; |
| 3659 | } |
| 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | |
| 3665 | /** |
| 3666 | * Returns the CDMA MIN. |
| 3667 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3668 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3669 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3671 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3672 | |
| 3673 | final long identity = Binder.clearCallingIdentity(); |
| 3674 | try { |
| 3675 | final Phone phone = getPhone(subId); |
| 3676 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3677 | return phone.getCdmaMin(); |
| 3678 | } else { |
| 3679 | return null; |
| 3680 | } |
| 3681 | } finally { |
| 3682 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3686 | @Override |
| 3687 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3688 | INumberVerificationCallback callback, String callingPackage) { |
| 3689 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3690 | != PERMISSION_GRANTED) { |
| 3691 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3692 | } |
| 3693 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3694 | |
| 3695 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3696 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3697 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3698 | + "calling package: " + callingPackage |
| 3699 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | if (range == null) { |
| 3703 | throw new NullPointerException("Range must be non-null"); |
| 3704 | } |
| 3705 | |
| 3706 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3707 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3708 | |
| 3709 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3710 | } |
| 3711 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3712 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3713 | * Returns true if CDMA provisioning needs to run. |
| 3714 | */ |
| 3715 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3716 | final long identity = Binder.clearCallingIdentity(); |
| 3717 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3718 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3719 | } finally { |
| 3720 | Binder.restoreCallingIdentity(identity); |
| 3721 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3725 | * Sets the voice mail number of a given subId. |
| 3726 | */ |
| 3727 | @Override |
| 3728 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3729 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3730 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3731 | |
| 3732 | final long identity = Binder.clearCallingIdentity(); |
| 3733 | try { |
| 3734 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3735 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3736 | return success; |
| 3737 | } finally { |
| 3738 | Binder.restoreCallingIdentity(identity); |
| 3739 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3740 | } |
| 3741 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3742 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3743 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3744 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3745 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3746 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3747 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3748 | throw new SecurityException("caller must be system dialer"); |
| 3749 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3750 | |
| 3751 | final long identity = Binder.clearCallingIdentity(); |
| 3752 | try { |
| 3753 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3754 | if (phoneAccountHandle == null) { |
| 3755 | return null; |
| 3756 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3757 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3758 | } finally { |
| 3759 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3760 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3764 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3765 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3766 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3768 | mApp, subId, callingPackage, callingFeatureId, |
| 3769 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3770 | return null; |
| 3771 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3772 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3773 | final long identity = Binder.clearCallingIdentity(); |
| 3774 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3775 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3776 | } finally { |
| 3777 | Binder.restoreCallingIdentity(identity); |
| 3778 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3782 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3783 | VisualVoicemailSmsFilterSettings settings) { |
| 3784 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3785 | |
| 3786 | final long identity = Binder.clearCallingIdentity(); |
| 3787 | try { |
| 3788 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3789 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(identity); |
| 3792 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3796 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3797 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3798 | |
| 3799 | final long identity = Binder.clearCallingIdentity(); |
| 3800 | try { |
| 3801 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3802 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(identity); |
| 3805 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3809 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3810 | String callingPackage, int subId) { |
| 3811 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3812 | |
| 3813 | final long identity = Binder.clearCallingIdentity(); |
| 3814 | try { |
| 3815 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3816 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(identity); |
| 3819 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3820 | } |
| 3821 | |
| 3822 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3823 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3824 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3825 | |
| 3826 | final long identity = Binder.clearCallingIdentity(); |
| 3827 | try { |
| 3828 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3829 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3830 | } finally { |
| 3831 | Binder.restoreCallingIdentity(identity); |
| 3832 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3836 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3837 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3838 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3839 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3840 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3841 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3842 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3843 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3844 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3845 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3846 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3847 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3848 | * Sets the voice activation state of a given subId. |
| 3849 | */ |
| 3850 | @Override |
| 3851 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3852 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3853 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3854 | |
| 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | final Phone phone = getPhone(subId); |
| 3858 | if (phone != null) { |
| 3859 | phone.setVoiceActivationState(activationState); |
| 3860 | } else { |
| 3861 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3862 | } |
| 3863 | } finally { |
| 3864 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3865 | } |
| 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * Sets the data activation state of a given subId. |
| 3870 | */ |
| 3871 | @Override |
| 3872 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3874 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3875 | |
| 3876 | final long identity = Binder.clearCallingIdentity(); |
| 3877 | try { |
| 3878 | final Phone phone = getPhone(subId); |
| 3879 | if (phone != null) { |
| 3880 | phone.setDataActivationState(activationState); |
| 3881 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3882 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3883 | } |
| 3884 | } finally { |
| 3885 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | /** |
| 3890 | * Returns the voice activation state of a given subId. |
| 3891 | */ |
| 3892 | @Override |
| 3893 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3895 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3896 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | if (phone != null) { |
| 3900 | return phone.getVoiceActivationState(); |
| 3901 | } else { |
| 3902 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3903 | } |
| 3904 | } finally { |
| 3905 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | /** |
| 3910 | * Returns the data activation state of a given subId. |
| 3911 | */ |
| 3912 | @Override |
| 3913 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3914 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3915 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3916 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3917 | final long identity = Binder.clearCallingIdentity(); |
| 3918 | try { |
| 3919 | if (phone != null) { |
| 3920 | return phone.getDataActivationState(); |
| 3921 | } else { |
| 3922 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3923 | } |
| 3924 | } finally { |
| 3925 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3926 | } |
| 3927 | } |
| 3928 | |
| 3929 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3930 | * Returns the unread count of voicemails for a subId |
| 3931 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3932 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3933 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3934 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3935 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3936 | mApp, subId, callingPackage, callingFeatureId, |
| 3937 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3938 | return 0; |
| 3939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3940 | final long identity = Binder.clearCallingIdentity(); |
| 3941 | try { |
| 3942 | final Phone phone = getPhone(subId); |
| 3943 | if (phone != null) { |
| 3944 | return phone.getVoiceMessageCount(); |
| 3945 | } else { |
| 3946 | return 0; |
| 3947 | } |
| 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3950 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3951 | } |
| 3952 | |
| 3953 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3954 | * returns true, if the device is in a state where both voice and data |
| 3955 | * are supported simultaneously. This can change based on location or network condition. |
| 3956 | */ |
| 3957 | @Override |
| 3958 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | final Phone phone = getPhone(subId); |
| 3962 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3963 | } finally { |
| 3964 | Binder.restoreCallingIdentity(identity); |
| 3965 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3969 | * Send the dialer code if called from the current default dialer or the caller has |
| 3970 | * carrier privilege. |
| 3971 | * @param inputCode The dialer code to send |
| 3972 | */ |
| 3973 | @Override |
| 3974 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3975 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3976 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3977 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3978 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3979 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3980 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3981 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3982 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3983 | |
| 3984 | final long identity = Binder.clearCallingIdentity(); |
| 3985 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3986 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
| 3989 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3990 | } |
| 3991 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3992 | @Override |
| 3993 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3994 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3995 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3996 | mApp, subId, "getNetworkSelectionMode"); |
| 3997 | final long identity = Binder.clearCallingIdentity(); |
| 3998 | try { |
| 3999 | if (!isActiveSubscription(subId)) { |
| 4000 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 4001 | } |
| 4002 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 4003 | } finally { |
| 4004 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4005 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4008 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4009 | public boolean isInEmergencySmsMode() { |
| 4010 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4011 | final long identity = Binder.clearCallingIdentity(); |
| 4012 | try { |
| 4013 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4014 | if (phone.isInEmergencySmsMode()) { |
| 4015 | return true; |
| 4016 | } |
| 4017 | } |
| 4018 | } finally { |
| 4019 | Binder.restoreCallingIdentity(identity); |
| 4020 | } |
| 4021 | return false; |
| 4022 | } |
| 4023 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4024 | /** |
| 4025 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4026 | * @param subId The subscription to use to check the configuration. |
| 4027 | * @param c The callback that will be used to send the result. |
| 4028 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4029 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4030 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4031 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4032 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4033 | mApp, subId, "registerImsRegistrationCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4034 | |
| 4035 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4036 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4037 | "IMS not available on device."); |
| 4038 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | final long token = Binder.clearCallingIdentity(); |
| 4040 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4041 | int slotId = getSlotIndexOrException(subId); |
| 4042 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4043 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4044 | } catch (ImsException e) { |
| 4045 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(token); |
| 4048 | } |
| 4049 | } |
| 4050 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4051 | /** |
| 4052 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4053 | * @param subId The subscription to use to check the configuration. |
| 4054 | * @param c The callback that will be used to send the result. |
| 4055 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4056 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4057 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4058 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4059 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4060 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4061 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4062 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4063 | final long token = Binder.clearCallingIdentity(); |
| 4064 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4065 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4066 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4067 | } catch (ImsException e) { |
| 4068 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4069 | + "is inactive, ignoring unregister."); |
| 4070 | // If the subscription is no longer active, just return, since the callback |
| 4071 | // will already have been removed internally. |
| 4072 | } finally { |
| 4073 | Binder.restoreCallingIdentity(token); |
| 4074 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | } |
| 4076 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4077 | /** |
| 4078 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4079 | */ |
| 4080 | @Override |
| 4081 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4082 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4083 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4084 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4085 | "IMS not available on device."); |
| 4086 | } |
| 4087 | final long token = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | Phone phone = getPhone(subId); |
| 4090 | if (phone == null) { |
| 4091 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4092 | + subId + "'"); |
| 4093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4094 | } |
| 4095 | phone.getImsRegistrationState(regState -> { |
| 4096 | try { |
| 4097 | consumer.accept((regState == null) |
| 4098 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4099 | } catch (RemoteException e) { |
| 4100 | // Ignore if the remote process is no longer available to call back. |
| 4101 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4102 | } |
| 4103 | }); |
| 4104 | } finally { |
| 4105 | Binder.restoreCallingIdentity(token); |
| 4106 | } |
| 4107 | } |
| 4108 | |
| 4109 | /** |
| 4110 | * Get the transport type for the IMS service registration state. |
| 4111 | */ |
| 4112 | @Override |
| 4113 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4114 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4115 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4116 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4118 | "IMS not available on device."); |
| 4119 | } |
| 4120 | final long token = Binder.clearCallingIdentity(); |
| 4121 | try { |
| 4122 | Phone phone = getPhone(subId); |
| 4123 | if (phone == null) { |
| 4124 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4125 | + subId + "'"); |
| 4126 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4127 | } |
| 4128 | phone.getImsRegistrationTech(regTech -> { |
| 4129 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4130 | int regTechConverted = (regTech == null) |
| 4131 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4132 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4133 | regTechConverted); |
| 4134 | try { |
| 4135 | consumer.accept(regTechConverted); |
| 4136 | } catch (RemoteException e) { |
| 4137 | // Ignore if the remote process is no longer available to call back. |
| 4138 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4139 | } |
| 4140 | }); |
| 4141 | } finally { |
| 4142 | Binder.restoreCallingIdentity(token); |
| 4143 | } |
| 4144 | } |
| 4145 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4146 | /** |
| 4147 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4148 | * @param subId The subscription to use to check the configuration. |
| 4149 | * @param c The callback that will be used to send the result. |
| 4150 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4151 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4152 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4153 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4154 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4155 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4156 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4157 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4158 | "IMS not available on device."); |
| 4159 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4160 | final long token = Binder.clearCallingIdentity(); |
| 4161 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4162 | int slotId = getSlotIndexOrException(subId); |
| 4163 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4164 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4165 | } catch (ImsException e) { |
| 4166 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4167 | } finally { |
| 4168 | Binder.restoreCallingIdentity(token); |
| 4169 | } |
| 4170 | } |
| 4171 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4172 | /** |
| 4173 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4174 | * @param subId The subscription to use to check the configuration. |
| 4175 | * @param c The callback that will be used to send the result. |
| 4176 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4178 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4179 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4180 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4181 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4182 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4183 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4184 | |
| 4185 | final long token = Binder.clearCallingIdentity(); |
| 4186 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4187 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4188 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4189 | } catch (ImsException e) { |
| 4190 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4191 | + "is inactive, ignoring unregister."); |
| 4192 | // If the subscription is no longer active, just return, since the callback |
| 4193 | // will already have been removed internally. |
| 4194 | } finally { |
| 4195 | Binder.restoreCallingIdentity(token); |
| 4196 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | } |
| 4198 | |
| 4199 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4200 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4201 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | final long token = Binder.clearCallingIdentity(); |
| 4203 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4204 | int slotId = getSlotIndexOrException(subId); |
| 4205 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4206 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
| 4207 | } catch (com.android.ims.ImsException e) { |
| 4208 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4209 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4210 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4211 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4212 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4213 | } finally { |
| 4214 | Binder.restoreCallingIdentity(token); |
| 4215 | } |
| 4216 | } |
| 4217 | |
| 4218 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4219 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4220 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4221 | final long token = Binder.clearCallingIdentity(); |
| 4222 | try { |
| 4223 | Phone phone = getPhone(subId); |
| 4224 | if (phone == null) return false; |
| 4225 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4226 | } catch (com.android.ims.ImsException e) { |
| 4227 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4228 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4229 | } finally { |
| 4230 | Binder.restoreCallingIdentity(token); |
| 4231 | } |
| 4232 | } |
| 4233 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4234 | /** |
| 4235 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4236 | * subscription. |
| 4237 | * @param subId The subscription to use to check the configuration. |
| 4238 | * @param callback The callback that will be used to send the result. |
| 4239 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4240 | * @param transportType The transport type of the MmTelFeature capability. |
| 4241 | */ |
| 4242 | @Override |
| 4243 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4244 | int transportType) { |
| 4245 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4246 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4247 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4248 | "IMS not available on device."); |
| 4249 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4250 | final long token = Binder.clearCallingIdentity(); |
| 4251 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4252 | int slotId = getSlotIndex(subId); |
| 4253 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4254 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4255 | + subId + "'"); |
| 4256 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4257 | } |
| 4258 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4259 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4260 | transportType, aBoolean -> { |
| 4261 | try { |
| 4262 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4263 | } catch (RemoteException e) { |
| 4264 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4265 | + "running. Ignore"); |
| 4266 | } |
| 4267 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4268 | } catch (ImsException e) { |
| 4269 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4270 | } finally { |
| 4271 | Binder.restoreCallingIdentity(token); |
| 4272 | } |
| 4273 | } |
| 4274 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4275 | /** |
| 4276 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4277 | * @param subId The subscription to use to check the configuration. |
| 4278 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4279 | @Override |
| 4280 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4281 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4282 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4283 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4284 | final long token = Binder.clearCallingIdentity(); |
| 4285 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4286 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4287 | // 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] | 4288 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4289 | } catch (ImsException e) { |
| 4290 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4291 | } finally { |
| 4292 | Binder.restoreCallingIdentity(token); |
| 4293 | } |
| 4294 | } |
| 4295 | |
| 4296 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4297 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4298 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4299 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4300 | final long identity = Binder.clearCallingIdentity(); |
| 4301 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4302 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4303 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4304 | // 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] | 4305 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4306 | } catch (ImsException e) { |
| 4307 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4308 | } finally { |
| 4309 | Binder.restoreCallingIdentity(identity); |
| 4310 | } |
| 4311 | } |
| 4312 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4313 | /** |
| 4314 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4315 | * @param subId The subscription to use to check the configuration. |
| 4316 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4317 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4318 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4319 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4320 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4321 | final long identity = Binder.clearCallingIdentity(); |
| 4322 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4323 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4324 | // 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] | 4325 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4326 | } catch (ImsException e) { |
| 4327 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4328 | } finally { |
| 4329 | Binder.restoreCallingIdentity(identity); |
| 4330 | } |
| 4331 | } |
| 4332 | |
| 4333 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4334 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4335 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4336 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4337 | final long identity = Binder.clearCallingIdentity(); |
| 4338 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4339 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4340 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4341 | // 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] | 4342 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4343 | } catch (ImsException e) { |
| 4344 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4345 | } finally { |
| 4346 | Binder.restoreCallingIdentity(identity); |
| 4347 | } |
| 4348 | } |
| 4349 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4350 | /** |
| 4351 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4352 | * @param subId The subscription to use to check the configuration. |
| 4353 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4354 | @Override |
| 4355 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4356 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4357 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4360 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4361 | // 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] | 4362 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4363 | } catch (ImsException e) { |
| 4364 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4365 | } finally { |
| 4366 | Binder.restoreCallingIdentity(identity); |
| 4367 | } |
| 4368 | } |
| 4369 | |
| 4370 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4371 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4372 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4373 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4374 | final long identity = Binder.clearCallingIdentity(); |
| 4375 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4376 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4377 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4378 | // 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] | 4379 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4380 | } catch (ImsException e) { |
| 4381 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
| 4384 | } |
| 4385 | } |
| 4386 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4387 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4388 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4389 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4390 | * @param subId The subscription to use to check the configuration. |
| 4391 | */ |
| 4392 | @Override |
| 4393 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4394 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4395 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4396 | final long identity = Binder.clearCallingIdentity(); |
| 4397 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4398 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4399 | // 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] | 4400 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4401 | } catch (ImsException e) { |
| 4402 | throw new ServiceSpecificException(e.getCode()); |
| 4403 | } finally { |
| 4404 | Binder.restoreCallingIdentity(identity); |
| 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | /** |
| 4409 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4410 | * Requires MODIFY_PHONE_STATE permission. |
| 4411 | * @param subId The subscription to use to check the configuration. |
| 4412 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4413 | * false otherwise |
| 4414 | */ |
| 4415 | @Override |
| 4416 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4417 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4418 | "setCrossSimCallingEnabled"); |
| 4419 | final long identity = Binder.clearCallingIdentity(); |
| 4420 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4421 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4422 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4423 | // 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] | 4424 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4425 | } catch (ImsException e) { |
| 4426 | throw new ServiceSpecificException(e.getCode()); |
| 4427 | } finally { |
| 4428 | Binder.restoreCallingIdentity(identity); |
| 4429 | } |
| 4430 | } |
| 4431 | |
| 4432 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4433 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4434 | * @param subId The subscription to use to check the configuration. |
| 4435 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4436 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4437 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4438 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4439 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4440 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4441 | final long identity = Binder.clearCallingIdentity(); |
| 4442 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4443 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4444 | // 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] | 4445 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4446 | } catch (ImsException e) { |
| 4447 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4448 | } finally { |
| 4449 | Binder.restoreCallingIdentity(identity); |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4454 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4456 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4457 | final long identity = Binder.clearCallingIdentity(); |
| 4458 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4459 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4460 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4461 | // 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] | 4462 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4463 | } catch (ImsException e) { |
| 4464 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4465 | } finally { |
| 4466 | Binder.restoreCallingIdentity(identity); |
| 4467 | } |
| 4468 | } |
| 4469 | |
| 4470 | @Override |
| 4471 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4472 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4473 | "setVoWiFiNonPersistent"); |
| 4474 | final long identity = Binder.clearCallingIdentity(); |
| 4475 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4476 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4477 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4478 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4479 | } catch (ImsException e) { |
| 4480 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4481 | } finally { |
| 4482 | Binder.restoreCallingIdentity(identity); |
| 4483 | } |
| 4484 | } |
| 4485 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4486 | /** |
| 4487 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4488 | * @param subId The subscription to use to check the configuration. |
| 4489 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4490 | @Override |
| 4491 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4492 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4493 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4494 | final long identity = Binder.clearCallingIdentity(); |
| 4495 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4496 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4497 | // 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] | 4498 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4499 | } catch (ImsException e) { |
| 4500 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4501 | } finally { |
| 4502 | Binder.restoreCallingIdentity(identity); |
| 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | @Override |
| 4507 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4508 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4509 | "setVoWiFiModeSetting"); |
| 4510 | final long identity = Binder.clearCallingIdentity(); |
| 4511 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4512 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4513 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4514 | // 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] | 4515 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4516 | } catch (ImsException e) { |
| 4517 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | @Override |
| 4524 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4525 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4526 | final long identity = Binder.clearCallingIdentity(); |
| 4527 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4528 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4529 | // 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] | 4530 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4531 | } catch (ImsException e) { |
| 4532 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4533 | } finally { |
| 4534 | Binder.restoreCallingIdentity(identity); |
| 4535 | } |
| 4536 | } |
| 4537 | |
| 4538 | @Override |
| 4539 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4540 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4541 | "setVoWiFiRoamingModeSetting"); |
| 4542 | final long identity = Binder.clearCallingIdentity(); |
| 4543 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4544 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4545 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4546 | // 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] | 4547 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4548 | } catch (ImsException e) { |
| 4549 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4550 | } finally { |
| 4551 | Binder.restoreCallingIdentity(identity); |
| 4552 | } |
| 4553 | } |
| 4554 | |
| 4555 | @Override |
| 4556 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4557 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4558 | "setRttCapabilityEnabled"); |
| 4559 | final long identity = Binder.clearCallingIdentity(); |
| 4560 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4561 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4562 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4563 | // 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] | 4564 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4565 | } catch (ImsException e) { |
| 4566 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(identity); |
| 4569 | } |
| 4570 | } |
| 4571 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4572 | /** |
| 4573 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4574 | * @param subId The subscription to use to check the configuration. |
| 4575 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4576 | @Override |
| 4577 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4578 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4579 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4580 | final long identity = Binder.clearCallingIdentity(); |
| 4581 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4582 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4583 | // 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] | 4584 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4585 | } catch (ImsException e) { |
| 4586 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4587 | } finally { |
| 4588 | Binder.restoreCallingIdentity(identity); |
| 4589 | } |
| 4590 | } |
| 4591 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4592 | @Override |
| 4593 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4594 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4595 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4596 | final long identity = Binder.clearCallingIdentity(); |
| 4597 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 4598 | if (!isImsAvailableOnDevice()) { |
| 4599 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4600 | "IMS not available on device."); |
| 4601 | } |
| 4602 | int slotId = getSlotIndexOrException(subId); |
| 4603 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4604 | ImsManager.getInstance(mApp, slotId) |
| 4605 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4606 | } catch (ImsException e) { |
| 4607 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4608 | } finally { |
| 4609 | Binder.restoreCallingIdentity(identity); |
| 4610 | } |
| 4611 | } |
| 4612 | |
| 4613 | @Override |
| 4614 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4615 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4616 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4617 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4618 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4619 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4620 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4621 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4622 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4623 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4624 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4625 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4626 | + "is inactive, ignoring unregister."); |
| 4627 | // If the subscription is no longer active, just return, since the callback will already |
| 4628 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4629 | } finally { |
| 4630 | Binder.restoreCallingIdentity(identity); |
| 4631 | } |
| 4632 | } |
| 4633 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4634 | @Override |
| 4635 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4636 | IFeatureProvisioningCallback callback) { |
| 4637 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4638 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4639 | |
| 4640 | final long identity = Binder.clearCallingIdentity(); |
| 4641 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4642 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4643 | } |
| 4644 | |
| 4645 | ImsProvisioningController.getInstance() |
| 4646 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4647 | |
| 4648 | Binder.restoreCallingIdentity(identity); |
| 4649 | } |
| 4650 | |
| 4651 | @Override |
| 4652 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4653 | IFeatureProvisioningCallback callback) { |
| 4654 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4655 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4656 | |
| 4657 | final long identity = Binder.clearCallingIdentity(); |
| 4658 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4659 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4660 | } |
| 4661 | |
| 4662 | ImsProvisioningController.getInstance() |
| 4663 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4664 | |
| 4665 | Binder.restoreCallingIdentity(identity); |
| 4666 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4667 | |
| 4668 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4669 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4670 | message); |
| 4671 | } |
| 4672 | |
| 4673 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4674 | boolean isMmtelCapability) { |
| 4675 | Phone phone = getPhone(subId); |
| 4676 | if (phone == null) { |
| 4677 | loge("phone instance null for subid " + subId); |
| 4678 | return false; |
| 4679 | } |
| 4680 | if (isMmtelCapability) { |
| 4681 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4682 | return false; |
| 4683 | } |
| 4684 | } else { |
| 4685 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4686 | return false; |
| 4687 | } |
| 4688 | } |
| 4689 | return true; |
| 4690 | } |
| 4691 | |
| 4692 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4693 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4694 | boolean isProvisioned) { |
| 4695 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4696 | |
| 4697 | final long identity = Binder.clearCallingIdentity(); |
| 4698 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4699 | ImsProvisioningController.getInstance() |
| 4700 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4701 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4702 | } finally { |
| 4703 | Binder.restoreCallingIdentity(identity); |
| 4704 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | |
| 4708 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4709 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4710 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4711 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4712 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4713 | final long identity = Binder.clearCallingIdentity(); |
| 4714 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4715 | return ImsProvisioningController.getInstance() |
| 4716 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4717 | } finally { |
| 4718 | Binder.restoreCallingIdentity(identity); |
| 4719 | } |
| 4720 | } |
| 4721 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4722 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4723 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4724 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4725 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4726 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4729 | ImsProvisioningController.getInstance() |
| 4730 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4731 | } finally { |
| 4732 | Binder.restoreCallingIdentity(identity); |
| 4733 | } |
| 4734 | } |
| 4735 | |
| 4736 | @Override |
| 4737 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4738 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4739 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4740 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4741 | final long identity = Binder.clearCallingIdentity(); |
| 4742 | try { |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4743 | return ImsProvisioningController.getInstance() |
| 4744 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4745 | |
| 4746 | } finally { |
| 4747 | Binder.restoreCallingIdentity(identity); |
| 4748 | } |
| 4749 | } |
| 4750 | |
| 4751 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4752 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4753 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4754 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4755 | |
| 4756 | final long identity = Binder.clearCallingIdentity(); |
| 4757 | try { |
| 4758 | return ImsProvisioningController.getInstance() |
| 4759 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4760 | } finally { |
| 4761 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4762 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | @Override |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4766 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4767 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4768 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4769 | |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4770 | final long identity = Binder.clearCallingIdentity(); |
| 4771 | try { |
| 4772 | return ImsProvisioningController.getInstance() |
| 4773 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(identity); |
| 4776 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4780 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4781 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4782 | } |
| 4783 | |
| 4784 | /** |
| 4785 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4786 | * carrier associated with the subscription id. |
| 4787 | */ |
| 4788 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4789 | int capability) { |
| 4790 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4791 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4792 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4793 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4794 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4795 | false); |
| 4796 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4797 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4798 | |
| 4799 | // First check to make sure that the capability requires provisioning. |
| 4800 | switch (capability) { |
| 4801 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4802 | // intentional fallthrough |
| 4803 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4804 | if (requireVoiceVtProvisioning) { |
| 4805 | // Voice and Video requires provisioning |
| 4806 | return true; |
| 4807 | } |
| 4808 | break; |
| 4809 | } |
| 4810 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4811 | if (requireUtProvisioning) { |
| 4812 | // UT requires provisioning |
| 4813 | return true; |
| 4814 | } |
| 4815 | break; |
| 4816 | } |
| 4817 | } |
| 4818 | return false; |
| 4819 | } |
| 4820 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4821 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4822 | int capability) { |
| 4823 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4824 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4825 | |
| 4826 | boolean requireRcsProvisioning = c.getBoolean( |
| 4827 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4828 | |
| 4829 | // First check to make sure that the capability requires provisioning. |
| 4830 | switch (capability) { |
| 4831 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4832 | // intentional fallthrough |
| 4833 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4834 | if (requireRcsProvisioning) { |
| 4835 | // OPTION or PRESENCE requires provisioning |
| 4836 | return true; |
| 4837 | } |
| 4838 | break; |
| 4839 | } |
| 4840 | } |
| 4841 | return false; |
| 4842 | } |
| 4843 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4844 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4845 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4846 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4847 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4848 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4849 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4850 | mApp, subId, "getImsProvisioningInt"); |
| 4851 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4852 | final long identity = Binder.clearCallingIdentity(); |
| 4853 | try { |
| 4854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4855 | int slotId = getSlotIndex(subId); |
| 4856 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4857 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4858 | + subId + "' for key:" + key); |
| 4859 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4860 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4861 | |
| 4862 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4863 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4864 | return retVal; |
| 4865 | } |
| 4866 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4867 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4868 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4869 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4870 | + subId + "' for key:" + key); |
| 4871 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4872 | } finally { |
| 4873 | Binder.restoreCallingIdentity(identity); |
| 4874 | } |
| 4875 | } |
| 4876 | |
| 4877 | @Override |
| 4878 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4879 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4880 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4881 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4882 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4883 | mApp, subId, "getImsProvisioningString"); |
| 4884 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4885 | final long identity = Binder.clearCallingIdentity(); |
| 4886 | try { |
| 4887 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4888 | int slotId = getSlotIndex(subId); |
| 4889 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4890 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4891 | + subId + "' for key:" + key); |
| 4892 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4893 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4894 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4895 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4896 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4897 | + subId + "' for key:" + key); |
| 4898 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4899 | } finally { |
| 4900 | Binder.restoreCallingIdentity(identity); |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | @Override |
| 4905 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4906 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4907 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4908 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4909 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4910 | "setImsProvisioningInt"); |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4911 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4912 | final long identity = Binder.clearCallingIdentity(); |
| 4913 | try { |
| 4914 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4915 | int slotId = getSlotIndex(subId); |
| 4916 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4917 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4918 | + subId + "' for key:" + key); |
| 4919 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4920 | } |
joonhunshin | cffb7fc | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4921 | |
| 4922 | int retVal = ImsProvisioningController.getInstance() |
| 4923 | .setProvisioningValue(subId, key, value); |
| 4924 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4925 | return retVal; |
| 4926 | } |
| 4927 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4928 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4929 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4930 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4931 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4932 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4933 | } finally { |
| 4934 | Binder.restoreCallingIdentity(identity); |
| 4935 | } |
| 4936 | } |
| 4937 | |
| 4938 | @Override |
| 4939 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4940 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4941 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4942 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4944 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4945 | final long identity = Binder.clearCallingIdentity(); |
| 4946 | try { |
| 4947 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4948 | int slotId = getSlotIndex(subId); |
| 4949 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4950 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4951 | + subId + "' for key:" + key); |
| 4952 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4953 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4954 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4955 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4956 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4957 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4958 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4959 | } finally { |
| 4960 | Binder.restoreCallingIdentity(identity); |
| 4961 | } |
| 4962 | } |
| 4963 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4964 | /** |
| 4965 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4966 | * for the given slot ID or no ImsResolver instance has been created. |
| 4967 | * @param slotId The slot ID that the IMS service is created for. |
| 4968 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4969 | */ |
| 4970 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4971 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4972 | ImsFeature.FEATURE_MMTEL)) { |
| 4973 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4974 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4975 | } |
| 4976 | } |
| 4977 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4978 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4979 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4980 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4981 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4982 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4983 | } |
| 4984 | return slotId; |
| 4985 | } |
| 4986 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4987 | private int getSlotIndex(int subId) { |
| 4988 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4989 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4990 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4991 | } |
| 4992 | return slotId; |
| 4993 | } |
| 4994 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4995 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4996 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4997 | */ |
| 4998 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4999 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5000 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 5001 | try { |
| 5002 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5003 | } catch (SecurityException se) { |
| 5004 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 5005 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5006 | + Binder.getCallingUid()); |
| 5007 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5008 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5009 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5010 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5011 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5012 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5013 | mApp, subId, callingPackage, callingFeatureId, |
| 5014 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5015 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5016 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5018 | final long identity = Binder.clearCallingIdentity(); |
| 5019 | try { |
| 5020 | final Phone phone = getPhone(subId); |
| 5021 | if (phone != null) { |
| 5022 | return phone.getServiceState().getDataNetworkType(); |
| 5023 | } else { |
| 5024 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5025 | } |
| 5026 | } finally { |
| 5027 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | /** |
| 5032 | * Returns the data network type |
| 5033 | */ |
| 5034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5035 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5036 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5037 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
| 5040 | /** |
| 5041 | * Returns the data network type for a subId |
| 5042 | */ |
| 5043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5044 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5045 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5046 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5047 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5048 | mApp, functionName)) { |
| 5049 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5050 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5051 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5052 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5053 | } |
| 5054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5055 | final long identity = Binder.clearCallingIdentity(); |
| 5056 | try { |
| 5057 | final Phone phone = getPhone(subId); |
| 5058 | if (phone != null) { |
| 5059 | return phone.getServiceState().getDataNetworkType(); |
| 5060 | } else { |
| 5061 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5062 | } |
| 5063 | } finally { |
| 5064 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5065 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5066 | } |
| 5067 | |
| 5068 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5069 | * Returns the Voice network type for a subId |
| 5070 | */ |
| 5071 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5072 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5073 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5074 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5075 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5076 | mApp, functionName)) { |
| 5077 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5078 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5079 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5080 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5081 | } |
| 5082 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
| 5085 | final Phone phone = getPhone(subId); |
| 5086 | if (phone != null) { |
| 5087 | return phone.getServiceState().getVoiceNetworkType(); |
| 5088 | } else { |
| 5089 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5090 | } |
| 5091 | } finally { |
| 5092 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5093 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | /** |
| 5097 | * @return true if a ICC card is present |
| 5098 | */ |
| 5099 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5100 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5101 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5102 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5106 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5107 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5108 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5109 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
| 5112 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5113 | if (phone != null) { |
| 5114 | return phone.getIccCard().hasIccCard(); |
| 5115 | } else { |
| 5116 | return false; |
| 5117 | } |
| 5118 | } finally { |
| 5119 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | /** |
| 5124 | * Return if the current radio is LTE on CDMA. This |
| 5125 | * is a tri-state return value as for a period of time |
| 5126 | * the mode may be unknown. |
| 5127 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5128 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5129 | * @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] | 5130 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5131 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5133 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5134 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5135 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5136 | } |
| 5137 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5138 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5139 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5140 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5141 | try { |
| 5142 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5143 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5144 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5145 | } |
| 5146 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
| 5149 | final Phone phone = getPhone(subId); |
| 5150 | if (phone == null) { |
| 5151 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5152 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5153 | return TelephonyProperties.lte_on_cdma_device() |
| 5154 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | } |
| 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5158 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5161 | /** |
| 5162 | * {@hide} |
| 5163 | * Returns Default subId, 0 in the case of single standby. |
| 5164 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5165 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5166 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5169 | private int getSlotForDefaultSubscription() { |
| 5170 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5171 | } |
| 5172 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5173 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5174 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5175 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5176 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5177 | private boolean isActiveSubscription(int subId) { |
| 5178 | return mSubscriptionController.isActiveSubId(subId); |
| 5179 | } |
| 5180 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5181 | /** |
| 5182 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5183 | */ |
| 5184 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5187 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5189 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5190 | } finally { |
| 5191 | Binder.restoreCallingIdentity(identity); |
| 5192 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5193 | } |
| 5194 | |
| 5195 | /** |
| 5196 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5197 | */ |
| 5198 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5199 | final long identity = Binder.clearCallingIdentity(); |
| 5200 | try { |
| 5201 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5202 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5203 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5204 | } finally { |
| 5205 | Binder.restoreCallingIdentity(identity); |
| 5206 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5207 | } |
| 5208 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5209 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5210 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5211 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5212 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5213 | |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5214 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5215 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5216 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5217 | if (phoneId == -1) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5218 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5219 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5220 | } |
| 5221 | return PhoneFactory.getPhone(phoneId); |
| 5222 | } |
| 5223 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5224 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5225 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5226 | @NonNull IccLogicalChannelRequest request) { |
| 5227 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5228 | /*message=*/ "iccOpenLogicalChannel"); |
| 5229 | |
| 5230 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5231 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5232 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5233 | |
| 5234 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5235 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5236 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5237 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5238 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5239 | Phone phone; |
| 5240 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5242 | mApp, request.subId, message); |
| 5243 | phone = getPhoneFromSubId(request.subId); |
| 5244 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5245 | enforceModifyPermission(); |
| 5246 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5247 | } else { |
| 5248 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5249 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5250 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5251 | } |
| 5252 | |
| 5253 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5254 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5255 | final long identity = Binder.clearCallingIdentity(); |
| 5256 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5257 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5258 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5259 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5260 | .getContext().getPackageManager()); |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5261 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5262 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | loge("The calling package is not allowed to access ISD-R."); |
| 5264 | throw new SecurityException( |
| 5265 | "The calling package is not allowed to access ISD-R."); |
| 5266 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5267 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5270 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5271 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5272 | return response; |
| 5273 | } finally { |
| 5274 | Binder.restoreCallingIdentity(identity); |
| 5275 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5276 | } |
| 5277 | |
| 5278 | @Override |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5279 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5280 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5281 | /*message=*/"iccCloseLogicalChannel"); |
| 5282 | |
| 5283 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5284 | |
| 5285 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5286 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5287 | |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5288 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5289 | IccLogicalChannelRequest request) { |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5290 | // before this feature is enabled, this API should only return false if |
| 5291 | // the operation fails instead of throwing runtime exception for |
| 5292 | // backward-compatibility. |
| 5293 | final boolean shouldThrowExceptionOnFailure = CompatChanges.isChangeEnabled( |
| 5294 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE, Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | final long identity = Binder.clearCallingIdentity(); |
| 5296 | try { |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5297 | if (request.channel < 0) { |
Chen Xu | 540470b | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5298 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5300 | Object result = sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5301 | null /* workSource */); |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5302 | Boolean success = false; |
| 5303 | if (result instanceof RuntimeException) { |
| 5304 | // if there is an exception returned, throw from the binder thread here. |
Chen Xu | a8f0dff | 2022-02-12 00:34:15 -0800 | [diff] [blame] | 5305 | if (shouldThrowExceptionOnFailure) { |
| 5306 | throw (RuntimeException) result; |
| 5307 | } else { |
| 5308 | return false; |
| 5309 | } |
Chen Xu | e9d737e | 2022-01-01 23:41:31 -0800 | [diff] [blame] | 5310 | } else if (result instanceof Boolean) { |
| 5311 | success = (Boolean) result; |
| 5312 | } else { |
| 5313 | loge("iccCloseLogicalChannelWithPermission: supported return type " + result); |
| 5314 | } |
Rambo Wang | a178270 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5315 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5316 | return success; |
| 5317 | } finally { |
| 5318 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5319 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5323 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5324 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5325 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5326 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5327 | if (DBG) { |
| 5328 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5329 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5330 | + p3 + " data=" + data); |
| 5331 | } |
| 5332 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5333 | command, p1, p2, p3, data); |
| 5334 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5335 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5336 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5337 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5338 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5339 | enforceModifyPermission(); |
| 5340 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5341 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5342 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5343 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5344 | } |
| 5345 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5346 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5347 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5348 | } |
| 5349 | |
| 5350 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5351 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | final long identity = Binder.clearCallingIdentity(); |
| 5353 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5354 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5355 | return ""; |
| 5356 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5357 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5359 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5360 | null /* workSource */); |
| 5361 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5363 | // Append the returned status code to the end of the response payload. |
| 5364 | String s = Integer.toHexString( |
| 5365 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5366 | if (response.payload != null) { |
| 5367 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5368 | } |
| 5369 | return s; |
| 5370 | } finally { |
| 5371 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5372 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5373 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5374 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5375 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5376 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5377 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5379 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5380 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5381 | if (DBG) { |
| 5382 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5383 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5384 | } |
| 5385 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5386 | cla, command, p1, p2, p3, data); |
| 5387 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5388 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5389 | @Override |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5390 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5391 | 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] | 5392 | enforceModifyPermission(); |
| 5393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5394 | if (DBG) { |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5395 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5396 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5397 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5398 | } |
| 5399 | |
| 5400 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | bd38d95 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5401 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5402 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5406 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5407 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | final long identity = Binder.clearCallingIdentity(); |
| 5409 | try { |
| 5410 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5411 | && TextUtils.equals(ISDR_AID, data)) { |
| 5412 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5413 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5414 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5415 | if (bestComponent == null |
| 5416 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5417 | loge("The calling package is not allowed to select ISD-R."); |
| 5418 | throw new SecurityException( |
| 5419 | "The calling package is not allowed to select ISD-R."); |
| 5420 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5421 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5422 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5423 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5424 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5425 | null /* workSource */); |
| 5426 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5428 | // Append the returned status code to the end of the response payload. |
| 5429 | String s = Integer.toHexString( |
| 5430 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5431 | if (response.payload != null) { |
| 5432 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5433 | } |
| 5434 | return s; |
| 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5437 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5441 | 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] | 5442 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5443 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5444 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5445 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5446 | final long identity = Binder.clearCallingIdentity(); |
| 5447 | try { |
| 5448 | if (DBG) { |
| 5449 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5450 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5451 | } |
| 5452 | |
| 5453 | IccIoResult response = |
| 5454 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5455 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5456 | subId); |
| 5457 | |
| 5458 | if (DBG) { |
| 5459 | log("Exchange SIM_IO [R]" + response); |
| 5460 | } |
| 5461 | |
| 5462 | byte[] result = null; |
| 5463 | int length = 2; |
| 5464 | if (response.payload != null) { |
| 5465 | length = 2 + response.payload.length; |
| 5466 | result = new byte[length]; |
| 5467 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5468 | } else { |
| 5469 | result = new byte[length]; |
| 5470 | } |
| 5471 | |
| 5472 | result[length - 1] = (byte) response.sw2; |
| 5473 | result[length - 2] = (byte) response.sw1; |
| 5474 | return result; |
| 5475 | } finally { |
| 5476 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5477 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5478 | } |
| 5479 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5480 | /** |
| 5481 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5482 | * on a particular subscription |
| 5483 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5484 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5485 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5487 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5488 | return null; |
| 5489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5490 | |
| 5491 | final long identity = Binder.clearCallingIdentity(); |
| 5492 | try { |
| 5493 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5494 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5495 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5496 | return null; |
| 5497 | } |
| 5498 | Object response = sendRequest( |
| 5499 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5500 | if (response instanceof String[]) { |
| 5501 | return (String[]) response; |
| 5502 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5503 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5504 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5505 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | } finally { |
| 5507 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5508 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5509 | } |
| 5510 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5511 | /** |
| 5512 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5513 | * subscription. |
| 5514 | * |
| 5515 | * @param subId the id of the subscription. |
| 5516 | * @param appType the uicc app type, must be USIM or SIM. |
| 5517 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5518 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5519 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5520 | * @return number of fplmns that is successfully written to the SIM. |
| 5521 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5522 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5523 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5525 | mApp, subId, "setForbiddenPlmns"); |
| 5526 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5527 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5528 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5529 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5530 | } |
| 5531 | if (fplmns == null) { |
| 5532 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5533 | } |
| 5534 | for (String fplmn : fplmns) { |
| 5535 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5536 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5537 | } |
| 5538 | } |
| 5539 | final long identity = Binder.clearCallingIdentity(); |
| 5540 | try { |
| 5541 | Object response = sendRequest( |
| 5542 | CMD_SET_FORBIDDEN_PLMNS, |
| 5543 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5544 | subId); |
| 5545 | return (int) response; |
| 5546 | } finally { |
| 5547 | Binder.restoreCallingIdentity(identity); |
| 5548 | } |
| 5549 | } |
| 5550 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5551 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5552 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5554 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5555 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5556 | final long identity = Binder.clearCallingIdentity(); |
| 5557 | try { |
| 5558 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5559 | if (response.payload == null) { |
| 5560 | return ""; |
| 5561 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5562 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5563 | // Append the returned status code to the end of the response payload. |
| 5564 | String s = Integer.toHexString( |
| 5565 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5566 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5567 | return s; |
| 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
| 5570 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5573 | /** |
| 5574 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5575 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5576 | * |
| 5577 | * @param itemID the ID of the item to read |
| 5578 | * @return the NV item as a String, or null on error. |
| 5579 | */ |
| 5580 | @Override |
| 5581 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5582 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5583 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5584 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5585 | |
| 5586 | final long identity = Binder.clearCallingIdentity(); |
| 5587 | try { |
| 5588 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5589 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5590 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5591 | return value; |
| 5592 | } finally { |
| 5593 | Binder.restoreCallingIdentity(identity); |
| 5594 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | /** |
| 5598 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5599 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5600 | * |
| 5601 | * @param itemID the ID of the item to read |
| 5602 | * @param itemValue the value to write, as a String |
| 5603 | * @return true on success; false on any failure |
| 5604 | */ |
| 5605 | @Override |
| 5606 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5607 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5609 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5610 | |
| 5611 | final long identity = Binder.clearCallingIdentity(); |
| 5612 | try { |
| 5613 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5614 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5615 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5616 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5617 | return success; |
| 5618 | } finally { |
| 5619 | Binder.restoreCallingIdentity(identity); |
| 5620 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | /** |
| 5624 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5625 | * Used for device configuration by some CDMA operators. |
| 5626 | * |
| 5627 | * @param preferredRoamingList byte array containing the new PRL |
| 5628 | * @return true on success; false on any failure |
| 5629 | */ |
| 5630 | @Override |
| 5631 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5633 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5634 | |
| 5635 | final long identity = Binder.clearCallingIdentity(); |
| 5636 | try { |
| 5637 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5638 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5639 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5640 | return success; |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5647 | * 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] | 5648 | * Used for device configuration by some CDMA operators. |
| 5649 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5650 | * @param slotIndex - device slot. |
| 5651 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5652 | * @return true on success; false on any failure |
| 5653 | */ |
| 5654 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5655 | public boolean resetModemConfig(int slotIndex) { |
| 5656 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5657 | if (phone != null) { |
| 5658 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5659 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5661 | final long identity = Binder.clearCallingIdentity(); |
| 5662 | try { |
| 5663 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5664 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5665 | return success; |
| 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
| 5668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5669 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5670 | return false; |
| 5671 | } |
| 5672 | |
| 5673 | /** |
| 5674 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5675 | * |
| 5676 | * @param slotIndex - device slot. |
| 5677 | * |
| 5678 | * @return true on success; false on any failure |
| 5679 | */ |
| 5680 | @Override |
| 5681 | public boolean rebootModem(int slotIndex) { |
| 5682 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5683 | if (phone != null) { |
| 5684 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5685 | mApp, phone.getSubId(), "rebootModem"); |
| 5686 | |
| 5687 | final long identity = Binder.clearCallingIdentity(); |
| 5688 | try { |
| 5689 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5690 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5691 | return success; |
| 5692 | } finally { |
| 5693 | Binder.restoreCallingIdentity(identity); |
| 5694 | } |
| 5695 | } |
| 5696 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5697 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5698 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5699 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5700 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5701 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5703 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5704 | return new String[0]; |
| 5705 | } |
| 5706 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5707 | final long identity = Binder.clearCallingIdentity(); |
| 5708 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5709 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
| 5712 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5713 | } |
| 5714 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5715 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5716 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5717 | * {@link #disableIms(int)}. |
| 5718 | * @param slotIndex device slot. |
| 5719 | */ |
| 5720 | public void resetIms(int slotIndex) { |
| 5721 | enforceModifyPermission(); |
| 5722 | |
| 5723 | final long identity = Binder.clearCallingIdentity(); |
| 5724 | try { |
| 5725 | if (mImsResolver == null) { |
| 5726 | // may happen if the does not support IMS. |
| 5727 | return; |
| 5728 | } |
| 5729 | mImsResolver.disableIms(slotIndex); |
| 5730 | mImsResolver.enableIms(slotIndex); |
| 5731 | } finally { |
| 5732 | Binder.restoreCallingIdentity(identity); |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5737 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5738 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5739 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5740 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5741 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | |
| 5743 | final long identity = Binder.clearCallingIdentity(); |
| 5744 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5745 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5746 | // may happen if the device does not support IMS. |
| 5747 | return; |
| 5748 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5749 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | } finally { |
| 5751 | Binder.restoreCallingIdentity(identity); |
| 5752 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5756 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5757 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5758 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5759 | public void disableIms(int slotId) { |
| 5760 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | |
| 5762 | final long identity = Binder.clearCallingIdentity(); |
| 5763 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5764 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5765 | // may happen if the device does not support IMS. |
| 5766 | return; |
| 5767 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5768 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5775 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5776 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5777 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5778 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5779 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5780 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | |
| 5782 | final long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5784 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5785 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5786 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5787 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5788 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5789 | } finally { |
| 5790 | Binder.restoreCallingIdentity(identity); |
| 5791 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5792 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5793 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5794 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5795 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5796 | @Override |
| 5797 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5798 | enforceModifyPermission(); |
| 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5803 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5804 | } finally { |
| 5805 | Binder.restoreCallingIdentity(identity); |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5810 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5811 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5812 | */ |
| 5813 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5814 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | |
| 5816 | final long identity = Binder.clearCallingIdentity(); |
| 5817 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5818 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5819 | // may happen if the device does not support IMS. |
| 5820 | return null; |
| 5821 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5822 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5823 | } finally { |
| 5824 | Binder.restoreCallingIdentity(identity); |
| 5825 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5826 | } |
| 5827 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5828 | /** |
| 5829 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5830 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5831 | */ |
| 5832 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5834 | |
| 5835 | final long identity = Binder.clearCallingIdentity(); |
| 5836 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5837 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5838 | // may happen if the device does not support IMS. |
| 5839 | return null; |
| 5840 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5841 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
| 5844 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5845 | } |
| 5846 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5847 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5848 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5849 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5850 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5851 | * @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] | 5852 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5853 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5854 | * @param packageName The name of the package that the current configuration will be replaced |
| 5855 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5856 | * @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] | 5857 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5858 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5859 | int[] featureTypes, String packageName) { |
| 5860 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5863 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5864 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5866 | final long identity = Binder.clearCallingIdentity(); |
| 5867 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5868 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5869 | // may happen if the device does not support IMS. |
| 5870 | return false; |
| 5871 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5872 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5873 | for (int featureType : featureTypes) { |
| 5874 | featureConfig.put(featureType, packageName); |
| 5875 | } |
| 5876 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5877 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5878 | } finally { |
| 5879 | Binder.restoreCallingIdentity(identity); |
| 5880 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5881 | } |
| 5882 | |
| 5883 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5884 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5885 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5886 | * |
| 5887 | * This should only be used for testing. |
| 5888 | * |
| 5889 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5890 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5891 | */ |
| 5892 | @Override |
| 5893 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5894 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5895 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5896 | "clearCarrierImsServiceOverride"); |
| 5897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5898 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5899 | "clearCarrierImsServiceOverride"); |
| 5900 | |
| 5901 | final long identity = Binder.clearCallingIdentity(); |
| 5902 | try { |
| 5903 | if (mImsResolver == null) { |
| 5904 | // may happen if the device does not support IMS. |
| 5905 | return false; |
| 5906 | } |
| 5907 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5908 | } finally { |
| 5909 | Binder.restoreCallingIdentity(identity); |
| 5910 | } |
| 5911 | } |
| 5912 | |
| 5913 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5914 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5915 | * |
| 5916 | * @param slotId The slot that the ImsService is associated with. |
| 5917 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5918 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5919 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5920 | * @return the package name of the ImsService configuration. |
| 5921 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5922 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5923 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5924 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5925 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5926 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5927 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5928 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5929 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5932 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5933 | // may happen if the device does not support IMS. |
| 5934 | return ""; |
| 5935 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5936 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5937 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5938 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(identity); |
| 5941 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5942 | } |
| 5943 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5944 | /** |
| 5945 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5946 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5947 | * @param callback A callback with an integer containing the |
| 5948 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5949 | */ |
| 5950 | @Override |
| 5951 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5952 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5953 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5954 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5955 | "IMS not available on device."); |
| 5956 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5957 | final long token = Binder.clearCallingIdentity(); |
| 5958 | try { |
Brad Ebinger | a262830 | 2022-02-18 03:44:55 +0000 | [diff] [blame] | 5959 | int slotId = getSlotIndex(subId); |
| 5960 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5961 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5962 | + subId + "'"); |
| 5963 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5964 | } |
| 5965 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 5966 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5967 | try { |
| 5968 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5969 | } catch (RemoteException e) { |
| 5970 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5971 | + "Ignore"); |
| 5972 | } |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5973 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5974 | } catch (ImsException e) { |
| 5975 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5976 | } finally { |
| 5977 | Binder.restoreCallingIdentity(token); |
| 5978 | } |
| 5979 | } |
| 5980 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5981 | /** |
| 5982 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5983 | */ |
| 5984 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5985 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | |
| 5987 | final long identity = Binder.clearCallingIdentity(); |
| 5988 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5989 | // NOTE: Before S, this method only set the default phone. |
| 5990 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5991 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5992 | phone.setImsRegistrationState(registered); |
| 5993 | } |
| 5994 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
| 5997 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5998 | } |
| 5999 | |
| 6000 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6001 | * Set the network selection mode to automatic. |
| 6002 | * |
| 6003 | */ |
| 6004 | @Override |
| 6005 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6007 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | |
| 6009 | final long identity = Binder.clearCallingIdentity(); |
| 6010 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 6011 | if (!isActiveSubscription(subId)) { |
| 6012 | return; |
| 6013 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 6015 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 6016 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | } finally { |
| 6018 | Binder.restoreCallingIdentity(identity); |
| 6019 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 6022 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6023 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6024 | * |
| 6025 | * @param subId the id of the subscription. |
| 6026 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6027 | * the operator to attach to. |
| 6028 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6029 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6030 | * normal network selection next time. |
| 6031 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6032 | */ |
| 6033 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6034 | public boolean setNetworkSelectionModeManual( |
| 6035 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6037 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6038 | |
| 6039 | if (!isActiveSubscription(subId)) { |
| 6040 | return false; |
| 6041 | } |
| 6042 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6043 | final long identity = Binder.clearCallingIdentity(); |
| 6044 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6045 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6046 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6047 | if (DBG) { |
| 6048 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6049 | + " operator: " + operatorInfo); |
| 6050 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6051 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6052 | } finally { |
| 6053 | Binder.restoreCallingIdentity(identity); |
| 6054 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6055 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6056 | /** |
| 6057 | * Get the manual network selection |
| 6058 | * |
| 6059 | * @param subId the id of the subscription. |
| 6060 | * |
| 6061 | * @return the previously saved user selected PLMN |
| 6062 | */ |
| 6063 | @Override |
| 6064 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6065 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6066 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6067 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6068 | |
| 6069 | final long identity = Binder.clearCallingIdentity(); |
| 6070 | try { |
| 6071 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6072 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6073 | } |
| 6074 | |
| 6075 | final Phone phone = getPhone(subId); |
| 6076 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6077 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6078 | } |
| 6079 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6080 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6081 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
| 6084 | } |
| 6085 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6086 | |
| 6087 | /** |
| 6088 | * Scans for available networks. |
| 6089 | */ |
| 6090 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6091 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6092 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6094 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6095 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6096 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6097 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6098 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6099 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6100 | .setCallingPid(Binder.getCallingPid()) |
| 6101 | .setCallingUid(Binder.getCallingUid()) |
| 6102 | .setMethod("getCellNetworkScanResults") |
| 6103 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6104 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6105 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6106 | .build()); |
| 6107 | switch (locationResult) { |
| 6108 | case DENIED_HARD: |
| 6109 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6110 | case DENIED_SOFT: |
| 6111 | return null; |
| 6112 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6113 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6114 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6115 | try { |
| 6116 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6117 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6118 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6119 | } finally { |
| 6120 | Binder.restoreCallingIdentity(identity); |
| 6121 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6125 | * Get the call forwarding info, given the call forwarding reason. |
| 6126 | */ |
| 6127 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6128 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6129 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6130 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6131 | long identity = Binder.clearCallingIdentity(); |
| 6132 | try { |
| 6133 | if (DBG) { |
| 6134 | log("getCallForwarding: subId " + subId |
| 6135 | + " callForwardingReason" + callForwardingReason); |
| 6136 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6137 | |
| 6138 | Phone phone = getPhone(subId); |
| 6139 | if (phone == null) { |
| 6140 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6141 | callback.onError( |
| 6142 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6143 | } catch (RemoteException e) { |
| 6144 | // ignore |
| 6145 | } |
| 6146 | return; |
| 6147 | } |
| 6148 | |
| 6149 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6150 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6151 | @Override |
| 6152 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6153 | try { |
| 6154 | callback.onCallForwardingInfoAvailable(info); |
| 6155 | } catch (RemoteException e) { |
| 6156 | // ignore |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | @Override |
| 6161 | public void onError(int error) { |
| 6162 | try { |
| 6163 | callback.onError(error); |
| 6164 | } catch (RemoteException e) { |
| 6165 | // ignore |
| 6166 | } |
| 6167 | } |
| 6168 | }); |
| 6169 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6170 | } finally { |
| 6171 | Binder.restoreCallingIdentity(identity); |
| 6172 | } |
| 6173 | } |
| 6174 | |
| 6175 | /** |
| 6176 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6177 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6178 | */ |
| 6179 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6180 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6181 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6182 | enforceModifyPermission(); |
| 6183 | long identity = Binder.clearCallingIdentity(); |
| 6184 | try { |
| 6185 | if (DBG) { |
| 6186 | log("setCallForwarding: subId " + subId |
| 6187 | + " callForwardingInfo" + callForwardingInfo); |
| 6188 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6189 | |
| 6190 | Phone phone = getPhone(subId); |
| 6191 | if (phone == null) { |
| 6192 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6193 | callback.accept( |
| 6194 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6195 | } catch (RemoteException e) { |
| 6196 | // ignore |
| 6197 | } |
| 6198 | return; |
| 6199 | } |
| 6200 | |
| 6201 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6202 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6203 | |
| 6204 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6205 | } finally { |
| 6206 | Binder.restoreCallingIdentity(identity); |
| 6207 | } |
| 6208 | } |
| 6209 | |
| 6210 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6211 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6212 | */ |
| 6213 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6214 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6215 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6216 | long identity = Binder.clearCallingIdentity(); |
| 6217 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6218 | Phone phone = getPhone(subId); |
| 6219 | if (phone == null) { |
| 6220 | try { |
| 6221 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6222 | } catch (RemoteException e) { |
| 6223 | // ignore |
| 6224 | } |
| 6225 | return; |
| 6226 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6227 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6228 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6229 | boolean requireUssd = c.getBoolean( |
| 6230 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6231 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6232 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6233 | if (requireUssd) { |
| 6234 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6235 | getSubscriptionCarrierId(subId)); |
| 6236 | String newUssdCommand = ""; |
| 6237 | try { |
| 6238 | newUssdCommand = carrierXmlParser.getFeature( |
| 6239 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6240 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6241 | } catch (NullPointerException e) { |
| 6242 | loge("Failed to generate USSD number" + e); |
| 6243 | } |
| 6244 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6245 | mMainThreadHandler, callback, carrierXmlParser, |
| 6246 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6247 | final String ussdCommand = newUssdCommand; |
| 6248 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6249 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6250 | }); |
| 6251 | } else { |
| 6252 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6253 | callback::accept); |
| 6254 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6255 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6256 | } finally { |
| 6257 | Binder.restoreCallingIdentity(identity); |
| 6258 | } |
| 6259 | } |
| 6260 | |
| 6261 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6262 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6263 | */ |
| 6264 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6265 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6266 | enforceModifyPermission(); |
| 6267 | long identity = Binder.clearCallingIdentity(); |
| 6268 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6269 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6270 | |
| 6271 | Phone phone = getPhone(subId); |
| 6272 | if (phone == null) { |
| 6273 | try { |
| 6274 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6275 | } catch (RemoteException e) { |
| 6276 | // ignore |
| 6277 | } |
| 6278 | return; |
| 6279 | } |
| 6280 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6281 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6282 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6283 | boolean requireUssd = c.getBoolean( |
| 6284 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6285 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6286 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6287 | if (requireUssd) { |
| 6288 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6289 | getSubscriptionCarrierId(subId)); |
| 6290 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6291 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6292 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6293 | String newUssdCommand = ""; |
| 6294 | try { |
| 6295 | newUssdCommand = carrierXmlParser.getFeature( |
| 6296 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6297 | .makeCommand(ssAction, null); |
| 6298 | } catch (NullPointerException e) { |
| 6299 | loge("Failed to generate USSD number" + e); |
| 6300 | } |
| 6301 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6302 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6303 | final String ussdCommand = newUssdCommand; |
| 6304 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6305 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6306 | }); |
| 6307 | } else { |
| 6308 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6309 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6310 | |
| 6311 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6312 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6313 | } finally { |
| 6314 | Binder.restoreCallingIdentity(identity); |
| 6315 | } |
| 6316 | } |
| 6317 | |
| 6318 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6319 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6320 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6321 | * @param subId id of the subscription |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6322 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6323 | * location related information which will be sent if the caller already possess |
| 6324 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6325 | * @param request contains the radio access networks with bands/channels to scan |
| 6326 | * @param messenger callback messenger for scan results or errors |
| 6327 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6328 | * @return the id of the requested scan which can be used to stop the scan. |
| 6329 | */ |
| 6330 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6331 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6332 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6333 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6335 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6336 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6337 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6338 | if (!renounceFineLocationAccess) { |
| 6339 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6340 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6341 | .setCallingPackage(callingPackage) |
| 6342 | .setCallingFeatureId(callingFeatureId) |
| 6343 | .setCallingPid(Binder.getCallingPid()) |
| 6344 | .setCallingUid(Binder.getCallingUid()) |
| 6345 | .setMethod("requestNetworkScan") |
| 6346 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6347 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6348 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6349 | .build()); |
| 6350 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6351 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6352 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6353 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6354 | if (e != null) { |
| 6355 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6356 | throw e; |
| 6357 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6358 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6359 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6360 | } |
| 6361 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6362 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6363 | int callingUid = Binder.getCallingUid(); |
| 6364 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6365 | final long identity = Binder.clearCallingIdentity(); |
| 6366 | try { |
| 6367 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6368 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6369 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6370 | } finally { |
| 6371 | Binder.restoreCallingIdentity(identity); |
| 6372 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6373 | } |
| 6374 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6375 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6376 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6377 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6378 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6379 | boolean hasNetworkScanPermission = |
| 6380 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6381 | == PERMISSION_GRANTED; |
| 6382 | |
| 6383 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6384 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6385 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6389 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6390 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6391 | return new SecurityException("Specific channels must not be" |
| 6392 | + " scanned without location access."); |
| 6393 | } |
| 6394 | } |
| 6395 | } |
| 6396 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6397 | return null; |
| 6398 | } |
| 6399 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6400 | /** |
| 6401 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6402 | * |
| 6403 | * @param subId id of the subscription |
| 6404 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6405 | */ |
| 6406 | @Override |
| 6407 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6408 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6409 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6410 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6411 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | final long identity = Binder.clearCallingIdentity(); |
| 6413 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6414 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | } finally { |
| 6416 | Binder.restoreCallingIdentity(identity); |
| 6417 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6418 | } |
| 6419 | |
| 6420 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6421 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6422 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6423 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6424 | */ |
| 6425 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6426 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6427 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6428 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6429 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6430 | |
| 6431 | final long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6433 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6434 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6435 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6436 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6437 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | } finally { |
| 6439 | Binder.restoreCallingIdentity(identity); |
| 6440 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6444 | * Get the allowed network types for certain reason. |
| 6445 | * |
| 6446 | * @param subId the id of the subscription. |
| 6447 | * @param reason the reason the allowed network type change is taking place |
| 6448 | * @return the allowed network types. |
| 6449 | */ |
| 6450 | @Override |
| 6451 | public long getAllowedNetworkTypesForReason(int subId, |
| 6452 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6453 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6454 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6455 | final long identity = Binder.clearCallingIdentity(); |
| 6456 | try { |
| 6457 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6458 | } finally { |
| 6459 | Binder.restoreCallingIdentity(identity); |
| 6460 | } |
| 6461 | } |
| 6462 | |
| 6463 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6464 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6465 | * @param subId subscription id of the sim card |
| 6466 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6467 | * This can be passed following states |
| 6468 | * <ol> |
| 6469 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6470 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6471 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6472 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6473 | * </ol> |
| 6474 | * @return operation result. |
| 6475 | */ |
| 6476 | @Override |
| 6477 | public int setNrDualConnectivityState(int subId, |
| 6478 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6479 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6480 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6481 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6482 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6483 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6484 | } |
| 6485 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6486 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6487 | final long identity = Binder.clearCallingIdentity(); |
| 6488 | try { |
| 6489 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6490 | nrDualConnectivityState, subId, |
| 6491 | workSource); |
| 6492 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6493 | return result; |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
| 6496 | } |
| 6497 | } |
| 6498 | |
| 6499 | /** |
| 6500 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6501 | * @return true if dual connectivity is enabled else false |
| 6502 | */ |
| 6503 | @Override |
| 6504 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6505 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6506 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6507 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6508 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6509 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6510 | return false; |
| 6511 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6512 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6513 | final long identity = Binder.clearCallingIdentity(); |
| 6514 | try { |
| 6515 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6516 | null, subId, workSource); |
| 6517 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6518 | return isEnabled; |
| 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6525 | * Set the allowed network types of the device and |
| 6526 | * provide the reason triggering the allowed network change. |
| 6527 | * |
| 6528 | * @param subId the id of the subscription. |
| 6529 | * @param reason the reason the allowed network type change is taking place |
| 6530 | * @param allowedNetworkTypes the allowed network types. |
| 6531 | * @return true on success; false on any failure. |
| 6532 | */ |
| 6533 | @Override |
| 6534 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6535 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6536 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6538 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6539 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6540 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6541 | return false; |
| 6542 | } |
| 6543 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6544 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6545 | return false; |
| 6546 | } |
| 6547 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6548 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6549 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6550 | |
| 6551 | |
| 6552 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6553 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6554 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6555 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6556 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6559 | Boolean success = (Boolean) sendRequest( |
| 6560 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6561 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6562 | |
| 6563 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6564 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6565 | } finally { |
| 6566 | Binder.restoreCallingIdentity(identity); |
| 6567 | } |
| 6568 | } |
| 6569 | |
| 6570 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6571 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6572 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6573 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6574 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6575 | * @hide |
| 6576 | */ |
| 6577 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6578 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6579 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6580 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6581 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6582 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6583 | if (phone != null) { |
| 6584 | return phone.hasMatchedTetherApnSetting(); |
| 6585 | } else { |
| 6586 | return false; |
| 6587 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6588 | } finally { |
| 6589 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6590 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6594 | * Get the user enabled state of Mobile Data. |
| 6595 | * |
| 6596 | * TODO: remove and use isUserDataEnabled. |
| 6597 | * This can't be removed now because some vendor codes |
| 6598 | * calls through ITelephony directly while they should |
| 6599 | * use TelephonyManager. |
| 6600 | * |
| 6601 | * @return true on enabled |
| 6602 | */ |
| 6603 | @Override |
| 6604 | public boolean getDataEnabled(int subId) { |
| 6605 | return isUserDataEnabled(subId); |
| 6606 | } |
| 6607 | |
| 6608 | /** |
| 6609 | * Get whether mobile data is enabled per user setting. |
| 6610 | * |
| 6611 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6612 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6613 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6614 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6615 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6616 | * |
| 6617 | * @return {@code true} if data is enabled else {@code false} |
| 6618 | */ |
| 6619 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6620 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6621 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6622 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6623 | try { |
| 6624 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6625 | functionName); |
| 6626 | } catch (Exception e) { |
| 6627 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6628 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6629 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6631 | mApp, subId, functionName); |
| 6632 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6633 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6634 | |
| 6635 | final long identity = Binder.clearCallingIdentity(); |
| 6636 | try { |
| 6637 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6638 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6639 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6640 | if (phone != null) { |
| 6641 | boolean retVal = phone.isUserDataEnabled(); |
| 6642 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6643 | return retVal; |
| 6644 | } else { |
| 6645 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6646 | return false; |
| 6647 | } |
| 6648 | } finally { |
| 6649 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6650 | } |
| 6651 | } |
| 6652 | |
| 6653 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6654 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6655 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6656 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6657 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6658 | * @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] | 6659 | */ |
| 6660 | @Override |
| 6661 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6662 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6663 | try { |
| 6664 | try { |
| 6665 | mApp.enforceCallingOrSelfPermission( |
| 6666 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6667 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6668 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6669 | try { |
| 6670 | mApp.enforceCallingOrSelfPermission( |
| 6671 | android.Manifest.permission.READ_PHONE_STATE, |
| 6672 | functionName); |
| 6673 | } catch (Exception e2) { |
| 6674 | mApp.enforceCallingOrSelfPermission( |
| 6675 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6676 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6677 | } |
| 6678 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6679 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6680 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6681 | |
| 6682 | final long identity = Binder.clearCallingIdentity(); |
| 6683 | try { |
| 6684 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6685 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6686 | if (phone != null) { |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6687 | boolean retVal; |
| 6688 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 2c094c5 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6689 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 4ad64e5 | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6690 | } else { |
| 6691 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6692 | } |
| 6693 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6694 | return retVal; |
| 6695 | } else { |
| 6696 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6697 | return false; |
| 6698 | } |
| 6699 | } finally { |
| 6700 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6701 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6702 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6703 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6704 | /** |
| 6705 | * Check if data is enabled for a specific reason |
| 6706 | * @param subId Subscription index |
| 6707 | * @param reason the reason the data enable change is taking place |
| 6708 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6709 | */ |
| 6710 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6711 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6712 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6713 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6714 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6715 | try { |
| 6716 | mApp.enforceCallingOrSelfPermission( |
| 6717 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6718 | functionName); |
| 6719 | } catch (Exception e) { |
| 6720 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6721 | functionName); |
| 6722 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6723 | } catch (Exception e) { |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6724 | try { |
| 6725 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6726 | functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6727 | } catch (Exception e2) { |
| 6728 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6729 | mApp, subId, functionName); |
Sooraj Sasindran | 0d909a0 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6730 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | |
| 6734 | final long identity = Binder.clearCallingIdentity(); |
| 6735 | try { |
| 6736 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6737 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6738 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6739 | + " reason=" + reason); |
| 6740 | } |
| 6741 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6742 | if (phone != null) { |
| 6743 | boolean retVal; |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6744 | if (phone.isUsingNewDataStack()) { |
| 6745 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6746 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6747 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6748 | retVal = phone.isUserDataEnabled(); |
| 6749 | } else { |
| 6750 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6751 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6752 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6753 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6754 | return retVal; |
| 6755 | } else { |
| 6756 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6757 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6758 | + subId + " retVal=false"); |
| 6759 | } |
| 6760 | return false; |
| 6761 | } |
| 6762 | } finally { |
| 6763 | Binder.restoreCallingIdentity(identity); |
| 6764 | } |
| 6765 | } |
| 6766 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6767 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6768 | Phone phone) { |
Sarah Chin | 3394efe | 2021-04-09 10:37:15 -0700 | [diff] [blame] | 6769 | if (uid == Process.PHONE_UID) { |
| 6770 | // Skip the check if it's the phone UID (system UID removed in b/184713596) |
| 6771 | // 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] | 6772 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6773 | } |
| 6774 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6775 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6776 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6777 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6778 | || subController == null) return privilegeFromSim; |
| 6779 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6780 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6781 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6782 | |
| 6783 | final long identity = Binder.clearCallingIdentity(); |
| 6784 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6785 | int subId = phone.getSubId(); |
| 6786 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6787 | // A test override is in place for the privileges for this subId, so don't try to |
| 6788 | // read the subscription privileges. |
| 6789 | return privilegeFromSim; |
| 6790 | } |
| 6791 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6792 | SubscriptionManager subManager = (SubscriptionManager) |
| 6793 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6794 | for (String pkg : packages) { |
| 6795 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6796 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6797 | } |
| 6798 | } |
| 6799 | return privilegeFromSim; |
| 6800 | } finally { |
| 6801 | Binder.restoreCallingIdentity(identity); |
| 6802 | } |
| 6803 | } |
| 6804 | |
| 6805 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6806 | String pkgName) { |
| 6807 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6808 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6809 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6810 | || subController == null) return privilegeFromSim; |
| 6811 | |
| 6812 | final long identity = Binder.clearCallingIdentity(); |
| 6813 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6814 | int subId = phone.getSubId(); |
| 6815 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6816 | // A test override is in place for the privileges for this subId, so don't try to |
| 6817 | // read the subscription privileges. |
| 6818 | return privilegeFromSim; |
| 6819 | } |
| 6820 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6821 | SubscriptionManager subManager = (SubscriptionManager) |
| 6822 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6823 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6824 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
| 6827 | } |
| 6828 | } |
| 6829 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6830 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6831 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6832 | // No permission needed; this only lets the caller inspect their own status. |
| 6833 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6834 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6835 | |
| 6836 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6837 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6838 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6839 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6840 | } |
| 6841 | |
| 6842 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6843 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6844 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6845 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6846 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6847 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6848 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6849 | if (cpt == null) { |
| 6850 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6851 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6852 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6853 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6857 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6858 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6859 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6860 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6861 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6862 | Phone phone = getPhone(subId); |
| 6863 | if (phone == null) { |
| 6864 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6865 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6866 | } |
| 6867 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6868 | if (cpt == null) { |
| 6869 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6870 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6871 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6872 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6873 | } |
| 6874 | |
| 6875 | @Override |
| 6876 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6877 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6878 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6879 | } |
| 6880 | |
| 6881 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6882 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6883 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6884 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6885 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6886 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6887 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6888 | if (phone == null) { |
| 6889 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6890 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6891 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6892 | if (cpt == null) { |
| 6893 | continue; |
| 6894 | } |
| 6895 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6896 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6897 | break; |
| 6898 | } |
| 6899 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6900 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6901 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6902 | |
| 6903 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6904 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6905 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6906 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6907 | if (phone == null) { |
| 6908 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6909 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6910 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6911 | if (cpt == null) { |
| 6912 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6913 | } |
Rambo Wang | 8a247eb | 2022-02-08 21:11:18 +0000 | [diff] [blame] | 6914 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6915 | } |
| 6916 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6917 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6918 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6919 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6920 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6921 | if (phone == null) { |
| 6922 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6923 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6924 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6925 | if (cpt == null) { |
| 6926 | return Collections.emptyList(); |
| 6927 | } |
| 6928 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6929 | } |
| 6930 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6931 | @Override |
| 6932 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6933 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6934 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6935 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6936 | try { |
| 6937 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6938 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6939 | } |
| 6940 | } finally { |
| 6941 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6942 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6943 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6944 | } |
| 6945 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6946 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6947 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6948 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6949 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6950 | return null; |
| 6951 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6952 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6953 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6954 | return null; |
| 6955 | } |
| 6956 | return iccId; |
| 6957 | } |
| 6958 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6959 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6960 | public void setCallComposerStatus(int subId, int status) { |
| 6961 | enforceModifyPermission(); |
| 6962 | |
| 6963 | final long identity = Binder.clearCallingIdentity(); |
| 6964 | try { |
| 6965 | Phone phone = getPhone(subId); |
| 6966 | if (phone != null) { |
| 6967 | Phone defaultPhone = phone.getImsPhone(); |
| 6968 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6969 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6970 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6971 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6972 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6973 | } |
| 6974 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6975 | } catch (ImsException e) { |
| 6976 | throw new ServiceSpecificException(e.getCode()); |
| 6977 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6978 | Binder.restoreCallingIdentity(identity); |
| 6979 | } |
| 6980 | } |
| 6981 | |
| 6982 | @Override |
| 6983 | public int getCallComposerStatus(int subId) { |
| 6984 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6985 | |
| 6986 | final long identity = Binder.clearCallingIdentity(); |
| 6987 | try { |
| 6988 | Phone phone = getPhone(subId); |
| 6989 | if (phone != null) { |
| 6990 | Phone defaultPhone = phone.getImsPhone(); |
| 6991 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6992 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6993 | return imsPhone.getCallComposerStatus(); |
| 6994 | } |
| 6995 | } |
| 6996 | } finally { |
| 6997 | Binder.restoreCallingIdentity(identity); |
| 6998 | } |
| 6999 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 7000 | } |
| 7001 | |
| 7002 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7003 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 7004 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7005 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7006 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7007 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | final long identity = Binder.clearCallingIdentity(); |
| 7009 | try { |
| 7010 | final String iccId = getIccId(subId); |
| 7011 | final Phone phone = getPhone(subId); |
| 7012 | if (phone == null) { |
| 7013 | return false; |
| 7014 | } |
| 7015 | final String subscriberId = phone.getSubscriberId(); |
| 7016 | |
| 7017 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7018 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | + subscriberId + " to " + number); |
| 7020 | } |
| 7021 | |
| 7022 | if (TextUtils.isEmpty(iccId)) { |
| 7023 | return false; |
| 7024 | } |
| 7025 | |
| 7026 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 7027 | |
| 7028 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7029 | if (alphaTag == null) { |
| 7030 | editor.remove(alphaTagPrefKey); |
| 7031 | } else { |
| 7032 | editor.putString(alphaTagPrefKey, alphaTag); |
| 7033 | } |
| 7034 | |
| 7035 | // Record both the line number and IMSI for this ICCID, since we need to |
| 7036 | // track all merged IMSIs based on line number |
| 7037 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7038 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7039 | if (number == null) { |
| 7040 | editor.remove(numberPrefKey); |
| 7041 | editor.remove(subscriberPrefKey); |
| 7042 | } else { |
| 7043 | editor.putString(numberPrefKey, number); |
| 7044 | editor.putString(subscriberPrefKey, subscriberId); |
| 7045 | } |
| 7046 | |
| 7047 | editor.commit(); |
| 7048 | return true; |
| 7049 | } finally { |
| 7050 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 7051 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7052 | } |
| 7053 | |
| 7054 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7055 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 7056 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 7057 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7058 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7059 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7060 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7061 | return null; |
| 7062 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7063 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 | final long identity = Binder.clearCallingIdentity(); |
| 7065 | try { |
| 7066 | String iccId = getIccId(subId); |
| 7067 | if (iccId != null) { |
| 7068 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7069 | if (DBG_MERGE) { |
| 7070 | log("getLine1NumberForDisplay returning " |
| 7071 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7072 | } |
| 7073 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7074 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7076 | return null; |
| 7077 | } finally { |
| 7078 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7079 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7080 | } |
| 7081 | |
| 7082 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7083 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7084 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7085 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7086 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7087 | return null; |
| 7088 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | final long identity = Binder.clearCallingIdentity(); |
| 7091 | try { |
| 7092 | String iccId = getIccId(subId); |
| 7093 | if (iccId != null) { |
| 7094 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7095 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7096 | } |
| 7097 | return null; |
| 7098 | } finally { |
| 7099 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7100 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7101 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7102 | |
| 7103 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7104 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7105 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7106 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7107 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7108 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7109 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7110 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7111 | return null; |
| 7112 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7113 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7114 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7115 | // the process, where TelephonyManager was instantiated. |
| 7116 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7117 | final long identity = Binder.clearCallingIdentity(); |
| 7118 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7119 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7121 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7122 | |
| 7123 | // Figure out what subscribers are currently active |
| 7124 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7125 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7126 | // Only consider subs which match the current subId |
| 7127 | // This logic can be simplified. See b/131189269 for progress. |
| 7128 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7129 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7130 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | |
| 7132 | // First pass, find a number override for an active subscriber |
| 7133 | String mergeNumber = null; |
| 7134 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7135 | for (String key : prefs.keySet()) { |
| 7136 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7137 | final String subscriberId = (String) prefs.get(key); |
| 7138 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7139 | final String iccId = key.substring( |
| 7140 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7141 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7142 | mergeNumber = (String) prefs.get(numberKey); |
| 7143 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7144 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | + " for active subscriber " + subscriberId); |
| 7146 | } |
| 7147 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7148 | break; |
| 7149 | } |
| 7150 | } |
| 7151 | } |
| 7152 | } |
| 7153 | |
| 7154 | // Shortcut when no active merged subscribers |
| 7155 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7156 | return null; |
| 7157 | } |
| 7158 | |
| 7159 | // Second pass, find all subscribers under that line override |
| 7160 | final ArraySet<String> result = new ArraySet<>(); |
| 7161 | for (String key : prefs.keySet()) { |
| 7162 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7163 | final String number = (String) prefs.get(key); |
| 7164 | if (mergeNumber.equals(number)) { |
| 7165 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7166 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7167 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7168 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7169 | result.add(subscriberId); |
| 7170 | } |
| 7171 | } |
| 7172 | } |
| 7173 | } |
| 7174 | |
| 7175 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7176 | Arrays.sort(resultArray); |
| 7177 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7178 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7180 | } |
| 7181 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7182 | } finally { |
| 7183 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7184 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7185 | } |
| 7186 | |
| 7187 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7188 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7189 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7190 | |
| 7191 | final long identity = Binder.clearCallingIdentity(); |
| 7192 | try { |
| 7193 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7194 | TelephonyManager.class); |
| 7195 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7196 | if (subscriberId == null) { |
| 7197 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7198 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7199 | + subId); |
| 7200 | } |
| 7201 | return null; |
| 7202 | } |
| 7203 | |
| 7204 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7205 | .getSubscriptionInfo(subId); |
| 7206 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7207 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7208 | if (groupUuid == null) { |
| 7209 | return new String[]{subscriberId}; |
| 7210 | } |
| 7211 | |
| 7212 | // Get all subscriberIds from the group. |
| 7213 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7214 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7215 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7216 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7217 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7218 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7219 | if (subscriberId != null) { |
| 7220 | mergedSubscriberIds.add(subscriberId); |
| 7221 | } |
| 7222 | } |
| 7223 | |
| 7224 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
| 7227 | |
| 7228 | } |
| 7229 | } |
| 7230 | |
| 7231 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7232 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7233 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7234 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | |
| 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
| 7238 | final Phone phone = getPhone(subId); |
| 7239 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
| 7242 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7243 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7244 | |
| 7245 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7246 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7247 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7248 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7249 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7250 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | |
| 7252 | final long identity = Binder.clearCallingIdentity(); |
| 7253 | try { |
| 7254 | final Phone phone = getPhone(subId); |
| 7255 | if (phone == null) { |
| 7256 | return false; |
| 7257 | } |
| 7258 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7259 | cdmaNonRoamingList); |
| 7260 | } finally { |
| 7261 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7262 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7263 | } |
| 7264 | |
| 7265 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7266 | @Deprecated |
| 7267 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7268 | enforceModifyPermission(); |
| 7269 | |
| 7270 | int returnValue = 0; |
| 7271 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7272 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7273 | if(result.exception == null) { |
| 7274 | if (result.result != null) { |
| 7275 | byte[] responseData = (byte[])(result.result); |
| 7276 | if(responseData.length > oemResp.length) { |
| 7277 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7278 | responseData.length + "bytes. Buffer Size is " + |
| 7279 | oemResp.length + "bytes."); |
| 7280 | } |
| 7281 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7282 | returnValue = responseData.length; |
| 7283 | } |
| 7284 | } else { |
| 7285 | CommandException ex = (CommandException) result.exception; |
| 7286 | returnValue = ex.getCommandError().ordinal(); |
| 7287 | if(returnValue > 0) returnValue *= -1; |
| 7288 | } |
| 7289 | } catch (RuntimeException e) { |
| 7290 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7291 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7292 | if(returnValue > 0) returnValue *= -1; |
| 7293 | } |
| 7294 | |
| 7295 | return returnValue; |
| 7296 | } |
| 7297 | |
| 7298 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7299 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7300 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7301 | try { |
| 7302 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7303 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7304 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7305 | } catch (SecurityException e) { |
| 7306 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7307 | throw e; |
| 7308 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7309 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7310 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7311 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7312 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | final long identity = Binder.clearCallingIdentity(); |
| 7314 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7315 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7316 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7317 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7318 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7319 | } finally { |
| 7320 | Binder.restoreCallingIdentity(identity); |
| 7321 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7322 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7323 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7324 | |
| 7325 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7326 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7327 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7328 | try { |
| 7329 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7330 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7331 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7332 | } |
| 7333 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7334 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7335 | } |
| 7336 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7337 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7338 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7339 | throw new SecurityException("App must be the dialer role holder to" |
| 7340 | + " upload a call composer pic"); |
| 7341 | } |
| 7342 | |
| 7343 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7344 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7345 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7346 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7347 | boolean readUntilEnd = false; |
| 7348 | int totalBytesRead = 0; |
| 7349 | byte[] buffer = new byte[16 * 1024]; |
| 7350 | while (true) { |
| 7351 | int numRead; |
| 7352 | try { |
| 7353 | numRead = input.read(buffer); |
| 7354 | } catch (IOException e) { |
| 7355 | try { |
| 7356 | fd.checkError(); |
| 7357 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7358 | null); |
| 7359 | } catch (IOException e1) { |
| 7360 | // This means that the other side closed explicitly with an error. If this |
| 7361 | // happens, log and ignore. |
| 7362 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7363 | } |
| 7364 | break; |
| 7365 | } |
| 7366 | if (numRead == -1) { |
| 7367 | readUntilEnd = true; |
| 7368 | break; |
| 7369 | } |
| 7370 | totalBytesRead += numRead; |
| 7371 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7372 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7373 | try { |
| 7374 | input.close(); |
| 7375 | } catch (IOException e) { |
| 7376 | // ignore |
| 7377 | } |
| 7378 | break; |
| 7379 | } |
| 7380 | output.write(buffer, 0, numRead); |
| 7381 | } |
| 7382 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7383 | // close is above, where the picture size is too big. |
| 7384 | |
| 7385 | try { |
| 7386 | fd.checkError(); |
| 7387 | } catch (IOException e) { |
| 7388 | loge("Remote end for call composer closed with an error: " + e); |
| 7389 | return; |
| 7390 | } |
| 7391 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7392 | if (!readUntilEnd) { |
| 7393 | loge("Did not finish reading entire image; aborting"); |
| 7394 | return; |
| 7395 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7396 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7397 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7398 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7399 | new CallComposerPictureTransfer.Factory() {}, |
| 7400 | imageData, |
| 7401 | (result) -> { |
| 7402 | if (result.first != null) { |
| 7403 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7404 | Bundle outputResult = new Bundle(); |
| 7405 | outputResult.putParcelable( |
| 7406 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7407 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7408 | outputResult); |
| 7409 | } else { |
| 7410 | callback.send(result.second, null); |
| 7411 | } |
| 7412 | } |
| 7413 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7414 | }); |
| 7415 | } |
| 7416 | |
| 7417 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7418 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7419 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7420 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7421 | |
| 7422 | final long identity = Binder.clearCallingIdentity(); |
| 7423 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7424 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7425 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7426 | } finally { |
| 7427 | Binder.restoreCallingIdentity(identity); |
| 7428 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7432 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7433 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7434 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7435 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7436 | return false; |
| 7437 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | final long identity = Binder.clearCallingIdentity(); |
| 7440 | try { |
| 7441 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7442 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7443 | // In the long run, we may instead need to check if there exists a connection service |
| 7444 | // which can support video calling. |
| 7445 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7446 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7447 | return imsManager.isVtEnabledByPlatform() |
| 7448 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7449 | && imsManager.isVtEnabledByUser(); |
| 7450 | } finally { |
| 7451 | Binder.restoreCallingIdentity(identity); |
| 7452 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7453 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7454 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7455 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7456 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7457 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7459 | mApp, subId, callingPackage, callingFeatureId, |
| 7460 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | return false; |
| 7462 | } |
| 7463 | |
| 7464 | final long identity = Binder.clearCallingIdentity(); |
| 7465 | try { |
| 7466 | CarrierConfigManager configManager = |
| 7467 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7468 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7470 | } finally { |
| 7471 | Binder.restoreCallingIdentity(identity); |
| 7472 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7473 | } |
| 7474 | |
| 7475 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7476 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7478 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | return false; |
| 7480 | } |
| 7481 | |
| 7482 | final long identity = Binder.clearCallingIdentity(); |
| 7483 | try { |
| 7484 | CarrierConfigManager configManager = |
| 7485 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7486 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7487 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
| 7490 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7491 | } |
| 7492 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7493 | @Override |
| 7494 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7495 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7496 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | @Override |
| 7500 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7501 | final long identity = Binder.clearCallingIdentity(); |
| 7502 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7503 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | } finally { |
| 7505 | Binder.restoreCallingIdentity(identity); |
| 7506 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7507 | } |
| 7508 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7509 | /** |
| 7510 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7511 | * support for the feature and device firmware support. |
| 7512 | * |
| 7513 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7514 | */ |
| 7515 | @Override |
| 7516 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7518 | final Phone phone = getPhone(subscriptionId); |
| 7519 | if (phone == null) { |
| 7520 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7521 | return false; |
| 7522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7523 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7524 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7526 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7527 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | return isCarrierSupported && isDeviceSupported; |
| 7529 | } finally { |
| 7530 | Binder.restoreCallingIdentity(identity); |
| 7531 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7532 | } |
| 7533 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7534 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7535 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7536 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7537 | * 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] | 7538 | */ |
| 7539 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7540 | final long identity = Binder.clearCallingIdentity(); |
| 7541 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7542 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7543 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7544 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7545 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7546 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7547 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | } finally { |
| 7549 | Binder.restoreCallingIdentity(identity); |
| 7550 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7551 | } |
| 7552 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7553 | @Deprecated |
| 7554 | @Override |
| 7555 | public String getDeviceId(String callingPackage) { |
| 7556 | return getDeviceIdWithFeature(callingPackage, null); |
| 7557 | } |
| 7558 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7559 | /** |
| 7560 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7561 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7562 | * |
| 7563 | * <p>Requires Permission: |
| 7564 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7565 | */ |
| 7566 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7567 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7568 | try { |
| 7569 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7570 | } catch (SecurityException se) { |
| 7571 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7572 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7573 | + Binder.getCallingUid()); |
| 7574 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7575 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7576 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7577 | return null; |
| 7578 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7579 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7580 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7581 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7582 | return null; |
| 7583 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7584 | |
| 7585 | final long identity = Binder.clearCallingIdentity(); |
| 7586 | try { |
| 7587 | return phone.getDeviceId(); |
| 7588 | } finally { |
| 7589 | Binder.restoreCallingIdentity(identity); |
| 7590 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7591 | } |
| 7592 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7593 | /** |
| 7594 | * {@hide} |
| 7595 | * Returns the IMS Registration Status on a particular subid |
| 7596 | * |
| 7597 | * @param subId |
| 7598 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7599 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7600 | Phone phone = getPhone(subId); |
| 7601 | if (phone != null) { |
| 7602 | return phone.isImsRegistered(); |
| 7603 | } else { |
| 7604 | return false; |
| 7605 | } |
| 7606 | } |
| 7607 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7608 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7609 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7610 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7611 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7612 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7613 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7614 | } |
| 7615 | final long identity = Binder.clearCallingIdentity(); |
| 7616 | try { |
| 7617 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7618 | } finally { |
| 7619 | Binder.restoreCallingIdentity(identity); |
| 7620 | } |
| 7621 | } |
| 7622 | |
| 7623 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7624 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7625 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7626 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7627 | mApp, |
| 7628 | subscriptionId, |
| 7629 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | Phone phone = getPhone(subscriptionId); |
| 7633 | if (phone == null) { |
| 7634 | return null; |
| 7635 | } |
| 7636 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7637 | } finally { |
| 7638 | Binder.restoreCallingIdentity(identity); |
| 7639 | } |
| 7640 | } |
| 7641 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7642 | /** |
| 7643 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7644 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7645 | public boolean isWifiCallingAvailable(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.isWifiCallingEnabled(); |
| 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 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7657 | } |
| 7658 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7659 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7660 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7661 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7662 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7663 | final long identity = Binder.clearCallingIdentity(); |
| 7664 | try { |
| 7665 | Phone phone = getPhone(subId); |
| 7666 | if (phone != null) { |
| 7667 | return phone.isVideoEnabled(); |
| 7668 | } else { |
| 7669 | return false; |
| 7670 | } |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7673 | } |
| 7674 | } |
| 7675 | |
| 7676 | /** |
| 7677 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7678 | * defined in {@link ImsRegistrationImplBase}. |
| 7679 | */ |
| 7680 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7681 | final long identity = Binder.clearCallingIdentity(); |
| 7682 | try { |
| 7683 | Phone phone = getPhone(subId); |
| 7684 | if (phone != null) { |
| 7685 | return phone.getImsRegistrationTech(); |
| 7686 | } else { |
| 7687 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7688 | } |
| 7689 | } finally { |
| 7690 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7691 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7694 | @Override |
| 7695 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7696 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7697 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7698 | return; |
| 7699 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7700 | Phone defaultPhone = getDefaultPhone(); |
| 7701 | if (defaultPhone != null) { |
| 7702 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7703 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7704 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7705 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7706 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7707 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7708 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7709 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7710 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7711 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7712 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7713 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7714 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7715 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7716 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7717 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7718 | // There has been issues when Sms raw table somehow stores orphan |
| 7719 | // fragments. They lead to garbled message when new fragments come |
| 7720 | // in and combined with those stale ones. In case this happens again, |
| 7721 | // user can reset all network settings which will clean up this table. |
| 7722 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7723 | // Clean up IMS settings as well here. |
| 7724 | int slotId = getSlotIndex(subId); |
| 7725 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7726 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7727 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7728 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7729 | if (defaultPhone == null) { |
| 7730 | return; |
| 7731 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7732 | // Erase modem config if erase modem on network setting is enabled. |
| 7733 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7734 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7735 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7736 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7737 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7738 | |
| 7739 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7740 | } finally { |
| 7741 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7742 | } |
| 7743 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7744 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7745 | @VisibleForTesting |
| 7746 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7747 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7748 | return; |
| 7749 | } |
| 7750 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7751 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7752 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7753 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7754 | "user=" + defaultNetworkType); |
| 7755 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7756 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7757 | defaultNetworkType, null); |
| 7758 | } |
| 7759 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7760 | private void cleanUpSmsRawTable(Context context) { |
| 7761 | ContentResolver resolver = context.getContentResolver(); |
| 7762 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7763 | resolver.delete(uri, null, null); |
| 7764 | } |
| 7765 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7766 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7767 | public String getSimLocaleForSubscriber(int subId) { |
| 7768 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7769 | final Phone phone = getPhone(subId); |
| 7770 | if (phone == null) { |
| 7771 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7772 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7773 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7774 | final long identity = Binder.clearCallingIdentity(); |
| 7775 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7776 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7777 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7778 | if (info == null) { |
| 7779 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7780 | return null; |
| 7781 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7783 | // preferences (EF-PL and EF-LI)... |
| 7784 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7785 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7786 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7787 | if (localeFromDefaultSim != null) { |
| 7788 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7789 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7790 | + localeFromDefaultSim); |
| 7791 | return localeFromDefaultSim.toLanguageTag(); |
| 7792 | } else { |
| 7793 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | } |
| 7795 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7797 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7798 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7799 | // the SIM and carrier preferences does not include a country we add the country |
| 7800 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7801 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7802 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7803 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7804 | return mccLocale.toLanguageTag(); |
| 7805 | } |
| 7806 | |
| 7807 | if (DBG) log("No locale found - returning null"); |
| 7808 | return null; |
| 7809 | } finally { |
| 7810 | Binder.restoreCallingIdentity(identity); |
| 7811 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7812 | } |
| 7813 | |
| 7814 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7815 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7816 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7817 | } |
| 7818 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7819 | /** |
| 7820 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7821 | */ |
| 7822 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7823 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7824 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7825 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7826 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7827 | private ActivityStatsTechSpecificInfo[] mLastModemActivitySpecificInfo = null; |
| 7828 | private ModemActivityInfo mLastModemActivityInfo = null; |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7829 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7830 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7831 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7832 | * representing the state of the modem. |
| 7833 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7834 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7835 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7836 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7837 | */ |
| 7838 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7839 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7840 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7841 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7842 | |
| 7843 | final long identity = Binder.clearCallingIdentity(); |
| 7844 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7845 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7846 | } finally { |
| 7847 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7848 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7849 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7850 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7851 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7852 | // less than total activity duration. |
| 7853 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7854 | if (info == null) { |
| 7855 | return false; |
| 7856 | } |
| 7857 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7858 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7859 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7860 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7861 | return (info.isValid() |
| 7862 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7863 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7864 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7865 | && (totalTxTimeMs <= activityDurationMs)); |
| 7866 | } |
| 7867 | |
Gary Jian | 3aa9a76 | 2022-01-24 16:41:19 +0800 | [diff] [blame] | 7868 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat, int freq) { |
| 7869 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7870 | int[] txTimeMs = info.getTransmitTimeMillis(rat, freq); |
| 7871 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat, freq); |
| 7872 | |
| 7873 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7874 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7875 | } |
| 7876 | |
| 7877 | mLastModemActivityInfo.setTransmitTimeMillis(rat, freq, mergedTxTimeMs); |
| 7878 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7879 | rat, |
| 7880 | freq, |
| 7881 | info.getReceiveTimeMillis(rat, freq) |
| 7882 | + mLastModemActivityInfo.getReceiveTimeMillis(rat, freq)); |
| 7883 | } |
| 7884 | |
| 7885 | private void updateLastModemActivityInfo(ModemActivityInfo info, int rat) { |
| 7886 | int[] mergedTxTimeMs = new int [ModemActivityInfo.getNumTxPowerLevels()]; |
| 7887 | int[] txTimeMs = info.getTransmitTimeMillis(rat); |
| 7888 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(rat); |
| 7889 | |
| 7890 | for (int lvl = 0; lvl < mergedTxTimeMs.length; lvl++) { |
| 7891 | mergedTxTimeMs[lvl] = txTimeMs[lvl] + lastModemTxTimeMs[lvl]; |
| 7892 | } |
| 7893 | mLastModemActivityInfo.setTransmitTimeMillis(rat, mergedTxTimeMs); |
| 7894 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 7895 | rat, |
| 7896 | info.getReceiveTimeMillis(rat) + mLastModemActivityInfo.getReceiveTimeMillis(rat)); |
| 7897 | } |
| 7898 | |
| 7899 | /** |
| 7900 | * Merge this ModemActivityInfo with mLastModemActivitySpecificInfo |
| 7901 | * @param info recent ModemActivityInfo |
| 7902 | */ |
| 7903 | private void mergeModemActivityInfo(ModemActivityInfo info) { |
| 7904 | List<ActivityStatsTechSpecificInfo> merged = new ArrayList<>(); |
| 7905 | ActivityStatsTechSpecificInfo mDeltaSpecificInfo; |
| 7906 | boolean matched; |
| 7907 | for (int i = 0; i < info.getSpecificInfoLength(); i++) { |
| 7908 | matched = false; |
| 7909 | int rat = info.getSpecificInfoRat(i); |
| 7910 | int freq = info.getSpecificInfoFrequencyRange(i); |
| 7911 | //Check each ActivityStatsTechSpecificInfo in this ModemActivityInfo for new rat returns |
| 7912 | //Add a new ActivityStatsTechSpecificInfo if is a new rat, and merge with the original |
| 7913 | //if it already exists |
| 7914 | for (int j = 0; j < mLastModemActivitySpecificInfo.length; j++) { |
| 7915 | if (rat == mLastModemActivityInfo.getSpecificInfoRat(j) && !matched) { |
| 7916 | //Merged based on frequency range (MMWAVE vs SUB6) for 5G |
| 7917 | if (rat == AccessNetworkConstants.AccessNetworkType.NGRAN) { |
| 7918 | if (freq == mLastModemActivityInfo.getSpecificInfoFrequencyRange(j)) { |
| 7919 | updateLastModemActivityInfo(info, rat, freq); |
| 7920 | matched = true; |
| 7921 | } |
| 7922 | } else { |
| 7923 | updateLastModemActivityInfo(info, rat); |
| 7924 | matched = true; |
| 7925 | } |
| 7926 | } |
| 7927 | } |
| 7928 | |
| 7929 | if (!matched) { |
| 7930 | mDeltaSpecificInfo = |
| 7931 | new ActivityStatsTechSpecificInfo( |
| 7932 | rat, |
| 7933 | freq, |
| 7934 | info.getTransmitTimeMillis(rat, freq), |
| 7935 | (int) info.getReceiveTimeMillis(rat, freq)); |
| 7936 | merged.addAll(Arrays.asList(mDeltaSpecificInfo)); |
| 7937 | } |
| 7938 | } |
| 7939 | merged.addAll(Arrays.asList(mLastModemActivitySpecificInfo)); |
| 7940 | mLastModemActivitySpecificInfo = |
| 7941 | new ActivityStatsTechSpecificInfo[merged.size()]; |
| 7942 | merged.toArray(mLastModemActivitySpecificInfo); |
| 7943 | |
| 7944 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
| 7945 | mLastModemActivityInfo.setSleepTimeMillis( |
| 7946 | info.getSleepTimeMillis() |
| 7947 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 7948 | mLastModemActivityInfo.setIdleTimeMillis( |
| 7949 | info.getIdleTimeMillis() |
| 7950 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 7951 | } |
| 7952 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7953 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7954 | * Returns the service state information on specified subscription. |
| 7955 | */ |
| 7956 | @Override |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7957 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7958 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7959 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7960 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7961 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7962 | return null; |
| 7963 | } |
| 7964 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7965 | boolean hasFinePermission = false; |
| 7966 | boolean hasCoarsePermission = false; |
| 7967 | if (!renounceFineLocationAccess) { |
| 7968 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7969 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7970 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7971 | .setCallingPackage(callingPackage) |
| 7972 | .setCallingFeatureId(callingFeatureId) |
| 7973 | .setCallingPid(Binder.getCallingPid()) |
| 7974 | .setCallingUid(Binder.getCallingUid()) |
| 7975 | .setMethod("getServiceStateForSubscriber") |
| 7976 | .setLogAsInfo(true) |
| 7977 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7978 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7979 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7980 | .build()); |
| 7981 | hasFinePermission = |
| 7982 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7983 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7984 | |
Sooraj Sasindran | 2250dc0 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7985 | if (!renounceCoarseLocationAccess) { |
| 7986 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7987 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7988 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7989 | .setCallingPackage(callingPackage) |
| 7990 | .setCallingFeatureId(callingFeatureId) |
| 7991 | .setCallingPid(Binder.getCallingPid()) |
| 7992 | .setCallingUid(Binder.getCallingUid()) |
| 7993 | .setMethod("getServiceStateForSubscriber") |
| 7994 | .setLogAsInfo(true) |
| 7995 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7996 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7997 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7998 | .build()); |
| 7999 | hasCoarsePermission = |
| 8000 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 8001 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8002 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8003 | final Phone phone = getPhone(subId); |
| 8004 | if (phone == null) { |
| 8005 | return null; |
| 8006 | } |
| 8007 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 8008 | final long identity = Binder.clearCallingIdentity(); |
| 8009 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8010 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 8011 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8012 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 8013 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 8014 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 8015 | Rlog.d(LOG_TAG, |
| 8016 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 8017 | return null; |
| 8018 | } |
| 8019 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 8020 | ServiceState ss = phone.getServiceState(); |
| 8021 | |
| 8022 | // Scrub out the location info in ServiceState depending on what level of access |
| 8023 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 8024 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 8025 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 8026 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8027 | } finally { |
| 8028 | Binder.restoreCallingIdentity(identity); |
| 8029 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 8030 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8031 | |
| 8032 | /** |
| 8033 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 8034 | * |
| 8035 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8036 | * voicemail ringtone. |
| 8037 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 8038 | * PhoneAccount. |
| 8039 | */ |
| 8040 | @Override |
| 8041 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8042 | final long identity = Binder.clearCallingIdentity(); |
| 8043 | try { |
| 8044 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8045 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8046 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8047 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 8050 | } finally { |
| 8051 | Binder.restoreCallingIdentity(identity); |
| 8052 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8053 | } |
| 8054 | |
| 8055 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8056 | * Sets the per-account voicemail ringtone. |
| 8057 | * |
| 8058 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8059 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8060 | * |
| 8061 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8062 | * voicemail ringtone. |
| 8063 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 8064 | * PhoneAccount. |
| 8065 | */ |
| 8066 | @Override |
| 8067 | public void setVoicemailRingtoneUri(String callingPackage, |
| 8068 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8069 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8070 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8071 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8072 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8074 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8075 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8076 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8077 | |
| 8078 | final long identity = Binder.clearCallingIdentity(); |
| 8079 | try { |
| 8080 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8081 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8082 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8083 | } |
| 8084 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 8085 | } finally { |
| 8086 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8087 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8091 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 8092 | * |
| 8093 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 8094 | * voicemail vibration setting. |
| 8095 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 8096 | */ |
| 8097 | @Override |
| 8098 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8099 | final long identity = Binder.clearCallingIdentity(); |
| 8100 | try { |
| 8101 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 8102 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8103 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8104 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8106 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 8107 | } finally { |
| 8108 | Binder.restoreCallingIdentity(identity); |
| 8109 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 8110 | } |
| 8111 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8112 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8113 | * Sets the per-account voicemail vibration. |
| 8114 | * |
| 8115 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 8116 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8117 | * |
| 8118 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 8119 | * voicemail vibration setting. |
| 8120 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 8121 | * specific PhoneAccount. |
| 8122 | */ |
| 8123 | @Override |
| 8124 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 8125 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8126 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8127 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 8128 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 8129 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8130 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8131 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 8132 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8133 | } |
| 8134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 8138 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8139 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8140 | } |
| 8141 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8144 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 8145 | } |
| 8146 | |
| 8147 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8148 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8149 | * |
| 8150 | * @throws SecurityException if the caller does not have the required permission |
| 8151 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8152 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8153 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8154 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8155 | } |
| 8156 | |
| 8157 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8158 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8159 | * permission. |
| 8160 | * |
| 8161 | * @throws SecurityException if the caller does not have the required permission |
| 8162 | */ |
| 8163 | private void enforceSendSmsPermission() { |
| 8164 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8165 | } |
| 8166 | |
| 8167 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8168 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8169 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8170 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8171 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8172 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8173 | final long identity = Binder.clearCallingIdentity(); |
| 8174 | try { |
| 8175 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8176 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8177 | if (componentName == null) { |
| 8178 | throw new SecurityException( |
| 8179 | "Caller not current active visual voicemail package[null]"); |
| 8180 | } |
| 8181 | String vvmPackage = componentName.getPackageName(); |
| 8182 | if (!callingPackage.equals(vvmPackage)) { |
| 8183 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8184 | + vvmPackage + "]"); |
| 8185 | } |
| 8186 | } finally { |
| 8187 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8188 | } |
| 8189 | } |
| 8190 | |
| 8191 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8192 | * Return the application ID for the app type. |
| 8193 | * |
| 8194 | * @param subId the subscription ID that this request applies to. |
| 8195 | * @param appType the uicc app type. |
| 8196 | * @return Application ID for specificied app type, or null if no uicc. |
| 8197 | */ |
| 8198 | @Override |
| 8199 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8200 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8201 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8202 | |
| 8203 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8204 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8205 | if (phone == null) { |
| 8206 | return null; |
| 8207 | } |
| 8208 | String aid = null; |
| 8209 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8210 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8211 | .getApplicationByType(appType).getAid(); |
| 8212 | } catch (Exception e) { |
| 8213 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8214 | } |
| 8215 | return aid; |
| 8216 | } finally { |
| 8217 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8218 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8219 | } |
| 8220 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8221 | /** |
| 8222 | * Return the Electronic Serial Number. |
| 8223 | * |
| 8224 | * @param subId the subscription ID that this request applies to. |
| 8225 | * @return ESN or null if error. |
| 8226 | */ |
| 8227 | @Override |
| 8228 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8229 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8230 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8231 | |
| 8232 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8233 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8234 | if (phone == null) { |
| 8235 | return null; |
| 8236 | } |
| 8237 | String esn = null; |
| 8238 | try { |
| 8239 | esn = phone.getEsn(); |
| 8240 | } catch (Exception e) { |
| 8241 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8242 | } |
| 8243 | return esn; |
| 8244 | } finally { |
| 8245 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8246 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8247 | } |
| 8248 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8249 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8250 | * Return the Preferred Roaming List Version. |
| 8251 | * |
| 8252 | * @param subId the subscription ID that this request applies to. |
| 8253 | * @return PRLVersion or null if error. |
| 8254 | */ |
| 8255 | @Override |
| 8256 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8257 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8258 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8259 | |
| 8260 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8261 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8262 | if (phone == null) { |
| 8263 | return null; |
| 8264 | } |
| 8265 | String cdmaPrlVersion = null; |
| 8266 | try { |
| 8267 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8268 | } catch (Exception e) { |
| 8269 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8270 | } |
| 8271 | return cdmaPrlVersion; |
| 8272 | } finally { |
| 8273 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8274 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8275 | } |
| 8276 | |
| 8277 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8278 | * Get snapshot of Telephony histograms |
| 8279 | * @return List of Telephony histograms |
| 8280 | * @hide |
| 8281 | */ |
| 8282 | @Override |
| 8283 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8285 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8286 | |
| 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | return RIL.getTelephonyRILTimingHistograms(); |
| 8290 | } finally { |
| 8291 | Binder.restoreCallingIdentity(identity); |
| 8292 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8293 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8294 | |
| 8295 | /** |
| 8296 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8297 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8298 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8299 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8300 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8301 | * @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] | 8302 | */ |
| 8303 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8304 | @TelephonyManager.SetCarrierRestrictionResult |
| 8305 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8306 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8307 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8308 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8309 | if (carrierRestrictionRules == null) { |
| 8310 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8311 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8313 | final long identity = Binder.clearCallingIdentity(); |
| 8314 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8315 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8316 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | /** |
| 8323 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8324 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8325 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8326 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8327 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8328 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8329 | */ |
| 8330 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8331 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8332 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8333 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8334 | |
| 8335 | final long identity = Binder.clearCallingIdentity(); |
| 8336 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8337 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8338 | if (response instanceof CarrierRestrictionRules) { |
| 8339 | return (CarrierRestrictionRules) response; |
| 8340 | } |
| 8341 | // Response is an Exception of some kind, |
| 8342 | // which is signalled to the user as a NULL retval |
| 8343 | return null; |
| 8344 | } catch (Exception e) { |
| 8345 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8346 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8347 | } finally { |
| 8348 | Binder.restoreCallingIdentity(identity); |
| 8349 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8350 | } |
| 8351 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8352 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8353 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8354 | * @param subId the subscription ID that this action applies to. |
| 8355 | * @param enabled control enable or disable radio. |
| 8356 | * {@hide} |
| 8357 | */ |
| 8358 | @Override |
| 8359 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8360 | enforceModifyPermission(); |
| 8361 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8362 | |
| 8363 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8364 | if (phone == null) { |
| 8365 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8366 | return; |
| 8367 | } |
| 8368 | try { |
| 8369 | phone.carrierActionSetRadioEnabled(enabled); |
| 8370 | } catch (Exception e) { |
| 8371 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8374 | } |
| 8375 | } |
| 8376 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8377 | /** |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8378 | * Enable or disable Voice over NR (VoNR) |
| 8379 | * @param subId the subscription ID that this action applies to. |
| 8380 | * @param enabled enable or disable VoNR. |
| 8381 | * @return operation result. |
| 8382 | */ |
| 8383 | @Override |
| 8384 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8385 | enforceModifyPermission(); |
| 8386 | final Phone phone = getPhone(subId); |
| 8387 | |
| 8388 | final long identity = Binder.clearCallingIdentity(); |
| 8389 | if (phone == null) { |
| 8390 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8391 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8392 | } |
| 8393 | |
| 8394 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8395 | try { |
| 8396 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8397 | workSource); |
| 8398 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8399 | |
| 8400 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8401 | if (DBG) { |
| 8402 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8403 | } |
| 8404 | SubscriptionManager.setSubscriptionProperty( |
| 8405 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8406 | (enabled ? "1" : "0")); |
| 8407 | } |
| 8408 | |
Sooraj Sasindran | daf060f | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8409 | return result; |
| 8410 | } finally { |
| 8411 | Binder.restoreCallingIdentity(identity); |
| 8412 | } |
| 8413 | } |
| 8414 | |
| 8415 | /** |
| 8416 | * Is voice over NR enabled |
| 8417 | * @return true if VoNR is enabled else false |
| 8418 | */ |
| 8419 | @Override |
| 8420 | public boolean isVoNrEnabled(int subId) { |
| 8421 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8422 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8423 | final long identity = Binder.clearCallingIdentity(); |
| 8424 | try { |
| 8425 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8426 | null, subId, workSource); |
| 8427 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8428 | return isEnabled; |
| 8429 | } finally { |
| 8430 | Binder.restoreCallingIdentity(identity); |
| 8431 | } |
| 8432 | } |
| 8433 | |
| 8434 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8435 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8436 | * network status based on which carrier apps could apply actions accordingly, |
| 8437 | * enable/disable default url handler for example. |
| 8438 | * |
| 8439 | * @param subId the subscription ID that this action applies to. |
| 8440 | * @param report control start/stop reporting the default network status. |
| 8441 | * {@hide} |
| 8442 | */ |
| 8443 | @Override |
| 8444 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8445 | enforceModifyPermission(); |
| 8446 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8447 | |
| 8448 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8449 | if (phone == null) { |
| 8450 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8451 | return; |
| 8452 | } |
| 8453 | try { |
| 8454 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8455 | } catch (Exception e) { |
| 8456 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8457 | } finally { |
| 8458 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8459 | } |
| 8460 | } |
| 8461 | |
| 8462 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8463 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8464 | * @param subId the subscription ID that this action applies to. |
| 8465 | * {@hide} |
| 8466 | */ |
| 8467 | @Override |
| 8468 | public void carrierActionResetAll(int subId) { |
| 8469 | enforceModifyPermission(); |
| 8470 | final Phone phone = getPhone(subId); |
| 8471 | if (phone == null) { |
| 8472 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8473 | return; |
| 8474 | } |
| 8475 | try { |
| 8476 | phone.carrierActionResetAll(); |
| 8477 | } catch (Exception e) { |
| 8478 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8479 | } |
| 8480 | } |
| 8481 | |
| 8482 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8483 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8484 | * bug report is being generated. |
| 8485 | */ |
| 8486 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8487 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8488 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8489 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8490 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8491 | + Binder.getCallingPid() |
| 8492 | + ", uid=" + Binder.getCallingUid() |
| 8493 | + "without permission " |
| 8494 | + android.Manifest.permission.DUMP); |
| 8495 | return; |
| 8496 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8497 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8498 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8499 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8500 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8501 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8502 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8503 | @NonNull String[] args) { |
| 8504 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8505 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8506 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8507 | } |
| 8508 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8509 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8510 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8511 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8512 | * @param reason the reason the data enable change is taking place |
| 8513 | * @param enabled True if enabling the data, otherwise disabling. |
| 8514 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8515 | */ |
| 8516 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8517 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8518 | boolean enabled) { |
| 8519 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8520 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8521 | try { |
| 8522 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8523 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8524 | } catch (SecurityException se) { |
| 8525 | enforceModifyPermission(); |
| 8526 | } |
| 8527 | } else { |
| 8528 | enforceModifyPermission(); |
| 8529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8530 | |
| 8531 | final long identity = Binder.clearCallingIdentity(); |
| 8532 | try { |
| 8533 | Phone phone = getPhone(subId); |
| 8534 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8535 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8536 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8537 | } else { |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8538 | if (phone.isUsingNewDataStack()) { |
| 8539 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8540 | } else { |
| 8541 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8542 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8543 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8544 | } |
| 8545 | } finally { |
| 8546 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8547 | } |
| 8548 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8549 | |
| 8550 | /** |
| 8551 | * Get Client request stats |
| 8552 | * @return List of Client Request Stats |
| 8553 | * @hide |
| 8554 | */ |
| 8555 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8556 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8557 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8558 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8559 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8560 | return null; |
| 8561 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8562 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8564 | final long identity = Binder.clearCallingIdentity(); |
| 8565 | try { |
| 8566 | if (phone != null) { |
| 8567 | return phone.getClientRequestStats(); |
| 8568 | } |
| 8569 | |
| 8570 | return null; |
| 8571 | } finally { |
| 8572 | Binder.restoreCallingIdentity(identity); |
| 8573 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8574 | } |
| 8575 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8576 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8577 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8578 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8579 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8580 | |
| 8581 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8582 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8583 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8584 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8585 | * @param state State of SIM (power down, power up, pass through) |
| 8586 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8587 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8588 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8589 | * |
| 8590 | **/ |
| 8591 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8592 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8593 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8594 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8595 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8596 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8597 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8601 | phone.setSimPowerState(state, null, workSource); |
| 8602 | } |
| 8603 | } finally { |
| 8604 | Binder.restoreCallingIdentity(identity); |
| 8605 | } |
| 8606 | } |
| 8607 | |
| 8608 | /** |
| 8609 | * Set SIM card power state. |
| 8610 | * |
| 8611 | * @param slotIndex SIM slot id. |
| 8612 | * @param state State of SIM (power down, power up, pass through) |
| 8613 | * @param callback callback to trigger after success or failure |
| 8614 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8615 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8616 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8617 | * |
| 8618 | **/ |
| 8619 | @Override |
| 8620 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8621 | IIntegerConsumer callback) { |
| 8622 | enforceModifyPermission(); |
| 8623 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8624 | |
| 8625 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8626 | |
| 8627 | final long identity = Binder.clearCallingIdentity(); |
| 8628 | try { |
| 8629 | if (phone != null) { |
| 8630 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8631 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8632 | } |
| 8633 | } finally { |
| 8634 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8635 | } |
| 8636 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8637 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8638 | private boolean isUssdApiAllowed(int subId) { |
| 8639 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8640 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8641 | if (configManager == null) { |
| 8642 | return false; |
| 8643 | } |
| 8644 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8645 | if (pb == null) { |
| 8646 | return false; |
| 8647 | } |
| 8648 | return pb.getBoolean( |
| 8649 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8650 | } |
| 8651 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8652 | /** |
| 8653 | * Check if phone is in emergency callback mode |
| 8654 | * @return true if phone is in emergency callback mode |
| 8655 | * @param subId sub id |
| 8656 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8657 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8658 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8659 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8660 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8661 | |
| 8662 | final long identity = Binder.clearCallingIdentity(); |
| 8663 | try { |
| 8664 | if (phone != null) { |
| 8665 | return phone.isInEcm(); |
| 8666 | } else { |
| 8667 | return false; |
| 8668 | } |
| 8669 | } finally { |
| 8670 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8671 | } |
| 8672 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8673 | |
| 8674 | /** |
| 8675 | * Get the current signal strength information for the given subscription. |
| 8676 | * Because this information is not updated when the device is in a low power state |
| 8677 | * it should not be relied-upon to be current. |
| 8678 | * @param subId Subscription index |
| 8679 | * @return the most recent cached signal strength info from the modem |
| 8680 | */ |
| 8681 | @Override |
| 8682 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8683 | final long identity = Binder.clearCallingIdentity(); |
| 8684 | try { |
| 8685 | Phone p = getPhone(subId); |
| 8686 | if (p == null) { |
| 8687 | return null; |
| 8688 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8690 | return p.getSignalStrength(); |
| 8691 | } finally { |
| 8692 | Binder.restoreCallingIdentity(identity); |
| 8693 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8694 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8695 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8696 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8697 | * Get the current modem radio state for the given slot. |
| 8698 | * @param slotIndex slot index. |
| 8699 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8700 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8701 | * @return the current radio power state from the modem |
| 8702 | */ |
| 8703 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8704 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8705 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8706 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8708 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8709 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8710 | } |
| 8711 | |
| 8712 | final long identity = Binder.clearCallingIdentity(); |
| 8713 | try { |
| 8714 | return phone.getRadioPowerState(); |
| 8715 | } finally { |
| 8716 | Binder.restoreCallingIdentity(identity); |
| 8717 | } |
| 8718 | } |
| 8719 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8720 | } |
| 8721 | |
| 8722 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8723 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8724 | * |
| 8725 | * <p>Requires one of the following permissions: |
| 8726 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8727 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8728 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8729 | * privileges. |
| 8730 | * |
| 8731 | * @param subId subscription id |
| 8732 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8733 | * {@code false}. |
| 8734 | */ |
| 8735 | @Override |
| 8736 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8737 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8738 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8739 | try { |
| 8740 | mApp.enforceCallingOrSelfPermission( |
| 8741 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8742 | functionName); |
| 8743 | } catch (Exception e) { |
| 8744 | mApp.enforceCallingOrSelfPermission( |
| 8745 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8746 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8747 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8748 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8749 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8750 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8751 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8752 | boolean isEnabled = false; |
| 8753 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8754 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8755 | Phone phone = getPhone(subId); |
| 8756 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8757 | } finally { |
| 8758 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8760 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8761 | } |
| 8762 | |
| 8763 | |
| 8764 | /** |
| 8765 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8766 | * |
| 8767 | * <p> Requires permission: |
| 8768 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8769 | * privileges. |
| 8770 | * |
| 8771 | * @param subId subscription id |
| 8772 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8773 | */ |
| 8774 | @Override |
| 8775 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8776 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8777 | mApp, subId, "setDataRoamingEnabled"); |
| 8778 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8779 | final long identity = Binder.clearCallingIdentity(); |
| 8780 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8781 | Phone phone = getPhone(subId); |
| 8782 | if (phone != null) { |
| 8783 | phone.setDataRoamingEnabled(isEnabled); |
| 8784 | } |
| 8785 | } finally { |
| 8786 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8787 | } |
| 8788 | } |
| 8789 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8790 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8791 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8792 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8793 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8794 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8795 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8796 | boolean isAllowed = true; |
| 8797 | final long identity = Binder.clearCallingIdentity(); |
| 8798 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8799 | Phone phone = getPhone(subId); |
| 8800 | if (phone != null) { |
| 8801 | isAllowed = phone.isCspPlmnEnabled(); |
| 8802 | } |
| 8803 | } finally { |
| 8804 | Binder.restoreCallingIdentity(identity); |
| 8805 | } |
| 8806 | return isAllowed; |
| 8807 | } |
| 8808 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8809 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8810 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8811 | if (profile == null) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8812 | return false; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8813 | } |
Hunter Knepshield | cad7f0b | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8814 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8815 | if (phone == null) { |
| 8816 | return false; |
| 8817 | } |
| 8818 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8819 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8820 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8821 | } |
| 8822 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8823 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8824 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8825 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8826 | mApp.getSystemService(AppOpsManager.class) |
| 8827 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8828 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8829 | boolean hasReadPermission = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8830 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8831 | try { |
| 8832 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8833 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8834 | } catch (SecurityException e) { |
| 8835 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8836 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8837 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8838 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8839 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8840 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8841 | } |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8842 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8843 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8844 | Binder.getCallingUid())) { |
| 8845 | isIccIdAccessRestricted = true; |
| 8846 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8847 | final long identity = Binder.clearCallingIdentity(); |
| 8848 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8849 | UiccController uiccController = UiccController.getInstance(); |
| 8850 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8851 | if (hasReadPermission) { |
| 8852 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8853 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8854 | |
| 8855 | // Remove private info if the caller doesn't have access |
| 8856 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8857 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8858 | //setting the value after compatibility check |
| 8859 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8860 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8861 | // is available |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8862 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8863 | if (card == null) { |
| 8864 | // assume no access if the card is unavailable |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8865 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8866 | continue; |
| 8867 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8868 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8869 | if (portInfos.isEmpty()) { |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8870 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8871 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8872 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8873 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8874 | for (UiccPortInfo portInfo : portInfos) { |
| 8875 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8876 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8877 | if (port == null) { |
| 8878 | // assume no access if port is null |
| 8879 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8880 | continue; |
| 8881 | } |
| 8882 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8883 | uiccPortInfos.add(portInfo); |
| 8884 | } else { |
| 8885 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8886 | } |
| 8887 | } |
| 8888 | filteredInfos.add(new UiccCardInfo( |
| 8889 | cardInfo.isEuicc(), |
| 8890 | cardInfo.getCardId(), |
| 8891 | null, |
| 8892 | cardInfo.getPhysicalSlotIndex(), |
| 8893 | cardInfo.isRemovable(), |
| 8894 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8895 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8896 | } |
| 8897 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8898 | } finally { |
| 8899 | Binder.restoreCallingIdentity(identity); |
| 8900 | } |
| 8901 | } |
| 8902 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8903 | /** |
| 8904 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8905 | * generally private and require carrier privileges to view. |
| 8906 | * |
| 8907 | * @hide |
| 8908 | */ |
| 8909 | @NonNull |
| 8910 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8911 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8912 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8913 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8914 | } |
| 8915 | return new UiccCardInfo( |
| 8916 | cardInfo.isEuicc(), |
| 8917 | cardInfo.getCardId(), |
| 8918 | null, |
| 8919 | cardInfo.getPhysicalSlotIndex(), |
| 8920 | cardInfo.isRemovable(), |
| 8921 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8922 | portinfo |
| 8923 | ); |
| 8924 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8925 | |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8926 | /** |
| 8927 | * @hide |
| 8928 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8929 | * These values are generally private and require carrier privileges to view. |
| 8930 | */ |
| 8931 | @NonNull |
| 8932 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8933 | return new UiccPortInfo( |
| 8934 | UiccPortInfo.ICCID_REDACTED, |
| 8935 | portInfo.getPortIndex(), |
| 8936 | portInfo.getLogicalSlotIndex(), |
| 8937 | portInfo.isActive() |
| 8938 | ); |
| 8939 | } |
| 8940 | @Override |
| 8941 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8942 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8943 | mApp.getSystemService(AppOpsManager.class) |
| 8944 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8945 | |
| 8946 | boolean hasReadPermission = false; |
| 8947 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8948 | |
| 8949 | try { |
| 8950 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8951 | hasReadPermission = true; |
| 8952 | } catch (SecurityException e) { |
| 8953 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8954 | // has carrier privileges on an active UICC |
Rambo Wang | e7209ce | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8955 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8956 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8957 | hasReadPermission = true; |
| 8958 | } |
| 8959 | } |
| 8960 | |
| 8961 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8962 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8963 | Binder.getCallingUid())) { |
| 8964 | isLogicalSlotAccessRestricted = true; |
| 8965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8966 | final long identity = Binder.clearCallingIdentity(); |
| 8967 | try { |
| 8968 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
Muralidhar Reddy | d196bbf | 2022-01-17 17:56:30 +0000 | [diff] [blame] | 8969 | if (slots == null || slots.length == 0) { |
| 8970 | Rlog.i(LOG_TAG, "slots is null or empty."); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8971 | return null; |
| 8972 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8973 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8974 | for (int i = 0; i < slots.length; i++) { |
| 8975 | UiccSlot slot = slots[i]; |
| 8976 | if (slot == null) { |
| 8977 | continue; |
| 8978 | } |
| 8979 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8980 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8981 | UiccCard card = slot.getUiccCard(); |
| 8982 | if (card != null) { |
| 8983 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8984 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8985 | cardId = slot.getEid(); |
| 8986 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8987 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8988 | // read permission otherwise set to null.(card is null which means no |
| 8989 | // carrier permission) |
| 8990 | cardId = hasReadPermission ? slot.getIccId( |
| 8991 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8992 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8993 | } |
| 8994 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8995 | if (cardId != null) { |
| 8996 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8997 | // if cardId is an EID, it's all digits so this is fine |
| 8998 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8999 | } |
| 9000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9001 | int cardState = 0; |
| 9002 | switch (slot.getCardState()) { |
| 9003 | case CARDSTATE_ABSENT: |
| 9004 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 9005 | break; |
| 9006 | case CARDSTATE_PRESENT: |
| 9007 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 9008 | break; |
| 9009 | case CARDSTATE_ERROR: |
| 9010 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 9011 | break; |
| 9012 | case CARDSTATE_RESTRICTED: |
| 9013 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 9014 | break; |
| 9015 | default: |
| 9016 | break; |
| 9017 | |
| 9018 | } |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9019 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 9020 | int[] portIndexes = slot.getPortList(); |
| 9021 | for (int portIdx : portIndexes) { |
| 9022 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 9023 | callingPackage, hasReadPermission)); |
Muralidhar Reddy | fbcff0c | 2022-01-19 13:07:57 +0000 | [diff] [blame] | 9024 | portInfos.add(new UiccPortInfo(iccId, portIdx, |
| 9025 | slot.getPhoneIdFromPortIndex(portIdx), slot.isPortActive(portIdx))); |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9026 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9027 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9028 | slot.isEuicc(), |
| 9029 | cardId, |
| 9030 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 9031 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9032 | slot.isRemovable(), portInfos); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9033 | //setting the value after compatibility check |
| 9034 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9035 | } |
| 9036 | return infos; |
| 9037 | } finally { |
| 9038 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 9039 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9040 | } |
| 9041 | |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9042 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 9043 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 9044 | boolean hasReadPermission) { |
| 9045 | String iccId = slot.getIccId(portIndex); |
| 9046 | if (hasReadPermission) { // if has read permission |
| 9047 | return iccId; |
| 9048 | } else { |
| 9049 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 9050 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 9051 | // if no read permission, checking carrier privilege access |
| 9052 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 9053 | return iccId; |
| 9054 | } |
| 9055 | } |
| 9056 | } |
| 9057 | // No read permission or carrier privilege access. |
| 9058 | return UiccPortInfo.ICCID_REDACTED; |
| 9059 | } |
| 9060 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9061 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9062 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9063 | public boolean switchSlots(int[] physicalSlots) { |
| 9064 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9065 | |
| 9066 | final long identity = Binder.clearCallingIdentity(); |
| 9067 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9068 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 9069 | for (int i = 0; i < physicalSlots.length; i++) { |
| 9070 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 9071 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 9072 | physicalSlots[i], i)); |
| 9073 | } |
| 9074 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9075 | } finally { |
| 9076 | Binder.restoreCallingIdentity(identity); |
| 9077 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 9078 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 9079 | |
| 9080 | @Override |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9081 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 9082 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 9083 | enforceModifyPermission(); |
| 9084 | |
| 9085 | final long identity = Binder.clearCallingIdentity(); |
| 9086 | try { |
Muralidhar Reddy | eb809e3 | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 9087 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | b6c8787 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 9088 | } finally { |
| 9089 | Binder.restoreCallingIdentity(identity); |
| 9090 | } |
| 9091 | } |
| 9092 | |
| 9093 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9094 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 9095 | final long identity = Binder.clearCallingIdentity(); |
| 9096 | try { |
| 9097 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 9098 | } finally { |
| 9099 | Binder.restoreCallingIdentity(identity); |
| 9100 | } |
| 9101 | } |
| 9102 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9103 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9104 | * A test API to reload the UICC profile. |
| 9105 | * |
| 9106 | * <p>Requires that the calling app has permission |
| 9107 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 9108 | * @hide |
| 9109 | */ |
| 9110 | @Override |
| 9111 | public void refreshUiccProfile(int subId) { |
| 9112 | enforceModifyPermission(); |
| 9113 | |
| 9114 | final long identity = Binder.clearCallingIdentity(); |
| 9115 | try { |
| 9116 | Phone phone = getPhone(subId); |
| 9117 | if (phone == null) { |
| 9118 | return; |
| 9119 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9120 | UiccPort uiccPort = phone.getUiccPort(); |
| 9121 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9122 | return; |
| 9123 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9124 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 9125 | if (uiccProfile == null) { |
| 9126 | return; |
| 9127 | } |
| 9128 | uiccProfile.refresh(); |
| 9129 | } finally { |
| 9130 | Binder.restoreCallingIdentity(identity); |
| 9131 | } |
| 9132 | } |
| 9133 | |
| 9134 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9135 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9136 | */ |
| 9137 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9138 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9139 | } |
| 9140 | |
| 9141 | /** |
| 9142 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9143 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9144 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9145 | */ |
| 9146 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9147 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9148 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9149 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9150 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9151 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9152 | return isDataRoamingEnabled; |
| 9153 | } |
| 9154 | |
| 9155 | /** |
| 9156 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9157 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9158 | */ |
| 9159 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9160 | List<Integer> list = TelephonyProperties.default_network(); |
| 9161 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9162 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9163 | return list.get(phoneId); |
| 9164 | } |
| 9165 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9166 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9167 | |
| 9168 | @Override |
| 9169 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9170 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9171 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9172 | |
| 9173 | final long identity = Binder.clearCallingIdentity(); |
| 9174 | try { |
| 9175 | final Phone phone = getPhone(subId); |
| 9176 | if (phone == null) { |
| 9177 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9178 | return; |
| 9179 | } |
Rambo Wang | 9c9ffdd | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9180 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9181 | if (cpt != null) { |
| 9182 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9183 | } |
| 9184 | // 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] | 9185 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9186 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9187 | if (carrierPrivilegeRules == null) { |
| 9188 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9189 | } else { |
| 9190 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9191 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9192 | } finally { |
| 9193 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9194 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9195 | } |
| 9196 | |
| 9197 | @Override |
| 9198 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9199 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9200 | |
| 9201 | final long identity = Binder.clearCallingIdentity(); |
| 9202 | try { |
| 9203 | final Phone phone = getPhone(subId); |
| 9204 | if (phone == null) { |
| 9205 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9206 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9207 | } |
| 9208 | return phone.getCarrierIdListVersion(); |
| 9209 | } finally { |
| 9210 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9211 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9212 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9213 | |
| 9214 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9215 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9216 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9217 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9218 | mApp, subId, callingPackage, callingFeatureId, |
| 9219 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9220 | return -1; |
| 9221 | } |
| 9222 | |
| 9223 | final long identity = Binder.clearCallingIdentity(); |
| 9224 | try { |
| 9225 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9226 | } finally { |
| 9227 | Binder.restoreCallingIdentity(identity); |
| 9228 | } |
| 9229 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9230 | |
| 9231 | @Override |
| 9232 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9233 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9234 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9235 | mApp, subId, "getCdmaRoamingMode"); |
| 9236 | |
| 9237 | final long identity = Binder.clearCallingIdentity(); |
| 9238 | try { |
| 9239 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9240 | } finally { |
| 9241 | Binder.restoreCallingIdentity(identity); |
| 9242 | } |
| 9243 | } |
| 9244 | |
| 9245 | @Override |
| 9246 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9248 | mApp, subId, "setCdmaRoamingMode"); |
| 9249 | |
| 9250 | final long identity = Binder.clearCallingIdentity(); |
| 9251 | try { |
| 9252 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9253 | } finally { |
| 9254 | Binder.restoreCallingIdentity(identity); |
| 9255 | } |
| 9256 | } |
| 9257 | |
| 9258 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9259 | public int getCdmaSubscriptionMode(int subId) { |
| 9260 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9261 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9262 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9263 | |
| 9264 | final long identity = Binder.clearCallingIdentity(); |
| 9265 | try { |
| 9266 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9267 | } finally { |
| 9268 | Binder.restoreCallingIdentity(identity); |
| 9269 | } |
| 9270 | } |
| 9271 | |
| 9272 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9273 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9275 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9276 | |
| 9277 | final long identity = Binder.clearCallingIdentity(); |
| 9278 | try { |
| 9279 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9280 | } finally { |
| 9281 | Binder.restoreCallingIdentity(identity); |
| 9282 | } |
| 9283 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9284 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9285 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9286 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9287 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9288 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9289 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9290 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9291 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9292 | } |
| 9293 | final long identity = Binder.clearCallingIdentity(); |
| 9294 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9295 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9296 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9297 | if (phone.getEmergencyNumberTracker() != null |
| 9298 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9299 | emergencyNumberListInternal.put( |
| 9300 | phone.getSubId(), |
| 9301 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9302 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9303 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9304 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9305 | } finally { |
| 9306 | Binder.restoreCallingIdentity(identity); |
| 9307 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9308 | } |
| 9309 | |
| 9310 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9311 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9312 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9313 | if (!exactMatch) { |
| 9314 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9315 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9316 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9317 | } |
| 9318 | final long identity = Binder.clearCallingIdentity(); |
| 9319 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9320 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9321 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9322 | && phone.getEmergencyNumberTracker() |
| 9323 | .isEmergencyNumber(number, exactMatch)) { |
| 9324 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9325 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9326 | } |
| 9327 | return false; |
| 9328 | } finally { |
| 9329 | Binder.restoreCallingIdentity(identity); |
| 9330 | } |
| 9331 | } |
| 9332 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9333 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9334 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9335 | */ |
| 9336 | @Override |
| 9337 | public void startEmergencyCallbackMode() { |
| 9338 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9339 | "startEmergencyCallbackMode"); |
| 9340 | enforceModifyPermission(); |
| 9341 | final long identity = Binder.clearCallingIdentity(); |
| 9342 | try { |
| 9343 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9344 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9345 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9346 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9347 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9348 | gsmCdmaPhone.obtainMessage( |
| 9349 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9350 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9351 | } |
| 9352 | } |
| 9353 | } finally { |
| 9354 | Binder.restoreCallingIdentity(identity); |
| 9355 | } |
| 9356 | } |
| 9357 | |
| 9358 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9359 | * Update emergency number list for test mode. |
| 9360 | */ |
| 9361 | @Override |
| 9362 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9363 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9364 | "updateEmergencyNumberListTestMode"); |
| 9365 | |
| 9366 | final long identity = Binder.clearCallingIdentity(); |
| 9367 | try { |
| 9368 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9369 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9370 | if (tracker != null) { |
| 9371 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9372 | } |
| 9373 | } |
| 9374 | } finally { |
| 9375 | Binder.restoreCallingIdentity(identity); |
| 9376 | } |
| 9377 | } |
| 9378 | |
| 9379 | /** |
| 9380 | * Get the full emergency number list for test mode. |
| 9381 | */ |
| 9382 | @Override |
| 9383 | public List<String> getEmergencyNumberListTestMode() { |
| 9384 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9385 | "getEmergencyNumberListTestMode"); |
| 9386 | |
| 9387 | final long identity = Binder.clearCallingIdentity(); |
| 9388 | try { |
| 9389 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9390 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9391 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9392 | if (tracker != null) { |
| 9393 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9394 | emergencyNumbers.add(num.getNumber()); |
| 9395 | } |
| 9396 | } |
| 9397 | } |
| 9398 | return new ArrayList<>(emergencyNumbers); |
| 9399 | } finally { |
| 9400 | Binder.restoreCallingIdentity(identity); |
| 9401 | } |
| 9402 | } |
| 9403 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9404 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9405 | public int getEmergencyNumberDbVersion(int subId) { |
| 9406 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9407 | |
| 9408 | final long identity = Binder.clearCallingIdentity(); |
| 9409 | try { |
| 9410 | final Phone phone = getPhone(subId); |
| 9411 | if (phone == null) { |
| 9412 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9413 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9414 | } |
| 9415 | return phone.getEmergencyNumberDbVersion(); |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
| 9418 | } |
| 9419 | } |
| 9420 | |
| 9421 | @Override |
| 9422 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9423 | enforceModifyPermission(); |
| 9424 | |
| 9425 | final long identity = Binder.clearCallingIdentity(); |
| 9426 | try { |
| 9427 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9428 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9429 | if (tracker != null) { |
| 9430 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9431 | } |
| 9432 | } |
| 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
| 9437 | |
| 9438 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9439 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9440 | enforceActiveEmergencySessionPermission(); |
| 9441 | |
| 9442 | final long identity = Binder.clearCallingIdentity(); |
| 9443 | try { |
| 9444 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9445 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9446 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9447 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9448 | } |
| 9449 | } |
| 9450 | } finally { |
| 9451 | Binder.restoreCallingIdentity(identity); |
| 9452 | } |
| 9453 | } |
| 9454 | |
| 9455 | @Override |
| 9456 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9457 | enforceActiveEmergencySessionPermission(); |
| 9458 | |
| 9459 | final long identity = Binder.clearCallingIdentity(); |
| 9460 | try { |
| 9461 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9462 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9463 | if (tracker != null) { |
| 9464 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9465 | } |
| 9466 | } |
| 9467 | } finally { |
| 9468 | Binder.restoreCallingIdentity(identity); |
| 9469 | } |
| 9470 | } |
| 9471 | |
| 9472 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9473 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9474 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9475 | Phone phone = getPhone(subId); |
| 9476 | if (phone == null) { |
| 9477 | return null; |
| 9478 | } |
| 9479 | final long identity = Binder.clearCallingIdentity(); |
| 9480 | try { |
| 9481 | UiccProfile profile = UiccController.getInstance() |
| 9482 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9483 | if (profile != null) { |
| 9484 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9485 | } |
| 9486 | } finally { |
| 9487 | Binder.restoreCallingIdentity(identity); |
| 9488 | } |
| 9489 | return null; |
| 9490 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9491 | |
| 9492 | /** |
| 9493 | * Enable or disable a modem stack. |
| 9494 | */ |
| 9495 | @Override |
| 9496 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9497 | enforceModifyPermission(); |
| 9498 | |
| 9499 | final long identity = Binder.clearCallingIdentity(); |
| 9500 | try { |
| 9501 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9502 | if (phone == null) { |
| 9503 | return false; |
| 9504 | } else { |
| 9505 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9506 | } |
| 9507 | } finally { |
| 9508 | Binder.restoreCallingIdentity(identity); |
| 9509 | } |
| 9510 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9511 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9512 | /** |
| 9513 | * Whether a modem stack is enabled or not. |
| 9514 | */ |
| 9515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9516 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9517 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9518 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9519 | if (phone == null) return false; |
| 9520 | |
| 9521 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9522 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9523 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9524 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9525 | } |
| 9526 | |
| 9527 | final long identity = Binder.clearCallingIdentity(); |
| 9528 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9529 | try { |
| 9530 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9531 | } catch (NoSuchElementException ex) { |
| 9532 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9533 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9534 | } finally { |
| 9535 | Binder.restoreCallingIdentity(identity); |
| 9536 | } |
| 9537 | } |
| 9538 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9539 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9540 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9541 | enforceModifyPermission(); |
| 9542 | |
| 9543 | final long identity = Binder.clearCallingIdentity(); |
| 9544 | try { |
| 9545 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9546 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9547 | .commit(); |
| 9548 | } finally { |
| 9549 | Binder.restoreCallingIdentity(identity); |
| 9550 | } |
| 9551 | } |
| 9552 | |
| 9553 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9554 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9555 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9556 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9557 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9558 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9559 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9560 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9561 | |
| 9562 | final long identity = Binder.clearCallingIdentity(); |
| 9563 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9564 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9565 | } finally { |
| 9566 | Binder.restoreCallingIdentity(identity); |
| 9567 | } |
| 9568 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9569 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9570 | @TelephonyManager.IsMultiSimSupportedResult |
| 9571 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9572 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9573 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9574 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9575 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9576 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9577 | } |
| 9578 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9579 | // supported by the modem, indicate that it is restricted. |
| 9580 | PhoneCapability staticCapability = |
| 9581 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9582 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9583 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9584 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9585 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9586 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9587 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9588 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9589 | } |
| 9590 | // Check if support of multiple SIMs is restricted by carrier |
| 9591 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9592 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9593 | } |
| 9594 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9595 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9596 | } |
| 9597 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9598 | /** |
| 9599 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9600 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9601 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9602 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9603 | * @param numOfSims number of active sims we want to switch to |
| 9604 | */ |
| 9605 | @Override |
| 9606 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9607 | if (numOfSims == 1) { |
| 9608 | enforceModifyPermission(); |
| 9609 | } else { |
| 9610 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9611 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9612 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9613 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9614 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9615 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9616 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9617 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9618 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9619 | return; |
| 9620 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9621 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9622 | } finally { |
| 9623 | Binder.restoreCallingIdentity(identity); |
| 9624 | } |
| 9625 | } |
| 9626 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9627 | @Override |
| 9628 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9629 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9630 | Phone phone = getPhone(subId); |
| 9631 | if (phone == null) { |
| 9632 | return false; |
| 9633 | } |
| 9634 | final long identity = Binder.clearCallingIdentity(); |
| 9635 | try { |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9636 | UiccPort uiccPort = phone.getUiccPort(); |
| 9637 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9638 | return false; |
| 9639 | } |
Muralidhar Reddy | 472c2ae | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9640 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9641 | if (uiccProfile == null) { |
| 9642 | return false; |
| 9643 | } |
| 9644 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9645 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9646 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9647 | } |
| 9648 | return false; |
| 9649 | } finally { |
| 9650 | Binder.restoreCallingIdentity(identity); |
| 9651 | } |
| 9652 | } |
| 9653 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9654 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9655 | * Get whether making changes to modem configurations will trigger reboot. |
| 9656 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9657 | */ |
| 9658 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9659 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9660 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9661 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9662 | mApp, subId, callingPackage, callingFeatureId, |
| 9663 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9664 | return false; |
| 9665 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9666 | final long identity = Binder.clearCallingIdentity(); |
| 9667 | try { |
| 9668 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9669 | } finally { |
| 9670 | Binder.restoreCallingIdentity(identity); |
| 9671 | } |
| 9672 | } |
| 9673 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9674 | private void updateModemStateMetrics() { |
| 9675 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9676 | // TODO: check the state for each modem if the api is ready. |
| 9677 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9678 | } |
| 9679 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9680 | @Override |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9681 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9682 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9683 | // Verify that the callingPackage belongs to the calling UID |
| 9684 | mApp.getSystemService(AppOpsManager.class) |
| 9685 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9686 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9687 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9688 | try { |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9689 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9690 | if (slotInfos != null) { |
| 9691 | for (int i = 0; i < slotInfos.length; i++) { |
| 9692 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9693 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9694 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9695 | portInfo.getLogicalSlotIndex())); |
| 9696 | } |
| 9697 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9698 | } |
| 9699 | } |
sandeepjs | a208e3b | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9700 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9701 | } finally { |
| 9702 | Binder.restoreCallingIdentity(identity); |
| 9703 | } |
| 9704 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9705 | |
| 9706 | /** |
| 9707 | * Get the IRadio HAL Version |
| 9708 | */ |
| 9709 | @Override |
| 9710 | public int getRadioHalVersion() { |
| 9711 | Phone phone = getDefaultPhone(); |
| 9712 | if (phone == null) return -1; |
| 9713 | HalVersion hv = phone.getHalVersion(); |
| 9714 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9715 | return hv.major * 100 + hv.minor; |
| 9716 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9717 | |
| 9718 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9719 | * Get the current calling package name. |
| 9720 | * @return the current calling package name |
| 9721 | */ |
| 9722 | @Override |
| 9723 | public String getCurrentPackageName() { |
| 9724 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9725 | } |
| 9726 | |
| 9727 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9728 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9729 | * corresponding network requests on a subId. |
| 9730 | * |
| 9731 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9732 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9733 | * 2) APN is un-metered for this subscription, or |
| 9734 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9735 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9736 | * |
| 9737 | * @return whether data is allowed for a apn type. |
| 9738 | * |
| 9739 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9740 | */ |
| 9741 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9742 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9743 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9744 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9745 | |
| 9746 | // Now that all security checks passes, perform the operation as ourselves. |
| 9747 | final long identity = Binder.clearCallingIdentity(); |
| 9748 | try { |
| 9749 | Phone phone = getPhone(subId); |
| 9750 | if (phone == null) return false; |
| 9751 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9752 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9753 | boolean isDataEnabled; |
| 9754 | if (phone.isUsingNewDataStack()) { |
| 9755 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9756 | } else { |
| 9757 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9758 | } |
| 9759 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9760 | } finally { |
| 9761 | Binder.restoreCallingIdentity(identity); |
| 9762 | } |
| 9763 | } |
| 9764 | |
| 9765 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9766 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9767 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9768 | |
| 9769 | // Now that all security checks passes, perform the operation as ourselves. |
| 9770 | final long identity = Binder.clearCallingIdentity(); |
| 9771 | try { |
| 9772 | Phone phone = getPhone(subId); |
| 9773 | if (phone == null) return true; // By default return true. |
| 9774 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9775 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9776 | } finally { |
| 9777 | Binder.restoreCallingIdentity(identity); |
| 9778 | } |
| 9779 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9780 | |
| 9781 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9782 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9783 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9784 | enforceModifyPermission(); |
| 9785 | long token = Binder.clearCallingIdentity(); |
| 9786 | try { |
| 9787 | Phone phone = getPhone(subscriptionId); |
| 9788 | if (phone == null) { |
| 9789 | try { |
| 9790 | if (resultCallback != null) { |
| 9791 | resultCallback.accept(false); |
| 9792 | } |
| 9793 | } catch (RemoteException e) { |
| 9794 | // ignore |
| 9795 | } |
| 9796 | return; |
| 9797 | } |
| 9798 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9799 | Pair.create(specifiers, (x) -> { |
| 9800 | try { |
| 9801 | if (resultCallback != null) { |
| 9802 | resultCallback.accept(x); |
| 9803 | } |
| 9804 | } catch (RemoteException e) { |
| 9805 | // ignore |
| 9806 | } |
| 9807 | }); |
| 9808 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9809 | } finally { |
| 9810 | Binder.restoreCallingIdentity(token); |
| 9811 | } |
| 9812 | } |
| 9813 | |
| 9814 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9815 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9816 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9817 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9818 | mApp, subId, "getSystemSelectionChannels"); |
| 9819 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9820 | final long identity = Binder.clearCallingIdentity(); |
| 9821 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9822 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9823 | if (result instanceof IllegalStateException) { |
| 9824 | throw (IllegalStateException) result; |
| 9825 | } |
| 9826 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9827 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9828 | return specifiers; |
| 9829 | } finally { |
| 9830 | Binder.restoreCallingIdentity(identity); |
| 9831 | } |
| 9832 | } |
| 9833 | |
| 9834 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9835 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9836 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9837 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9838 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9839 | if (iccRecords == null) { |
| 9840 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9841 | return false; |
| 9842 | } |
| 9843 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9844 | } |
| 9845 | |
| 9846 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9847 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9848 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9849 | if (callingPackage == null) { |
| 9850 | callingPackage = getCurrentPackageName(); |
| 9851 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9852 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9853 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9854 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9855 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9856 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9857 | } |
| 9858 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9859 | Intent intent = new Intent(); |
| 9860 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9861 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9862 | // Bring up choose default SMS subscription dialog right now |
| 9863 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9864 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9865 | mApp.startActivity(intent); |
| 9866 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9867 | |
| 9868 | @Override |
| 9869 | public String getMmsUAProfUrl(int subId) { |
| 9870 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9871 | final long identity = Binder.clearCallingIdentity(); |
| 9872 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9873 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9874 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9875 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9876 | return carrierUAProfUrl; |
| 9877 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9878 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9879 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9880 | } finally { |
| 9881 | Binder.restoreCallingIdentity(identity); |
| 9882 | } |
| 9883 | } |
| 9884 | |
| 9885 | @Override |
| 9886 | public String getMmsUserAgent(int subId) { |
| 9887 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9888 | final long identity = Binder.clearCallingIdentity(); |
| 9889 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9890 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9891 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9892 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9893 | return carrierUserAgent; |
| 9894 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9895 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9896 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9897 | } finally { |
| 9898 | Binder.restoreCallingIdentity(identity); |
| 9899 | } |
| 9900 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9901 | |
| 9902 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9903 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9904 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9905 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9906 | final long identity = Binder.clearCallingIdentity(); |
| 9907 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9908 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9909 | if (phone == null) return false; |
| 9910 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9911 | switch (policy) { |
| 9912 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9913 | if (phone.isUsingNewDataStack()) { |
| 9914 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9915 | } else { |
| 9916 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9917 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9918 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9919 | if (phone.isUsingNewDataStack()) { |
| 9920 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9921 | } else { |
| 9922 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9923 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9924 | default: |
| 9925 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9926 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9927 | } finally { |
| 9928 | Binder.restoreCallingIdentity(identity); |
| 9929 | } |
| 9930 | } |
| 9931 | |
| 9932 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9933 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9934 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9935 | enforceModifyPermission(); |
| 9936 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9937 | final long identity = Binder.clearCallingIdentity(); |
| 9938 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9939 | Phone phone = getPhone(subscriptionId); |
| 9940 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9941 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9942 | switch (policy) { |
| 9943 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9944 | if (phone.isUsingNewDataStack()) { |
| 9945 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9946 | } else { |
| 9947 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9948 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9949 | break; |
| 9950 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 99e8733 | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9951 | if (phone.isUsingNewDataStack()) { |
| 9952 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9953 | } else { |
| 9954 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9955 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9956 | break; |
| 9957 | default: |
| 9958 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9959 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9960 | } finally { |
| 9961 | Binder.restoreCallingIdentity(identity); |
| 9962 | } |
| 9963 | } |
| 9964 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9965 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9966 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9967 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9968 | * otherwise. |
| 9969 | */ |
| 9970 | @Override |
| 9971 | public void setCepEnabled(boolean isCepEnabled) { |
| 9972 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9973 | |
| 9974 | final long identity = Binder.clearCallingIdentity(); |
| 9975 | try { |
| 9976 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9977 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9978 | Phone defaultPhone = phone.getImsPhone(); |
| 9979 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9980 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9981 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9982 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9983 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9984 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9985 | + imsPhone.getMsisdn()); |
| 9986 | } |
| 9987 | } |
| 9988 | } finally { |
| 9989 | Binder.restoreCallingIdentity(identity); |
| 9990 | } |
| 9991 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9992 | |
| 9993 | /** |
| 9994 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9995 | * |
| 9996 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9997 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9998 | * before being read. |
| 9999 | */ |
| 10000 | @Override |
| 10001 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 10002 | isCompressed) { |
| 10003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10004 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10005 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10006 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10007 | } |
| 10008 | if (!isImsAvailableOnDevice()) { |
| 10009 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10010 | "IMS not available on device."); |
| 10011 | } |
| 10012 | |
| 10013 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10014 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10015 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 10016 | } finally { |
| 10017 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 10018 | } |
| 10019 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 10020 | |
| 10021 | @Override |
| 10022 | public boolean isIccLockEnabled(int subId) { |
| 10023 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 10024 | |
| 10025 | // Now that all security checks passes, perform the operation as ourselves. |
| 10026 | final long identity = Binder.clearCallingIdentity(); |
| 10027 | try { |
| 10028 | Phone phone = getPhone(subId); |
| 10029 | if (phone != null && phone.getIccCard() != null) { |
| 10030 | return phone.getIccCard().getIccLockEnabled(); |
| 10031 | } else { |
| 10032 | return false; |
| 10033 | } |
| 10034 | } finally { |
| 10035 | Binder.restoreCallingIdentity(identity); |
| 10036 | } |
| 10037 | } |
| 10038 | |
| 10039 | /** |
| 10040 | * Set the ICC pin lock enabled or disabled. |
| 10041 | * |
| 10042 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 10043 | * three cases: |
| 10044 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 10045 | * successfully. |
| 10046 | * - Positive number and zero for remaining password attempts. |
| 10047 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10048 | * |
| 10049 | */ |
| 10050 | @Override |
| 10051 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 10052 | enforceModifyPermission(); |
| 10053 | |
| 10054 | Phone phone = getPhone(subId); |
| 10055 | if (phone == null) { |
| 10056 | return 0; |
| 10057 | } |
| 10058 | // Now that all security checks passes, perform the operation as ourselves. |
| 10059 | final long identity = Binder.clearCallingIdentity(); |
| 10060 | try { |
| 10061 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 10062 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 10063 | return attemptsRemaining; |
| 10064 | |
| 10065 | } catch (Exception e) { |
| 10066 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 10067 | } finally { |
| 10068 | Binder.restoreCallingIdentity(identity); |
| 10069 | } |
| 10070 | return 0; |
| 10071 | } |
| 10072 | |
| 10073 | /** |
| 10074 | * Change the ICC password used in ICC pin lock. |
| 10075 | * |
| 10076 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 10077 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 10078 | * - Positive number and zero for remaining password attempts. |
| 10079 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 10080 | * |
| 10081 | */ |
| 10082 | @Override |
| 10083 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 10084 | enforceModifyPermission(); |
| 10085 | |
| 10086 | Phone phone = getPhone(subId); |
| 10087 | if (phone == null) { |
| 10088 | return 0; |
| 10089 | } |
| 10090 | // Now that all security checks passes, perform the operation as ourselves. |
| 10091 | final long identity = Binder.clearCallingIdentity(); |
| 10092 | try { |
| 10093 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 10094 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 10095 | return attemptsRemaining; |
| 10096 | |
| 10097 | } catch (Exception e) { |
| 10098 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 10099 | } finally { |
| 10100 | Binder.restoreCallingIdentity(identity); |
| 10101 | } |
| 10102 | return 0; |
| 10103 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 10104 | |
| 10105 | /** |
| 10106 | * Request for receiving user activity notification |
| 10107 | */ |
| 10108 | @Override |
| 10109 | public void requestUserActivityNotification() { |
| 10110 | if (!mNotifyUserActivity.get() |
| 10111 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 10112 | mNotifyUserActivity.set(true); |
| 10113 | } |
| 10114 | } |
| 10115 | |
| 10116 | /** |
| 10117 | * Called when userActivity is signalled in the power manager. |
| 10118 | * This is safe to call from any thread, with any window manager locks held or not. |
| 10119 | */ |
| 10120 | @Override |
| 10121 | public void userActivity() { |
| 10122 | // *************************************** |
| 10123 | // * Inherited from PhoneWindowManager * |
| 10124 | // *************************************** |
| 10125 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 10126 | // WITH ITS LOCKS HELD. |
| 10127 | // |
| 10128 | // This code must be VERY careful about the locks |
| 10129 | // it acquires. |
| 10130 | // In fact, the current code acquires way too many, |
| 10131 | // and probably has lurking deadlocks. |
| 10132 | |
| 10133 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10134 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10135 | } |
| 10136 | |
| 10137 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10138 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10139 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10140 | } |
| 10141 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10142 | |
| 10143 | @Override |
| 10144 | public boolean canConnectTo5GInDsdsMode() { |
| 10145 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10146 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10147 | |
| 10148 | @Override |
| 10149 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10150 | String callingFeatureId) { |
| 10151 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10152 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10153 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10154 | } |
| 10155 | |
| 10156 | Phone phone = getPhone(subId); |
| 10157 | if (phone == null) { |
| 10158 | throw new RuntimeException("phone is not available"); |
| 10159 | } |
| 10160 | // Now that all security checks passes, perform the operation as ourselves. |
| 10161 | final long identity = Binder.clearCallingIdentity(); |
| 10162 | try { |
| 10163 | return phone.getEquivalentHomePlmns(); |
| 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10168 | |
| 10169 | @Override |
| 10170 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10171 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10172 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10173 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10174 | if (radioInterfaceCapabilities == null) { |
| 10175 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10176 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10177 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10178 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10179 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10180 | @Override |
| 10181 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10182 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10183 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10184 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10185 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10186 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10187 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10188 | if (DBG) { |
| 10189 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10190 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10191 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10192 | } |
| 10193 | |
| 10194 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10195 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10196 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10197 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10198 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10199 | if (callback != null) { |
| 10200 | try { |
| 10201 | callback.onAuthenticationFailure( |
| 10202 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10203 | } catch (RemoteException exception) { |
| 10204 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10205 | } |
| 10206 | return; |
| 10207 | } |
| 10208 | } |
| 10209 | |
| 10210 | final long token = Binder.clearCallingIdentity(); |
| 10211 | try { |
| 10212 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10213 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10214 | forceBootStrapping, callback)); |
| 10215 | } finally { |
| 10216 | Binder.restoreCallingIdentity(token); |
| 10217 | } |
| 10218 | } |
| 10219 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10220 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10221 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10222 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10223 | * requested radio power state will actually be set. See {@link |
| 10224 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10225 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10226 | * @param enable {@code true} if trying to turn radio on. |
| 10227 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10228 | * false}. |
| 10229 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10230 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10231 | boolean isPhoneAvailable = false; |
| 10232 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10233 | Phone phone = PhoneFactory.getPhone(i); |
| 10234 | if (phone != null) { |
| 10235 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10236 | isPhoneAvailable = true; |
| 10237 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10238 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10239 | |
| 10240 | // return true if successfully informed the phone object about the thermal radio power |
| 10241 | // request. |
| 10242 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10243 | } |
| 10244 | |
| 10245 | private int handleDataThrottlingRequest(int subId, |
| 10246 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10247 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10248 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10249 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10250 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10251 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10252 | } |
| 10253 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10254 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10255 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10256 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10257 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10258 | } |
| 10259 | |
| 10260 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10261 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10262 | if (isDataThrottlingSupported) { |
| 10263 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10264 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10265 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10266 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10267 | } else if (thermalMitigationResult |
| 10268 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10269 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10270 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10271 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10272 | } |
| 10273 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10274 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10275 | |
| 10276 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10277 | } |
| 10278 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10279 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10280 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10281 | for (String pckg : context.getResources() |
| 10282 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10283 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10284 | } |
| 10285 | } |
| 10286 | |
| 10287 | return sThermalMitigationAllowlistedPackages; |
| 10288 | } |
| 10289 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10290 | private boolean isAnyPhoneInEmergencyState() { |
| 10291 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10292 | if (tm.isInEmergencyCall()) { |
| 10293 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10294 | return true; |
| 10295 | } |
| 10296 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10297 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10298 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10299 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10300 | + phone.isInEcm()); |
| 10301 | return true; |
| 10302 | } |
| 10303 | } |
| 10304 | |
| 10305 | return false; |
| 10306 | } |
| 10307 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10308 | /** |
| 10309 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10310 | * @param packageName name of package to be allowlisted |
| 10311 | * @param context |
| 10312 | */ |
| 10313 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10314 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10315 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10316 | } |
| 10317 | |
| 10318 | /** |
| 10319 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10320 | * @param packageName name of package to remove from allowlist |
| 10321 | * @param context |
| 10322 | */ |
| 10323 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10324 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10325 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10326 | } |
| 10327 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10328 | /** |
| 10329 | * Thermal mitigation request to control functionalities at modem. |
| 10330 | * |
| 10331 | * @param subId the id of the subscription. |
| 10332 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10333 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10334 | * |
| 10335 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10336 | */ |
| 10337 | @Override |
| 10338 | @ThermalMitigationResult |
| 10339 | public int sendThermalMitigationRequest( |
| 10340 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10341 | ThermalMitigationRequest thermalMitigationRequest, |
| 10342 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10343 | enforceModifyPermission(); |
| 10344 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10345 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10346 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10347 | .contains(callingPackage)) { |
| 10348 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10349 | + "calling package: " + callingPackage); |
| 10350 | } |
| 10351 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10352 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10353 | final long identity = Binder.clearCallingIdentity(); |
| 10354 | |
| 10355 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10356 | try { |
| 10357 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10358 | switch (thermalMitigationAction) { |
| 10359 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10360 | thermalMitigationResult = |
| 10361 | handleDataThrottlingRequest(subId, |
| 10362 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10363 | break; |
| 10364 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10365 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10366 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10367 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10368 | } |
| 10369 | |
| 10370 | // Ensure that radio is on. If not able to power on due to phone being |
| 10371 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10372 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10373 | thermalMitigationResult = |
| 10374 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10375 | break; |
| 10376 | } |
| 10377 | |
| 10378 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10379 | false); |
| 10380 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10381 | break; |
| 10382 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10383 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10384 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10385 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10386 | } |
| 10387 | |
| 10388 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10389 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10390 | Phone phone = getPhone(subId); |
| 10391 | if (phone == null) { |
| 10392 | thermalMitigationResult = |
| 10393 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10394 | break; |
| 10395 | } |
| 10396 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10397 | TelephonyConnectionService service = |
| 10398 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10399 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10400 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10401 | thermalMitigationResult = |
| 10402 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10403 | break; |
| 10404 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10405 | thermalMitigationResult = |
| 10406 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10407 | break; |
| 10408 | } |
| 10409 | } else { |
| 10410 | thermalMitigationResult = |
| 10411 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10412 | break; |
| 10413 | } |
| 10414 | |
| 10415 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10416 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10417 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10418 | thermalMitigationResult = |
| 10419 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10420 | break; |
| 10421 | } |
| 10422 | thermalMitigationResult = |
| 10423 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10424 | break; |
| 10425 | default: |
| 10426 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10427 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10428 | } |
| 10429 | } catch (IllegalArgumentException e) { |
| 10430 | throw e; |
| 10431 | } catch (Exception e) { |
| 10432 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10433 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10434 | } finally { |
| 10435 | Binder.restoreCallingIdentity(identity); |
| 10436 | } |
| 10437 | |
| 10438 | if (DBG) { |
| 10439 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10440 | + thermalMitigationResult); |
| 10441 | } |
| 10442 | |
| 10443 | return thermalMitigationResult; |
| 10444 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10445 | |
| 10446 | /** |
| 10447 | * Set the GbaService Package Name that Telephony will bind to. |
| 10448 | * |
| 10449 | * @param subId The sim that the GbaService is associated with. |
| 10450 | * @param packageName The name of the package to be replaced with. |
| 10451 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10452 | */ |
| 10453 | @Override |
| 10454 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10455 | enforceModifyPermission(); |
| 10456 | |
| 10457 | final long identity = Binder.clearCallingIdentity(); |
| 10458 | try { |
| 10459 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10460 | } finally { |
| 10461 | Binder.restoreCallingIdentity(identity); |
| 10462 | } |
| 10463 | } |
| 10464 | |
| 10465 | /** |
| 10466 | * Return the package name of the currently bound GbaService. |
| 10467 | * |
| 10468 | * @param subId The sim that the GbaService is associated with. |
| 10469 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10470 | */ |
| 10471 | @Override |
| 10472 | public String getBoundGbaService(int subId) { |
| 10473 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10474 | |
| 10475 | final long identity = Binder.clearCallingIdentity(); |
| 10476 | try { |
| 10477 | return getGbaManager(subId).getServicePackage(); |
| 10478 | } finally { |
| 10479 | Binder.restoreCallingIdentity(identity); |
| 10480 | } |
| 10481 | } |
| 10482 | |
| 10483 | /** |
| 10484 | * Set the release time for telephony to unbind GbaService. |
| 10485 | * |
| 10486 | * @param subId The sim that the GbaService is associated with. |
| 10487 | * @param interval The release time to unbind GbaService by millisecond. |
| 10488 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10489 | */ |
| 10490 | @Override |
| 10491 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10492 | enforceModifyPermission(); |
| 10493 | |
| 10494 | final long identity = Binder.clearCallingIdentity(); |
| 10495 | try { |
| 10496 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10497 | } finally { |
| 10498 | Binder.restoreCallingIdentity(identity); |
| 10499 | } |
| 10500 | } |
| 10501 | |
| 10502 | /** |
| 10503 | * Return the release time for telephony to unbind GbaService. |
| 10504 | * |
| 10505 | * @param subId The sim that the GbaService is associated with. |
| 10506 | * @return The release time to unbind GbaService by millisecond. |
| 10507 | */ |
| 10508 | @Override |
| 10509 | public int getGbaReleaseTime(int subId) { |
| 10510 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10511 | |
| 10512 | final long identity = Binder.clearCallingIdentity(); |
| 10513 | try { |
| 10514 | return getGbaManager(subId).getReleaseTime(); |
| 10515 | } finally { |
| 10516 | Binder.restoreCallingIdentity(identity); |
| 10517 | } |
| 10518 | } |
| 10519 | |
| 10520 | private GbaManager getGbaManager(int subId) { |
| 10521 | GbaManager instance = GbaManager.getInstance(subId); |
| 10522 | if (instance == null) { |
| 10523 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10524 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10525 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10526 | } |
| 10527 | return instance; |
| 10528 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10529 | |
| 10530 | /** |
| 10531 | * indicate whether the device and the carrier can support |
| 10532 | * RCS VoLTE single registration. |
| 10533 | */ |
| 10534 | @Override |
| 10535 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10536 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10537 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10538 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10539 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10540 | |
| 10541 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10542 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10543 | } |
| 10544 | |
| 10545 | final long identity = Binder.clearCallingIdentity(); |
| 10546 | try { |
| 10547 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10548 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10549 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10550 | if (isCapable != null) { |
| 10551 | return isCapable; |
| 10552 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10553 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10554 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10555 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10556 | } finally { |
| 10557 | Binder.restoreCallingIdentity(identity); |
| 10558 | } |
| 10559 | } |
| 10560 | |
| 10561 | /** |
| 10562 | * Register RCS provisioning callback. |
| 10563 | */ |
| 10564 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10565 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10566 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10567 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10568 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10569 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10570 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10571 | |
| 10572 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10573 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10574 | } |
| 10575 | if (!isImsAvailableOnDevice()) { |
| 10576 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10577 | "IMS not available on device."); |
| 10578 | } |
| 10579 | |
| 10580 | final long identity = Binder.clearCallingIdentity(); |
| 10581 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10582 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10583 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10584 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10585 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10586 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10587 | } finally { |
| 10588 | Binder.restoreCallingIdentity(identity); |
| 10589 | } |
| 10590 | } |
| 10591 | |
| 10592 | /** |
| 10593 | * Unregister RCS provisioning callback. |
| 10594 | */ |
| 10595 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10596 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10597 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10598 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10599 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10600 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10601 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10602 | |
| 10603 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10604 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10605 | } |
| 10606 | if (!isImsAvailableOnDevice()) { |
| 10607 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10608 | "IMS not available on device."); |
| 10609 | } |
| 10610 | |
| 10611 | final long identity = Binder.clearCallingIdentity(); |
| 10612 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10613 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10614 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10615 | } finally { |
| 10616 | Binder.restoreCallingIdentity(identity); |
| 10617 | } |
| 10618 | } |
| 10619 | |
| 10620 | /** |
| 10621 | * trigger RCS reconfiguration. |
| 10622 | */ |
| 10623 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10624 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10625 | "triggerRcsReconfiguration", |
| 10626 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10627 | |
| 10628 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10629 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10630 | } |
| 10631 | if (!isImsAvailableOnDevice()) { |
| 10632 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10633 | "IMS not available on device."); |
| 10634 | } |
| 10635 | |
| 10636 | final long identity = Binder.clearCallingIdentity(); |
| 10637 | try { |
| 10638 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10639 | } finally { |
| 10640 | Binder.restoreCallingIdentity(identity); |
| 10641 | } |
| 10642 | } |
| 10643 | |
| 10644 | /** |
| 10645 | * Provide the client configuration parameters of the RCS application. |
| 10646 | */ |
| 10647 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10648 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10649 | "setRcsClientConfiguration", |
| 10650 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10651 | |
| 10652 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10653 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10654 | } |
| 10655 | if (!isImsAvailableOnDevice()) { |
| 10656 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10657 | "IMS not available on device."); |
| 10658 | } |
| 10659 | |
| 10660 | final long identity = Binder.clearCallingIdentity(); |
| 10661 | |
| 10662 | try { |
| 10663 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10664 | if (configBinder == null) { |
| 10665 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10666 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10667 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10668 | } else { |
| 10669 | configBinder.setRcsClientConfiguration(rcc); |
| 10670 | } |
joonhunshin | 3e15424 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10671 | |
| 10672 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10673 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10674 | } catch (RemoteException e) { |
| 10675 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10677 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10678 | } finally { |
| 10679 | Binder.restoreCallingIdentity(identity); |
| 10680 | } |
| 10681 | } |
| 10682 | |
| 10683 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10684 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10685 | */ |
| 10686 | @Override |
| 10687 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10688 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10689 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10690 | |
| 10691 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10692 | } |
| 10693 | |
| 10694 | /** |
| 10695 | * Gets the test mode for RCS VoLTE single registration. |
| 10696 | */ |
| 10697 | @Override |
| 10698 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10699 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10700 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10701 | |
| 10702 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10703 | } |
| 10704 | |
| 10705 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10706 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10707 | */ |
| 10708 | @Override |
| 10709 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10710 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10711 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10712 | enforceModifyPermission(); |
| 10713 | |
| 10714 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10715 | : Boolean.parseBoolean(enabledStr); |
| 10716 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10717 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10718 | } |
| 10719 | |
| 10720 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10721 | * Sends a device to device communication message. Only usable via shell. |
| 10722 | * @param message message to send. |
| 10723 | * @param value message value. |
| 10724 | */ |
| 10725 | @Override |
| 10726 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10727 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10728 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10729 | enforceModifyPermission(); |
| 10730 | |
| 10731 | final long identity = Binder.clearCallingIdentity(); |
| 10732 | try { |
| 10733 | TelephonyConnectionService service = |
| 10734 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10735 | if (service == null) { |
| 10736 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10737 | return; |
| 10738 | } |
| 10739 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10740 | } finally { |
| 10741 | Binder.restoreCallingIdentity(identity); |
| 10742 | } |
| 10743 | } |
| 10744 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10745 | /** |
| 10746 | * Sets the specified device to device transport active. |
| 10747 | * @param transport The transport to set active. |
| 10748 | */ |
| 10749 | @Override |
| 10750 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10751 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10752 | "setActiveDeviceToDeviceTransport"); |
| 10753 | enforceModifyPermission(); |
| 10754 | |
| 10755 | final long identity = Binder.clearCallingIdentity(); |
| 10756 | try { |
| 10757 | TelephonyConnectionService service = |
| 10758 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10759 | if (service == null) { |
| 10760 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10761 | return; |
| 10762 | } |
| 10763 | service.setActiveDeviceToDeviceTransport(transport); |
| 10764 | } finally { |
| 10765 | Binder.restoreCallingIdentity(identity); |
| 10766 | } |
| 10767 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10768 | |
Tyler Gunn | d433926 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10769 | @Override |
| 10770 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10771 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10772 | "setDeviceToDeviceForceEnabled"); |
| 10773 | |
| 10774 | final long identity = Binder.clearCallingIdentity(); |
| 10775 | try { |
| 10776 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10777 | p -> { |
| 10778 | Phone thePhone = p.getImsPhone(); |
| 10779 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10780 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10781 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10782 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10783 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10784 | (ImsPhoneCallTracker) tracker; |
| 10785 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10786 | } |
| 10787 | } |
| 10788 | } |
| 10789 | ); |
| 10790 | } finally { |
| 10791 | Binder.restoreCallingIdentity(identity); |
| 10792 | } |
| 10793 | } |
| 10794 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10795 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10796 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10797 | */ |
| 10798 | @Override |
| 10799 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10800 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10801 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10802 | } |
| 10803 | |
| 10804 | /** |
| 10805 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10806 | */ |
| 10807 | @Override |
| 10808 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10809 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10810 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10811 | enforceModifyPermission(); |
| 10812 | |
| 10813 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10814 | : Boolean.parseBoolean(enabledStr); |
| 10815 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10816 | subId, enabled); |
| 10817 | } |
| 10818 | |
| 10819 | /** |
| 10820 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10821 | */ |
| 10822 | @Override |
| 10823 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10824 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10825 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10826 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10827 | |
| 10828 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10829 | * Overrides the ims feature validation result |
| 10830 | */ |
| 10831 | @Override |
| 10832 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10833 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10834 | "setImsFeatureValidationOverride"); |
| 10835 | |
| 10836 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10837 | : Boolean.parseBoolean(enabledStr); |
| 10838 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10839 | subId, enabled); |
| 10840 | } |
| 10841 | |
| 10842 | /** |
| 10843 | * Gets the ims feature validation override value |
| 10844 | */ |
| 10845 | @Override |
| 10846 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10847 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10848 | "getImsFeatureValidationOverride"); |
| 10849 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10850 | } |
| 10851 | |
| 10852 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10853 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10854 | * their mobile plan. |
| 10855 | */ |
| 10856 | @Override |
| 10857 | public String getMobileProvisioningUrl() { |
| 10858 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10859 | final long identity = Binder.clearCallingIdentity(); |
| 10860 | try { |
| 10861 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10862 | } finally { |
| 10863 | Binder.restoreCallingIdentity(identity); |
| 10864 | } |
| 10865 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10866 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10867 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10868 | * Get the EAB contact from the EAB database. |
| 10869 | */ |
| 10870 | @Override |
| 10871 | public String getContactFromEab(String contact) { |
| 10872 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10873 | enforceModifyPermission(); |
| 10874 | final long identity = Binder.clearCallingIdentity(); |
| 10875 | try { |
| 10876 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10877 | } finally { |
| 10878 | Binder.restoreCallingIdentity(identity); |
| 10879 | } |
| 10880 | } |
| 10881 | |
| 10882 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10883 | * Get the EAB capability from the EAB database. |
| 10884 | */ |
| 10885 | @Override |
| 10886 | public String getCapabilityFromEab(String contact) { |
| 10887 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10888 | enforceModifyPermission(); |
| 10889 | final long identity = Binder.clearCallingIdentity(); |
| 10890 | try { |
| 10891 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10892 | } finally { |
| 10893 | Binder.restoreCallingIdentity(identity); |
| 10894 | } |
| 10895 | } |
| 10896 | |
| 10897 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10898 | * Remove the EAB contacts from the EAB database. |
| 10899 | */ |
| 10900 | @Override |
| 10901 | public int removeContactFromEab(int subId, String contacts) { |
| 10902 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10903 | enforceModifyPermission(); |
| 10904 | final long identity = Binder.clearCallingIdentity(); |
| 10905 | try { |
| 10906 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10907 | } finally { |
| 10908 | Binder.restoreCallingIdentity(identity); |
| 10909 | } |
| 10910 | } |
| 10911 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10912 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10913 | public boolean getDeviceUceEnabled() { |
| 10914 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10915 | final long identity = Binder.clearCallingIdentity(); |
| 10916 | try { |
| 10917 | return mApp.getDeviceUceEnabled(); |
| 10918 | } finally { |
| 10919 | Binder.restoreCallingIdentity(identity); |
| 10920 | } |
| 10921 | } |
| 10922 | |
| 10923 | @Override |
| 10924 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10925 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10926 | final long identity = Binder.clearCallingIdentity(); |
| 10927 | try { |
| 10928 | mApp.setDeviceUceEnabled(isEnabled); |
| 10929 | } finally { |
| 10930 | Binder.restoreCallingIdentity(identity); |
| 10931 | } |
| 10932 | } |
| 10933 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10934 | /** |
| 10935 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10936 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10937 | */ |
| 10938 | // Used for SHELL command only right now. |
| 10939 | @Override |
| 10940 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10941 | List<String> featureTags) { |
| 10942 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10943 | "addUceRegistrationOverrideShell"); |
| 10944 | final long identity = Binder.clearCallingIdentity(); |
| 10945 | try { |
| 10946 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10947 | new ArraySet<>(featureTags)); |
| 10948 | } catch (ImsException e) { |
| 10949 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10950 | } finally { |
| 10951 | Binder.restoreCallingIdentity(identity); |
| 10952 | } |
| 10953 | } |
| 10954 | |
| 10955 | /** |
| 10956 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10957 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10958 | */ |
| 10959 | // Used for SHELL command only right now. |
| 10960 | @Override |
| 10961 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10962 | List<String> featureTags) { |
| 10963 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10964 | "removeUceRegistrationOverrideShell"); |
| 10965 | final long identity = Binder.clearCallingIdentity(); |
| 10966 | try { |
| 10967 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10968 | new ArraySet<>(featureTags)); |
| 10969 | } catch (ImsException e) { |
| 10970 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10971 | } finally { |
| 10972 | Binder.restoreCallingIdentity(identity); |
| 10973 | } |
| 10974 | } |
| 10975 | |
| 10976 | /** |
| 10977 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10978 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10979 | */ |
| 10980 | // Used for SHELL command only right now. |
| 10981 | @Override |
| 10982 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10983 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10984 | "clearUceRegistrationOverrideShell"); |
| 10985 | final long identity = Binder.clearCallingIdentity(); |
| 10986 | try { |
| 10987 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10988 | } catch (ImsException e) { |
| 10989 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10990 | } finally { |
| 10991 | Binder.restoreCallingIdentity(identity); |
| 10992 | } |
| 10993 | } |
| 10994 | |
| 10995 | /** |
| 10996 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10997 | */ |
| 10998 | // Used for SHELL command only right now. |
| 10999 | @Override |
| 11000 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 11001 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 11002 | "getLatestRcsContactUceCapabilityShell"); |
| 11003 | final long identity = Binder.clearCallingIdentity(); |
| 11004 | try { |
| 11005 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 11006 | } catch (ImsException e) { |
| 11007 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11008 | } finally { |
| 11009 | Binder.restoreCallingIdentity(identity); |
| 11010 | } |
| 11011 | } |
| 11012 | |
| 11013 | /** |
| 11014 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 11015 | * device does not have an active PUBLISH. |
| 11016 | */ |
| 11017 | // Used for SHELL command only right now. |
| 11018 | @Override |
| 11019 | public String getLastUcePidfXmlShell(int subId) { |
| 11020 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 11021 | final long identity = Binder.clearCallingIdentity(); |
| 11022 | try { |
| 11023 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 11024 | } catch (ImsException e) { |
| 11025 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11026 | } finally { |
| 11027 | Binder.restoreCallingIdentity(identity); |
| 11028 | } |
| 11029 | } |
| 11030 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 11031 | /** |
| 11032 | * Remove UCE requests cannot be sent to the network status. |
| 11033 | */ |
| 11034 | // Used for SHELL command only right now. |
| 11035 | @Override |
| 11036 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 11037 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 11038 | final long identity = Binder.clearCallingIdentity(); |
| 11039 | try { |
| 11040 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 11041 | } catch (ImsException e) { |
| 11042 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11043 | } finally { |
| 11044 | Binder.restoreCallingIdentity(identity); |
| 11045 | } |
| 11046 | } |
| 11047 | |
James.cf Lin | 18bb900 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 11048 | /** |
| 11049 | * Remove UCE requests cannot be sent to the network status. |
| 11050 | */ |
| 11051 | // Used for SHELL command only. |
| 11052 | @Override |
| 11053 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 11054 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 11055 | final long identity = Binder.clearCallingIdentity(); |
| 11056 | try { |
| 11057 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 11058 | } catch (ImsException e) { |
| 11059 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 11060 | } finally { |
| 11061 | Binder.restoreCallingIdentity(identity); |
| 11062 | } |
| 11063 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 11064 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 11065 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11066 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11067 | String callingPackage) { |
| 11068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11069 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 11070 | |
| 11071 | final int callingUid = Binder.getCallingUid(); |
| 11072 | // Verify that tha callingPackage belongs to the calling UID |
| 11073 | mApp.getSystemService(AppOpsManager.class) |
| 11074 | .checkPackage(callingUid, callingPackage); |
| 11075 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11076 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11077 | |
| 11078 | final long identity = Binder.clearCallingIdentity(); |
| 11079 | try { |
| 11080 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11081 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11082 | |
| 11083 | if (result instanceof IllegalStateException) { |
| 11084 | throw (IllegalStateException) result; |
| 11085 | } |
| 11086 | } finally { |
| 11087 | Binder.restoreCallingIdentity(identity); |
| 11088 | } |
| 11089 | } |
| 11090 | |
| 11091 | @Override |
| 11092 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 11093 | String callingPackage) { |
| 11094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 11095 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 11096 | |
| 11097 | final int callingUid = Binder.getCallingUid(); |
| 11098 | // Verify that tha callingPackage belongs to the calling UID |
| 11099 | mApp.getSystemService(AppOpsManager.class) |
| 11100 | .checkPackage(callingUid, callingPackage); |
| 11101 | |
| 11102 | final long identity = Binder.clearCallingIdentity(); |
| 11103 | try { |
| 11104 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 11105 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 11106 | |
| 11107 | if (result instanceof IllegalStateException) { |
| 11108 | throw (IllegalStateException) result; |
| 11109 | } |
| 11110 | } finally { |
| 11111 | Binder.restoreCallingIdentity(identity); |
| 11112 | } |
| 11113 | } |
| 11114 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11115 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 11116 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11117 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 11118 | // phone/system process do not have further restriction on request |
| 11119 | return; |
| 11120 | } |
| 11121 | |
| 11122 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11123 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11124 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 11125 | context.enforceCallingOrSelfPermission( |
| 11126 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 11127 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 11128 | } |
| 11129 | |
| 11130 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 11131 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11132 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11133 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11134 | || info.isEnabled()) { |
| 11135 | throw new IllegalArgumentException( |
| 11136 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11137 | } |
| 11138 | |
| 11139 | // Thresholds length for each RAN need in range. This has been validated in |
| 11140 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11141 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11142 | final int[] thresholds = info.getThresholds(); |
| 11143 | Objects.requireNonNull(thresholds); |
| 11144 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11145 | || thresholds.length |
| 11146 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11147 | throw new IllegalArgumentException( |
| 11148 | "thresholds length is out of range: " + thresholds.length); |
| 11149 | } |
| 11150 | } |
| 11151 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11152 | |
| 11153 | /** |
| 11154 | * Gets the current phone capability. |
| 11155 | * |
| 11156 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11157 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11158 | * It's used to evaluate possible phone config change, for example from single |
| 11159 | * SIM device to multi-SIM device. |
| 11160 | */ |
| 11161 | @Override |
| 11162 | public PhoneCapability getPhoneCapability() { |
| 11163 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11164 | final long identity = Binder.clearCallingIdentity(); |
| 11165 | try { |
| 11166 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11167 | } finally { |
| 11168 | Binder.restoreCallingIdentity(identity); |
| 11169 | } |
| 11170 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11171 | |
| 11172 | /** |
| 11173 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11174 | * required to be done shortly after the API is invoked. |
| 11175 | */ |
| 11176 | @Override |
| 11177 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11178 | public int prepareForUnattendedReboot() { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11179 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11180 | enforceRebootPermission(); |
| 11181 | |
| 11182 | final long identity = Binder.clearCallingIdentity(); |
| 11183 | try { |
Rafael Higuera Silva | d963064 | 2021-09-20 15:32:01 +0000 | [diff] [blame] | 11184 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null, workSource); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11185 | } finally { |
| 11186 | Binder.restoreCallingIdentity(identity); |
| 11187 | } |
| 11188 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11189 | |
| 11190 | /** |
| 11191 | * Request to get the current slicing configuration including URSP rules and |
| 11192 | * NSSAIs (configured, allowed and rejected). |
| 11193 | * |
| 11194 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11195 | */ |
| 11196 | @Override |
| 11197 | public void getSlicingConfig(ResultReceiver callback) { |
| 11198 | enforceReadPrivilegedPermission("getSlicingConfig"); |
| 11199 | |
| 11200 | final long identity = Binder.clearCallingIdentity(); |
| 11201 | try { |
| 11202 | Phone phone = getDefaultPhone(); |
| 11203 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11204 | } finally { |
| 11205 | Binder.restoreCallingIdentity(identity); |
| 11206 | } |
| 11207 | } |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11208 | |
| 11209 | /** |
| 11210 | * Register an IMS connection state callback |
| 11211 | */ |
| 11212 | @Override |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11213 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11214 | String callingPackage) { |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11215 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11216 | // ImsMmTelManager |
| 11217 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11218 | TelephonyPermissions |
| 11219 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11220 | mApp, subId, "registerImsStateCallback"); |
| 11221 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11222 | // ImsRcsManager or SipDelegateManager |
| 11223 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11224 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11225 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11226 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11227 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11228 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11229 | } |
| 11230 | |
| 11231 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11232 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11233 | "IMS not available on device."); |
| 11234 | } |
| 11235 | |
| 11236 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11237 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11238 | } |
| 11239 | |
| 11240 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11241 | if (controller == null) { |
| 11242 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11243 | "IMS not available on device."); |
| 11244 | } |
| 11245 | |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11246 | if (callingPackage == null) { |
| 11247 | callingPackage = getCurrentPackageName(); |
| 11248 | } |
| 11249 | |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11250 | final long token = Binder.clearCallingIdentity(); |
| 11251 | try { |
| 11252 | int slotId = getSlotIndexOrException(subId); |
Hunsuk Choi | 89bd22c | 2021-11-01 13:04:54 +0000 | [diff] [blame] | 11253 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
Hunsuk Choi | 3b742d6 | 2021-10-25 19:48:34 +0000 | [diff] [blame] | 11254 | } catch (ImsException e) { |
| 11255 | throw new ServiceSpecificException(e.getCode()); |
| 11256 | } finally { |
| 11257 | Binder.restoreCallingIdentity(token); |
| 11258 | } |
| 11259 | } |
| 11260 | |
| 11261 | /** |
| 11262 | * Unregister an IMS connection state callback |
| 11263 | */ |
| 11264 | @Override |
| 11265 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11266 | final long token = Binder.clearCallingIdentity(); |
| 11267 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11268 | if (controller == null) { |
| 11269 | return; |
| 11270 | } |
| 11271 | try { |
| 11272 | controller.unregisterImsStateCallback(cb); |
| 11273 | } finally { |
| 11274 | Binder.restoreCallingIdentity(token); |
| 11275 | } |
| 11276 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11277 | |
| 11278 | /** |
| 11279 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11280 | * |
| 11281 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11282 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11283 | * SecurityException. |
| 11284 | * If there is current registered network this value will be same as the registered cell |
| 11285 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11286 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11287 | * it will be cleared and null will be returned. |
| 11288 | * |
| 11289 | */ |
| 11290 | @Override |
| 11291 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11292 | String callingFeatureId) { |
| 11293 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11294 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11295 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11296 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11297 | .setCallingPackage(callingPackage) |
| 11298 | .setCallingFeatureId(callingFeatureId) |
| 11299 | .setCallingPid(Binder.getCallingPid()) |
| 11300 | .setCallingUid(Binder.getCallingUid()) |
| 11301 | .setMethod("getLastKnownCellIdentity") |
| 11302 | .setLogAsInfo(true) |
| 11303 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11304 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11305 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11306 | .build()); |
| 11307 | |
| 11308 | boolean hasFinePermission = |
| 11309 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11310 | if (!hasFinePermission |
| 11311 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11312 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11313 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11314 | } |
| 11315 | |
| 11316 | final long identity = Binder.clearCallingIdentity(); |
| 11317 | try { |
| 11318 | Phone phone = getPhone(subId); |
| 11319 | if (phone == null) return null; |
| 11320 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11321 | if (sst == null) return null; |
| 11322 | return sst.getLastKnownCellIdentity(); |
| 11323 | } finally { |
| 11324 | Binder.restoreCallingIdentity(identity); |
| 11325 | } |
| 11326 | } |
Jack Yu | 4c0a550 | 2021-12-03 23:58:26 -0800 | [diff] [blame] | 11327 | |
| 11328 | @Override |
| 11329 | public boolean isUsingNewDataStack() { |
| 11330 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "isUsingNewDataStack"); |
| 11331 | return getDefaultPhone().isUsingNewDataStack(); |
| 11332 | } |
jimsun | 3b9ccac | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11333 | |
| 11334 | /** |
| 11335 | * Sets the modem service class Name that Telephony will bind to. |
| 11336 | * |
| 11337 | * @param serviceName The class name of the modem service. |
| 11338 | * @return true if the operation is succeed, otherwise false. |
| 11339 | */ |
| 11340 | public boolean setModemService(String serviceName) { |
| 11341 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11342 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11343 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11344 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11345 | "setModemService"); |
| 11346 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11347 | } |
| 11348 | |
| 11349 | /** |
| 11350 | * Return the class name of the currently bounded modem service. |
| 11351 | * |
| 11352 | * @return the class name of the modem service. |
| 11353 | */ |
| 11354 | public String getModemService() { |
| 11355 | String result; |
| 11356 | Log.d(LOG_TAG, "getModemService"); |
| 11357 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11358 | TelephonyPermissions |
| 11359 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11360 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11361 | "getModemService"); |
| 11362 | result = mPhoneConfigurationManager.getModemService(); |
| 11363 | Log.d(LOG_TAG, "result = " + result); |
| 11364 | return result; |
| 11365 | } |
Hunter Knepshield | 2b076fa | 2022-01-19 02:26:22 -0800 | [diff] [blame] | 11366 | |
| 11367 | @Override |
| 11368 | public void setVoiceServiceStateOverride(int subId, boolean hasService, String callingPackage) { |
| 11369 | // Only telecom (and shell, for CTS purposes) is allowed to call this method. |
| 11370 | mApp.enforceCallingOrSelfPermission( |
| 11371 | permission.BIND_TELECOM_CONNECTION_SERVICE, "setVoiceServiceStateOverride"); |
| 11372 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11373 | |
| 11374 | final long identity = Binder.clearCallingIdentity(); |
| 11375 | try { |
| 11376 | Phone phone = getPhone(subId); |
| 11377 | if (phone == null) return; |
| 11378 | phone.setVoiceServiceStateOverride(hasService); |
| 11379 | } finally { |
| 11380 | Binder.restoreCallingIdentity(identity); |
| 11381 | } |
| 11382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11383 | } |