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 | fa31464 | 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 | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 31 | import android.annotation.RequiresPermission; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 33 | import android.app.PendingIntent; |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 34 | import android.app.compat.CompatChanges; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 35 | import android.app.role.RoleManager; |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 36 | import android.compat.Compatibility; |
sandeepjs | 0a502c4 | 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; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 75 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 76 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 77 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 78 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 79 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 80 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 81 | import android.telephony.CellIdentityCdma; |
| 82 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 83 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 84 | import android.telephony.CellInfoGsm; |
| 85 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 86 | import android.telephony.ClientRequestStats; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 87 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 88 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 89 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 90 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 91 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 92 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 93 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 94 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 95 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 96 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 97 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 99 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 100 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 101 | import android.telephony.SignalStrengthUpdateRequest; |
| 102 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 103 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 104 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 105 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 106 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 107 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 108 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 109 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 110 | import android.telephony.UiccCardInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 111 | import android.telephony.UiccPortInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 112 | import android.telephony.UiccSlotInfo; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 113 | import android.telephony.UiccSlotMapping; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 114 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 115 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 116 | import android.telephony.data.ApnSetting; |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 117 | import android.telephony.data.NetworkSlicingConfig; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 118 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 119 | import android.telephony.gba.GbaAuthRequest; |
| 120 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 121 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 123 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 124 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 125 | import android.telephony.ims.RegistrationManager; |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 126 | import android.telephony.ims.aidl.IFeatureProvisioningCallback; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 127 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 128 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 129 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 130 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 131 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 132 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 133 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 134 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 135 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 136 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 137 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 139 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 140 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 143 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 144 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 145 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 146 | import com.android.ims.rcs.uce.eab.EabUtil; |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 147 | import com.android.internal.annotations.VisibleForTesting; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.CallStateException; |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.CallTracker; |
Rambo Wang | a743688 | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.CarrierPrivilegesTracker; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.GbaManager; |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.GsmCdmaPhone; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 163 | import com.android.internal.telephony.IImsStateCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.IccCard; |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.IccLogicalChannelRequest; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.RIL; |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 179 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 183 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 184 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 185 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 186 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 187 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 189 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 190 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 191 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 192 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 193 | import com.android.internal.telephony.metrics.RcsStats; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 194 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 195 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 196 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 197 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 198 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 199 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 200 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 201 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 202 | import com.android.internal.telephony.uicc.UiccController; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 203 | import com.android.internal.telephony.uicc.UiccPort; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 204 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 205 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 206 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 207 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 208 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 210 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 211 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 212 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 213 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 214 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 215 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 216 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 217 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 218 | import com.android.services.telephony.TelecomAccountRegistry; |
| 219 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 220 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 221 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 222 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 223 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 224 | import java.io.IOException; |
| 225 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 226 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 228 | import java.util.Arrays; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 229 | import java.util.Collection; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 230 | import java.util.Collections; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 231 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 232 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 234 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 235 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 236 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 237 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 238 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 239 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 240 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 241 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * Implementation of the ITelephony interface. |
| 245 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 246 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 247 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 248 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 249 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 250 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 251 | |
| 252 | // Message codes used with mMainThreadHandler |
| 253 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 254 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 255 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 256 | private static final int CMD_OPEN_CHANNEL = 9; |
| 257 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 258 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 259 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 260 | private static final int CMD_NV_READ_ITEM = 13; |
| 261 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 262 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 263 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 264 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 265 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 266 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 267 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 268 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 269 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 270 | private static final int CMD_SEND_ENVELOPE = 25; |
| 271 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 272 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 273 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 274 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 275 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 276 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 277 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 278 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 279 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 280 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 281 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 282 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 283 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 284 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 285 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 286 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 287 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 288 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 289 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 290 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 291 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 292 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 293 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 294 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 295 | private static final int CMD_SWITCH_SLOTS = 50; |
| 296 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 297 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 298 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 299 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 300 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 301 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 302 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 303 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 304 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 305 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 306 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 307 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 308 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 309 | private static final int CMD_MODEM_REBOOT = 64; |
| 310 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 311 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 312 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 313 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 314 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 315 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 316 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 317 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 318 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 319 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 320 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 321 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 322 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 323 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 324 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 325 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 326 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 327 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 328 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 329 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 330 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 331 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 332 | private static final int CMD_GET_CALL_WAITING = 87; |
| 333 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 334 | private static final int CMD_SET_CALL_WAITING = 89; |
| 335 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 336 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 337 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 338 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 339 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 340 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 341 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 342 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 343 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 344 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 345 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 346 | private static final int CMD_SET_SIM_POWER = 101; |
| 347 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 348 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 349 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 350 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 351 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 352 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 353 | 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] | 354 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 355 | private static final int CMD_GET_SLICING_CONFIG = 110; |
| 356 | private static final int EVENT_GET_SLICING_CONFIG_DONE = 111; |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 357 | private static final int CMD_ERASE_DATA_SHARED_PREFERENCES = 112; |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 358 | private static final int CMD_ENABLE_VONR = 113; |
| 359 | private static final int EVENT_ENABLE_VONR_DONE = 114; |
| 360 | private static final int CMD_IS_VONR_ENABLED = 115; |
| 361 | private static final int EVENT_IS_VONR_ENABLED_DONE = 116; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 363 | // Parameters of select command. |
| 364 | private static final int SELECT_COMMAND = 0xA4; |
| 365 | private static final int SELECT_P1 = 0x04; |
| 366 | private static final int SELECT_P2 = 0; |
| 367 | private static final int SELECT_P3 = 0x10; |
| 368 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 369 | /** The singleton instance. */ |
| 370 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 371 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 372 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 373 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 374 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 375 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 376 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 377 | private AppOpsManager mAppOps; |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 378 | private PackageManager mPm; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 379 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 380 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 381 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 382 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 383 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 385 | /** User Activity */ |
| 386 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 387 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 388 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 389 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 390 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 391 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 392 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 393 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 394 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 395 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 396 | // String to store multi SIM allowed |
| 397 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 398 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 399 | // The AID of ISD-R. |
| 400 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 401 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 402 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 403 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 404 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 405 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 406 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 407 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 408 | 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] | 409 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 410 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 411 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 412 | */ |
| 413 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 414 | "reset_network_erase_modem_config_enabled"; |
| 415 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 416 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 417 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 418 | /** |
| 419 | * With support for MEP(multiple enabled profile) in Android T, a SIM card can have more than |
| 420 | * one ICCID active at the same time. |
| 421 | * Apps should use below API signatures if targeting SDK is T and beyond. |
| 422 | * |
| 423 | * @hide |
| 424 | */ |
| 425 | @ChangeId |
| 426 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 427 | public static final long GET_API_SIGNATURES_FROM_UICC_PORT_INFO = 202110963L; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 428 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 429 | /** |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 430 | * Apps targeting on Android T and beyond will get exception whenever icc close channel |
| 431 | * operation fails. |
| 432 | */ |
| 433 | @ChangeId |
| 434 | @EnabledSince(targetSdkVersion = Build.VERSION_CODES.TIRAMISU) |
| 435 | public static final long ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE = 208739934L; |
| 436 | |
| 437 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 438 | * A request object to use for transmitting data to an ICC. |
| 439 | */ |
| 440 | private static final class IccAPDUArgument { |
| 441 | public int channel, cla, command, p1, p2, p3; |
| 442 | public String data; |
| 443 | |
| 444 | public IccAPDUArgument(int channel, int cla, int command, |
| 445 | int p1, int p2, int p3, String data) { |
| 446 | this.channel = channel; |
| 447 | this.cla = cla; |
| 448 | this.command = command; |
| 449 | this.p1 = p1; |
| 450 | this.p2 = p2; |
| 451 | this.p3 = p3; |
| 452 | this.data = data; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 457 | * A request object to use for transmitting data to an ICC. |
| 458 | */ |
| 459 | private static final class ManualNetworkSelectionArgument { |
| 460 | public OperatorInfo operatorInfo; |
| 461 | public boolean persistSelection; |
| 462 | |
| 463 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 464 | this.operatorInfo = operatorInfo; |
| 465 | this.persistSelection = persistSelection; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 470 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 471 | * request after sending. The main thread will notify the request when it is complete. |
| 472 | */ |
| 473 | private static final class MainThreadRequest { |
| 474 | /** The argument to use for the request */ |
| 475 | public Object argument; |
| 476 | /** The result of the request that is run on the main thread */ |
| 477 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 478 | // The subscriber id that this request applies to. Defaults to |
| 479 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 480 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 482 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 483 | public Phone phone; |
| 484 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 485 | public WorkSource workSource; |
| 486 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | public MainThreadRequest(Object argument) { |
| 488 | this.argument = argument; |
| 489 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 490 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 491 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 492 | this.argument = argument; |
| 493 | if (phone != null) { |
| 494 | this.phone = phone; |
| 495 | } |
| 496 | this.workSource = workSource; |
| 497 | } |
| 498 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 499 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 500 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 501 | if (subId != null) { |
| 502 | this.subId = subId; |
| 503 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 504 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 508 | private static final class IncomingThirdPartyCallArgs { |
| 509 | public final ComponentName component; |
| 510 | public final String callId; |
| 511 | public final String callerDisplayName; |
| 512 | |
| 513 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 514 | String callerDisplayName) { |
| 515 | this.component = component; |
| 516 | this.callId = callId; |
| 517 | this.callerDisplayName = callerDisplayName; |
| 518 | } |
| 519 | } |
| 520 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | /** |
| 522 | * A handler that processes messages on the main thread in the phone process. Since many |
| 523 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 524 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 525 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 526 | * on, which will be notified when the operation completes and will contain the result of the |
| 527 | * request. |
| 528 | * |
| 529 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 530 | * note that request.result must be set to something non-null for the calling thread to |
| 531 | * unblock. |
| 532 | */ |
| 533 | private final class MainThreadHandler extends Handler { |
| 534 | @Override |
| 535 | public void handleMessage(Message msg) { |
| 536 | MainThreadRequest request; |
| 537 | Message onCompleted; |
| 538 | AsyncResult ar; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 539 | UiccPort uiccPort; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 541 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 542 | |
| 543 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | case CMD_HANDLE_USSD_REQUEST: { |
| 545 | request = (MainThreadRequest) msg.obj; |
| 546 | final Phone phone = getPhoneFromRequest(request); |
| 547 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 548 | String ussdRequest = ussdObject.first; |
| 549 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 550 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | if (!isUssdApiAllowed(request.subId)) { |
| 552 | // Carrier does not support use of this API, return failure. |
| 553 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 554 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 555 | Bundle returnData = new Bundle(); |
| 556 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 557 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 558 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | request.result = true; |
| 560 | notifyRequester(request); |
| 561 | return; |
| 562 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 563 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | try { |
| 565 | request.result = phone != null |
| 566 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 567 | } catch (CallStateException cse) { |
| 568 | request.result = false; |
| 569 | } |
| 570 | // Wake up the requesting thread |
| 571 | notifyRequester(request); |
| 572 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 575 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 576 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 577 | final Phone phone = getPhoneFromRequest(request); |
| 578 | request.result = phone != null ? |
| 579 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 580 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 581 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 582 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 583 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 585 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 586 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 587 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 589 | uiccPort = getUiccPortFromRequest(request); |
| 590 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 591 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 592 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 595 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 596 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 597 | uiccPort.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 598 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 599 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 600 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 602 | break; |
| 603 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 604 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 605 | ar = (AsyncResult) msg.obj; |
| 606 | request = (MainThreadRequest) ar.userObj; |
| 607 | if (ar.exception == null && ar.result != null) { |
| 608 | request.result = ar.result; |
| 609 | } else { |
| 610 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 611 | if (ar.result == null) { |
| 612 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 613 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 615 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 616 | } else { |
| 617 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 618 | } |
| 619 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 623 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 624 | request = (MainThreadRequest) msg.obj; |
| 625 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 626 | uiccPort = getUiccPortFromRequest(request); |
| 627 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 628 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 629 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | } else { |
| 632 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 633 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 634 | uiccPort.iccTransmitApduBasicChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 636 | iccArgument.p3, iccArgument.data, onCompleted); |
| 637 | } |
| 638 | break; |
| 639 | |
| 640 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
| 643 | if (ar.exception == null && ar.result != null) { |
| 644 | request.result = ar.result; |
| 645 | } else { |
| 646 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 647 | if (ar.result == null) { |
| 648 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 649 | } else if (ar.exception instanceof CommandException) { |
| 650 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 651 | ar.exception); |
| 652 | } else { |
| 653 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 654 | } |
| 655 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 656 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case CMD_EXCHANGE_SIM_IO: |
| 660 | request = (MainThreadRequest) msg.obj; |
| 661 | iccArgument = (IccAPDUArgument) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 662 | uiccPort = getUiccPortFromRequest(request); |
| 663 | if (uiccPort == null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | loge("iccExchangeSimIO: No UICC"); |
| 665 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 669 | request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 670 | uiccPort.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 671 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 672 | iccArgument.data, onCompleted); |
| 673 | } |
| 674 | break; |
| 675 | |
| 676 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 677 | ar = (AsyncResult) msg.obj; |
| 678 | request = (MainThreadRequest) ar.userObj; |
| 679 | if (ar.exception == null && ar.result != null) { |
| 680 | request.result = ar.result; |
| 681 | } else { |
| 682 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 683 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 687 | case CMD_SEND_ENVELOPE: |
| 688 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 689 | uiccPort = getUiccPortFromRequest(request); |
| 690 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | loge("sendEnvelopeWithStatus: No UICC"); |
| 692 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | } else { |
| 695 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 696 | uiccPort.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 697 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_SEND_ENVELOPE_DONE: |
| 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 705 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 706 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 707 | if (ar.result == null) { |
| 708 | loge("sendEnvelopeWithStatus: Empty response"); |
| 709 | } else if (ar.exception instanceof CommandException) { |
| 710 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 711 | ar.exception); |
| 712 | } else { |
| 713 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 714 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 715 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 717 | break; |
| 718 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | case CMD_OPEN_CHANNEL: |
| 720 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 721 | uiccPort = getUiccPortFromRequest(request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 722 | IccLogicalChannelRequest openChannelRequest = |
| 723 | (IccLogicalChannelRequest) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 724 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 726 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 727 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | } else { |
| 730 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 731 | uiccPort.iccOpenLogicalChannel(openChannelRequest.aid, |
| 732 | openChannelRequest.p2, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 733 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_OPEN_CHANNEL_DONE: |
| 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 739 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 741 | int[] result = (int[]) ar.result; |
| 742 | int channelId = result[0]; |
| 743 | byte[] selectResponse = null; |
| 744 | if (result.length > 1) { |
| 745 | selectResponse = new byte[result.length - 1]; |
| 746 | for (int i = 1; i < result.length; ++i) { |
| 747 | selectResponse[i - 1] = (byte) result[i]; |
| 748 | } |
| 749 | } |
| 750 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 751 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Rambo Wang | 805c717 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 752 | |
| 753 | uiccPort = getUiccPortFromRequest(request); |
| 754 | IccLogicalChannelRequest channelRequest = |
| 755 | (IccLogicalChannelRequest) request.argument; |
| 756 | channelRequest.channel = channelId; |
| 757 | uiccPort.onLogicalChannelOpened(channelRequest); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 759 | if (ar.result == null) { |
| 760 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 762 | if (ar.exception != null) { |
| 763 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 764 | } |
| 765 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 766 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 767 | if (ar.exception instanceof CommandException) { |
| 768 | CommandException.Error error = |
| 769 | ((CommandException) (ar.exception)).getCommandError(); |
| 770 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 771 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 772 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 773 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 774 | } |
| 775 | } |
| 776 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 777 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 778 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 779 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 780 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case CMD_CLOSE_CHANNEL: |
| 784 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 785 | uiccPort = getUiccPortFromRequest(request); |
| 786 | if (uiccPort == null) { |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 787 | loge("iccCloseLogicalChannel: No UICC"); |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 788 | throw new IllegalArgumentException("iccCloseLogicalChannel: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 789 | } else { |
| 790 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 791 | uiccPort.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 792 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 793 | break; |
| 794 | |
| 795 | case EVENT_CLOSE_CHANNEL_DONE: |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 796 | ar = (AsyncResult) msg.obj; |
| 797 | request = (MainThreadRequest) ar.userObj; |
| 798 | if (ar.exception == null) { |
| 799 | request.result = true; |
Rambo Wang | 805c717 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 800 | uiccPort = getUiccPortFromRequest(request); |
| 801 | final int channelId = (Integer) request.argument; |
| 802 | uiccPort.onLogicalChannelClosed(channelId); |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 803 | } else { |
| 804 | request.result = false; |
| 805 | if (ar.exception instanceof CommandException) { |
| 806 | loge("iccCloseLogicalChannel: CommandException: " + ar.exception); |
| 807 | CommandException.Error error = |
| 808 | ((CommandException) (ar.exception)).getCommandError(); |
| 809 | // before this feature is enabled, this API should only return false if |
| 810 | // the operation fails instead of throwing runtime exception for |
| 811 | // backward-compatibility. |
| 812 | if (Compatibility.isChangeEnabled( |
| 813 | ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE) |
| 814 | && error == CommandException.Error.INVALID_ARGUMENTS) { |
| 815 | throw new IllegalArgumentException( |
| 816 | "iccCloseLogicalChannel: invalid argument "); |
| 817 | } |
| 818 | } else { |
| 819 | loge("iccCloseLogicalChannel: Unknown exception"); |
| 820 | } |
| 821 | if (Compatibility.isChangeEnabled(ICC_CLOSE_CHANNEL_EXCEPTION_ON_FAILURE)) { |
| 822 | throw new IllegalStateException( |
| 823 | "exception from modem to close iccLogical Channel"); |
| 824 | } |
| 825 | } |
| 826 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case CMD_NV_READ_ITEM: |
| 830 | request = (MainThreadRequest) msg.obj; |
| 831 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 832 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 833 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 837 | ar = (AsyncResult) msg.obj; |
| 838 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 839 | if (ar.exception == null && ar.result != null) { |
| 840 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 841 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 842 | request.result = ""; |
| 843 | if (ar.result == null) { |
| 844 | loge("nvReadItem: Empty response"); |
| 845 | } else if (ar.exception instanceof CommandException) { |
| 846 | loge("nvReadItem: CommandException: " + |
| 847 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 848 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 849 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 850 | } |
| 851 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 852 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 853 | break; |
| 854 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 855 | case CMD_NV_WRITE_ITEM: |
| 856 | request = (MainThreadRequest) msg.obj; |
| 857 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 858 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 859 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 860 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 861 | break; |
| 862 | |
| 863 | case EVENT_NV_WRITE_ITEM_DONE: |
| 864 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 865 | break; |
| 866 | |
| 867 | case CMD_NV_WRITE_CDMA_PRL: |
| 868 | request = (MainThreadRequest) msg.obj; |
| 869 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 870 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 874 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 875 | break; |
| 876 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 877 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 878 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 879 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 880 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 881 | break; |
| 882 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 883 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 884 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 885 | break; |
| 886 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 887 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 888 | request = (MainThreadRequest) msg.obj; |
| 889 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 890 | request); |
| 891 | Phone phone = getPhoneFromRequest(request); |
| 892 | if (phone != null) { |
| 893 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 894 | } else { |
| 895 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 896 | request.result = false; |
| 897 | notifyRequester(request); |
| 898 | } |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 903 | ar = (AsyncResult) msg.obj; |
| 904 | request = (MainThreadRequest) ar.userObj; |
| 905 | if (ar.exception == null && ar.result != null) { |
| 906 | request.result = ar.result; |
| 907 | } else { |
| 908 | // request.result must be set to something non-null |
| 909 | // for the calling thread to unblock |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 910 | if (ar.result != null) { |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 911 | request.result = ar.result; |
| 912 | } else { |
| 913 | request.result = false; |
| 914 | } |
| 915 | if (ar.result == null) { |
| 916 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 917 | } else if (ar.exception instanceof CommandException) { |
| 918 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 919 | + ar.exception); |
| 920 | } else { |
| 921 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 922 | } |
| 923 | } |
| 924 | notifyRequester(request); |
| 925 | break; |
| 926 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 927 | case CMD_IS_VONR_ENABLED: { |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_IS_VONR_ENABLED_DONE, |
| 930 | request); |
| 931 | Phone phone = getPhoneFromRequest(request); |
| 932 | if (phone != null) { |
| 933 | phone.isVoNrEnabled(onCompleted, request.workSource); |
| 934 | } else { |
| 935 | loge("isVoNrEnabled: No phone object"); |
| 936 | request.result = false; |
| 937 | notifyRequester(request); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | case EVENT_IS_VONR_ENABLED_DONE: |
| 943 | ar = (AsyncResult) msg.obj; |
| 944 | request = (MainThreadRequest) ar.userObj; |
| 945 | if (ar.exception == null && ar.result != null) { |
| 946 | request.result = ar.result; |
| 947 | } else { |
| 948 | // request.result must be set to something non-null |
| 949 | // for the calling thread to unblock |
| 950 | if (ar.result != null) { |
| 951 | request.result = ar.result; |
| 952 | } else { |
| 953 | request.result = false; |
| 954 | } |
| 955 | if (ar.result == null) { |
| 956 | loge("isVoNrEnabled: Empty response"); |
| 957 | } else if (ar.exception instanceof CommandException) { |
| 958 | loge("isVoNrEnabled: CommandException: " |
| 959 | + ar.exception); |
| 960 | } else { |
| 961 | loge("isVoNrEnabled: Unknown exception"); |
| 962 | } |
| 963 | } |
| 964 | notifyRequester(request); |
| 965 | break; |
| 966 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 967 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 968 | request = (MainThreadRequest) msg.obj; |
| 969 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 970 | Phone phone = getPhoneFromRequest(request); |
| 971 | if (phone != null) { |
| 972 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 973 | request.workSource); |
| 974 | } else { |
| 975 | loge("enableNrDualConnectivity: No phone object"); |
| 976 | request.result = |
| 977 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 978 | notifyRequester(request); |
| 979 | } |
| 980 | break; |
| 981 | } |
| 982 | |
| 983 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 984 | ar = (AsyncResult) msg.obj; |
| 985 | request = (MainThreadRequest) ar.userObj; |
| 986 | if (ar.exception == null) { |
| 987 | request.result = |
| 988 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 989 | } else { |
| 990 | request.result = |
| 991 | TelephonyManager |
| 992 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 993 | if (ar.exception instanceof CommandException) { |
| 994 | CommandException.Error error = |
| 995 | ((CommandException) (ar.exception)).getCommandError(); |
| 996 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 997 | request.result = |
| 998 | TelephonyManager |
| 999 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 1000 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1001 | request.result = |
| 1002 | TelephonyManager |
| 1003 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 1004 | } |
| 1005 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 1006 | + ar.exception); |
| 1007 | } else { |
| 1008 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 1009 | } |
| 1010 | } |
| 1011 | notifyRequester(request); |
| 1012 | break; |
| 1013 | } |
| 1014 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 1015 | case CMD_ENABLE_VONR: { |
| 1016 | request = (MainThreadRequest) msg.obj; |
| 1017 | onCompleted = obtainMessage(EVENT_ENABLE_VONR_DONE, request); |
| 1018 | Phone phone = getPhoneFromRequest(request); |
| 1019 | if (phone != null) { |
| 1020 | phone.setVoNrEnabled((boolean) request.argument, onCompleted, |
| 1021 | request.workSource); |
| 1022 | } else { |
| 1023 | loge("setVoNrEnabled: No phone object"); |
| 1024 | request.result = |
| 1025 | TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1026 | notifyRequester(request); |
| 1027 | } |
| 1028 | break; |
| 1029 | } |
| 1030 | |
| 1031 | case EVENT_ENABLE_VONR_DONE: { |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
| 1034 | if (ar.exception == null) { |
| 1035 | request.result = TelephonyManager.ENABLE_VONR_SUCCESS; |
| 1036 | } else { |
| 1037 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1038 | if (ar.exception instanceof CommandException) { |
| 1039 | CommandException.Error error = |
| 1040 | ((CommandException) (ar.exception)).getCommandError(); |
| 1041 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1042 | request.result = TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 1043 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1044 | request.result = TelephonyManager.ENABLE_VONR_REQUEST_NOT_SUPPORTED; |
| 1045 | } else { |
| 1046 | request.result = TelephonyManager.ENABLE_VONR_RADIO_ERROR; |
| 1047 | } |
| 1048 | loge("setVoNrEnabled" + ": CommandException: " |
| 1049 | + ar.exception); |
| 1050 | } else { |
| 1051 | loge("setVoNrEnabled" + ": Unknown exception"); |
| 1052 | } |
| 1053 | } |
| 1054 | notifyRequester(request); |
| 1055 | break; |
| 1056 | } |
| 1057 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1058 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1059 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1060 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 1061 | request); |
| 1062 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1063 | break; |
| 1064 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1065 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
| 1068 | if (ar.exception == null && ar.result != null) { |
| 1069 | request.result = ar.result; // Integer |
| 1070 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 1071 | // request.result must be set to something non-null |
| 1072 | // for the calling thread to unblock |
| 1073 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1074 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1075 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1076 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1077 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 1078 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1079 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1080 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1081 | } |
| 1082 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1083 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1084 | break; |
| 1085 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1086 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1087 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1088 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 1089 | request); |
| 1090 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 1091 | (Pair<Integer, Long>) request.argument; |
| 1092 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 1093 | reasonWithNetworkTypes.first, |
| 1094 | reasonWithNetworkTypes.second, |
| 1095 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1096 | break; |
| 1097 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 1098 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 1099 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 1100 | break; |
| 1101 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1102 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 1103 | request = (MainThreadRequest)msg.obj; |
| 1104 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1105 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1106 | break; |
| 1107 | |
| 1108 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 1109 | ar = (AsyncResult)msg.obj; |
| 1110 | request = (MainThreadRequest)ar.userObj; |
| 1111 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1112 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 1113 | break; |
| 1114 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1115 | case CMD_SET_VOICEMAIL_NUMBER: |
| 1116 | request = (MainThreadRequest) msg.obj; |
| 1117 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 1118 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1119 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 1120 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 1124 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 1125 | break; |
| 1126 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 1127 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 1128 | request = (MainThreadRequest) msg.obj; |
| 1129 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 1130 | request); |
| 1131 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 1132 | break; |
| 1133 | |
| 1134 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 1135 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 1136 | break; |
| 1137 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1138 | case CMD_PERFORM_NETWORK_SCAN: |
| 1139 | request = (MainThreadRequest) msg.obj; |
| 1140 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 1141 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 1142 | break; |
| 1143 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1144 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1145 | request = (MainThreadRequest) msg.obj; |
| 1146 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1147 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 1148 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1149 | request.argument; |
| 1150 | int callForwardingReason = args.first; |
| 1151 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1152 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1153 | } |
| 1154 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1155 | ar = (AsyncResult) msg.obj; |
| 1156 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1157 | TelephonyManager.CallForwardingInfoCallback callback = |
| 1158 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 1159 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1160 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1161 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1162 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 1163 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 1164 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 1165 | // any service for voice call. |
| 1166 | if ((callForwardInfo.serviceClass |
| 1167 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Yuchen Dong | 69cc141 | 2021-09-27 20:27:01 +0800 | [diff] [blame] | 1168 | callForwardingInfo = new CallForwardingInfo( |
| 1169 | callForwardInfo.status |
| 1170 | == CommandsInterface.CF_ACTION_ENABLE, |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1171 | callForwardInfo.reason, |
| 1172 | callForwardInfo.number, |
| 1173 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1174 | break; |
| 1175 | } |
| 1176 | } |
| 1177 | // Didn't find a call forward info for voice call. |
| 1178 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1179 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1180 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1181 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1182 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1183 | } else { |
| 1184 | if (ar.result == null) { |
| 1185 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1186 | } |
| 1187 | if (ar.exception != null) { |
| 1188 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1189 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1190 | int errorCode = TelephonyManager |
| 1191 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1192 | if (ar.exception instanceof CommandException) { |
| 1193 | CommandException.Error error = |
| 1194 | ((CommandException) (ar.exception)).getCommandError(); |
| 1195 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1196 | errorCode = TelephonyManager |
| 1197 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1198 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1199 | errorCode = TelephonyManager |
| 1200 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1201 | } |
| 1202 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1203 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1204 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1205 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1206 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1207 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1208 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1209 | request = (MainThreadRequest) msg.obj; |
| 1210 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1211 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1212 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1213 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1214 | request.argument).first; |
| 1215 | request.phone.setCallForwardingOption( |
| 1216 | callForwardingInfoToSet.isEnabled() |
Calvin Pan | 258f1f7 | 2021-07-28 21:46:56 +0800 | [diff] [blame] | 1217 | ? CommandsInterface.CF_ACTION_REGISTRATION |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1218 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1219 | callForwardingInfoToSet.getReason(), |
| 1220 | callForwardingInfoToSet.getNumber(), |
| 1221 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1222 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1223 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1224 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1225 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1226 | ar = (AsyncResult) msg.obj; |
| 1227 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1228 | Consumer<Integer> callback = |
| 1229 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1230 | request.argument).second; |
| 1231 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1232 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1233 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1234 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1235 | if (ar.exception instanceof CommandException) { |
| 1236 | CommandException.Error error = |
| 1237 | ((CommandException) (ar.exception)).getCommandError(); |
| 1238 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1239 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1240 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1241 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1242 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1243 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1244 | } |
| 1245 | } |
| 1246 | callback.accept(errorCode); |
| 1247 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1248 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1249 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1250 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1251 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1252 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1253 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1254 | request = (MainThreadRequest) msg.obj; |
| 1255 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1256 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1257 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1258 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1259 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1260 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1263 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1264 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1265 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1266 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1267 | // Service Class is a bit mask per 3gpp 27.007. |
| 1268 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1269 | if (callForwardResults.length > 1 |
| 1270 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1271 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1272 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1273 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1274 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1275 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1276 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1277 | } |
| 1278 | } else { |
| 1279 | if (ar.result == null) { |
| 1280 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1281 | } |
| 1282 | if (ar.exception != null) { |
| 1283 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1284 | } |
| 1285 | if (ar.exception instanceof CommandException) { |
| 1286 | CommandException.Error error = |
| 1287 | ((CommandException) (ar.exception)).getCommandError(); |
| 1288 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1289 | callForwardingStatus = |
| 1290 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1291 | } |
| 1292 | } |
| 1293 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1294 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1295 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1296 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1297 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1298 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1299 | request = (MainThreadRequest) msg.obj; |
| 1300 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1301 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1302 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1303 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1304 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1305 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1306 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1307 | ar = (AsyncResult) msg.obj; |
| 1308 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1309 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1310 | Consumer<Integer> callback = |
| 1311 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1312 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1313 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1314 | if (ar.exception instanceof CommandException) { |
| 1315 | CommandException.Error error = |
| 1316 | ((CommandException) (ar.exception)).getCommandError(); |
| 1317 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1318 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1319 | } else { |
| 1320 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1321 | } |
| 1322 | } else { |
| 1323 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1324 | } |
| 1325 | } else { |
| 1326 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1327 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1328 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1329 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1330 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1331 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1332 | ar = (AsyncResult) msg.obj; |
| 1333 | request = (MainThreadRequest) ar.userObj; |
| 1334 | CellNetworkScanResult cellScanResult; |
| 1335 | if (ar.exception == null && ar.result != null) { |
| 1336 | cellScanResult = new CellNetworkScanResult( |
| 1337 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1338 | (List<OperatorInfo>) ar.result); |
| 1339 | } else { |
| 1340 | if (ar.result == null) { |
| 1341 | loge("getCellNetworkScanResults: Empty response"); |
| 1342 | } |
| 1343 | if (ar.exception != null) { |
| 1344 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1345 | } |
| 1346 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1347 | if (ar.exception instanceof CommandException) { |
| 1348 | CommandException.Error error = |
| 1349 | ((CommandException) (ar.exception)).getCommandError(); |
| 1350 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1351 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1352 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1353 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1354 | } |
| 1355 | } |
| 1356 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1357 | } |
| 1358 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1359 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1360 | break; |
| 1361 | |
| 1362 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1363 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1364 | ManualNetworkSelectionArgument selArg = |
| 1365 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1366 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1367 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1368 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1369 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1370 | break; |
| 1371 | |
| 1372 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1373 | ar = (AsyncResult) msg.obj; |
| 1374 | request = (MainThreadRequest) ar.userObj; |
| 1375 | if (ar.exception == null) { |
| 1376 | request.result = true; |
| 1377 | } else { |
| 1378 | request.result = false; |
| 1379 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1380 | } |
| 1381 | notifyRequester(request); |
| 1382 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1383 | break; |
| 1384 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1385 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1386 | request = (MainThreadRequest) msg.obj; |
| 1387 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1388 | if (defaultPhone != null) { |
| 1389 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1390 | } else { |
| 1391 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1392 | Bundle bundle = new Bundle(); |
| 1393 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1394 | new ModemActivityInfo(0, 0, 0, |
| 1395 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1396 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1397 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1398 | break; |
| 1399 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1400 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1401 | ar = (AsyncResult) msg.obj; |
| 1402 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1403 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1404 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1405 | ModemActivityInfo ret = null; |
| 1406 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1407 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1408 | // Update the last modem activity info and the result of the request. |
| 1409 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1410 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1411 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1412 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1413 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1414 | .getTransmitTimeMillis(); |
| 1415 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1416 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1417 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1418 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1419 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1420 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1421 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1422 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1423 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1424 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1425 | info.getReceiveTimeMillis() |
| 1426 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1427 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1428 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1429 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1430 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1431 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1432 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1433 | } else { |
| 1434 | if (ar.result == null) { |
| 1435 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1436 | error = TelephonyManager.ModemActivityInfoException |
| 1437 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1438 | } else if (ar.exception instanceof CommandException) { |
| 1439 | loge("queryModemActivityInfo: CommandException: " + |
| 1440 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1441 | error = TelephonyManager.ModemActivityInfoException |
| 1442 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1443 | } else { |
| 1444 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1445 | error = TelephonyManager.ModemActivityInfoException |
| 1446 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1447 | } |
| 1448 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1449 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1450 | if (ret != null) { |
| 1451 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1452 | } else { |
| 1453 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1454 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1455 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1456 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1457 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1458 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1459 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1460 | case CMD_SET_ALLOWED_CARRIERS: |
| 1461 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1462 | CarrierRestrictionRules argument = |
| 1463 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1464 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1465 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1466 | break; |
| 1467 | |
| 1468 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1469 | ar = (AsyncResult) msg.obj; |
| 1470 | request = (MainThreadRequest) ar.userObj; |
| 1471 | if (ar.exception == null && ar.result != null) { |
| 1472 | request.result = ar.result; |
| 1473 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1474 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1475 | if (ar.exception instanceof CommandException) { |
| 1476 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1477 | CommandException.Error error = |
| 1478 | ((CommandException) (ar.exception)).getCommandError(); |
| 1479 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1480 | request.result = |
| 1481 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1482 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1483 | } else { |
| 1484 | loge("setAllowedCarriers: Unknown exception"); |
| 1485 | } |
| 1486 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1487 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1488 | break; |
| 1489 | |
| 1490 | case CMD_GET_ALLOWED_CARRIERS: |
| 1491 | request = (MainThreadRequest) msg.obj; |
| 1492 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1493 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1494 | break; |
| 1495 | |
| 1496 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1497 | ar = (AsyncResult) msg.obj; |
| 1498 | request = (MainThreadRequest) ar.userObj; |
| 1499 | if (ar.exception == null && ar.result != null) { |
| 1500 | request.result = ar.result; |
| 1501 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1502 | request.result = new IllegalStateException( |
| 1503 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1504 | if (ar.result == null) { |
| 1505 | loge("getAllowedCarriers: Empty response"); |
| 1506 | } else if (ar.exception instanceof CommandException) { |
| 1507 | loge("getAllowedCarriers: CommandException: " + |
| 1508 | ar.exception); |
| 1509 | } else { |
| 1510 | loge("getAllowedCarriers: Unknown exception"); |
| 1511 | } |
| 1512 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1513 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1514 | break; |
| 1515 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1516 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1517 | ar = (AsyncResult) msg.obj; |
| 1518 | request = (MainThreadRequest) ar.userObj; |
| 1519 | if (ar.exception == null && ar.result != null) { |
| 1520 | request.result = ar.result; |
| 1521 | } else { |
| 1522 | request.result = new IllegalArgumentException( |
| 1523 | "Failed to retrieve Forbidden Plmns"); |
| 1524 | if (ar.result == null) { |
| 1525 | loge("getForbiddenPlmns: Empty response"); |
| 1526 | } else { |
| 1527 | loge("getForbiddenPlmns: Unknown exception"); |
| 1528 | } |
| 1529 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1530 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1531 | break; |
| 1532 | |
| 1533 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1534 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1535 | uiccPort = getUiccPortFromRequest(request); |
| 1536 | if (uiccPort == null) { |
| 1537 | loge("getForbiddenPlmns() UiccPort is null"); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1538 | request.result = new IllegalArgumentException( |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1539 | "getForbiddenPlmns() UiccPort is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1540 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | } |
| 1543 | Integer appType = (Integer) request.argument; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1544 | UiccCardApplication uiccApp = uiccPort.getApplicationByType(appType); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1545 | if (uiccApp == null) { |
| 1546 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1547 | + appType); |
| 1548 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1549 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1550 | break; |
| 1551 | } else { |
| 1552 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1553 | + " specified type -- " + appType); |
| 1554 | } |
| 1555 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1556 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1557 | onCompleted); |
| 1558 | break; |
| 1559 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1560 | case CMD_SWITCH_SLOTS: |
| 1561 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1562 | List<UiccSlotMapping> slotMapping = (List<UiccSlotMapping>) request.argument; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1563 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 1564 | UiccController.getInstance().switchSlots(slotMapping, onCompleted); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1565 | break; |
| 1566 | |
| 1567 | case EVENT_SWITCH_SLOTS_DONE: |
| 1568 | ar = (AsyncResult) msg.obj; |
| 1569 | request = (MainThreadRequest) ar.userObj; |
| 1570 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1571 | notifyRequester(request); |
| 1572 | break; |
| 1573 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1574 | request = (MainThreadRequest) msg.obj; |
| 1575 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1576 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1577 | break; |
| 1578 | |
| 1579 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1580 | ar = (AsyncResult) msg.obj; |
| 1581 | request = (MainThreadRequest) ar.userObj; |
| 1582 | if (ar.exception != null) { |
| 1583 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1584 | } else { |
| 1585 | int mode = ((int[]) ar.result)[0]; |
| 1586 | if (mode == 0) { |
| 1587 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1588 | } else { |
| 1589 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1590 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1591 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1592 | notifyRequester(request); |
| 1593 | break; |
| 1594 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1595 | request = (MainThreadRequest) msg.obj; |
| 1596 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1597 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1598 | break; |
| 1599 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1600 | ar = (AsyncResult) msg.obj; |
| 1601 | request = (MainThreadRequest) ar.userObj; |
| 1602 | if (ar.exception != null) { |
| 1603 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1604 | } else { |
| 1605 | request.result = ((int[]) ar.result)[0]; |
| 1606 | } |
| 1607 | notifyRequester(request); |
| 1608 | break; |
| 1609 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1610 | request = (MainThreadRequest) msg.obj; |
| 1611 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1612 | int mode = (int) request.argument; |
| 1613 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1614 | break; |
| 1615 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1616 | ar = (AsyncResult) msg.obj; |
| 1617 | request = (MainThreadRequest) ar.userObj; |
| 1618 | request.result = ar.exception == null; |
| 1619 | notifyRequester(request); |
| 1620 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1621 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1622 | request = (MainThreadRequest) msg.obj; |
| 1623 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1624 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1625 | break; |
| 1626 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1627 | ar = (AsyncResult) msg.obj; |
| 1628 | request = (MainThreadRequest) ar.userObj; |
| 1629 | if (ar.exception != null) { |
| 1630 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1631 | } else { |
| 1632 | request.result = ((int[]) ar.result)[0]; |
| 1633 | } |
| 1634 | notifyRequester(request); |
| 1635 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1636 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1637 | request = (MainThreadRequest) msg.obj; |
| 1638 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1639 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1640 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1641 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1642 | break; |
| 1643 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1644 | ar = (AsyncResult) msg.obj; |
| 1645 | request = (MainThreadRequest) ar.userObj; |
| 1646 | request.result = ar.exception == null; |
| 1647 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1648 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1649 | case CMD_GET_ALL_CELL_INFO: |
| 1650 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1651 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1652 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1653 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1654 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1655 | ar = (AsyncResult) msg.obj; |
| 1656 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1657 | // If a timeout occurs, the response will be null |
| 1658 | request.result = (ar.exception == null && ar.result != null) |
| 1659 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1660 | synchronized (request) { |
| 1661 | request.notifyAll(); |
| 1662 | } |
| 1663 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1664 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1665 | request = (MainThreadRequest) msg.obj; |
| 1666 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1667 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1668 | break; |
| 1669 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1670 | ar = (AsyncResult) msg.obj; |
| 1671 | request = (MainThreadRequest) ar.userObj; |
| 1672 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1673 | try { |
| 1674 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1675 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1676 | cb.onError( |
| 1677 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1678 | ar.exception.getClass().getName(), |
| 1679 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1680 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1681 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1682 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1683 | } else { |
| 1684 | // use the result as returned |
| 1685 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1686 | } |
| 1687 | } catch (RemoteException re) { |
| 1688 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1689 | } |
| 1690 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1691 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1692 | request = (MainThreadRequest) msg.obj; |
| 1693 | WorkSource ws = (WorkSource) request.argument; |
| 1694 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1695 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1696 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1697 | } |
| 1698 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1699 | ar = (AsyncResult) msg.obj; |
| 1700 | request = (MainThreadRequest) ar.userObj; |
| 1701 | if (ar.exception == null) { |
| 1702 | request.result = ar.result; |
| 1703 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1704 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1705 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1706 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | synchronized (request) { |
| 1710 | request.notifyAll(); |
| 1711 | } |
| 1712 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1713 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1714 | case CMD_MODEM_REBOOT: |
| 1715 | request = (MainThreadRequest) msg.obj; |
| 1716 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1717 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1718 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1719 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1720 | handleNullReturnEvent(msg, "rebootModem"); |
| 1721 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1722 | case CMD_REQUEST_ENABLE_MODEM: |
| 1723 | request = (MainThreadRequest) msg.obj; |
| 1724 | boolean enable = (boolean) request.argument; |
| 1725 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1726 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1727 | PhoneConfigurationManager.getInstance() |
| 1728 | .enablePhone(request.phone, enable, onCompleted); |
| 1729 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1730 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1731 | ar = (AsyncResult) msg.obj; |
| 1732 | request = (MainThreadRequest) ar.userObj; |
| 1733 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1734 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1735 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1736 | if ((boolean) request.result) { |
| 1737 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1738 | updateModemStateMetrics(); |
| 1739 | } else { |
| 1740 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1741 | + ar.exception); |
| 1742 | } |
| 1743 | notifyRequester(request); |
| 1744 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1745 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1746 | case CMD_GET_MODEM_STATUS: |
| 1747 | request = (MainThreadRequest) msg.obj; |
| 1748 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1749 | PhoneConfigurationManager.getInstance() |
| 1750 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1751 | break; |
| 1752 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1753 | ar = (AsyncResult) msg.obj; |
| 1754 | request = (MainThreadRequest) ar.userObj; |
| 1755 | int id = request.phone.getPhoneId(); |
| 1756 | if (ar.exception == null && ar.result != null) { |
| 1757 | request.result = ar.result; |
| 1758 | //update the cache as modem status has changed |
| 1759 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1760 | (boolean) request.result); |
| 1761 | } else { |
| 1762 | // Return true if modem status cannot be retrieved. For most cases, |
| 1763 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1764 | // and disable modem are not supported. Modem is always on. |
| 1765 | // TODO: this should be fixed in R to support a third |
| 1766 | // status UNKNOWN b/131631629 |
| 1767 | request.result = true; |
| 1768 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1769 | + ar.exception); |
| 1770 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1771 | notifyRequester(request); |
| 1772 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1773 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1774 | request = (MainThreadRequest) msg.obj; |
| 1775 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1776 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1777 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1778 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1779 | break; |
| 1780 | } |
| 1781 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1782 | ar = (AsyncResult) msg.obj; |
| 1783 | request = (MainThreadRequest) ar.userObj; |
| 1784 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1785 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1786 | args.second.accept(ar.exception == null); |
| 1787 | notifyRequester(request); |
| 1788 | break; |
| 1789 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1790 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1791 | request = (MainThreadRequest) msg.obj; |
| 1792 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1793 | Phone phone = getPhoneFromRequest(request); |
| 1794 | if (phone != null) { |
| 1795 | phone.getSystemSelectionChannels(onCompleted); |
| 1796 | } else { |
| 1797 | loge("getSystemSelectionChannels: No phone object"); |
| 1798 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1799 | notifyRequester(request); |
| 1800 | } |
| 1801 | break; |
| 1802 | } |
| 1803 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1804 | ar = (AsyncResult) msg.obj; |
| 1805 | request = (MainThreadRequest) ar.userObj; |
| 1806 | if (ar.exception == null && ar.result != null) { |
| 1807 | request.result = ar.result; |
| 1808 | } else { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 1809 | request.result = new IllegalStateException( |
| 1810 | "Failed to retrieve system selecton channels"); |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1811 | if (ar.result == null) { |
| 1812 | loge("getSystemSelectionChannels: Empty response"); |
| 1813 | } else { |
| 1814 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1815 | } |
| 1816 | } |
| 1817 | notifyRequester(request); |
| 1818 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1819 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1820 | ar = (AsyncResult) msg.obj; |
| 1821 | request = (MainThreadRequest) ar.userObj; |
| 1822 | if (ar.exception == null && ar.result != null) { |
| 1823 | request.result = ar.result; |
| 1824 | } else { |
| 1825 | request.result = -1; |
| 1826 | loge("Failed to set Forbidden Plmns"); |
| 1827 | if (ar.result == null) { |
| 1828 | loge("setForbidenPlmns: Empty response"); |
| 1829 | } else if (ar.exception != null) { |
| 1830 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1831 | request.result = -1; |
| 1832 | } else { |
| 1833 | loge("setForbiddenPlmns: Unknown exception"); |
| 1834 | } |
| 1835 | } |
| 1836 | notifyRequester(request); |
| 1837 | break; |
| 1838 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1839 | request = (MainThreadRequest) msg.obj; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1840 | uiccPort = getUiccPortFromRequest(request); |
| 1841 | if (uiccPort == null) { |
| 1842 | loge("setForbiddenPlmns: UiccPort is null"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1843 | request.result = -1; |
| 1844 | notifyRequester(request); |
| 1845 | break; |
| 1846 | } |
| 1847 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1848 | (Pair<Integer, List<String>>) request.argument; |
| 1849 | appType = setFplmnsArgs.first; |
| 1850 | List<String> fplmns = setFplmnsArgs.second; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 1851 | uiccApp = uiccPort.getApplicationByType(appType); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1852 | if (uiccApp == null) { |
| 1853 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1854 | request.result = -1; |
| 1855 | loge("Failed to get UICC App"); |
| 1856 | notifyRequester(request); |
| 1857 | } else { |
| 1858 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1859 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1860 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1861 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1862 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1863 | case CMD_ERASE_MODEM_CONFIG: |
| 1864 | request = (MainThreadRequest) msg.obj; |
| 1865 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1866 | defaultPhone.eraseModemConfig(onCompleted); |
| 1867 | break; |
| 1868 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1869 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1870 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1871 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 1872 | case CMD_ERASE_DATA_SHARED_PREFERENCES: |
| 1873 | request = (MainThreadRequest) msg.obj; |
| 1874 | request.result = defaultPhone.eraseDataInSharedPreferences(); |
| 1875 | notifyRequester(request); |
| 1876 | break; |
| 1877 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1878 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1879 | request = (MainThreadRequest) msg.obj; |
| 1880 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1881 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1882 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1883 | changed.first, changed.second, onCompleted); |
| 1884 | break; |
| 1885 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1886 | ar = (AsyncResult) msg.obj; |
| 1887 | request = (MainThreadRequest) ar.userObj; |
| 1888 | if (ar.exception == null) { |
| 1889 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1890 | // If the operation is successful, update the PIN storage |
| 1891 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1892 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1893 | UiccController.getInstance().getPinStorage() |
| 1894 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1895 | } else { |
| 1896 | request.result = msg.arg1; |
| 1897 | } |
| 1898 | notifyRequester(request); |
| 1899 | break; |
| 1900 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1901 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1902 | request = (MainThreadRequest) msg.obj; |
| 1903 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1904 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1905 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1906 | enabled.first, enabled.second, onCompleted); |
| 1907 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1908 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1909 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1910 | ar = (AsyncResult) msg.obj; |
| 1911 | request = (MainThreadRequest) ar.userObj; |
| 1912 | if (ar.exception == null) { |
| 1913 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1914 | // If the operation is successful, update the PIN storage |
| 1915 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1916 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1917 | if (enabled.first) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 1918 | UiccController.getInstance().getPinStorage() |
| 1919 | .storePin(enabled.second, phoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1920 | } else { |
| 1921 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1922 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1923 | } else { |
| 1924 | request.result = msg.arg1; |
| 1925 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1926 | |
| 1927 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1928 | notifyRequester(request); |
| 1929 | break; |
| 1930 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1931 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1932 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1933 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1934 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1935 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1936 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1937 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1938 | |
| 1939 | case CMD_SET_DATA_THROTTLING: { |
| 1940 | request = (MainThreadRequest) msg.obj; |
| 1941 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1942 | DataThrottlingRequest dataThrottlingRequest = |
| 1943 | (DataThrottlingRequest) request.argument; |
| 1944 | Phone phone = getPhoneFromRequest(request); |
| 1945 | if (phone != null) { |
| 1946 | phone.setDataThrottling(onCompleted, |
| 1947 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1948 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1949 | } else { |
| 1950 | loge("setDataThrottling: No phone object"); |
| 1951 | request.result = |
| 1952 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1953 | notifyRequester(request); |
| 1954 | } |
| 1955 | |
| 1956 | break; |
| 1957 | } |
| 1958 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1959 | ar = (AsyncResult) msg.obj; |
| 1960 | request = (MainThreadRequest) ar.userObj; |
| 1961 | |
| 1962 | if (ar.exception == null) { |
| 1963 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1964 | } else if (ar.exception instanceof CommandException) { |
| 1965 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1966 | CommandException.Error error = |
| 1967 | ((CommandException) (ar.exception)).getCommandError(); |
| 1968 | |
| 1969 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1970 | request.result = TelephonyManager |
| 1971 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1972 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1973 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1974 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1975 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1976 | } else { |
| 1977 | request.result = |
| 1978 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1979 | } |
| 1980 | } else { |
| 1981 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1982 | } |
| 1983 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1984 | notifyRequester(request); |
| 1985 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1986 | |
| 1987 | case CMD_SET_SIM_POWER: { |
| 1988 | request = (MainThreadRequest) msg.obj; |
| 1989 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1990 | request = (MainThreadRequest) msg.obj; |
| 1991 | int stateToSet = |
| 1992 | ((Pair<Integer, IIntegerConsumer>) |
| 1993 | request.argument).first; |
| 1994 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1995 | break; |
| 1996 | } |
| 1997 | case EVENT_SET_SIM_POWER_DONE: { |
| 1998 | ar = (AsyncResult) msg.obj; |
| 1999 | request = (MainThreadRequest) ar.userObj; |
| 2000 | IIntegerConsumer callback = |
| 2001 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 2002 | if (ar.exception != null) { |
| 2003 | loge("setSimPower exception: " + ar.exception); |
| 2004 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 2005 | .RESULT_ERROR_UNKNOWN; |
| 2006 | if (ar.exception instanceof CommandException) { |
| 2007 | CommandException.Error error = |
| 2008 | ((CommandException) (ar.exception)).getCommandError(); |
| 2009 | if (error == CommandException.Error.SIM_ERR) { |
| 2010 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 2011 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 2012 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 2013 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 2014 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 2015 | } else { |
| 2016 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 2017 | } |
| 2018 | } |
| 2019 | try { |
| 2020 | callback.accept(errorCode); |
| 2021 | } catch (RemoteException e) { |
| 2022 | // Ignore if the remote process is no longer available to call back. |
| 2023 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2024 | } |
| 2025 | } else { |
| 2026 | try { |
| 2027 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 2028 | } catch (RemoteException e) { |
| 2029 | // Ignore if the remote process is no longer available to call back. |
| 2030 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 2031 | } |
| 2032 | } |
| 2033 | break; |
| 2034 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2035 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2036 | request = (MainThreadRequest) msg.obj; |
| 2037 | |
| 2038 | final Phone phone = getPhoneFromRequest(request); |
| 2039 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2040 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2041 | notifyRequester(request); |
| 2042 | break; |
| 2043 | } |
| 2044 | |
| 2045 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2046 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2047 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2048 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2049 | phone.getSignalStrengthController().setSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2050 | request.subId, pair.first /*callingUid*/, |
| 2051 | pair.second /*request*/, onCompleted); |
| 2052 | break; |
| 2053 | } |
| 2054 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2055 | ar = (AsyncResult) msg.obj; |
| 2056 | request = (MainThreadRequest) ar.userObj; |
| 2057 | // request.result will be the exception of ar if present, true otherwise. |
| 2058 | // Be cautious not to leave result null which will wait() forever |
| 2059 | request.result = ar.exception != null ? ar.exception : true; |
| 2060 | notifyRequester(request); |
| 2061 | break; |
| 2062 | } |
| 2063 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 2064 | request = (MainThreadRequest) msg.obj; |
| 2065 | |
| 2066 | Phone phone = getPhoneFromRequest(request); |
| 2067 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 2068 | request.result = new IllegalStateException("Phone or SST is null"); |
| 2069 | notifyRequester(request); |
| 2070 | break; |
| 2071 | } |
| 2072 | |
| 2073 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 2074 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 2075 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 2076 | request); |
Rambo Wang | 6568f17 | 2021-02-03 16:56:47 -0800 | [diff] [blame] | 2077 | phone.getSignalStrengthController().clearSignalStrengthUpdateRequest( |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 2078 | request.subId, pair.first /*callingUid*/, |
| 2079 | pair.second /*request*/, onCompleted); |
| 2080 | break; |
| 2081 | } |
| 2082 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 2083 | ar = (AsyncResult) msg.obj; |
| 2084 | request = (MainThreadRequest) ar.userObj; |
| 2085 | request.result = ar.exception != null ? ar.exception : true; |
| 2086 | notifyRequester(request); |
| 2087 | break; |
| 2088 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 2089 | |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2090 | case CMD_GET_SLICING_CONFIG: { |
| 2091 | request = (MainThreadRequest) msg.obj; |
| 2092 | onCompleted = obtainMessage(EVENT_GET_SLICING_CONFIG_DONE, request); |
| 2093 | request.phone.getSlicingConfig(onCompleted); |
| 2094 | break; |
| 2095 | } |
| 2096 | case EVENT_GET_SLICING_CONFIG_DONE: { |
| 2097 | ar = (AsyncResult) msg.obj; |
| 2098 | request = (MainThreadRequest) ar.userObj; |
| 2099 | ResultReceiver result = (ResultReceiver) request.argument; |
| 2100 | |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2101 | NetworkSlicingConfig slicingConfig = null; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2102 | Bundle bundle = new Bundle(); |
| 2103 | int resultCode = 0; |
| 2104 | if (ar.exception != null) { |
| 2105 | Log.e(LOG_TAG, "Exception retrieving slicing configuration=" |
| 2106 | + ar.exception); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2107 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_MODEM_ERROR; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2108 | } else if (ar.result == null) { |
| 2109 | Log.w(LOG_TAG, "Timeout Waiting for slicing configuration!"); |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2110 | resultCode = TelephonyManager.NetworkSlicingException.ERROR_TIMEOUT; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2111 | } else { |
| 2112 | // use the result as returned |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2113 | resultCode = TelephonyManager.NetworkSlicingException.SUCCESS; |
| 2114 | slicingConfig = (NetworkSlicingConfig) ar.result; |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | if (slicingConfig == null) { |
Hongbo Zeng | 0e18b16 | 2021-04-07 16:52:18 +0800 | [diff] [blame] | 2118 | slicingConfig = new NetworkSlicingConfig(); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 2119 | } |
| 2120 | bundle.putParcelable(TelephonyManager.KEY_SLICING_CONFIG_HANDLE, slicingConfig); |
| 2121 | result.send(resultCode, bundle); |
| 2122 | notifyRequester(request); |
| 2123 | break; |
| 2124 | } |
| 2125 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2126 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 2127 | request = (MainThreadRequest) msg.obj; |
| 2128 | request.result = |
| 2129 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 2130 | notifyRequester(request); |
| 2131 | break; |
| 2132 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2133 | default: |
| 2134 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 2135 | break; |
| 2136 | } |
| 2137 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2138 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2139 | private void notifyRequester(MainThreadRequest request) { |
| 2140 | synchronized (request) { |
| 2141 | request.notifyAll(); |
| 2142 | } |
| 2143 | } |
| 2144 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2145 | private void handleNullReturnEvent(Message msg, String command) { |
| 2146 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2147 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 2148 | if (ar.exception == null) { |
| 2149 | request.result = true; |
| 2150 | } else { |
| 2151 | request.result = false; |
| 2152 | if (ar.exception instanceof CommandException) { |
| 2153 | loge(command + ": CommandException: " + ar.exception); |
| 2154 | } else { |
| 2155 | loge(command + ": Unknown exception"); |
| 2156 | } |
| 2157 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2158 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2159 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | /** |
| 2163 | * Posts the specified command to be executed on the main thread, |
| 2164 | * waits for the request to complete, and returns the result. |
| 2165 | * @see #sendRequestAsync |
| 2166 | */ |
| 2167 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2168 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 2169 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * Posts the specified command to be executed on the main thread, |
| 2174 | * waits for the request to complete, and returns the result. |
| 2175 | * @see #sendRequestAsync |
| 2176 | */ |
| 2177 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 2178 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2179 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | /** |
| 2183 | * Posts the specified command to be executed on the main thread, |
| 2184 | * waits for the request to complete, and returns the result. |
| 2185 | * @see #sendRequestAsync |
| 2186 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2187 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2188 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 2189 | } |
| 2190 | |
| 2191 | /** |
| 2192 | * Posts the specified command to be executed on the main thread, |
| 2193 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 2194 | * if not timeout or null otherwise. |
| 2195 | * @see #sendRequestAsync |
| 2196 | */ |
| 2197 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 2198 | long timeoutInMs) { |
| 2199 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | /** |
| 2203 | * Posts the specified command to be executed on the main thread, |
| 2204 | * waits for the request to complete, and returns the result. |
| 2205 | * @see #sendRequestAsync |
| 2206 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2207 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2208 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | /** |
| 2212 | * Posts the specified command to be executed on the main thread, |
| 2213 | * waits for the request to complete, and returns the result. |
| 2214 | * @see #sendRequestAsync |
| 2215 | */ |
| 2216 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2217 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 2218 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2222 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 2223 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 2224 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2225 | * @see #sendRequestAsync |
| 2226 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2227 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 2228 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2229 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2230 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2231 | } |
| 2232 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2233 | MainThreadRequest request = null; |
| 2234 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2235 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2236 | } else if (phone != null) { |
| 2237 | request = new MainThreadRequest(argument, phone, workSource); |
| 2238 | } else { |
| 2239 | request = new MainThreadRequest(argument, subId, workSource); |
| 2240 | } |
| 2241 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2243 | msg.sendToTarget(); |
| 2244 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2245 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2246 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2247 | if (timeoutInMs >= 0) { |
| 2248 | // Wait for at least timeoutInMs before returning null request result |
| 2249 | long now = SystemClock.elapsedRealtime(); |
| 2250 | long deadline = now + timeoutInMs; |
Grace Jia | 8a0a1e8 | 2021-05-23 22:59:52 -0700 | [diff] [blame] | 2251 | while (request.result == null && now < deadline) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2252 | try { |
| 2253 | request.wait(deadline - now); |
| 2254 | } catch (InterruptedException e) { |
| 2255 | // Do nothing, go back and check if request is completed or timeout |
| 2256 | } finally { |
| 2257 | now = SystemClock.elapsedRealtime(); |
| 2258 | } |
| 2259 | } |
| 2260 | } else { |
| 2261 | // Wait for the request to complete |
| 2262 | while (request.result == null) { |
| 2263 | try { |
| 2264 | request.wait(); |
| 2265 | } catch (InterruptedException e) { |
| 2266 | // Do nothing, go back and wait until the request is complete |
| 2267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2271 | if (request.result == null) { |
| 2272 | Log.wtf(LOG_TAG, |
| 2273 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2274 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | return request.result; |
| 2276 | } |
| 2277 | |
| 2278 | /** |
| 2279 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2280 | * Posts the specified command to be executed on the main thread, and |
| 2281 | * returns immediately. |
| 2282 | * @see #sendRequest |
| 2283 | */ |
| 2284 | private void sendRequestAsync(int command) { |
| 2285 | mMainThreadHandler.sendEmptyMessage(command); |
| 2286 | } |
| 2287 | |
| 2288 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2289 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2290 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2291 | */ |
| 2292 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2293 | sendRequestAsync(command, argument, null, null); |
| 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2298 | * @see {@link #sendRequest(int,Object)} |
| 2299 | */ |
| 2300 | private void sendRequestAsync( |
| 2301 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2302 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2303 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2304 | msg.sendToTarget(); |
| 2305 | } |
| 2306 | |
| 2307 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2309 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2310 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2311 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | synchronized (PhoneInterfaceManager.class) { |
| 2313 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2314 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2315 | } else { |
| 2316 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2317 | } |
| 2318 | return sInstance; |
| 2319 | } |
| 2320 | } |
| 2321 | |
| 2322 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2323 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2324 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2325 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | d1947d8 | 2021-05-17 20:54:49 +0000 | [diff] [blame] | 2326 | mImsResolver = ImsResolver.getInstance(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2327 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2328 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 2329 | mPm = app.getSystemService(PackageManager.class); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2331 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2332 | mTelephonySharedPreferences = |
| 2333 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2334 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2335 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 2336 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2337 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2338 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | publish(); |
| 2340 | } |
| 2341 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2342 | private Phone getDefaultPhone() { |
| 2343 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2344 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2345 | } |
| 2346 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | private void publish() { |
| 2348 | if (DBG) log("publish: " + this); |
| 2349 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2350 | TelephonyFrameworkInitializer |
| 2351 | .getTelephonyServiceManager() |
| 2352 | .getTelephonyServiceRegisterer() |
| 2353 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2356 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2357 | if (request.phone != null) { |
| 2358 | return request.phone; |
| 2359 | } else { |
| 2360 | return getPhoneFromSubId(request.subId); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | private Phone getPhoneFromSubId(int subId) { |
| 2365 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2366 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2369 | private UiccPort getUiccPortFromRequest(MainThreadRequest request) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2370 | Phone phone = getPhoneFromRequest(request); |
| 2371 | return phone == null ? null : |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 2372 | UiccController.getInstance().getUiccPort(phone.getPhoneId()); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2373 | } |
| 2374 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2375 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2376 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2377 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2378 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2379 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 2380 | private void sendEraseModemConfig(@NonNull Phone phone) { |
| 2381 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2382 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2383 | } |
| 2384 | |
| 2385 | private void sendEraseDataInSharedPreferences(@NonNull Phone phone) { |
| 2386 | Boolean success = (Boolean) sendRequest(CMD_ERASE_DATA_SHARED_PREFERENCES, null); |
| 2387 | if (DBG) log("eraseDataInSharedPreferences:" + ' ' + (success ? "ok" : "fail")); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2390 | private boolean isImsAvailableOnDevice() { |
| 2391 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2392 | if (pm == null) { |
| 2393 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2394 | // so do not throw error and allow. |
| 2395 | return true; |
| 2396 | } |
| 2397 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2398 | } |
| 2399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2401 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2404 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2405 | if (DBG) log("dial: " + number); |
| 2406 | // No permission check needed here: This is just a wrapper around the |
| 2407 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2408 | // the UI before it does anything. |
| 2409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2410 | final long identity = Binder.clearCallingIdentity(); |
| 2411 | try { |
| 2412 | String url = createTelUrl(number); |
| 2413 | if (url == null) { |
| 2414 | return; |
| 2415 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2418 | PhoneConstants.State state = mCM.getState(subId); |
| 2419 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2420 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2421 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2422 | mApp.startActivity(intent); |
| 2423 | } |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2430 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2431 | } |
| 2432 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2433 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2434 | if (DBG) log("call: " + number); |
| 2435 | |
| 2436 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2437 | // need to do a permission check since we're calling startActivity() |
| 2438 | // from the context of the phone app. |
| 2439 | enforceCallPermission(); |
| 2440 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2441 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | != AppOpsManager.MODE_ALLOWED) { |
| 2443 | return; |
| 2444 | } |
| 2445 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
| 2448 | String url = createTelUrl(number); |
| 2449 | if (url == null) { |
| 2450 | return; |
| 2451 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2452 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | boolean isValid = false; |
| 2454 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2455 | if (slist != null) { |
| 2456 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2457 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2458 | isValid = true; |
| 2459 | break; |
| 2460 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2461 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2462 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | if (!isValid) { |
| 2464 | return; |
| 2465 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2466 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2467 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2468 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2469 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2470 | mApp.startActivity(intent); |
| 2471 | } finally { |
| 2472 | Binder.restoreCallingIdentity(identity); |
| 2473 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2476 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2477 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2478 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2479 | } |
| 2480 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2481 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2482 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2483 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2484 | } |
| 2485 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2486 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2488 | |
| 2489 | final long identity = Binder.clearCallingIdentity(); |
| 2490 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2491 | Phone phone = getPhone(subId); |
| 2492 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | checkSimPin.start(); |
| 2494 | return checkSimPin.unlockSim(null, pin); |
| 2495 | } finally { |
| 2496 | Binder.restoreCallingIdentity(identity); |
| 2497 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2500 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2502 | |
| 2503 | final long identity = Binder.clearCallingIdentity(); |
| 2504 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2505 | Phone phone = getPhone(subId); |
| 2506 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | checkSimPuk.start(); |
| 2508 | return checkSimPuk.unlockSim(puk, pin); |
| 2509 | } finally { |
| 2510 | Binder.restoreCallingIdentity(identity); |
| 2511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2515 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2516 | * a synchronous one. |
| 2517 | */ |
| 2518 | private static class UnlockSim extends Thread { |
| 2519 | |
| 2520 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2521 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2522 | |
| 2523 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2524 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2525 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | |
| 2527 | // For replies from SimCard interface |
| 2528 | private Handler mHandler; |
| 2529 | |
| 2530 | // For async handler to identify request type |
| 2531 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2532 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2533 | UnlockSim(int phoneId, IccCard simCard) { |
| 2534 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | mSimCard = simCard; |
| 2536 | } |
| 2537 | |
| 2538 | @Override |
| 2539 | public void run() { |
| 2540 | Looper.prepare(); |
| 2541 | synchronized (UnlockSim.this) { |
| 2542 | mHandler = new Handler() { |
| 2543 | @Override |
| 2544 | public void handleMessage(Message msg) { |
| 2545 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2546 | switch (msg.what) { |
| 2547 | case SUPPLY_PIN_COMPLETE: |
| 2548 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2549 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2550 | mRetryCount = msg.arg1; |
| 2551 | if (ar.exception != null) { |
| 2552 | if (ar.exception instanceof CommandException && |
| 2553 | ((CommandException)(ar.exception)).getCommandError() |
| 2554 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2555 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2556 | } //When UiccCardApp dispose,handle message and return exception |
| 2557 | else if (ar.exception instanceof CommandException && |
| 2558 | ((CommandException) (ar.exception)).getCommandError() |
| 2559 | == CommandException.Error.ABORTED) { |
| 2560 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2561 | } else { |
| 2562 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2563 | } |
| 2564 | } else { |
| 2565 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2566 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | mDone = true; |
| 2568 | UnlockSim.this.notifyAll(); |
| 2569 | } |
| 2570 | break; |
| 2571 | } |
| 2572 | } |
| 2573 | }; |
| 2574 | UnlockSim.this.notifyAll(); |
| 2575 | } |
| 2576 | Looper.loop(); |
| 2577 | } |
| 2578 | |
| 2579 | /* |
| 2580 | * Use PIN or PUK to unlock SIM card |
| 2581 | * |
| 2582 | * If PUK is null, unlock SIM card with PIN |
| 2583 | * |
| 2584 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2585 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2586 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2587 | |
| 2588 | while (mHandler == null) { |
| 2589 | try { |
| 2590 | wait(); |
| 2591 | } catch (InterruptedException e) { |
| 2592 | Thread.currentThread().interrupt(); |
| 2593 | } |
| 2594 | } |
| 2595 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2596 | |
| 2597 | if (puk == null) { |
| 2598 | mSimCard.supplyPin(pin, callback); |
| 2599 | } else { |
| 2600 | mSimCard.supplyPuk(puk, pin, callback); |
| 2601 | } |
| 2602 | |
| 2603 | while (!mDone) { |
| 2604 | try { |
| 2605 | Log.d(LOG_TAG, "wait for done"); |
| 2606 | wait(); |
| 2607 | } catch (InterruptedException e) { |
| 2608 | // Restore the interrupted status |
| 2609 | Thread.currentThread().interrupt(); |
| 2610 | } |
| 2611 | } |
| 2612 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2613 | int[] resultArray = new int[2]; |
| 2614 | resultArray[0] = mResult; |
| 2615 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2616 | |
| 2617 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
Jon Spivack | bb77752 | 2021-10-06 20:53:09 +0000 | [diff] [blame] | 2618 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2621 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2625 | /** |
| 2626 | * This method has been removed due to privacy and stability concerns. |
| 2627 | */ |
| 2628 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2629 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2630 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2631 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2634 | @Override |
| 2635 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2636 | mApp.getSystemService(AppOpsManager.class) |
| 2637 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2638 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2639 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2640 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2641 | // Callers targeting S have no business invoking this method. |
| 2642 | return; |
| 2643 | } |
| 2644 | |
| 2645 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2646 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2647 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2648 | .setCallingPackage(callingPackage) |
| 2649 | .setCallingFeatureId(null) |
| 2650 | .setCallingPid(Binder.getCallingPid()) |
| 2651 | .setCallingUid(Binder.getCallingUid()) |
| 2652 | .setMethod("updateServiceLocation") |
| 2653 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2654 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2655 | .build()); |
| 2656 | // Apps that lack location permission have no business calling this method; |
| 2657 | // however, because no permission was declared in the public API, denials must |
| 2658 | // all be "soft". |
| 2659 | switch (locationResult) { |
| 2660 | case DENIED_HARD: /* fall through */ |
| 2661 | case DENIED_SOFT: |
| 2662 | return; |
| 2663 | } |
| 2664 | |
| 2665 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | final long identity = Binder.clearCallingIdentity(); |
| 2667 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2668 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2669 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2670 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | } |
| 2672 | } finally { |
| 2673 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2674 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2677 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2678 | @Override |
| 2679 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2680 | return isRadioOnWithFeature(callingPackage, null); |
| 2681 | } |
| 2682 | |
| 2683 | |
| 2684 | @Override |
| 2685 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2686 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2687 | callingFeatureId); |
| 2688 | } |
| 2689 | |
| 2690 | @Deprecated |
| 2691 | @Override |
| 2692 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2693 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2697 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2698 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2699 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2700 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2701 | return false; |
| 2702 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | |
| 2704 | final long identity = Binder.clearCallingIdentity(); |
| 2705 | try { |
| 2706 | return isRadioOnForSubscriber(subId); |
| 2707 | } finally { |
| 2708 | Binder.restoreCallingIdentity(identity); |
| 2709 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2713 | final long identity = Binder.clearCallingIdentity(); |
| 2714 | try { |
| 2715 | final Phone phone = getPhone(subId); |
| 2716 | if (phone != null) { |
| 2717 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2718 | } else { |
| 2719 | return false; |
| 2720 | } |
| 2721 | } finally { |
| 2722 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2723 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2727 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2728 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2729 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2730 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2732 | |
| 2733 | final long identity = Binder.clearCallingIdentity(); |
| 2734 | try { |
| 2735 | final Phone phone = getPhone(subId); |
| 2736 | if (phone != null) { |
| 2737 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2738 | } |
| 2739 | } finally { |
| 2740 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2741 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2745 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2748 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2749 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2750 | |
| 2751 | final long identity = Binder.clearCallingIdentity(); |
| 2752 | try { |
| 2753 | final Phone phone = getPhone(subId); |
| 2754 | if (phone == null) { |
| 2755 | return false; |
| 2756 | } |
| 2757 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2758 | toggleRadioOnOffForSubscriber(subId); |
| 2759 | } |
| 2760 | return true; |
| 2761 | } finally { |
| 2762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2764 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2765 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2766 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2767 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2768 | /* |
| 2769 | * If any of the Radios are available, it will need to be |
| 2770 | * shutdown. So return true if any Radio is available. |
| 2771 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | final long identity = Binder.clearCallingIdentity(); |
| 2773 | try { |
| 2774 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2775 | Phone phone = PhoneFactory.getPhone(i); |
| 2776 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2777 | } |
| 2778 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2779 | return false; |
| 2780 | } finally { |
| 2781 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2782 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2785 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2786 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2787 | enforceModifyPermission(); |
| 2788 | |
| 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
| 2791 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2792 | logv("Shutting down Phone " + i); |
| 2793 | shutdownRadioUsingPhoneId(i); |
| 2794 | } |
| 2795 | } finally { |
| 2796 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2801 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2802 | if (phone != null && phone.isRadioAvailable()) { |
| 2803 | phone.shutdownRadio(); |
| 2804 | } |
| 2805 | } |
| 2806 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2807 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2808 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2813 | if (defaultPhone != null) { |
| 2814 | defaultPhone.setRadioPower(turnOn); |
| 2815 | return true; |
| 2816 | } else { |
| 2817 | loge("There's no default phone."); |
| 2818 | return false; |
| 2819 | } |
| 2820 | } finally { |
| 2821 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2822 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2825 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2826 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2827 | |
| 2828 | final long identity = Binder.clearCallingIdentity(); |
| 2829 | try { |
| 2830 | final Phone phone = getPhone(subId); |
| 2831 | if (phone != null) { |
| 2832 | phone.setRadioPower(turnOn); |
| 2833 | return true; |
| 2834 | } else { |
| 2835 | return false; |
| 2836 | } |
| 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2839 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2842 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2843 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2844 | public boolean enableDataConnectivity() { |
| 2845 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2846 | |
| 2847 | final long identity = Binder.clearCallingIdentity(); |
| 2848 | try { |
| 2849 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2850 | final Phone phone = getPhone(subId); |
| 2851 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2852 | if (phone.isUsingNewDataStack()) { |
| 2853 | phone.getDataSettingsManager().setDataEnabled( |
| 2854 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2855 | } else { |
| 2856 | phone.getDataEnabledSettings().setDataEnabled( |
| 2857 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
| 2858 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2859 | return true; |
| 2860 | } else { |
| 2861 | return false; |
| 2862 | } |
| 2863 | } finally { |
| 2864 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2865 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2868 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2869 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2870 | public boolean disableDataConnectivity() { |
| 2871 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | |
| 2873 | final long identity = Binder.clearCallingIdentity(); |
| 2874 | try { |
| 2875 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2876 | final Phone phone = getPhone(subId); |
| 2877 | if (phone != null) { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 2878 | if (phone.isUsingNewDataStack()) { |
| 2879 | phone.getDataSettingsManager().setDataEnabled( |
| 2880 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2881 | } else { |
| 2882 | phone.getDataEnabledSettings().setDataEnabled( |
| 2883 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
| 2884 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | return true; |
| 2886 | } else { |
| 2887 | return false; |
| 2888 | } |
| 2889 | } finally { |
| 2890 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2891 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2894 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2895 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 | final long identity = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | final Phone phone = getPhone(subId); |
| 2899 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2900 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | } else { |
| 2902 | return false; |
| 2903 | } |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2906 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2910 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2911 | } |
| 2912 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2913 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2914 | enforceCallPermission(); |
| 2915 | |
| 2916 | final long identity = Binder.clearCallingIdentity(); |
| 2917 | try { |
| 2918 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2919 | return; |
| 2920 | } |
| 2921 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2922 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(identity); |
| 2925 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2926 | }; |
| 2927 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2928 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2930 | |
| 2931 | final long identity = Binder.clearCallingIdentity(); |
| 2932 | try { |
| 2933 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2934 | return false; |
| 2935 | } |
| 2936 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2939 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2942 | /** |
| 2943 | * @deprecated This method is deprecated and is only being kept due to an UnsupportedAppUsage |
| 2944 | * tag on getCallState Binder call. |
| 2945 | */ |
| 2946 | @Deprecated |
| 2947 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2948 | public int getCallState() { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2949 | if (CompatChanges.isChangeEnabled( |
| 2950 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2951 | Binder.getCallingUid())) { |
| 2952 | // Do not allow this API to be called on API version 31+, it should only be |
| 2953 | // called on old apps using this Binder call directly. |
| 2954 | throw new SecurityException("This method can only be used for applications " |
| 2955 | + "targeting API version 30 or less."); |
| 2956 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | final long identity = Binder.clearCallingIdentity(); |
| 2958 | try { |
Brad Ebinger | 4f6208e | 2021-03-23 21:04:45 +0000 | [diff] [blame] | 2959 | Phone phone = getPhone(getDefaultSubscription()); |
| 2960 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2961 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2962 | } finally { |
| 2963 | Binder.restoreCallingIdentity(identity); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | @Override |
| 2968 | public int getCallStateForSubscription(int subId, String callingPackage, String featureId) { |
| 2969 | if (CompatChanges.isChangeEnabled( |
| 2970 | TelecomManager.ENABLE_GET_CALL_STATE_PERMISSION_PROTECTION, |
| 2971 | Binder.getCallingUid())) { |
| 2972 | // Check READ_PHONE_STATE for API version 31+ |
| 2973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2974 | featureId, "getCallStateForSubscription")) { |
| 2975 | throw new SecurityException("getCallState requires READ_PHONE_STATE for apps " |
| 2976 | + "targeting API level 31+."); |
| 2977 | } |
| 2978 | } |
| 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2982 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2983 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2984 | } finally { |
| 2985 | Binder.restoreCallingIdentity(identity); |
| 2986 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2989 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2990 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2991 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2992 | } |
| 2993 | |
| 2994 | @Override |
| 2995 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | final long identity = Binder.clearCallingIdentity(); |
| 2997 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2998 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2999 | if (phone != null) { |
Jack Yu | 4accbd9 | 2021-11-29 11:36:17 -0800 | [diff] [blame] | 3000 | if (phone.isUsingNewDataStack()) { |
| 3001 | return phone.getDataNetworkController().getInternetDataNetworkState(); |
| 3002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 3004 | } else { |
| 3005 | return PhoneConstantConversions.convertDataState( |
| 3006 | PhoneConstants.DataState.DISCONNECTED); |
| 3007 | } |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3013 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 3014 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3015 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 3016 | } |
| 3017 | |
| 3018 | @Override |
| 3019 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 3022 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3023 | if (phone != null) { |
| 3024 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 3025 | } else { |
| 3026 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 3027 | } |
| 3028 | } finally { |
| 3029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3034 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3035 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3036 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3037 | |
| 3038 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3039 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3040 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3041 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3042 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3043 | .setCallingPid(Binder.getCallingPid()) |
| 3044 | .setCallingUid(Binder.getCallingUid()) |
| 3045 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 3046 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3047 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3048 | .build()); |
| 3049 | switch (locationResult) { |
| 3050 | case DENIED_HARD: |
| 3051 | throw new SecurityException("Not allowed to access cell location"); |
| 3052 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3053 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 3054 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3055 | } |
| 3056 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3057 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3058 | final long identity = Binder.clearCallingIdentity(); |
| 3059 | try { |
| 3060 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3061 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 3062 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3063 | } finally { |
| 3064 | Binder.restoreCallingIdentity(identity); |
| 3065 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 3069 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3070 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 3071 | // registered cell info, so return a NULL country instead. |
| 3072 | final long identity = Binder.clearCallingIdentity(); |
| 3073 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 3074 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 3075 | // Get default phone in this case. |
| 3076 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 3077 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3078 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3079 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 3080 | if (phone == null) return ""; |
| 3081 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 3082 | if (sst == null) return ""; |
| 3083 | LocaleTracker lt = sst.getLocaleTracker(); |
| 3084 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 3085 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3086 | } finally { |
| 3087 | Binder.restoreCallingIdentity(identity); |
| 3088 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3089 | } |
| 3090 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3091 | /** |
| 3092 | * This method was removed due to potential issues caused by performing partial |
| 3093 | * updates of service state, and lack of a credible use case. |
| 3094 | * |
| 3095 | * This has the ability to break the telephony implementation by disabling notification of |
| 3096 | * changes in device connectivity. DO NOT USE THIS! |
| 3097 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 3098 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3099 | public void enableLocationUpdates() { |
| 3100 | mApp.enforceCallingOrSelfPermission( |
| 3101 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3102 | } |
| 3103 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 3104 | /** |
| 3105 | * This method was removed due to potential issues caused by performing partial |
| 3106 | * updates of service state, and lack of a credible use case. |
| 3107 | * |
| 3108 | * This has the ability to break the telephony implementation by disabling notification of |
| 3109 | * changes in device connectivity. DO NOT USE THIS! |
| 3110 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3111 | @Override |
| 3112 | public void disableLocationUpdates() { |
| 3113 | mApp.enforceCallingOrSelfPermission( |
| 3114 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | @Override |
| 3118 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3119 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 3120 | String callingFeatureId) { |
Nathan Harold | b55f63b | 2021-07-27 11:27:38 -0700 | [diff] [blame] | 3121 | try { |
| 3122 | mApp.getSystemService(AppOpsManager.class) |
| 3123 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 3124 | } catch (SecurityException e) { |
| 3125 | EventLog.writeEvent(0x534e4554, "190619791", Binder.getCallingUid()); |
| 3126 | throw e; |
| 3127 | } |
| 3128 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3129 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 3130 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3131 | throw new SecurityException( |
| 3132 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 3133 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 3134 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 3135 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3136 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 3137 | return null; |
| 3138 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 3139 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3140 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3141 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3142 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3143 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3144 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3145 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 3146 | for (CellInfo ci : info) { |
| 3147 | if (ci instanceof CellInfoGsm) { |
| 3148 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 3149 | } else if (ci instanceof CellInfoWcdma) { |
| 3150 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 3151 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3152 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 3153 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3154 | } |
| 3155 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3156 | private List<CellInfo> getCachedCellInfo() { |
| 3157 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3158 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3159 | List<CellInfo> info = phone.getAllCellInfo(); |
| 3160 | if (info != null) cellInfos.addAll(info); |
| 3161 | } |
| 3162 | return cellInfos; |
| 3163 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3164 | |
| 3165 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3166 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3167 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 3168 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3169 | |
| 3170 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3171 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3172 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3173 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3174 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3175 | .setCallingPid(Binder.getCallingPid()) |
| 3176 | .setCallingUid(Binder.getCallingUid()) |
| 3177 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 3178 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3179 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 3180 | .build()); |
| 3181 | switch (locationResult) { |
| 3182 | case DENIED_HARD: |
| 3183 | throw new SecurityException("Not allowed to access cell info"); |
| 3184 | case DENIED_SOFT: |
| 3185 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3188 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3189 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 3190 | return getCachedCellInfo(); |
| 3191 | } |
| 3192 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 3193 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3194 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | final long identity = Binder.clearCallingIdentity(); |
| 3196 | try { |
| 3197 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 3198 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 3199 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 3200 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3201 | if (info != null) cellInfos.addAll(info); |
| 3202 | } |
| 3203 | return cellInfos; |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3206 | } |
| 3207 | } |
| 3208 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 3209 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3210 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 3211 | String callingFeatureId) { |
| 3212 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 3213 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3217 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 3218 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3219 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3220 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3223 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 3224 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3225 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3226 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3227 | |
| 3228 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 3229 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 3230 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 3231 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 3232 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3233 | .setCallingPid(Binder.getCallingPid()) |
| 3234 | .setCallingUid(Binder.getCallingUid()) |
| 3235 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3236 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 3237 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3238 | .build()); |
| 3239 | switch (locationResult) { |
| 3240 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3241 | if (TelephonyPermissions |
| 3242 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3243 | // Safetynet logging for b/154934934 |
| 3244 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3245 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3246 | throw new SecurityException("Not allowed to access cell info"); |
| 3247 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 3248 | if (TelephonyPermissions |
| 3249 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 3250 | // Safetynet logging for b/154934934 |
| 3251 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 3252 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 3253 | try { |
| 3254 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 3255 | } catch (RemoteException re) { |
| 3256 | // Drop without consequences |
| 3257 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 3258 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3259 | } |
| 3260 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 3261 | |
| 3262 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 3263 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 3264 | |
| 3265 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 3266 | } |
| 3267 | |
| 3268 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3269 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 3270 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 3271 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | |
| 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3275 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3276 | } finally { |
| 3277 | Binder.restoreCallingIdentity(identity); |
| 3278 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3281 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3282 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3283 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3284 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3285 | return null; |
| 3286 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3287 | int subId = phone.getSubId(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3288 | enforceCallingPackage(callingPackage, Binder.getCallingUid(), "getImeiForSlot"); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3289 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3290 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3291 | return null; |
| 3292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3293 | |
| 3294 | final long identity = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | return phone.getImei(); |
| 3297 | } finally { |
| 3298 | Binder.restoreCallingIdentity(identity); |
| 3299 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3300 | } |
| 3301 | |
| 3302 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3303 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3304 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3305 | String tac = null; |
| 3306 | if (phone != null) { |
| 3307 | String imei = phone.getImei(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3308 | try { |
| 3309 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3310 | } catch (IndexOutOfBoundsException e) { |
| 3311 | Log.e(LOG_TAG, "IMEI length shorter than upper index."); |
| 3312 | return null; |
| 3313 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3314 | } |
| 3315 | return tac; |
| 3316 | } |
| 3317 | |
| 3318 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3319 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 3320 | try { |
| 3321 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3322 | } catch (SecurityException se) { |
| 3323 | EventLog.writeEvent(0x534e4554, "186530496", Binder.getCallingUid()); |
| 3324 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 3325 | + Binder.getCallingUid()); |
| 3326 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3327 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3328 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3329 | return null; |
| 3330 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3331 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3332 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3333 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3334 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3335 | return null; |
| 3336 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3337 | |
| 3338 | final long identity = Binder.clearCallingIdentity(); |
| 3339 | try { |
| 3340 | return phone.getMeid(); |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
| 3343 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3347 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3348 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3349 | String manufacturerCode = null; |
| 3350 | if (phone != null) { |
| 3351 | String meid = phone.getMeid(); |
Vala Zadeh | ab00555 | 2021-09-21 15:54:29 -0700 | [diff] [blame] | 3352 | try { |
| 3353 | manufacturerCode = |
| 3354 | meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3355 | } catch (IndexOutOfBoundsException e) { |
| 3356 | Log.e(LOG_TAG, "MEID length shorter than upper index."); |
| 3357 | return null; |
| 3358 | } |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3359 | } |
| 3360 | return manufacturerCode; |
| 3361 | } |
| 3362 | |
| 3363 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3364 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3365 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3366 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3367 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3368 | return null; |
| 3369 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3370 | int subId = phone.getSubId(); |
| 3371 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3372 | mApp, subId, callingPackage, callingFeatureId, |
| 3373 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3374 | return null; |
| 3375 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3376 | |
| 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | return phone.getDeviceSvn(); |
| 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
| 3382 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3385 | @Override |
| 3386 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | final long identity = Binder.clearCallingIdentity(); |
| 3388 | try { |
| 3389 | final Phone phone = getPhone(subId); |
| 3390 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3391 | } finally { |
| 3392 | Binder.restoreCallingIdentity(identity); |
| 3393 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | @Override |
| 3397 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3398 | final long identity = Binder.clearCallingIdentity(); |
| 3399 | try { |
| 3400 | final Phone phone = getPhone(subId); |
| 3401 | return phone == null ? null : phone.getCarrierName(); |
| 3402 | } finally { |
| 3403 | Binder.restoreCallingIdentity(identity); |
| 3404 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3405 | } |
| 3406 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3407 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3408 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | final Phone phone = getPhone(subId); |
| 3412 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3413 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3414 | } finally { |
| 3415 | Binder.restoreCallingIdentity(identity); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3420 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
| 3423 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3424 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3425 | } finally { |
| 3426 | Binder.restoreCallingIdentity(identity); |
| 3427 | } |
| 3428 | } |
| 3429 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3430 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3431 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3432 | if (!isSubscriptionMccMnc) { |
| 3433 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3434 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3435 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3436 | if (phone == null) { |
| 3437 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3438 | } |
| 3439 | final long identity = Binder.clearCallingIdentity(); |
| 3440 | try { |
| 3441 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3442 | } finally { |
| 3443 | Binder.restoreCallingIdentity(identity); |
| 3444 | } |
| 3445 | } |
| 3446 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3447 | // |
| 3448 | // Internal helper methods. |
| 3449 | // |
| 3450 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3451 | /** |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3452 | * Make sure the caller is the calling package itself |
| 3453 | * |
| 3454 | * @throws SecurityException if the caller is not the calling package |
| 3455 | */ |
| 3456 | private void enforceCallingPackage(String callingPackage, int callingUid, String message) { |
| 3457 | int packageUid = -1; |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3458 | PackageManager pm = mApp.getBaseContext().createContextAsUser( |
| 3459 | UserHandle.getUserHandleForUid(callingUid), 0).getPackageManager(); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3460 | try { |
Grace Jia | dbefca0 | 2021-04-26 15:13:31 -0700 | [diff] [blame] | 3461 | packageUid = pm.getPackageUid(callingPackage, 0); |
Grace Jia | 0ddb361 | 2021-04-22 13:35:26 -0700 | [diff] [blame] | 3462 | } catch (PackageManager.NameNotFoundException e) { |
| 3463 | // packageUid is -1 |
| 3464 | } |
| 3465 | if (packageUid != callingUid) { |
| 3466 | throw new SecurityException(message + ": Package " + callingPackage |
| 3467 | + " does not belong to " + callingUid); |
| 3468 | } |
| 3469 | } |
| 3470 | |
| 3471 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3472 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3473 | * |
| 3474 | * @throws SecurityException if the caller does not have the required permission |
| 3475 | */ |
| 3476 | private void enforceModifyPermission() { |
| 3477 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3478 | } |
| 3479 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3480 | private void enforceActiveEmergencySessionPermission() { |
| 3481 | mApp.enforceCallingOrSelfPermission( |
| 3482 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3483 | } |
| 3484 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3485 | /** |
| 3486 | * Make sure the caller has the CALL_PHONE permission. |
| 3487 | * |
| 3488 | * @throws SecurityException if the caller does not have the required permission |
| 3489 | */ |
| 3490 | private void enforceCallPermission() { |
| 3491 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3492 | } |
| 3493 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3494 | private void enforceSettingsPermission() { |
| 3495 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3498 | private void enforceRebootPermission() { |
| 3499 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3500 | } |
| 3501 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3502 | private String createTelUrl(String number) { |
| 3503 | if (TextUtils.isEmpty(number)) { |
| 3504 | return null; |
| 3505 | } |
| 3506 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3507 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3508 | } |
| 3509 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3510 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3511 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3512 | } |
| 3513 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3514 | private static void logv(String msg) { |
| 3515 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3516 | } |
| 3517 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3518 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3519 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3520 | } |
| 3521 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3522 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3523 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3524 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3527 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3528 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | final long identity = Binder.clearCallingIdentity(); |
| 3530 | try { |
| 3531 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3532 | if (phone == null) { |
| 3533 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3534 | } else { |
| 3535 | return phone.getPhoneType(); |
| 3536 | } |
| 3537 | } finally { |
| 3538 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | /** |
| 3543 | * Returns the CDMA ERI icon index to display |
| 3544 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3545 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3546 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3547 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3548 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3551 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3552 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3553 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3554 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3555 | mApp, subId, callingPackage, callingFeatureId, |
| 3556 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3557 | return -1; |
| 3558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3559 | |
| 3560 | final long identity = Binder.clearCallingIdentity(); |
| 3561 | try { |
| 3562 | final Phone phone = getPhone(subId); |
| 3563 | if (phone != null) { |
| 3564 | return phone.getCdmaEriIconIndex(); |
| 3565 | } else { |
| 3566 | return -1; |
| 3567 | } |
| 3568 | } finally { |
| 3569 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3570 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | /** |
| 3574 | * Returns the CDMA ERI icon mode, |
| 3575 | * 0 - ON |
| 3576 | * 1 - FLASHING |
| 3577 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3578 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3579 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3580 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3581 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3582 | } |
| 3583 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3584 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3585 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3586 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3587 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3588 | mApp, subId, callingPackage, callingFeatureId, |
| 3589 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3590 | return -1; |
| 3591 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | |
| 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | final Phone phone = getPhone(subId); |
| 3596 | if (phone != null) { |
| 3597 | return phone.getCdmaEriIconMode(); |
| 3598 | } else { |
| 3599 | return -1; |
| 3600 | } |
| 3601 | } finally { |
| 3602 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3603 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | /** |
| 3607 | * Returns the CDMA ERI text, |
| 3608 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3609 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3610 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3611 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3612 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3613 | } |
| 3614 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3615 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3616 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3617 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3618 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3619 | mApp, subId, callingPackage, callingFeatureId, |
| 3620 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3621 | return null; |
| 3622 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3623 | |
| 3624 | final long identity = Binder.clearCallingIdentity(); |
| 3625 | try { |
| 3626 | final Phone phone = getPhone(subId); |
| 3627 | if (phone != null) { |
| 3628 | return phone.getCdmaEriText(); |
| 3629 | } else { |
| 3630 | return null; |
| 3631 | } |
| 3632 | } finally { |
| 3633 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3634 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3638 | * Returns the CDMA MDN. |
| 3639 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3640 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3641 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3643 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | |
| 3645 | final long identity = Binder.clearCallingIdentity(); |
| 3646 | try { |
| 3647 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3648 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3649 | return phone.getLine1Number(); |
| 3650 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3651 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3652 | return null; |
| 3653 | } |
| 3654 | } finally { |
| 3655 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3656 | } |
| 3657 | } |
| 3658 | |
| 3659 | /** |
| 3660 | * Returns the CDMA MIN. |
| 3661 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3662 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3663 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3665 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3666 | |
| 3667 | final long identity = Binder.clearCallingIdentity(); |
| 3668 | try { |
| 3669 | final Phone phone = getPhone(subId); |
| 3670 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3671 | return phone.getCdmaMin(); |
| 3672 | } else { |
| 3673 | return null; |
| 3674 | } |
| 3675 | } finally { |
| 3676 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3677 | } |
| 3678 | } |
| 3679 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3680 | @Override |
| 3681 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3682 | INumberVerificationCallback callback, String callingPackage) { |
| 3683 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3684 | != PERMISSION_GRANTED) { |
| 3685 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3686 | } |
| 3687 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3688 | |
| 3689 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3690 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3691 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3692 | + "calling package: " + callingPackage |
| 3693 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | if (range == null) { |
| 3697 | throw new NullPointerException("Range must be non-null"); |
| 3698 | } |
| 3699 | |
| 3700 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3701 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3702 | |
| 3703 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3704 | } |
| 3705 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3706 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3707 | * Returns true if CDMA provisioning needs to run. |
| 3708 | */ |
| 3709 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3710 | final long identity = Binder.clearCallingIdentity(); |
| 3711 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3712 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3713 | } finally { |
| 3714 | Binder.restoreCallingIdentity(identity); |
| 3715 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3716 | } |
| 3717 | |
| 3718 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3719 | * Sets the voice mail number of a given subId. |
| 3720 | */ |
| 3721 | @Override |
| 3722 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3723 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3724 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3725 | |
| 3726 | final long identity = Binder.clearCallingIdentity(); |
| 3727 | try { |
| 3728 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3729 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3730 | return success; |
| 3731 | } finally { |
| 3732 | Binder.restoreCallingIdentity(identity); |
| 3733 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3734 | } |
| 3735 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3736 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3737 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3738 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3739 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3740 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3741 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3742 | throw new SecurityException("caller must be system dialer"); |
| 3743 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3744 | |
| 3745 | final long identity = Binder.clearCallingIdentity(); |
| 3746 | try { |
| 3747 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3748 | if (phoneAccountHandle == null) { |
| 3749 | return null; |
| 3750 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3751 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3752 | } finally { |
| 3753 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3754 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3758 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3759 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3760 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3761 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3762 | mApp, subId, callingPackage, callingFeatureId, |
| 3763 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3764 | return null; |
| 3765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3766 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3767 | final long identity = Binder.clearCallingIdentity(); |
| 3768 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3769 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3770 | } finally { |
| 3771 | Binder.restoreCallingIdentity(identity); |
| 3772 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3776 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3777 | VisualVoicemailSmsFilterSettings settings) { |
| 3778 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3779 | |
| 3780 | final long identity = Binder.clearCallingIdentity(); |
| 3781 | try { |
| 3782 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3783 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(identity); |
| 3786 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3790 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3791 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3792 | |
| 3793 | final long identity = Binder.clearCallingIdentity(); |
| 3794 | try { |
| 3795 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3796 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
| 3799 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3803 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3804 | String callingPackage, int subId) { |
| 3805 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3806 | |
| 3807 | final long identity = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3810 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3811 | } finally { |
| 3812 | Binder.restoreCallingIdentity(identity); |
| 3813 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3817 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3818 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3819 | |
| 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3823 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3824 | } finally { |
| 3825 | Binder.restoreCallingIdentity(identity); |
| 3826 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3827 | } |
| 3828 | |
| 3829 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3830 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3831 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3832 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3833 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3834 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3835 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3836 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3837 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3838 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3839 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3840 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3841 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3842 | * Sets the voice activation state of a given subId. |
| 3843 | */ |
| 3844 | @Override |
| 3845 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3846 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3847 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3848 | |
| 3849 | final long identity = Binder.clearCallingIdentity(); |
| 3850 | try { |
| 3851 | final Phone phone = getPhone(subId); |
| 3852 | if (phone != null) { |
| 3853 | phone.setVoiceActivationState(activationState); |
| 3854 | } else { |
| 3855 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3856 | } |
| 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3859 | } |
| 3860 | } |
| 3861 | |
| 3862 | /** |
| 3863 | * Sets the data activation state of a given subId. |
| 3864 | */ |
| 3865 | @Override |
| 3866 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3868 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3869 | |
| 3870 | final long identity = Binder.clearCallingIdentity(); |
| 3871 | try { |
| 3872 | final Phone phone = getPhone(subId); |
| 3873 | if (phone != null) { |
| 3874 | phone.setDataActivationState(activationState); |
| 3875 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3876 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3877 | } |
| 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | /** |
| 3884 | * Returns the voice activation state of a given subId. |
| 3885 | */ |
| 3886 | @Override |
| 3887 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3888 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3889 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3890 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3891 | final long identity = Binder.clearCallingIdentity(); |
| 3892 | try { |
| 3893 | if (phone != null) { |
| 3894 | return phone.getVoiceActivationState(); |
| 3895 | } else { |
| 3896 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3897 | } |
| 3898 | } finally { |
| 3899 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | /** |
| 3904 | * Returns the data activation state of a given subId. |
| 3905 | */ |
| 3906 | @Override |
| 3907 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3908 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3909 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3910 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3911 | final long identity = Binder.clearCallingIdentity(); |
| 3912 | try { |
| 3913 | if (phone != null) { |
| 3914 | return phone.getDataActivationState(); |
| 3915 | } else { |
| 3916 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3917 | } |
| 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3924 | * Returns the unread count of voicemails for a subId |
| 3925 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3926 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3927 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3928 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3929 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3930 | mApp, subId, callingPackage, callingFeatureId, |
| 3931 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3932 | return 0; |
| 3933 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3934 | final long identity = Binder.clearCallingIdentity(); |
| 3935 | try { |
| 3936 | final Phone phone = getPhone(subId); |
| 3937 | if (phone != null) { |
| 3938 | return phone.getVoiceMessageCount(); |
| 3939 | } else { |
| 3940 | return 0; |
| 3941 | } |
| 3942 | } finally { |
| 3943 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3944 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3948 | * returns true, if the device is in a state where both voice and data |
| 3949 | * are supported simultaneously. This can change based on location or network condition. |
| 3950 | */ |
| 3951 | @Override |
| 3952 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3953 | final long identity = Binder.clearCallingIdentity(); |
| 3954 | try { |
| 3955 | final Phone phone = getPhone(subId); |
| 3956 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3957 | } finally { |
| 3958 | Binder.restoreCallingIdentity(identity); |
| 3959 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3963 | * Send the dialer code if called from the current default dialer or the caller has |
| 3964 | * carrier privilege. |
| 3965 | * @param inputCode The dialer code to send |
| 3966 | */ |
| 3967 | @Override |
| 3968 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3969 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3970 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3971 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3972 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3973 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3974 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3975 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3977 | |
| 3978 | final long identity = Binder.clearCallingIdentity(); |
| 3979 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3980 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3981 | } finally { |
| 3982 | Binder.restoreCallingIdentity(identity); |
| 3983 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3984 | } |
| 3985 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3986 | @Override |
| 3987 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3988 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3989 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3990 | mApp, subId, "getNetworkSelectionMode"); |
| 3991 | final long identity = Binder.clearCallingIdentity(); |
| 3992 | try { |
| 3993 | if (!isActiveSubscription(subId)) { |
| 3994 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3995 | } |
| 3996 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3997 | } finally { |
| 3998 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3999 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4000 | } |
| 4001 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4002 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4003 | public boolean isInEmergencySmsMode() { |
| 4004 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 4005 | final long identity = Binder.clearCallingIdentity(); |
| 4006 | try { |
| 4007 | for (Phone phone : PhoneFactory.getPhones()) { |
| 4008 | if (phone.isInEmergencySmsMode()) { |
| 4009 | return true; |
| 4010 | } |
| 4011 | } |
| 4012 | } finally { |
| 4013 | Binder.restoreCallingIdentity(identity); |
| 4014 | } |
| 4015 | return false; |
| 4016 | } |
| 4017 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4018 | /** |
| 4019 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4020 | * @param subId The subscription to use to check the configuration. |
| 4021 | * @param c The callback that will be used to send the result. |
| 4022 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 4023 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4024 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 4025 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4026 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4027 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4028 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4029 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4030 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4031 | "IMS not available on device."); |
| 4032 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4033 | final long token = Binder.clearCallingIdentity(); |
| 4034 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4035 | int slotId = getSlotIndexOrException(subId); |
| 4036 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4037 | ImsManager.getInstance(mApp, slotId).addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | } catch (ImsException e) { |
| 4039 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(token); |
| 4042 | } |
| 4043 | } |
| 4044 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4045 | /** |
| 4046 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4047 | * @param subId The subscription to use to check the configuration. |
| 4048 | * @param c The callback that will be used to send the result. |
| 4049 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4051 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4052 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4053 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4054 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4055 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4056 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4057 | final long token = Binder.clearCallingIdentity(); |
| 4058 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4059 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4060 | .removeRegistrationCallbackForSubscription(c, subId); |
| 4061 | } catch (ImsException e) { |
| 4062 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 4063 | + "is inactive, ignoring unregister."); |
| 4064 | // If the subscription is no longer active, just return, since the callback |
| 4065 | // will already have been removed internally. |
| 4066 | } finally { |
| 4067 | Binder.restoreCallingIdentity(token); |
| 4068 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4071 | /** |
| 4072 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 4073 | */ |
| 4074 | @Override |
| 4075 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 4076 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 4077 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4078 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4079 | "IMS not available on device."); |
| 4080 | } |
| 4081 | final long token = Binder.clearCallingIdentity(); |
| 4082 | try { |
| 4083 | Phone phone = getPhone(subId); |
| 4084 | if (phone == null) { |
| 4085 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4086 | + subId + "'"); |
| 4087 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4088 | } |
| 4089 | phone.getImsRegistrationState(regState -> { |
| 4090 | try { |
| 4091 | consumer.accept((regState == null) |
| 4092 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 4093 | } catch (RemoteException e) { |
| 4094 | // Ignore if the remote process is no longer available to call back. |
| 4095 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4096 | } |
| 4097 | }); |
| 4098 | } finally { |
| 4099 | Binder.restoreCallingIdentity(token); |
| 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | /** |
| 4104 | * Get the transport type for the IMS service registration state. |
| 4105 | */ |
| 4106 | @Override |
| 4107 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4108 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4109 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 4110 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4111 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4112 | "IMS not available on device."); |
| 4113 | } |
| 4114 | final long token = Binder.clearCallingIdentity(); |
| 4115 | try { |
| 4116 | Phone phone = getPhone(subId); |
| 4117 | if (phone == null) { |
| 4118 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 4119 | + subId + "'"); |
| 4120 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4121 | } |
| 4122 | phone.getImsRegistrationTech(regTech -> { |
| 4123 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 4124 | int regTechConverted = (regTech == null) |
| 4125 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 4126 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 4127 | regTechConverted); |
| 4128 | try { |
| 4129 | consumer.accept(regTechConverted); |
| 4130 | } catch (RemoteException e) { |
| 4131 | // Ignore if the remote process is no longer available to call back. |
| 4132 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 4133 | } |
| 4134 | }); |
| 4135 | } finally { |
| 4136 | Binder.restoreCallingIdentity(token); |
| 4137 | } |
| 4138 | } |
| 4139 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4140 | /** |
| 4141 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4142 | * @param subId The subscription to use to check the configuration. |
| 4143 | * @param c The callback that will be used to send the result. |
| 4144 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4146 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 4147 | throws RemoteException { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4148 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4149 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4150 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4151 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4152 | "IMS not available on device."); |
| 4153 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4154 | final long token = Binder.clearCallingIdentity(); |
| 4155 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4156 | int slotId = getSlotIndexOrException(subId); |
| 4157 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4158 | ImsManager.getInstance(mApp, slotId).addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4159 | } catch (ImsException e) { |
| 4160 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | } finally { |
| 4162 | Binder.restoreCallingIdentity(token); |
| 4163 | } |
| 4164 | } |
| 4165 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4166 | /** |
| 4167 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4168 | * @param subId The subscription to use to check the configuration. |
| 4169 | * @param c The callback that will be used to send the result. |
| 4170 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4171 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4172 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4173 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4174 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4175 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4176 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4177 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4178 | |
| 4179 | final long token = Binder.clearCallingIdentity(); |
| 4180 | try { |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4181 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4182 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 4183 | } catch (ImsException e) { |
| 4184 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 4185 | + "is inactive, ignoring unregister."); |
| 4186 | // If the subscription is no longer active, just return, since the callback |
| 4187 | // will already have been removed internally. |
| 4188 | } finally { |
| 4189 | Binder.restoreCallingIdentity(token); |
| 4190 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4194 | public boolean isCapable(int subId, int capability, int regTech) { |
| 4195 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | final long token = Binder.clearCallingIdentity(); |
| 4197 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4198 | int slotId = getSlotIndexOrException(subId); |
| 4199 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4200 | return ImsManager.getInstance(mApp, slotId).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4201 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4202 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 4203 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4204 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 4205 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 4206 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(token); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4213 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 4214 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | final long token = Binder.clearCallingIdentity(); |
| 4216 | try { |
| 4217 | Phone phone = getPhone(subId); |
| 4218 | if (phone == null) return false; |
| 4219 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 4220 | } catch (com.android.ims.ImsException e) { |
| 4221 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 4222 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4223 | } finally { |
| 4224 | Binder.restoreCallingIdentity(token); |
| 4225 | } |
| 4226 | } |
| 4227 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4228 | /** |
| 4229 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 4230 | * subscription. |
| 4231 | * @param subId The subscription to use to check the configuration. |
| 4232 | * @param callback The callback that will be used to send the result. |
| 4233 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 4234 | * @param transportType The transport type of the MmTelFeature capability. |
| 4235 | */ |
| 4236 | @Override |
| 4237 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 4238 | int transportType) { |
| 4239 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 4240 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4241 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4242 | "IMS not available on device."); |
| 4243 | } |
| 4244 | final long token = Binder.clearCallingIdentity(); |
| 4245 | try { |
| 4246 | int slotId = getSlotIndex(subId); |
| 4247 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4248 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 4249 | + subId + "'"); |
| 4250 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4251 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4252 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4253 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 4254 | transportType, aBoolean -> { |
| 4255 | try { |
| 4256 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 4257 | } catch (RemoteException e) { |
| 4258 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 4259 | + "running. Ignore"); |
| 4260 | } |
| 4261 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4262 | } catch (ImsException e) { |
| 4263 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4264 | } finally { |
| 4265 | Binder.restoreCallingIdentity(token); |
| 4266 | } |
| 4267 | } |
| 4268 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4269 | /** |
| 4270 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4271 | * @param subId The subscription to use to check the configuration. |
| 4272 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4273 | @Override |
| 4274 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4275 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4276 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4277 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4278 | final long token = Binder.clearCallingIdentity(); |
| 4279 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4280 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4281 | // 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] | 4282 | return ImsManager.getInstance(mApp, slotId).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4283 | } catch (ImsException e) { |
| 4284 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4285 | } finally { |
| 4286 | Binder.restoreCallingIdentity(token); |
| 4287 | } |
| 4288 | } |
| 4289 | |
| 4290 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4291 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4292 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4293 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4294 | final long identity = Binder.clearCallingIdentity(); |
| 4295 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4296 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4297 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4298 | // 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] | 4299 | ImsManager.getInstance(mApp, slotId).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4300 | } catch (ImsException e) { |
| 4301 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(identity); |
| 4304 | } |
| 4305 | } |
| 4306 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4307 | /** |
| 4308 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4309 | * @param subId The subscription to use to check the configuration. |
| 4310 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4311 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4312 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4313 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4314 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4317 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4318 | // 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] | 4319 | return ImsManager.getInstance(mApp, slotId).isVtEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4320 | } catch (ImsException e) { |
| 4321 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4322 | } finally { |
| 4323 | Binder.restoreCallingIdentity(identity); |
| 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4328 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4330 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4331 | final long identity = Binder.clearCallingIdentity(); |
| 4332 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4333 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4334 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4335 | // 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] | 4336 | ImsManager.getInstance(mApp, slotId).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4337 | } catch (ImsException e) { |
| 4338 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(identity); |
| 4341 | } |
| 4342 | } |
| 4343 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4344 | /** |
| 4345 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4346 | * @param subId The subscription to use to check the configuration. |
| 4347 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4348 | @Override |
| 4349 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4350 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4351 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4352 | final long identity = Binder.clearCallingIdentity(); |
| 4353 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4354 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4355 | // 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] | 4356 | return ImsManager.getInstance(mApp, slotId).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4357 | } catch (ImsException e) { |
| 4358 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
| 4361 | } |
| 4362 | } |
| 4363 | |
| 4364 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4365 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4366 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4367 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4370 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4371 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4372 | // 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] | 4373 | ImsManager.getInstance(mApp, slotId).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4374 | } catch (ImsException e) { |
| 4375 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
| 4378 | } |
| 4379 | } |
| 4380 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4381 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4382 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4383 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4384 | * @param subId The subscription to use to check the configuration. |
| 4385 | */ |
| 4386 | @Override |
| 4387 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4389 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4390 | final long identity = Binder.clearCallingIdentity(); |
| 4391 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4392 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4393 | // 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] | 4394 | return ImsManager.getInstance(mApp, slotId).isCrossSimCallingEnabledByUser(); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4395 | } catch (ImsException e) { |
| 4396 | throw new ServiceSpecificException(e.getCode()); |
| 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | /** |
| 4403 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4404 | * Requires MODIFY_PHONE_STATE permission. |
| 4405 | * @param subId The subscription to use to check the configuration. |
| 4406 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4407 | * false otherwise |
| 4408 | */ |
| 4409 | @Override |
| 4410 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4411 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4412 | "setCrossSimCallingEnabled"); |
| 4413 | final long identity = Binder.clearCallingIdentity(); |
| 4414 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4415 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4416 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4417 | // 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] | 4418 | ImsManager.getInstance(mApp, slotId).setCrossSimCallingEnabled(isEnabled); |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4419 | } catch (ImsException e) { |
| 4420 | throw new ServiceSpecificException(e.getCode()); |
| 4421 | } finally { |
| 4422 | Binder.restoreCallingIdentity(identity); |
| 4423 | } |
| 4424 | } |
| 4425 | |
| 4426 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4427 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4428 | * @param subId The subscription to use to check the configuration. |
| 4429 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4430 | @Override |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4431 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4432 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4433 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4434 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4435 | final long identity = Binder.clearCallingIdentity(); |
| 4436 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4437 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4438 | // 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] | 4439 | return ImsManager.getInstance(mApp, slotId).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4440 | } catch (ImsException e) { |
| 4441 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4442 | } finally { |
| 4443 | Binder.restoreCallingIdentity(identity); |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4448 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4449 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4450 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4451 | final long identity = Binder.clearCallingIdentity(); |
| 4452 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4453 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4454 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4455 | // 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] | 4456 | ImsManager.getInstance(mApp, slotId).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4457 | } catch (ImsException e) { |
| 4458 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4459 | } finally { |
| 4460 | Binder.restoreCallingIdentity(identity); |
| 4461 | } |
| 4462 | } |
| 4463 | |
| 4464 | @Override |
| 4465 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4466 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4467 | "setVoWiFiNonPersistent"); |
| 4468 | final long identity = Binder.clearCallingIdentity(); |
| 4469 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4470 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4471 | // This setting will be ignored if the ImsService isn't up. |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4472 | ImsManager.getInstance(mApp, slotId).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4473 | } catch (ImsException e) { |
| 4474 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4475 | } finally { |
| 4476 | Binder.restoreCallingIdentity(identity); |
| 4477 | } |
| 4478 | } |
| 4479 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4480 | /** |
| 4481 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4482 | * @param subId The subscription to use to check the configuration. |
| 4483 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4484 | @Override |
| 4485 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4486 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4487 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4488 | final long identity = Binder.clearCallingIdentity(); |
| 4489 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4490 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4491 | // 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] | 4492 | return ImsManager.getInstance(mApp, slotId).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4493 | } catch (ImsException e) { |
| 4494 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4495 | } finally { |
| 4496 | Binder.restoreCallingIdentity(identity); |
| 4497 | } |
| 4498 | } |
| 4499 | |
| 4500 | @Override |
| 4501 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4503 | "setVoWiFiModeSetting"); |
| 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4506 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4507 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4508 | // 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] | 4509 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4510 | } catch (ImsException e) { |
| 4511 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4512 | } finally { |
| 4513 | Binder.restoreCallingIdentity(identity); |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | @Override |
| 4518 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4519 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4522 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4523 | // 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] | 4524 | return ImsManager.getInstance(mApp, slotId).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4525 | } catch (ImsException e) { |
| 4526 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(identity); |
| 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | @Override |
| 4533 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4535 | "setVoWiFiRoamingModeSetting"); |
| 4536 | final long identity = Binder.clearCallingIdentity(); |
| 4537 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4538 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4539 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4540 | // 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] | 4541 | ImsManager.getInstance(mApp, slotId).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4542 | } catch (ImsException e) { |
| 4543 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(identity); |
| 4546 | } |
| 4547 | } |
| 4548 | |
| 4549 | @Override |
| 4550 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4551 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4552 | "setRttCapabilityEnabled"); |
| 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4555 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4556 | // This setting doesn't require an active ImsService connection, so do not verify. The |
| 4557 | // 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] | 4558 | ImsManager.getInstance(mApp, slotId).setRttEnabled(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4559 | } catch (ImsException e) { |
| 4560 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
| 4563 | } |
| 4564 | } |
| 4565 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4566 | /** |
| 4567 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4568 | * @param subId The subscription to use to check the configuration. |
| 4569 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4570 | @Override |
| 4571 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4572 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4573 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4574 | final long identity = Binder.clearCallingIdentity(); |
| 4575 | try { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4576 | int slotId = getSlotIndexOrException(subId); |
Brad Ebinger | 735c5ce | 2021-07-12 13:58:21 -0700 | [diff] [blame] | 4577 | // 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] | 4578 | return ImsManager.getInstance(mApp, slotId).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4579 | } catch (ImsException e) { |
| 4580 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4581 | } finally { |
| 4582 | Binder.restoreCallingIdentity(identity); |
| 4583 | } |
| 4584 | } |
| 4585 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4586 | @Override |
| 4587 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4588 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4589 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4590 | final long identity = Binder.clearCallingIdentity(); |
| 4591 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4592 | if (!isImsAvailableOnDevice()) { |
| 4593 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4594 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4595 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4596 | int slotId = getSlotIndexOrException(subId); |
| 4597 | verifyImsMmTelConfiguredOrThrow(slotId); |
| 4598 | ImsManager.getInstance(mApp, slotId) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4599 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4600 | } catch (ImsException e) { |
| 4601 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4602 | } finally { |
| 4603 | Binder.restoreCallingIdentity(identity); |
| 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | @Override |
| 4608 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4609 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4610 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4611 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4612 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4613 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4614 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4615 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4616 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4617 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4618 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4619 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4620 | + "is inactive, ignoring unregister."); |
| 4621 | // If the subscription is no longer active, just return, since the callback will already |
| 4622 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4623 | } finally { |
| 4624 | Binder.restoreCallingIdentity(identity); |
| 4625 | } |
| 4626 | } |
| 4627 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4628 | @Override |
| 4629 | public void registerFeatureProvisioningChangedCallback(int subId, |
| 4630 | IFeatureProvisioningCallback callback) { |
| 4631 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4632 | mApp, subId, "registerFeatureProvisioningChangedCallback"); |
| 4633 | |
| 4634 | final long identity = Binder.clearCallingIdentity(); |
| 4635 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4636 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4637 | } |
| 4638 | |
| 4639 | ImsProvisioningController.getInstance() |
| 4640 | .addFeatureProvisioningChangedCallback(subId, callback); |
| 4641 | |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
| 4644 | |
| 4645 | @Override |
| 4646 | public void unregisterFeatureProvisioningChangedCallback(int subId, |
| 4647 | IFeatureProvisioningCallback callback) { |
| 4648 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4649 | mApp, subId, "unregisterFeatureProvisioningChangedCallback"); |
| 4650 | |
| 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4653 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4654 | } |
| 4655 | |
| 4656 | ImsProvisioningController.getInstance() |
| 4657 | .removeFeatureProvisioningChangedCallback(subId, callback); |
| 4658 | |
| 4659 | Binder.restoreCallingIdentity(identity); |
| 4660 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4661 | |
| 4662 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4664 | message); |
| 4665 | } |
| 4666 | |
| 4667 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4668 | boolean isMmtelCapability) { |
| 4669 | Phone phone = getPhone(subId); |
| 4670 | if (phone == null) { |
| 4671 | loge("phone instance null for subid " + subId); |
| 4672 | return false; |
| 4673 | } |
| 4674 | if (isMmtelCapability) { |
| 4675 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4676 | return false; |
| 4677 | } |
| 4678 | } else { |
| 4679 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4680 | return false; |
| 4681 | } |
| 4682 | } |
| 4683 | return true; |
| 4684 | } |
| 4685 | |
| 4686 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4687 | public void setRcsProvisioningStatusForCapability(int subId, int capability, int tech, |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4688 | boolean isProvisioned) { |
| 4689 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4690 | |
| 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4693 | ImsProvisioningController.getInstance() |
| 4694 | .setRcsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
| 4695 | return; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(identity); |
| 4698 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4699 | } |
| 4700 | |
| 4701 | |
| 4702 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4703 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4704 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4705 | mApp, subId, "getRcsProvisioningStatusForCapability"); |
| 4706 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4707 | final long identity = Binder.clearCallingIdentity(); |
| 4708 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4709 | return ImsProvisioningController.getInstance() |
| 4710 | .getRcsProvisioningStatusForCapability(subId, capability, tech); |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4711 | } finally { |
| 4712 | Binder.restoreCallingIdentity(identity); |
| 4713 | } |
| 4714 | } |
| 4715 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4716 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4717 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4718 | boolean isProvisioned) { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4719 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4720 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4723 | ImsProvisioningController.getInstance() |
| 4724 | .setImsProvisioningStatusForCapability(subId, capability, tech, isProvisioned); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4725 | } finally { |
| 4726 | Binder.restoreCallingIdentity(identity); |
| 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | @Override |
| 4731 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4732 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4733 | mApp, subId, "getProvisioningStatusForCapability"); |
| 4734 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4735 | final long identity = Binder.clearCallingIdentity(); |
| 4736 | try { |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4737 | return ImsProvisioningController.getInstance() |
| 4738 | .getImsProvisioningStatusForCapability(subId, capability, tech); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4739 | |
| 4740 | } finally { |
| 4741 | Binder.restoreCallingIdentity(identity); |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4746 | public boolean isProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4747 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4748 | mApp, subId, "isProvisioningRequiredForCapability"); |
| 4749 | |
| 4750 | final long identity = Binder.clearCallingIdentity(); |
| 4751 | try { |
| 4752 | return ImsProvisioningController.getInstance() |
| 4753 | .isImsProvisioningRequiredForCapability(subId, capability, tech); |
| 4754 | } finally { |
| 4755 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4756 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4757 | } |
| 4758 | |
| 4759 | @Override |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4760 | public boolean isRcsProvisioningRequiredForCapability(int subId, int capability, int tech) { |
| 4761 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4762 | mApp, subId, "isProvisioningRequiredForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4763 | |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4764 | final long identity = Binder.clearCallingIdentity(); |
| 4765 | try { |
| 4766 | return ImsProvisioningController.getInstance() |
| 4767 | .isRcsProvisioningRequiredForCapability(subId, capability, tech); |
| 4768 | } finally { |
| 4769 | Binder.restoreCallingIdentity(identity); |
| 4770 | } |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4774 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4775 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4776 | } |
| 4777 | |
| 4778 | /** |
| 4779 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4780 | * carrier associated with the subscription id. |
| 4781 | */ |
| 4782 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4783 | int capability) { |
| 4784 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4785 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4786 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4787 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4788 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4789 | false); |
| 4790 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4791 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4792 | |
| 4793 | // First check to make sure that the capability requires provisioning. |
| 4794 | switch (capability) { |
| 4795 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4796 | // intentional fallthrough |
| 4797 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4798 | if (requireVoiceVtProvisioning) { |
| 4799 | // Voice and Video requires provisioning |
| 4800 | return true; |
| 4801 | } |
| 4802 | break; |
| 4803 | } |
| 4804 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4805 | if (requireUtProvisioning) { |
| 4806 | // UT requires provisioning |
| 4807 | return true; |
| 4808 | } |
| 4809 | break; |
| 4810 | } |
| 4811 | } |
| 4812 | return false; |
| 4813 | } |
| 4814 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4815 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4816 | int capability) { |
| 4817 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4818 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4819 | |
| 4820 | boolean requireRcsProvisioning = c.getBoolean( |
| 4821 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4822 | |
| 4823 | // First check to make sure that the capability requires provisioning. |
| 4824 | switch (capability) { |
| 4825 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4826 | // intentional fallthrough |
| 4827 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4828 | if (requireRcsProvisioning) { |
| 4829 | // OPTION or PRESENCE requires provisioning |
| 4830 | return true; |
| 4831 | } |
| 4832 | break; |
| 4833 | } |
| 4834 | } |
| 4835 | return false; |
| 4836 | } |
| 4837 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4838 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4839 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4840 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4841 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4842 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4843 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4844 | mApp, subId, "getImsProvisioningInt"); |
| 4845 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4846 | final long identity = Binder.clearCallingIdentity(); |
| 4847 | try { |
| 4848 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4849 | int slotId = getSlotIndex(subId); |
| 4850 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4851 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4852 | + subId + "' for key:" + key); |
| 4853 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4854 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4855 | |
| 4856 | int retVal = ImsProvisioningController.getInstance().getProvisioningValue(subId, key); |
| 4857 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4858 | return retVal; |
| 4859 | } |
| 4860 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4861 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4862 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4863 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4864 | + subId + "' for key:" + key); |
| 4865 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
| 4869 | } |
| 4870 | |
| 4871 | @Override |
| 4872 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4873 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4874 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4875 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4876 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4877 | mApp, subId, "getImsProvisioningString"); |
| 4878 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4879 | final long identity = Binder.clearCallingIdentity(); |
| 4880 | try { |
| 4881 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4882 | int slotId = getSlotIndex(subId); |
| 4883 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4884 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4885 | + subId + "' for key:" + key); |
| 4886 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4887 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4888 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4889 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4890 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4891 | + subId + "' for key:" + key); |
| 4892 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4893 | } finally { |
| 4894 | Binder.restoreCallingIdentity(identity); |
| 4895 | } |
| 4896 | } |
| 4897 | |
| 4898 | @Override |
| 4899 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4900 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4901 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4902 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4904 | "setImsProvisioningInt"); |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4905 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4906 | final long identity = Binder.clearCallingIdentity(); |
| 4907 | try { |
| 4908 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4909 | int slotId = getSlotIndex(subId); |
| 4910 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4911 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4912 | + subId + "' for key:" + key); |
| 4913 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4914 | } |
joonhunshin | 2c3e423 | 2021-11-28 07:32:01 +0000 | [diff] [blame] | 4915 | |
| 4916 | int retVal = ImsProvisioningController.getInstance() |
| 4917 | .setProvisioningValue(subId, key, value); |
| 4918 | if (retVal != ImsConfigImplBase.CONFIG_RESULT_UNKNOWN) { |
| 4919 | return retVal; |
| 4920 | } |
| 4921 | |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4922 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4923 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4924 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4925 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4926 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(identity); |
| 4929 | } |
| 4930 | } |
| 4931 | |
| 4932 | @Override |
| 4933 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4934 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4935 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4936 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4938 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4939 | final long identity = Binder.clearCallingIdentity(); |
| 4940 | try { |
| 4941 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4942 | int slotId = getSlotIndex(subId); |
| 4943 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4944 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4945 | + subId + "' for key:" + key); |
| 4946 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4947 | } |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4948 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4949 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4950 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | b5a3406 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4951 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4952 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4953 | } finally { |
| 4954 | Binder.restoreCallingIdentity(identity); |
| 4955 | } |
| 4956 | } |
| 4957 | |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 4958 | /** |
| 4959 | * Throw an ImsException if the IMS resolver does not have an ImsService configured for MMTEL |
| 4960 | * for the given slot ID or no ImsResolver instance has been created. |
| 4961 | * @param slotId The slot ID that the IMS service is created for. |
| 4962 | * @throws ImsException If there is no ImsService configured for this slot. |
| 4963 | */ |
| 4964 | private void verifyImsMmTelConfiguredOrThrow(int slotId) throws ImsException { |
| 4965 | if (mImsResolver == null || !mImsResolver.isImsServiceConfiguredForFeature(slotId, |
| 4966 | ImsFeature.FEATURE_MMTEL)) { |
| 4967 | throw new ImsException("This subscription does not support MMTEL over IMS", |
| 4968 | ImsException.CODE_ERROR_UNSUPPORTED_OPERATION); |
| 4969 | } |
| 4970 | } |
| 4971 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4972 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4973 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4974 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4975 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4976 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4977 | } |
| 4978 | return slotId; |
| 4979 | } |
| 4980 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4981 | private int getSlotIndex(int subId) { |
| 4982 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4983 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4984 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4985 | } |
| 4986 | return slotId; |
| 4987 | } |
| 4988 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4989 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4990 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4991 | */ |
| 4992 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4993 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4994 | String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 4995 | try { |
| 4996 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4997 | } catch (SecurityException se) { |
| 4998 | EventLog.writeEvent(0x534e4554, "186776740", Binder.getCallingUid()); |
| 4999 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 5000 | + Binder.getCallingUid()); |
| 5001 | } |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 5002 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5003 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5004 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 5005 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 5006 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5007 | mApp, subId, callingPackage, callingFeatureId, |
| 5008 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5009 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5010 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | final long identity = Binder.clearCallingIdentity(); |
| 5013 | try { |
| 5014 | final Phone phone = getPhone(subId); |
| 5015 | if (phone != null) { |
| 5016 | return phone.getServiceState().getDataNetworkType(); |
| 5017 | } else { |
| 5018 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5019 | } |
| 5020 | } finally { |
| 5021 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5022 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
| 5025 | /** |
| 5026 | * Returns the data network type |
| 5027 | */ |
| 5028 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5029 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 5030 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 5031 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | /** |
| 5035 | * Returns the data network type for a subId |
| 5036 | */ |
| 5037 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5038 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5039 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5040 | String functionName = "getDataNetworkTypeForSubscriber"; |
| 5041 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5042 | mApp, functionName)) { |
| 5043 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5044 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5045 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5046 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5047 | } |
| 5048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5049 | final long identity = Binder.clearCallingIdentity(); |
| 5050 | try { |
| 5051 | final Phone phone = getPhone(subId); |
| 5052 | if (phone != null) { |
| 5053 | return phone.getServiceState().getDataNetworkType(); |
| 5054 | } else { |
| 5055 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5056 | } |
| 5057 | } finally { |
| 5058 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5059 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5063 | * Returns the Voice network type for a subId |
| 5064 | */ |
| 5065 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5066 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 5067 | String callingFeatureId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 5068 | String functionName = "getVoiceNetworkTypeForSubscriber"; |
| 5069 | if (!TelephonyPermissions.checkCallingOrSelfReadNonDangerousPhoneStateNoThrow( |
| 5070 | mApp, functionName)) { |
| 5071 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 5072 | mApp, subId, callingPackage, callingFeatureId, functionName)) { |
| 5073 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5074 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 5075 | } |
| 5076 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5077 | final long identity = Binder.clearCallingIdentity(); |
| 5078 | try { |
| 5079 | final Phone phone = getPhone(subId); |
| 5080 | if (phone != null) { |
| 5081 | return phone.getServiceState().getVoiceNetworkType(); |
| 5082 | } else { |
| 5083 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 5084 | } |
| 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5087 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | /** |
| 5091 | * @return true if a ICC card is present |
| 5092 | */ |
| 5093 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5094 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5095 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 5096 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5100 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5101 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5102 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 5103 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | final long identity = Binder.clearCallingIdentity(); |
| 5105 | try { |
| 5106 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5107 | if (phone != null) { |
| 5108 | return phone.getIccCard().hasIccCard(); |
| 5109 | } else { |
| 5110 | return false; |
| 5111 | } |
| 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 5114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
| 5117 | /** |
| 5118 | * Return if the current radio is LTE on CDMA. This |
| 5119 | * is a tri-state return value as for a period of time |
| 5120 | * the mode may be unknown. |
| 5121 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5122 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5123 | * @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] | 5124 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5125 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5126 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5127 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 5128 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 5129 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5132 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5133 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 5134 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 5135 | try { |
| 5136 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 5137 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5138 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5139 | } |
| 5140 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5141 | final long identity = Binder.clearCallingIdentity(); |
| 5142 | try { |
| 5143 | final Phone phone = getPhone(subId); |
| 5144 | if (phone == null) { |
| 5145 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 5146 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 5147 | return TelephonyProperties.lte_on_cdma_device() |
| 5148 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | } |
| 5150 | } finally { |
| 5151 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5152 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5153 | } |
| 5154 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5155 | /** |
| 5156 | * {@hide} |
| 5157 | * Returns Default subId, 0 in the case of single standby. |
| 5158 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5159 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5160 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 5163 | private int getSlotForDefaultSubscription() { |
| 5164 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 5165 | } |
| 5166 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5167 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 5168 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 5169 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5170 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5171 | private boolean isActiveSubscription(int subId) { |
| 5172 | return mSubscriptionController.isActiveSubId(subId); |
| 5173 | } |
| 5174 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5175 | /** |
| 5176 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5177 | */ |
| 5178 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5181 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5182 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 5183 | getWhenToMakeWifiCallsDefaultPreference()); |
| 5184 | } finally { |
| 5185 | Binder.restoreCallingIdentity(identity); |
| 5186 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 5191 | */ |
| 5192 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | final long identity = Binder.clearCallingIdentity(); |
| 5194 | try { |
| 5195 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5196 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 5198 | } finally { |
| 5199 | Binder.restoreCallingIdentity(identity); |
| 5200 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 5203 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 5204 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 5205 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 5206 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 5207 | |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5208 | private Phone getPhoneFromSlotPortIndexOrThrowException(int slotIndex, int portIndex) { |
| 5209 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotPortIndex(slotIndex, |
| 5210 | portIndex); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5211 | if (phoneId == -1) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5212 | throw new IllegalArgumentException("Given slot index: " + slotIndex + " port index: " |
| 5213 | + portIndex + " does not correspond to an active phone"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5214 | } |
| 5215 | return PhoneFactory.getPhone(phoneId); |
| 5216 | } |
| 5217 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5218 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5219 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5220 | @NonNull IccLogicalChannelRequest request) { |
| 5221 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5222 | /*message=*/ "iccOpenLogicalChannel"); |
| 5223 | |
| 5224 | if (DBG) log("iccOpenLogicalChannel: request=" + request); |
| 5225 | // Verify that the callingPackage in the request belongs to the calling UID |
| 5226 | mAppOps.checkPackage(Binder.getCallingUid(), request.callingPackage); |
| 5227 | |
| 5228 | return iccOpenLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5229 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5230 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5231 | private Phone getPhoneFromValidIccLogicalChannelRequest( |
| 5232 | @NonNull IccLogicalChannelRequest request, String message) { |
| 5233 | Phone phone; |
| 5234 | if (request.subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { |
| 5235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5236 | mApp, request.subId, message); |
| 5237 | phone = getPhoneFromSubId(request.subId); |
| 5238 | } else if (request.slotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5239 | enforceModifyPermission(); |
| 5240 | phone = getPhoneFromSlotPortIndexOrThrowException(request.slotIndex, request.portIndex); |
| 5241 | } else { |
| 5242 | throw new IllegalArgumentException("Both subId and slotIndex in request are invalid."); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5243 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5244 | return phone; |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5248 | IccLogicalChannelRequest channelRequest) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5249 | final long identity = Binder.clearCallingIdentity(); |
| 5250 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5251 | if (TextUtils.equals(ISDR_AID, channelRequest.aid)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5253 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5254 | .getContext().getPackageManager()); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5255 | if (bestComponent == null || !TextUtils.equals(channelRequest.callingPackage, |
| 5256 | bestComponent.packageName)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | loge("The calling package is not allowed to access ISD-R."); |
| 5258 | throw new SecurityException( |
| 5259 | "The calling package is not allowed to access ISD-R."); |
| 5260 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5261 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 5262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5263 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5264 | CMD_OPEN_CHANNEL, channelRequest, phone, null /* workSource */); |
| 5265 | if (DBG) log("iccOpenLogicalChannelWithPermission: response=" + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5266 | return response; |
| 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
| 5269 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5270 | } |
| 5271 | |
| 5272 | @Override |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5273 | public boolean iccCloseLogicalChannel(@NonNull IccLogicalChannelRequest request) { |
| 5274 | Phone phone = getPhoneFromValidIccLogicalChannelRequest(request, |
| 5275 | /*message=*/"iccCloseLogicalChannel"); |
| 5276 | |
| 5277 | if (DBG) log("iccCloseLogicalChannel: request=" + request); |
| 5278 | |
| 5279 | return iccCloseLogicalChannelWithPermission(phone, request); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5280 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5281 | |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5282 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, |
| 5283 | IccLogicalChannelRequest request) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | final long identity = Binder.clearCallingIdentity(); |
| 5285 | try { |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5286 | if (request.channel < 0) { |
Chen Xu | 9040b47 | 2021-12-14 17:15:47 -0800 | [diff] [blame] | 5287 | throw new IllegalArgumentException("request.channel is less than 0"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | } |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5289 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, request.channel, phone, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5290 | null /* workSource */); |
Rambo Wang | e162e30 | 2021-11-10 20:15:19 -0800 | [diff] [blame] | 5291 | if (DBG) log("iccCloseLogicalChannelWithPermission: success=" + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | return success; |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5295 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5299 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5300 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5301 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5302 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5303 | if (DBG) { |
| 5304 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5305 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5306 | + p3 + " data=" + data); |
| 5307 | } |
| 5308 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5309 | command, p1, p2, p3, data); |
| 5310 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5311 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5312 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5313 | public String iccTransmitApduLogicalChannelByPort(int slotIndex, int portIndex, int channel, |
| 5314 | int cla, int command, int p1, int p2, int p3, String data) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5315 | enforceModifyPermission(); |
| 5316 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5317 | log("iccTransmitApduLogicalChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5318 | + portIndex + " chnl=" + channel + " cla=" + cla + " cmd=" + command + " p1=" |
| 5319 | + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5320 | } |
| 5321 | return iccTransmitApduLogicalChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5322 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), channel, cla, |
| 5323 | command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5327 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5328 | final long identity = Binder.clearCallingIdentity(); |
| 5329 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5330 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5331 | return ""; |
| 5332 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5333 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5334 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5335 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5336 | null /* workSource */); |
| 5337 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5339 | // Append the returned status code to the end of the response payload. |
| 5340 | String s = Integer.toHexString( |
| 5341 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5342 | if (response.payload != null) { |
| 5343 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5344 | } |
| 5345 | return s; |
| 5346 | } finally { |
| 5347 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5348 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5349 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5350 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5351 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5352 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5353 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5354 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5355 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5357 | if (DBG) { |
| 5358 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5359 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5360 | } |
| 5361 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5362 | cla, command, p1, p2, p3, data); |
| 5363 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5364 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5365 | @Override |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5366 | public String iccTransmitApduBasicChannelByPort(int slotIndex, int portIndex, |
| 5367 | 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] | 5368 | enforceModifyPermission(); |
| 5369 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5370 | if (DBG) { |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5371 | log("iccTransmitApduBasicChannelByPort: slotIndex=" + slotIndex + " portIndex=" |
| 5372 | + portIndex + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" |
| 5373 | + p2 + " p3=" + p3 + " data=" + data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | return iccTransmitApduBasicChannelWithPermission( |
Muralidhar Reddy | c4c6a69 | 2021-12-02 21:04:16 +0000 | [diff] [blame] | 5377 | getPhoneFromSlotPortIndexOrThrowException(slotIndex, portIndex), callingPackage, |
| 5378 | cla, command, p1, p2, p3, data); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5382 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5383 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5384 | final long identity = Binder.clearCallingIdentity(); |
| 5385 | try { |
| 5386 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5387 | && TextUtils.equals(ISDR_AID, data)) { |
| 5388 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5389 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5390 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5391 | if (bestComponent == null |
| 5392 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5393 | loge("The calling package is not allowed to select ISD-R."); |
| 5394 | throw new SecurityException( |
| 5395 | "The calling package is not allowed to select ISD-R."); |
| 5396 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5397 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5398 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5399 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5400 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5401 | null /* workSource */); |
| 5402 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5403 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5404 | // Append the returned status code to the end of the response payload. |
| 5405 | String s = Integer.toHexString( |
| 5406 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5407 | if (response.payload != null) { |
| 5408 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5409 | } |
| 5410 | return s; |
| 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5413 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5417 | 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] | 5418 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5419 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5420 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5421 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | final long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | if (DBG) { |
| 5425 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5426 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5427 | } |
| 5428 | |
| 5429 | IccIoResult response = |
| 5430 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5431 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5432 | subId); |
| 5433 | |
| 5434 | if (DBG) { |
| 5435 | log("Exchange SIM_IO [R]" + response); |
| 5436 | } |
| 5437 | |
| 5438 | byte[] result = null; |
| 5439 | int length = 2; |
| 5440 | if (response.payload != null) { |
| 5441 | length = 2 + response.payload.length; |
| 5442 | result = new byte[length]; |
| 5443 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5444 | } else { |
| 5445 | result = new byte[length]; |
| 5446 | } |
| 5447 | |
| 5448 | result[length - 1] = (byte) response.sw2; |
| 5449 | result[length - 2] = (byte) response.sw1; |
| 5450 | return result; |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5453 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5456 | /** |
| 5457 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5458 | * on a particular subscription |
| 5459 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5460 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5461 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5462 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5463 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5464 | return null; |
| 5465 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | |
| 5467 | final long identity = Binder.clearCallingIdentity(); |
| 5468 | try { |
| 5469 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5470 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5471 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5472 | return null; |
| 5473 | } |
| 5474 | Object response = sendRequest( |
| 5475 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5476 | if (response instanceof String[]) { |
| 5477 | return (String[]) response; |
| 5478 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5479 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5481 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5484 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5487 | /** |
| 5488 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5489 | * subscription. |
| 5490 | * |
| 5491 | * @param subId the id of the subscription. |
| 5492 | * @param appType the uicc app type, must be USIM or SIM. |
| 5493 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5494 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5495 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5496 | * @return number of fplmns that is successfully written to the SIM. |
| 5497 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5498 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5499 | String callingFeatureId) { |
Jayachandran C | 5b0d75a | 2021-10-21 22:15:27 -0700 | [diff] [blame] | 5500 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5501 | mApp, subId, "setForbiddenPlmns"); |
| 5502 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5503 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5504 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5505 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5506 | } |
| 5507 | if (fplmns == null) { |
| 5508 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5509 | } |
| 5510 | for (String fplmn : fplmns) { |
| 5511 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5512 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5513 | } |
| 5514 | } |
| 5515 | final long identity = Binder.clearCallingIdentity(); |
| 5516 | try { |
| 5517 | Object response = sendRequest( |
| 5518 | CMD_SET_FORBIDDEN_PLMNS, |
| 5519 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5520 | subId); |
| 5521 | return (int) response; |
| 5522 | } finally { |
| 5523 | Binder.restoreCallingIdentity(identity); |
| 5524 | } |
| 5525 | } |
| 5526 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5527 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5528 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5530 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5531 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5532 | final long identity = Binder.clearCallingIdentity(); |
| 5533 | try { |
| 5534 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5535 | if (response.payload == null) { |
| 5536 | return ""; |
| 5537 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5538 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | // Append the returned status code to the end of the response payload. |
| 5540 | String s = Integer.toHexString( |
| 5541 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5542 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5543 | return s; |
| 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
| 5546 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5549 | /** |
| 5550 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5551 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5552 | * |
| 5553 | * @param itemID the ID of the item to read |
| 5554 | * @return the NV item as a String, or null on error. |
| 5555 | */ |
| 5556 | @Override |
| 5557 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5558 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5560 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5565 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5566 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5567 | return value; |
| 5568 | } finally { |
| 5569 | Binder.restoreCallingIdentity(identity); |
| 5570 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | /** |
| 5574 | * Write 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 | * @param itemValue the value to write, as a String |
| 5579 | * @return true on success; false on any failure |
| 5580 | */ |
| 5581 | @Override |
| 5582 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5583 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5584 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5585 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5586 | |
| 5587 | final long identity = Binder.clearCallingIdentity(); |
| 5588 | try { |
| 5589 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5590 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5591 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5592 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5593 | return success; |
| 5594 | } finally { |
| 5595 | Binder.restoreCallingIdentity(identity); |
| 5596 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | /** |
| 5600 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5601 | * Used for device configuration by some CDMA operators. |
| 5602 | * |
| 5603 | * @param preferredRoamingList byte array containing the new PRL |
| 5604 | * @return true on success; false on any failure |
| 5605 | */ |
| 5606 | @Override |
| 5607 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5608 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5609 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
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("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5614 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5615 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5616 | return success; |
| 5617 | } finally { |
| 5618 | Binder.restoreCallingIdentity(identity); |
| 5619 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5623 | * 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] | 5624 | * Used for device configuration by some CDMA operators. |
| 5625 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5626 | * @param slotIndex - device slot. |
| 5627 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5628 | * @return true on success; false on any failure |
| 5629 | */ |
| 5630 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5631 | public boolean resetModemConfig(int slotIndex) { |
| 5632 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5633 | if (phone != null) { |
| 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5636 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5637 | final long identity = Binder.clearCallingIdentity(); |
| 5638 | try { |
| 5639 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5640 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5641 | return success; |
| 5642 | } finally { |
| 5643 | Binder.restoreCallingIdentity(identity); |
| 5644 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5646 | return false; |
| 5647 | } |
| 5648 | |
| 5649 | /** |
| 5650 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5651 | * |
| 5652 | * @param slotIndex - device slot. |
| 5653 | * |
| 5654 | * @return true on success; false on any failure |
| 5655 | */ |
| 5656 | @Override |
| 5657 | public boolean rebootModem(int slotIndex) { |
| 5658 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5659 | if (phone != null) { |
| 5660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5661 | mApp, phone.getSubId(), "rebootModem"); |
| 5662 | |
| 5663 | final long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
| 5665 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5666 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5667 | return success; |
| 5668 | } finally { |
| 5669 | Binder.restoreCallingIdentity(identity); |
| 5670 | } |
| 5671 | } |
| 5672 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5673 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5674 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5675 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5676 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5677 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5679 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5680 | return new String[0]; |
| 5681 | } |
| 5682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | final long identity = Binder.clearCallingIdentity(); |
| 5684 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5685 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | } finally { |
| 5687 | Binder.restoreCallingIdentity(identity); |
| 5688 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5689 | } |
| 5690 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5691 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5692 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5693 | * {@link #disableIms(int)}. |
| 5694 | * @param slotIndex device slot. |
| 5695 | */ |
| 5696 | public void resetIms(int slotIndex) { |
| 5697 | enforceModifyPermission(); |
| 5698 | |
| 5699 | final long identity = Binder.clearCallingIdentity(); |
| 5700 | try { |
| 5701 | if (mImsResolver == null) { |
| 5702 | // may happen if the does not support IMS. |
| 5703 | return; |
| 5704 | } |
| 5705 | mImsResolver.disableIms(slotIndex); |
| 5706 | mImsResolver.enableIms(slotIndex); |
| 5707 | } finally { |
| 5708 | Binder.restoreCallingIdentity(identity); |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5713 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5714 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5715 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5716 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5717 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5718 | |
| 5719 | final long identity = Binder.clearCallingIdentity(); |
| 5720 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5721 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5722 | // may happen if the device does not support IMS. |
| 5723 | return; |
| 5724 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5725 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
| 5728 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5732 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5733 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5734 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5735 | public void disableIms(int slotId) { |
| 5736 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | |
| 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5740 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5741 | // may happen if the device does not support IMS. |
| 5742 | return; |
| 5743 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5744 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5745 | } finally { |
| 5746 | Binder.restoreCallingIdentity(identity); |
| 5747 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5748 | } |
| 5749 | |
| 5750 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5751 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5752 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5753 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5754 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5755 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5756 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5757 | |
| 5758 | final long identity = Binder.clearCallingIdentity(); |
| 5759 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5760 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5762 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5763 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5764 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
| 5767 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5768 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5769 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5770 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5771 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5772 | @Override |
| 5773 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5774 | enforceModifyPermission(); |
| 5775 | |
| 5776 | final long identity = Binder.clearCallingIdentity(); |
| 5777 | try { |
| 5778 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5779 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5780 | } finally { |
| 5781 | Binder.restoreCallingIdentity(identity); |
| 5782 | } |
| 5783 | } |
| 5784 | |
| 5785 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5786 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5787 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5788 | */ |
| 5789 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5790 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5791 | |
| 5792 | final long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5794 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5795 | // may happen if the device does not support IMS. |
| 5796 | return null; |
| 5797 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5798 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5799 | } finally { |
| 5800 | Binder.restoreCallingIdentity(identity); |
| 5801 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5802 | } |
| 5803 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5804 | /** |
| 5805 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5806 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5807 | */ |
| 5808 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5809 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5810 | |
| 5811 | final long identity = Binder.clearCallingIdentity(); |
| 5812 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5813 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5814 | // may happen if the device does not support IMS. |
| 5815 | return null; |
| 5816 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5817 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5818 | } finally { |
| 5819 | Binder.restoreCallingIdentity(identity); |
| 5820 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5821 | } |
| 5822 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5823 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5824 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5825 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5826 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5827 | * @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] | 5828 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5829 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5830 | * @param packageName The name of the package that the current configuration will be replaced |
| 5831 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5832 | * @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] | 5833 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5834 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5835 | int[] featureTypes, String packageName) { |
| 5836 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5837 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5839 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5840 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5841 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | final long identity = Binder.clearCallingIdentity(); |
| 5843 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5844 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5845 | // may happen if the device does not support IMS. |
| 5846 | return false; |
| 5847 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5848 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5849 | for (int featureType : featureTypes) { |
| 5850 | featureConfig.put(featureType, packageName); |
| 5851 | } |
| 5852 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5853 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5854 | } finally { |
| 5855 | Binder.restoreCallingIdentity(identity); |
| 5856 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5857 | } |
| 5858 | |
| 5859 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5860 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5861 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5862 | * |
| 5863 | * This should only be used for testing. |
| 5864 | * |
| 5865 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5866 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5867 | */ |
| 5868 | @Override |
| 5869 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5870 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5871 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5872 | "clearCarrierImsServiceOverride"); |
| 5873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5874 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5875 | "clearCarrierImsServiceOverride"); |
| 5876 | |
| 5877 | final long identity = Binder.clearCallingIdentity(); |
| 5878 | try { |
| 5879 | if (mImsResolver == null) { |
| 5880 | // may happen if the device does not support IMS. |
| 5881 | return false; |
| 5882 | } |
| 5883 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5884 | } finally { |
| 5885 | Binder.restoreCallingIdentity(identity); |
| 5886 | } |
| 5887 | } |
| 5888 | |
| 5889 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5890 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5891 | * |
| 5892 | * @param slotId The slot that the ImsService is associated with. |
| 5893 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5894 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5895 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5896 | * @return the package name of the ImsService configuration. |
| 5897 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5898 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5899 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5900 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5901 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5902 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5903 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5904 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5905 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5906 | final long identity = Binder.clearCallingIdentity(); |
| 5907 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5908 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5909 | // may happen if the device does not support IMS. |
| 5910 | return ""; |
| 5911 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5912 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5913 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5914 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5915 | } finally { |
| 5916 | Binder.restoreCallingIdentity(identity); |
| 5917 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5918 | } |
| 5919 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5920 | /** |
| 5921 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5922 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5923 | * @param callback A callback with an integer containing the |
| 5924 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5925 | */ |
| 5926 | @Override |
| 5927 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5928 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5929 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5930 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5931 | "IMS not available on device."); |
| 5932 | } |
| 5933 | final long token = Binder.clearCallingIdentity(); |
| 5934 | try { |
| 5935 | int slotId = getSlotIndex(subId); |
| 5936 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5937 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5938 | + subId + "'"); |
| 5939 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5940 | } |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5941 | verifyImsMmTelConfiguredOrThrow(slotId); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5942 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5943 | try { |
| 5944 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5945 | } catch (RemoteException e) { |
| 5946 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5947 | + "Ignore"); |
| 5948 | } |
| 5949 | }); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 5950 | } catch (ImsException e) { |
| 5951 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(token); |
| 5954 | } |
| 5955 | } |
| 5956 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5957 | /** |
| 5958 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5959 | */ |
| 5960 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5961 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5962 | |
| 5963 | final long identity = Binder.clearCallingIdentity(); |
| 5964 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5965 | // NOTE: Before S, this method only set the default phone. |
| 5966 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5967 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5968 | phone.setImsRegistrationState(registered); |
| 5969 | } |
| 5970 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | } finally { |
| 5972 | Binder.restoreCallingIdentity(identity); |
| 5973 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5977 | * Set the network selection mode to automatic. |
| 5978 | * |
| 5979 | */ |
| 5980 | @Override |
| 5981 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5983 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5984 | |
| 5985 | final long identity = Binder.clearCallingIdentity(); |
| 5986 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5987 | if (!isActiveSubscription(subId)) { |
| 5988 | return; |
| 5989 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5990 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5991 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5992 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | } finally { |
| 5994 | Binder.restoreCallingIdentity(identity); |
| 5995 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5996 | } |
| 5997 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5998 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5999 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 6000 | * |
| 6001 | * @param subId the id of the subscription. |
| 6002 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 6003 | * the operator to attach to. |
| 6004 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 6005 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 6006 | * normal network selection next time. |
| 6007 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6008 | */ |
| 6009 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6010 | public boolean setNetworkSelectionModeManual( |
| 6011 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6013 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 6014 | |
| 6015 | if (!isActiveSubscription(subId)) { |
| 6016 | return false; |
| 6017 | } |
| 6018 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6019 | final long identity = Binder.clearCallingIdentity(); |
| 6020 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6021 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6022 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 6023 | if (DBG) { |
| 6024 | log("setNetworkSelectionModeManual: subId: " + subId |
| 6025 | + " operator: " + operatorInfo); |
| 6026 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6031 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6032 | /** |
| 6033 | * Get the manual network selection |
| 6034 | * |
| 6035 | * @param subId the id of the subscription. |
| 6036 | * |
| 6037 | * @return the previously saved user selected PLMN |
| 6038 | */ |
| 6039 | @Override |
| 6040 | public String getManualNetworkSelectionPlmn(int subId) { |
| 6041 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6042 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6043 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 6044 | |
| 6045 | final long identity = Binder.clearCallingIdentity(); |
| 6046 | try { |
| 6047 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6048 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | final Phone phone = getPhone(subId); |
| 6052 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 6053 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 6054 | } |
| 6055 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 6056 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 6057 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 6058 | } finally { |
| 6059 | Binder.restoreCallingIdentity(identity); |
| 6060 | } |
| 6061 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6062 | |
| 6063 | /** |
| 6064 | * Scans for available networks. |
| 6065 | */ |
| 6066 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6067 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 6068 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6070 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6071 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6072 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6073 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6074 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6075 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6076 | .setCallingPid(Binder.getCallingPid()) |
| 6077 | .setCallingUid(Binder.getCallingUid()) |
| 6078 | .setMethod("getCellNetworkScanResults") |
| 6079 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6080 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6081 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6082 | .build()); |
| 6083 | switch (locationResult) { |
| 6084 | case DENIED_HARD: |
| 6085 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 6086 | case DENIED_SOFT: |
| 6087 | return null; |
| 6088 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6089 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6090 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | try { |
| 6092 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6093 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | } finally { |
| 6096 | Binder.restoreCallingIdentity(identity); |
| 6097 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6101 | * Get the call forwarding info, given the call forwarding reason. |
| 6102 | */ |
| 6103 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6104 | public void getCallForwarding(int subId, int callForwardingReason, |
| 6105 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6106 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 6107 | long identity = Binder.clearCallingIdentity(); |
| 6108 | try { |
| 6109 | if (DBG) { |
| 6110 | log("getCallForwarding: subId " + subId |
| 6111 | + " callForwardingReason" + callForwardingReason); |
| 6112 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6113 | |
| 6114 | Phone phone = getPhone(subId); |
| 6115 | if (phone == null) { |
| 6116 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6117 | callback.onError( |
| 6118 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6119 | } catch (RemoteException e) { |
| 6120 | // ignore |
| 6121 | } |
| 6122 | return; |
| 6123 | } |
| 6124 | |
| 6125 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 6126 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 6127 | @Override |
| 6128 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 6129 | try { |
| 6130 | callback.onCallForwardingInfoAvailable(info); |
| 6131 | } catch (RemoteException e) { |
| 6132 | // ignore |
| 6133 | } |
| 6134 | } |
| 6135 | |
| 6136 | @Override |
| 6137 | public void onError(int error) { |
| 6138 | try { |
| 6139 | callback.onError(error); |
| 6140 | } catch (RemoteException e) { |
| 6141 | // ignore |
| 6142 | } |
| 6143 | } |
| 6144 | }); |
| 6145 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6146 | } finally { |
| 6147 | Binder.restoreCallingIdentity(identity); |
| 6148 | } |
| 6149 | } |
| 6150 | |
| 6151 | /** |
| 6152 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 6153 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 6154 | */ |
| 6155 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6156 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 6157 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6158 | enforceModifyPermission(); |
| 6159 | long identity = Binder.clearCallingIdentity(); |
| 6160 | try { |
| 6161 | if (DBG) { |
| 6162 | log("setCallForwarding: subId " + subId |
| 6163 | + " callForwardingInfo" + callForwardingInfo); |
| 6164 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6165 | |
| 6166 | Phone phone = getPhone(subId); |
| 6167 | if (phone == null) { |
| 6168 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 6169 | callback.accept( |
| 6170 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6171 | } catch (RemoteException e) { |
| 6172 | // ignore |
| 6173 | } |
| 6174 | return; |
| 6175 | } |
| 6176 | |
| 6177 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 6178 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6179 | |
| 6180 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6181 | } finally { |
| 6182 | Binder.restoreCallingIdentity(identity); |
| 6183 | } |
| 6184 | } |
| 6185 | |
| 6186 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6187 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6188 | */ |
| 6189 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6190 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6191 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6192 | long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6194 | Phone phone = getPhone(subId); |
| 6195 | if (phone == null) { |
| 6196 | try { |
| 6197 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6198 | } catch (RemoteException e) { |
| 6199 | // ignore |
| 6200 | } |
| 6201 | return; |
| 6202 | } |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6203 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6204 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6205 | boolean requireUssd = c.getBoolean( |
| 6206 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6207 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6208 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6209 | if (requireUssd) { |
| 6210 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6211 | getSubscriptionCarrierId(subId)); |
| 6212 | String newUssdCommand = ""; |
| 6213 | try { |
| 6214 | newUssdCommand = carrierXmlParser.getFeature( |
| 6215 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6216 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 6217 | } catch (NullPointerException e) { |
| 6218 | loge("Failed to generate USSD number" + e); |
| 6219 | } |
| 6220 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6221 | mMainThreadHandler, callback, carrierXmlParser, |
| 6222 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 6223 | final String ussdCommand = newUssdCommand; |
| 6224 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6225 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6226 | }); |
| 6227 | } else { |
| 6228 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 6229 | callback::accept); |
| 6230 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 6231 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6232 | } finally { |
| 6233 | Binder.restoreCallingIdentity(identity); |
| 6234 | } |
| 6235 | } |
| 6236 | |
| 6237 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6238 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6239 | */ |
| 6240 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6241 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6242 | enforceModifyPermission(); |
| 6243 | long identity = Binder.clearCallingIdentity(); |
| 6244 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6245 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 6246 | |
| 6247 | Phone phone = getPhone(subId); |
| 6248 | if (phone == null) { |
| 6249 | try { |
| 6250 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 6251 | } catch (RemoteException e) { |
| 6252 | // ignore |
| 6253 | } |
| 6254 | return; |
| 6255 | } |
| 6256 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6257 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 6258 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 6259 | boolean requireUssd = c.getBoolean( |
| 6260 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 6261 | |
SongFerngWang | 0e76799 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 6262 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 6263 | if (requireUssd) { |
| 6264 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 6265 | getSubscriptionCarrierId(subId)); |
| 6266 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 6267 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 6268 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 6269 | String newUssdCommand = ""; |
| 6270 | try { |
| 6271 | newUssdCommand = carrierXmlParser.getFeature( |
| 6272 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 6273 | .makeCommand(ssAction, null); |
| 6274 | } catch (NullPointerException e) { |
| 6275 | loge("Failed to generate USSD number" + e); |
| 6276 | } |
| 6277 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 6278 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 6279 | final String ussdCommand = newUssdCommand; |
| 6280 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6281 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 6282 | }); |
| 6283 | } else { |
| 6284 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 6285 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 6286 | |
| 6287 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 6288 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 6289 | } finally { |
| 6290 | Binder.restoreCallingIdentity(identity); |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6295 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6296 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6297 | * @param subId id of the subscription |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6298 | * @param renounceFineLocationAccess Set this to true if the caller would not like to receive |
| 6299 | * location related information which will be sent if the caller already possess |
| 6300 | * {@android.Manifest.permission.ACCESS_FINE_LOCATION} and do not renounce the permission |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6301 | * @param request contains the radio access networks with bands/channels to scan |
| 6302 | * @param messenger callback messenger for scan results or errors |
| 6303 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6304 | * @return the id of the requested scan which can be used to stop the scan. |
| 6305 | */ |
| 6306 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6307 | public int requestNetworkScan(int subId, boolean renounceFineLocationAccess, |
| 6308 | NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6309 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6311 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6312 | LocationAccessPolicy.LocationPermissionResult locationResult = |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6313 | LocationAccessPolicy.LocationPermissionResult.DENIED_HARD; |
| 6314 | if (!renounceFineLocationAccess) { |
| 6315 | locationResult = LocationAccessPolicy.checkLocationPermission(mApp, |
| 6316 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6317 | .setCallingPackage(callingPackage) |
| 6318 | .setCallingFeatureId(callingFeatureId) |
| 6319 | .setCallingPid(Binder.getCallingPid()) |
| 6320 | .setCallingUid(Binder.getCallingUid()) |
| 6321 | .setMethod("requestNetworkScan") |
| 6322 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6323 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6324 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 6325 | .build()); |
| 6326 | } |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6327 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6328 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6329 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6330 | if (e != null) { |
| 6331 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6332 | throw e; |
| 6333 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6334 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6335 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6336 | } |
| 6337 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6338 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6339 | int callingUid = Binder.getCallingUid(); |
| 6340 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6341 | final long identity = Binder.clearCallingIdentity(); |
| 6342 | try { |
| 6343 | return mNetworkScanRequestTracker.startNetworkScan( |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 6344 | renounceFineLocationAccess, request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6345 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6346 | } finally { |
| 6347 | Binder.restoreCallingIdentity(identity); |
| 6348 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6351 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6352 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6353 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6354 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6355 | boolean hasNetworkScanPermission = |
| 6356 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6357 | == PERMISSION_GRANTED; |
| 6358 | |
| 6359 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6360 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6361 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6362 | } |
| 6363 | |
| 6364 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6365 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6366 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6367 | return new SecurityException("Specific channels must not be" |
| 6368 | + " scanned without location access."); |
| 6369 | } |
| 6370 | } |
| 6371 | } |
| 6372 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6373 | return null; |
| 6374 | } |
| 6375 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6376 | /** |
| 6377 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6378 | * |
| 6379 | * @param subId id of the subscription |
| 6380 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6381 | */ |
| 6382 | @Override |
| 6383 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6384 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6385 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6387 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6388 | final long identity = Binder.clearCallingIdentity(); |
| 6389 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6390 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6391 | } finally { |
| 6392 | Binder.restoreCallingIdentity(identity); |
| 6393 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6397 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6398 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6399 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6400 | */ |
| 6401 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6402 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6403 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6404 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6405 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6406 | |
| 6407 | final long identity = Binder.clearCallingIdentity(); |
| 6408 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6409 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6410 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6411 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6412 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6413 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | } finally { |
| 6415 | Binder.restoreCallingIdentity(identity); |
| 6416 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6417 | } |
| 6418 | |
| 6419 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6420 | * Get the allowed network types for certain reason. |
| 6421 | * |
| 6422 | * @param subId the id of the subscription. |
| 6423 | * @param reason the reason the allowed network type change is taking place |
| 6424 | * @return the allowed network types. |
| 6425 | */ |
| 6426 | @Override |
| 6427 | public long getAllowedNetworkTypesForReason(int subId, |
| 6428 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6429 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6430 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6431 | final long identity = Binder.clearCallingIdentity(); |
| 6432 | try { |
| 6433 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6434 | } finally { |
| 6435 | Binder.restoreCallingIdentity(identity); |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6440 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6441 | * @param subId subscription id of the sim card |
| 6442 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6443 | * This can be passed following states |
| 6444 | * <ol> |
| 6445 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6446 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6447 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6448 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6449 | * </ol> |
| 6450 | * @return operation result. |
| 6451 | */ |
| 6452 | @Override |
| 6453 | public int setNrDualConnectivityState(int subId, |
| 6454 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6456 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6457 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6458 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6459 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6460 | } |
| 6461 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6462 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6463 | final long identity = Binder.clearCallingIdentity(); |
| 6464 | try { |
| 6465 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6466 | nrDualConnectivityState, subId, |
| 6467 | workSource); |
| 6468 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6469 | return result; |
| 6470 | } finally { |
| 6471 | Binder.restoreCallingIdentity(identity); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | /** |
| 6476 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6477 | * @return true if dual connectivity is enabled else false |
| 6478 | */ |
| 6479 | @Override |
| 6480 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6481 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6482 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6483 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6484 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6485 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6486 | return false; |
| 6487 | } |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6488 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6489 | final long identity = Binder.clearCallingIdentity(); |
| 6490 | try { |
| 6491 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6492 | null, subId, workSource); |
| 6493 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6494 | return isEnabled; |
| 6495 | } finally { |
| 6496 | Binder.restoreCallingIdentity(identity); |
| 6497 | } |
| 6498 | } |
| 6499 | |
| 6500 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6501 | * Set the allowed network types of the device and |
| 6502 | * provide the reason triggering the allowed network change. |
| 6503 | * |
| 6504 | * @param subId the id of the subscription. |
| 6505 | * @param reason the reason the allowed network type change is taking place |
| 6506 | * @param allowedNetworkTypes the allowed network types. |
| 6507 | * @return true on success; false on any failure. |
| 6508 | */ |
| 6509 | @Override |
| 6510 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6511 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6512 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6514 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6515 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
SongFerngWang | 7ffc273 | 2021-04-15 19:46:33 +0800 | [diff] [blame] | 6516 | loge("setAllowedNetworkTypesForReason: Invalid allowed network type reason: " + reason); |
| 6517 | return false; |
| 6518 | } |
| 6519 | if (!SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 6520 | loge("setAllowedNetworkTypesForReason: Invalid subscriptionId:" + subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6521 | return false; |
| 6522 | } |
| 6523 | |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6524 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6525 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6526 | |
| 6527 | |
| 6528 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6529 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6530 | return true; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6531 | } |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6532 | |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6535 | Boolean success = (Boolean) sendRequest( |
| 6536 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6537 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6538 | |
| 6539 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6540 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
| 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6547 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6548 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6549 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6550 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6551 | * @hide |
| 6552 | */ |
| 6553 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6554 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6555 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6557 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6559 | if (phone != null) { |
| 6560 | return phone.hasMatchedTetherApnSetting(); |
| 6561 | } else { |
| 6562 | return false; |
| 6563 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | } finally { |
| 6565 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6566 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6567 | } |
| 6568 | |
| 6569 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6570 | * Get the user enabled state of Mobile Data. |
| 6571 | * |
| 6572 | * TODO: remove and use isUserDataEnabled. |
| 6573 | * This can't be removed now because some vendor codes |
| 6574 | * calls through ITelephony directly while they should |
| 6575 | * use TelephonyManager. |
| 6576 | * |
| 6577 | * @return true on enabled |
| 6578 | */ |
| 6579 | @Override |
| 6580 | public boolean getDataEnabled(int subId) { |
| 6581 | return isUserDataEnabled(subId); |
| 6582 | } |
| 6583 | |
| 6584 | /** |
| 6585 | * Get whether mobile data is enabled per user setting. |
| 6586 | * |
| 6587 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6588 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6589 | * |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6590 | * Accepts either READ_BASIC_PHONE_STATE, ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE |
| 6591 | * or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6592 | * |
| 6593 | * @return {@code true} if data is enabled else {@code false} |
| 6594 | */ |
| 6595 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6596 | public boolean isUserDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6597 | String functionName = "isUserDataEnabled"; |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6598 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6599 | try { |
| 6600 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6601 | functionName); |
| 6602 | } catch (Exception e) { |
| 6603 | mApp.enforceCallingOrSelfPermission(permission.ACCESS_NETWORK_STATE, functionName); |
| 6604 | } |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6605 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6607 | mApp, subId, functionName); |
| 6608 | |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6609 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | |
| 6611 | final long identity = Binder.clearCallingIdentity(); |
| 6612 | try { |
| 6613 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6614 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6615 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6616 | if (phone != null) { |
| 6617 | boolean retVal = phone.isUserDataEnabled(); |
| 6618 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6619 | return retVal; |
| 6620 | } else { |
| 6621 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6622 | return false; |
| 6623 | } |
| 6624 | } finally { |
| 6625 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6626 | } |
| 6627 | } |
| 6628 | |
| 6629 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6630 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6631 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6632 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6633 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6634 | * @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] | 6635 | */ |
| 6636 | @Override |
| 6637 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6638 | String functionName = "isDataEnabled"; |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6639 | try { |
| 6640 | try { |
| 6641 | mApp.enforceCallingOrSelfPermission( |
| 6642 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6643 | functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6644 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6645 | try { |
| 6646 | mApp.enforceCallingOrSelfPermission( |
| 6647 | android.Manifest.permission.READ_PHONE_STATE, |
| 6648 | functionName); |
| 6649 | } catch (Exception e2) { |
| 6650 | mApp.enforceCallingOrSelfPermission( |
| 6651 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 6652 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6653 | } |
| 6654 | } catch (Exception e) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6655 | enforceReadPrivilegedPermission(functionName); |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6656 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | |
| 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
| 6660 | int phoneId = mSubscriptionController.getPhoneId(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6661 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6662 | if (phone != null) { |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6663 | boolean retVal; |
| 6664 | if (phone.isUsingNewDataStack()) { |
Sarah Chin | 8619e16 | 2022-03-09 13:57:52 -0800 | [diff] [blame] | 6665 | retVal = phone.getDataSettingsManager().isDataEnabled(); |
Jack Yu | 3fb3a6b | 2021-12-03 14:23:53 -0800 | [diff] [blame] | 6666 | } else { |
| 6667 | retVal = phone.getDataEnabledSettings().isDataEnabled(); |
| 6668 | } |
| 6669 | if (DBG) log("isDataEnabled: " + retVal + ", subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | return retVal; |
| 6671 | } else { |
| 6672 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6673 | return false; |
| 6674 | } |
| 6675 | } finally { |
| 6676 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6677 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6678 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6679 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6680 | /** |
| 6681 | * Check if data is enabled for a specific reason |
| 6682 | * @param subId Subscription index |
| 6683 | * @param reason the reason the data enable change is taking place |
| 6684 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6685 | */ |
| 6686 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6687 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6688 | @TelephonyManager.DataEnabledReason int reason) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6689 | String functionName = "isDataEnabledForReason"; |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6690 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6691 | try { |
| 6692 | mApp.enforceCallingOrSelfPermission( |
| 6693 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6694 | functionName); |
| 6695 | } catch (Exception e) { |
| 6696 | mApp.enforceCallingOrSelfPermission(permission.READ_BASIC_PHONE_STATE, |
| 6697 | functionName); |
| 6698 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6699 | } catch (Exception e) { |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6700 | try { |
| 6701 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6702 | functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6703 | } catch (Exception e2) { |
| 6704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 6705 | mApp, subId, functionName); |
Sooraj Sasindran | 72a2276 | 2021-11-08 12:01:16 -0800 | [diff] [blame] | 6706 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6707 | } |
| 6708 | |
| 6709 | |
| 6710 | final long identity = Binder.clearCallingIdentity(); |
| 6711 | try { |
| 6712 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6713 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6714 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6715 | + " reason=" + reason); |
| 6716 | } |
| 6717 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6718 | if (phone != null) { |
| 6719 | boolean retVal; |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6720 | if (phone.isUsingNewDataStack()) { |
| 6721 | retVal = phone.getDataSettingsManager().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6722 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 6723 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6724 | retVal = phone.isUserDataEnabled(); |
| 6725 | } else { |
| 6726 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
| 6727 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6728 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6729 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6730 | return retVal; |
| 6731 | } else { |
| 6732 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6733 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6734 | + subId + " retVal=false"); |
| 6735 | } |
| 6736 | return false; |
| 6737 | } |
| 6738 | } finally { |
| 6739 | Binder.restoreCallingIdentity(identity); |
| 6740 | } |
| 6741 | } |
| 6742 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6743 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6744 | public int getCarrierPrivilegeStatus(int subId) { |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6745 | // No permission needed; this only lets the caller inspect their own status. |
| 6746 | return getCarrierPrivilegeStatusForUidWithPermission(subId, Binder.getCallingUid()); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6747 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6748 | |
| 6749 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6750 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6751 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6752 | return getCarrierPrivilegeStatusForUidWithPermission(subId, uid); |
| 6753 | } |
| 6754 | |
| 6755 | private int getCarrierPrivilegeStatusForUidWithPermission(int subId, int uid) { |
| 6756 | Phone phone = getPhone(subId); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6757 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6758 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6759 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6760 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6761 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6762 | if (cpt == null) { |
| 6763 | loge("getCarrierPrivilegeStatusForUid: No CarrierPrivilegesTracker"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6764 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6765 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6766 | return cpt.getCarrierPrivilegeStatusForUid(uid); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6767 | } |
| 6768 | |
| 6769 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6770 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6771 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackage"); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6772 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6773 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6774 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6775 | Phone phone = getPhone(subId); |
| 6776 | if (phone == null) { |
| 6777 | loge("checkCarrierPrivilegesForPackage: Invalid subId"); |
| 6778 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6779 | } |
| 6780 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6781 | if (cpt == null) { |
| 6782 | loge("checkCarrierPrivilegesForPackage: No CarrierPrivilegesTracker"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6783 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6784 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6785 | return cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6786 | } |
| 6787 | |
| 6788 | @Override |
| 6789 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6790 | enforceReadPrivilegedPermission("checkCarrierPrivilegesForPackageAnyPhone"); |
Rambo Wang | 04d1ace | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 6791 | return checkCarrierPrivilegesForPackageAnyPhoneWithPermission(pkgName); |
| 6792 | } |
| 6793 | |
| 6794 | private int checkCarrierPrivilegesForPackageAnyPhoneWithPermission(String pkgName) { |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6795 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6796 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6797 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6798 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6799 | for (int phoneId = 0; phoneId < TelephonyManager.getDefault().getPhoneCount(); phoneId++) { |
| 6800 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6801 | if (phone == null) { |
| 6802 | continue; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6803 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6804 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6805 | if (cpt == null) { |
| 6806 | continue; |
| 6807 | } |
| 6808 | result = cpt.getCarrierPrivilegeStatusForPackage(pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6809 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6810 | break; |
| 6811 | } |
| 6812 | } |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6813 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6814 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6815 | |
| 6816 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6817 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6818 | enforceReadPrivilegedPermission("getCarrierPackageNamesForIntentAndPhone"); |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame] | 6819 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6820 | if (phone == null) { |
| 6821 | return Collections.emptyList(); |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6822 | } |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame] | 6823 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6824 | if (cpt == null) { |
| 6825 | return Collections.emptyList(); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6826 | } |
Hunter Knepshield | b0eb479 | 2021-12-14 18:49:15 -0800 | [diff] [blame] | 6827 | return cpt.getCarrierPackageNamesForIntent(intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6828 | } |
| 6829 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6830 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6831 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin | 1adf456 | 2021-03-29 15:35:30 -0700 | [diff] [blame] | 6832 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivileges"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6833 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6834 | if (phone == null) { |
| 6835 | return Collections.emptyList(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6836 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6837 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6838 | if (cpt == null) { |
| 6839 | return Collections.emptyList(); |
| 6840 | } |
| 6841 | return new ArrayList<>(cpt.getPackagesWithCarrierPrivileges()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6842 | } |
| 6843 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6844 | @Override |
| 6845 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6846 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6847 | Set<String> privilegedPackages = new ArraySet<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6848 | final long identity = Binder.clearCallingIdentity(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6849 | try { |
| 6850 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6851 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6852 | } |
| 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6855 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 6856 | return new ArrayList<>(privilegedPackages); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6857 | } |
| 6858 | |
Rambo Wang | 9b91ffd | 2022-03-15 16:54:17 -0700 | [diff] [blame] | 6859 | @Override |
| 6860 | public @Nullable String getCarrierServicePackageNameForLogicalSlot(int logicalSlotIndex) { |
| 6861 | enforceReadPrivilegedPermission("getCarrierServicePackageNameForLogicalSlot"); |
| 6862 | |
| 6863 | final Phone phone = PhoneFactory.getPhone(logicalSlotIndex); |
| 6864 | if (phone == null) { |
| 6865 | return null; |
| 6866 | } |
| 6867 | final CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 6868 | if (cpt == null) { |
| 6869 | return null; |
| 6870 | } |
| 6871 | return cpt.getCarrierServicePackageName(); |
| 6872 | } |
| 6873 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6874 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6875 | final Phone phone = getPhone(subId); |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6876 | UiccPort port = phone == null ? null : phone.getUiccPort(); |
| 6877 | if (port == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6878 | return null; |
| 6879 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 6880 | String iccId = port.getIccId(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6881 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6882 | return null; |
| 6883 | } |
| 6884 | return iccId; |
| 6885 | } |
| 6886 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6887 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6888 | public void setCallComposerStatus(int subId, int status) { |
| 6889 | enforceModifyPermission(); |
| 6890 | |
| 6891 | final long identity = Binder.clearCallingIdentity(); |
| 6892 | try { |
| 6893 | Phone phone = getPhone(subId); |
| 6894 | if (phone != null) { |
| 6895 | Phone defaultPhone = phone.getImsPhone(); |
| 6896 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6897 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6898 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6899 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6900 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6901 | } |
| 6902 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6903 | } catch (ImsException e) { |
| 6904 | throw new ServiceSpecificException(e.getCode()); |
| 6905 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6906 | Binder.restoreCallingIdentity(identity); |
| 6907 | } |
| 6908 | } |
| 6909 | |
| 6910 | @Override |
| 6911 | public int getCallComposerStatus(int subId) { |
| 6912 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6913 | |
| 6914 | final long identity = Binder.clearCallingIdentity(); |
| 6915 | try { |
| 6916 | Phone phone = getPhone(subId); |
| 6917 | if (phone != null) { |
| 6918 | Phone defaultPhone = phone.getImsPhone(); |
| 6919 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6920 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6921 | return imsPhone.getCallComposerStatus(); |
| 6922 | } |
| 6923 | } |
| 6924 | } finally { |
| 6925 | Binder.restoreCallingIdentity(identity); |
| 6926 | } |
| 6927 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6928 | } |
| 6929 | |
| 6930 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6931 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6932 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6933 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6934 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6935 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6936 | final long identity = Binder.clearCallingIdentity(); |
| 6937 | try { |
| 6938 | final String iccId = getIccId(subId); |
| 6939 | final Phone phone = getPhone(subId); |
| 6940 | if (phone == null) { |
| 6941 | return false; |
| 6942 | } |
| 6943 | final String subscriberId = phone.getSubscriberId(); |
| 6944 | |
| 6945 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6946 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6947 | + subscriberId + " to " + number); |
| 6948 | } |
| 6949 | |
| 6950 | if (TextUtils.isEmpty(iccId)) { |
| 6951 | return false; |
| 6952 | } |
| 6953 | |
| 6954 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6955 | |
| 6956 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6957 | if (alphaTag == null) { |
| 6958 | editor.remove(alphaTagPrefKey); |
| 6959 | } else { |
| 6960 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6961 | } |
| 6962 | |
| 6963 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6964 | // track all merged IMSIs based on line number |
| 6965 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6966 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6967 | if (number == null) { |
| 6968 | editor.remove(numberPrefKey); |
| 6969 | editor.remove(subscriberPrefKey); |
| 6970 | } else { |
| 6971 | editor.putString(numberPrefKey, number); |
| 6972 | editor.putString(subscriberPrefKey, subscriberId); |
| 6973 | } |
| 6974 | |
| 6975 | editor.commit(); |
| 6976 | return true; |
| 6977 | } finally { |
| 6978 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6979 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
| 6982 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6983 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6984 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6985 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6986 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6987 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6988 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6989 | return null; |
| 6990 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6991 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 | final long identity = Binder.clearCallingIdentity(); |
| 6993 | try { |
| 6994 | String iccId = getIccId(subId); |
| 6995 | if (iccId != null) { |
| 6996 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6997 | if (DBG_MERGE) { |
| 6998 | log("getLine1NumberForDisplay returning " |
| 6999 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 7000 | } |
| 7001 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 7002 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 7004 | return null; |
| 7005 | } finally { |
| 7006 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7007 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7011 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 7012 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7013 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7014 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7015 | return null; |
| 7016 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 7017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | final long identity = Binder.clearCallingIdentity(); |
| 7019 | try { |
| 7020 | String iccId = getIccId(subId); |
| 7021 | if (iccId != null) { |
| 7022 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 7023 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 7024 | } |
| 7025 | return null; |
| 7026 | } finally { |
| 7027 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7028 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 7029 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7030 | |
| 7031 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7032 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 7033 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7034 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 7035 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7036 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7037 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7038 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7039 | return null; |
| 7040 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7041 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7042 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 7043 | // the process, where TelephonyManager was instantiated. |
| 7044 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7045 | final long identity = Binder.clearCallingIdentity(); |
| 7046 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7047 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | final TelephonyManager tele = TelephonyManager.from(context); |
| 7049 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 7050 | |
| 7051 | // Figure out what subscribers are currently active |
| 7052 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 7054 | // Only consider subs which match the current subId |
| 7055 | // This logic can be simplified. See b/131189269 for progress. |
| 7056 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7057 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 7058 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | |
| 7060 | // First pass, find a number override for an active subscriber |
| 7061 | String mergeNumber = null; |
| 7062 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 7063 | for (String key : prefs.keySet()) { |
| 7064 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 7065 | final String subscriberId = (String) prefs.get(key); |
| 7066 | if (activeSubscriberIds.contains(subscriberId)) { |
| 7067 | final String iccId = key.substring( |
| 7068 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 7069 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 7070 | mergeNumber = (String) prefs.get(numberKey); |
| 7071 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7072 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | + " for active subscriber " + subscriberId); |
| 7074 | } |
| 7075 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 7076 | break; |
| 7077 | } |
| 7078 | } |
| 7079 | } |
| 7080 | } |
| 7081 | |
| 7082 | // Shortcut when no active merged subscribers |
| 7083 | if (TextUtils.isEmpty(mergeNumber)) { |
| 7084 | return null; |
| 7085 | } |
| 7086 | |
| 7087 | // Second pass, find all subscribers under that line override |
| 7088 | final ArraySet<String> result = new ArraySet<>(); |
| 7089 | for (String key : prefs.keySet()) { |
| 7090 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 7091 | final String number = (String) prefs.get(key); |
| 7092 | if (mergeNumber.equals(number)) { |
| 7093 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 7094 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 7095 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 7096 | if (!TextUtils.isEmpty(subscriberId)) { |
| 7097 | result.add(subscriberId); |
| 7098 | } |
| 7099 | } |
| 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 7104 | Arrays.sort(resultArray); |
| 7105 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 7106 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7107 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 7108 | } |
| 7109 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 7110 | } finally { |
| 7111 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7112 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7116 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 7117 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7118 | |
| 7119 | final long identity = Binder.clearCallingIdentity(); |
| 7120 | try { |
| 7121 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 7122 | TelephonyManager.class); |
| 7123 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 7124 | if (subscriberId == null) { |
| 7125 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 7126 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7127 | + subId); |
| 7128 | } |
| 7129 | return null; |
| 7130 | } |
| 7131 | |
| 7132 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 7133 | .getSubscriptionInfo(subId); |
| 7134 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 7135 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 7136 | if (groupUuid == null) { |
| 7137 | return new String[]{subscriberId}; |
| 7138 | } |
| 7139 | |
| 7140 | // Get all subscriberIds from the group. |
| 7141 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 7142 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7143 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7144 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 7145 | for (SubscriptionInfo subInfo : groupInfos) { |
| 7146 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 7147 | if (subscriberId != null) { |
| 7148 | mergedSubscriberIds.add(subscriberId); |
| 7149 | } |
| 7150 | } |
| 7151 | |
| 7152 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | |
| 7156 | } |
| 7157 | } |
| 7158 | |
| 7159 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7160 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7161 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7162 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7163 | |
| 7164 | final long identity = Binder.clearCallingIdentity(); |
| 7165 | try { |
| 7166 | final Phone phone = getPhone(subId); |
| 7167 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 7168 | } finally { |
| 7169 | Binder.restoreCallingIdentity(identity); |
| 7170 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 7171 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 7172 | |
| 7173 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7174 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7175 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 7176 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 7177 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 7178 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | |
| 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | final Phone phone = getPhone(subId); |
| 7183 | if (phone == null) { |
| 7184 | return false; |
| 7185 | } |
| 7186 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 7187 | cdmaNonRoamingList); |
| 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 7190 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7194 | @Deprecated |
| 7195 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 7196 | enforceModifyPermission(); |
| 7197 | |
| 7198 | int returnValue = 0; |
| 7199 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7200 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 7201 | if(result.exception == null) { |
| 7202 | if (result.result != null) { |
| 7203 | byte[] responseData = (byte[])(result.result); |
| 7204 | if(responseData.length > oemResp.length) { |
| 7205 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 7206 | responseData.length + "bytes. Buffer Size is " + |
| 7207 | oemResp.length + "bytes."); |
| 7208 | } |
| 7209 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 7210 | returnValue = responseData.length; |
| 7211 | } |
| 7212 | } else { |
| 7213 | CommandException ex = (CommandException) result.exception; |
| 7214 | returnValue = ex.getCommandError().ordinal(); |
| 7215 | if(returnValue > 0) returnValue *= -1; |
| 7216 | } |
| 7217 | } catch (RuntimeException e) { |
| 7218 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 7219 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 7220 | if(returnValue > 0) returnValue *= -1; |
| 7221 | } |
| 7222 | |
| 7223 | return returnValue; |
| 7224 | } |
| 7225 | |
| 7226 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 7227 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7228 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7229 | try { |
| 7230 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7231 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 7232 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7233 | } catch (SecurityException e) { |
| 7234 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 7235 | throw e; |
| 7236 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7237 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7238 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7239 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7240 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7241 | final long identity = Binder.clearCallingIdentity(); |
| 7242 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7243 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7244 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7245 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 7246 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7247 | } finally { |
| 7248 | Binder.restoreCallingIdentity(identity); |
| 7249 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 7250 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 7251 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7252 | |
| 7253 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7254 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 7255 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7256 | try { |
| 7257 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 7258 | Binder.getCallingUid())) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7259 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7260 | } |
| 7261 | } catch (PackageManager.NameNotFoundException e) { |
Tyler Gunn | b87925a | 2021-06-10 14:54:27 -0700 | [diff] [blame] | 7262 | throw new SecurityException("Invalid package:" + callingPackage); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7263 | } |
| 7264 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 7265 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 7266 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 7267 | throw new SecurityException("App must be the dialer role holder to" |
| 7268 | + " upload a call composer pic"); |
| 7269 | } |
| 7270 | |
| 7271 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7272 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7273 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7274 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7275 | boolean readUntilEnd = false; |
| 7276 | int totalBytesRead = 0; |
| 7277 | byte[] buffer = new byte[16 * 1024]; |
| 7278 | while (true) { |
| 7279 | int numRead; |
| 7280 | try { |
| 7281 | numRead = input.read(buffer); |
| 7282 | } catch (IOException e) { |
| 7283 | try { |
| 7284 | fd.checkError(); |
| 7285 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7286 | null); |
| 7287 | } catch (IOException e1) { |
| 7288 | // This means that the other side closed explicitly with an error. If this |
| 7289 | // happens, log and ignore. |
| 7290 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7291 | } |
| 7292 | break; |
| 7293 | } |
| 7294 | if (numRead == -1) { |
| 7295 | readUntilEnd = true; |
| 7296 | break; |
| 7297 | } |
| 7298 | totalBytesRead += numRead; |
| 7299 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7300 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7301 | try { |
| 7302 | input.close(); |
| 7303 | } catch (IOException e) { |
| 7304 | // ignore |
| 7305 | } |
| 7306 | break; |
| 7307 | } |
| 7308 | output.write(buffer, 0, numRead); |
| 7309 | } |
| 7310 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7311 | // close is above, where the picture size is too big. |
| 7312 | |
| 7313 | try { |
| 7314 | fd.checkError(); |
| 7315 | } catch (IOException e) { |
| 7316 | loge("Remote end for call composer closed with an error: " + e); |
| 7317 | return; |
| 7318 | } |
| 7319 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7320 | if (!readUntilEnd) { |
| 7321 | loge("Did not finish reading entire image; aborting"); |
| 7322 | return; |
| 7323 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7324 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7325 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7326 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7327 | new CallComposerPictureTransfer.Factory() {}, |
| 7328 | imageData, |
| 7329 | (result) -> { |
| 7330 | if (result.first != null) { |
| 7331 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7332 | Bundle outputResult = new Bundle(); |
| 7333 | outputResult.putParcelable( |
| 7334 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7335 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7336 | outputResult); |
| 7337 | } else { |
| 7338 | callback.send(result.second, null); |
| 7339 | } |
| 7340 | } |
| 7341 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7342 | }); |
| 7343 | } |
| 7344 | |
| 7345 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7346 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7347 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7348 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7349 | |
| 7350 | final long identity = Binder.clearCallingIdentity(); |
| 7351 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7352 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7353 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7354 | } finally { |
| 7355 | Binder.restoreCallingIdentity(identity); |
| 7356 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7357 | } |
| 7358 | |
| 7359 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7360 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7361 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7362 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7363 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7364 | return false; |
| 7365 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7366 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7367 | final long identity = Binder.clearCallingIdentity(); |
| 7368 | try { |
| 7369 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7370 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7371 | // In the long run, we may instead need to check if there exists a connection service |
| 7372 | // which can support video calling. |
| 7373 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7374 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7375 | return imsManager.isVtEnabledByPlatform() |
| 7376 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7377 | && imsManager.isVtEnabledByUser(); |
| 7378 | } finally { |
| 7379 | Binder.restoreCallingIdentity(identity); |
| 7380 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7381 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7382 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7383 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7384 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7385 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7386 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7387 | mApp, subId, callingPackage, callingFeatureId, |
| 7388 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | return false; |
| 7390 | } |
| 7391 | |
| 7392 | final long identity = Binder.clearCallingIdentity(); |
| 7393 | try { |
| 7394 | CarrierConfigManager configManager = |
| 7395 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7396 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7397 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7398 | } finally { |
| 7399 | Binder.restoreCallingIdentity(identity); |
| 7400 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7401 | } |
| 7402 | |
| 7403 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7404 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7406 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7407 | return false; |
| 7408 | } |
| 7409 | |
| 7410 | final long identity = Binder.clearCallingIdentity(); |
| 7411 | try { |
| 7412 | CarrierConfigManager configManager = |
| 7413 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7414 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7415 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7416 | } finally { |
| 7417 | Binder.restoreCallingIdentity(identity); |
| 7418 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7419 | } |
| 7420 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7421 | @Override |
| 7422 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7423 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7424 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7425 | } |
| 7426 | |
| 7427 | @Override |
| 7428 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7429 | final long identity = Binder.clearCallingIdentity(); |
| 7430 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7431 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7432 | } finally { |
| 7433 | Binder.restoreCallingIdentity(identity); |
| 7434 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7435 | } |
| 7436 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7437 | /** |
| 7438 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7439 | * support for the feature and device firmware support. |
| 7440 | * |
| 7441 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7442 | */ |
| 7443 | @Override |
| 7444 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7446 | final Phone phone = getPhone(subscriptionId); |
| 7447 | if (phone == null) { |
| 7448 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7449 | return false; |
| 7450 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7451 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7452 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7453 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7454 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7455 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | return isCarrierSupported && isDeviceSupported; |
| 7457 | } finally { |
| 7458 | Binder.restoreCallingIdentity(identity); |
| 7459 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7460 | } |
| 7461 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7462 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7463 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7464 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7465 | * 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] | 7466 | */ |
| 7467 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | final long identity = Binder.clearCallingIdentity(); |
| 7469 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7470 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7471 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7472 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7473 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7474 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7475 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7476 | } finally { |
| 7477 | Binder.restoreCallingIdentity(identity); |
| 7478 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7479 | } |
| 7480 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7481 | @Deprecated |
| 7482 | @Override |
| 7483 | public String getDeviceId(String callingPackage) { |
| 7484 | return getDeviceIdWithFeature(callingPackage, null); |
| 7485 | } |
| 7486 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7487 | /** |
| 7488 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7489 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7490 | * |
| 7491 | * <p>Requires Permission: |
| 7492 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7493 | */ |
| 7494 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7495 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Shuo Qian | 13d8915 | 2021-05-10 23:58:11 -0700 | [diff] [blame] | 7496 | try { |
| 7497 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 7498 | } catch (SecurityException se) { |
| 7499 | EventLog.writeEvent(0x534e4554, "186530889", Binder.getCallingUid()); |
| 7500 | throw new SecurityException("Package " + callingPackage + " does not belong to " |
| 7501 | + Binder.getCallingUid()); |
| 7502 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7503 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7504 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7505 | return null; |
| 7506 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7507 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7508 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7509 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7510 | return null; |
| 7511 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | |
| 7513 | final long identity = Binder.clearCallingIdentity(); |
| 7514 | try { |
| 7515 | return phone.getDeviceId(); |
| 7516 | } finally { |
| 7517 | Binder.restoreCallingIdentity(identity); |
| 7518 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7519 | } |
| 7520 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7521 | /** |
| 7522 | * {@hide} |
| 7523 | * Returns the IMS Registration Status on a particular subid |
| 7524 | * |
| 7525 | * @param subId |
| 7526 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7527 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7528 | Phone phone = getPhone(subId); |
| 7529 | if (phone != null) { |
| 7530 | return phone.isImsRegistered(); |
| 7531 | } else { |
| 7532 | return false; |
| 7533 | } |
| 7534 | } |
| 7535 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7536 | @Override |
| 7537 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
| 7540 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7544 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7545 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7546 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7547 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7548 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7549 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7550 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7551 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7552 | } |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
| 7558 | } |
| 7559 | } |
| 7560 | |
| 7561 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7562 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7563 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 7564 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Alireza Forouzan | 4ac4f98 | 2021-03-16 22:18:52 -0700 | [diff] [blame] | 7565 | mApp, |
| 7566 | subscriptionId, |
| 7567 | "getPhoneAccountHandleForSubscriptionId, " + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7568 | final long identity = Binder.clearCallingIdentity(); |
| 7569 | try { |
| 7570 | Phone phone = getPhone(subscriptionId); |
| 7571 | if (phone == null) { |
| 7572 | return null; |
| 7573 | } |
| 7574 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7575 | } finally { |
| 7576 | Binder.restoreCallingIdentity(identity); |
| 7577 | } |
| 7578 | } |
| 7579 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7580 | /** |
| 7581 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7582 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7583 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7584 | final long identity = Binder.clearCallingIdentity(); |
| 7585 | try { |
| 7586 | Phone phone = getPhone(subId); |
| 7587 | if (phone != null) { |
| 7588 | return phone.isWifiCallingEnabled(); |
| 7589 | } else { |
| 7590 | return false; |
| 7591 | } |
| 7592 | } finally { |
| 7593 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7594 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7595 | } |
| 7596 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7597 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7598 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7599 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7600 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | final long identity = Binder.clearCallingIdentity(); |
| 7602 | try { |
| 7603 | Phone phone = getPhone(subId); |
| 7604 | if (phone != null) { |
| 7605 | return phone.isVideoEnabled(); |
| 7606 | } else { |
| 7607 | return false; |
| 7608 | } |
| 7609 | } finally { |
| 7610 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7611 | } |
| 7612 | } |
| 7613 | |
| 7614 | /** |
| 7615 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7616 | * defined in {@link ImsRegistrationImplBase}. |
| 7617 | */ |
| 7618 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7619 | final long identity = Binder.clearCallingIdentity(); |
| 7620 | try { |
| 7621 | Phone phone = getPhone(subId); |
| 7622 | if (phone != null) { |
| 7623 | return phone.getImsRegistrationTech(); |
| 7624 | } else { |
| 7625 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7626 | } |
| 7627 | } finally { |
| 7628 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7629 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7630 | } |
| 7631 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7632 | @Override |
| 7633 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7634 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7635 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7636 | return; |
| 7637 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7638 | Phone defaultPhone = getDefaultPhone(); |
| 7639 | if (defaultPhone != null) { |
| 7640 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7641 | mApp, getDefaultPhone().getSubId(), "factoryReset"); |
| 7642 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7643 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7644 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7645 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7646 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7647 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7648 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7649 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7650 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 8c6e82e | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7651 | Phone phone = getPhone(subId); |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7652 | cleanUpAllowedNetworkTypes(phone, subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7653 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
Jordan Liu | 857e73a | 2021-03-05 16:24:04 -0800 | [diff] [blame] | 7654 | getPhone(subId).resetCarrierKeysForImsiEncryption(); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7655 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7656 | // There has been issues when Sms raw table somehow stores orphan |
| 7657 | // fragments. They lead to garbled message when new fragments come |
| 7658 | // in and combined with those stale ones. In case this happens again, |
| 7659 | // user can reset all network settings which will clean up this table. |
| 7660 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7661 | // Clean up IMS settings as well here. |
| 7662 | int slotId = getSlotIndex(subId); |
| 7663 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7664 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7665 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7666 | |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7667 | if (defaultPhone == null) { |
| 7668 | return; |
| 7669 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7670 | // Erase modem config if erase modem on network setting is enabled. |
| 7671 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7672 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7673 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7674 | sendEraseModemConfig(defaultPhone); |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7675 | } |
Kai Shi | f70f46f | 2021-03-03 13:59:46 -0800 | [diff] [blame] | 7676 | |
| 7677 | sendEraseDataInSharedPreferences(defaultPhone); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7678 | } finally { |
| 7679 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7680 | } |
| 7681 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7682 | |
SongFerngWang | fd89b10 | 2021-05-27 22:44:54 +0800 | [diff] [blame] | 7683 | @VisibleForTesting |
| 7684 | void cleanUpAllowedNetworkTypes(Phone phone, int subId) { |
| 7685 | if (phone == null || !SubscriptionManager.isUsableSubscriptionId(subId)) { |
| 7686 | return; |
| 7687 | } |
| 7688 | long defaultNetworkType = RadioAccessFamily.getRafFromNetworkType( |
| 7689 | RILConstants.PREFERRED_NETWORK_MODE); |
| 7690 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7691 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7692 | "user=" + defaultNetworkType); |
| 7693 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7694 | phone.setAllowedNetworkTypes(TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7695 | defaultNetworkType, null); |
| 7696 | } |
| 7697 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7698 | private void cleanUpSmsRawTable(Context context) { |
| 7699 | ContentResolver resolver = context.getContentResolver(); |
| 7700 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7701 | resolver.delete(uri, null, null); |
| 7702 | } |
| 7703 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7704 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7705 | public String getSimLocaleForSubscriber(int subId) { |
| 7706 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7707 | final Phone phone = getPhone(subId); |
| 7708 | if (phone == null) { |
| 7709 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7710 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7711 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7712 | final long identity = Binder.clearCallingIdentity(); |
| 7713 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7714 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7715 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7716 | if (info == null) { |
| 7717 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7718 | return null; |
| 7719 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7720 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7721 | // preferences (EF-PL and EF-LI)... |
| 7722 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7723 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7724 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7725 | if (localeFromDefaultSim != null) { |
| 7726 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7727 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7728 | + localeFromDefaultSim); |
| 7729 | return localeFromDefaultSim.toLanguageTag(); |
| 7730 | } else { |
| 7731 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | } |
| 7733 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7736 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7737 | // the SIM and carrier preferences does not include a country we add the country |
| 7738 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7739 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7740 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7741 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7742 | return mccLocale.toLanguageTag(); |
| 7743 | } |
| 7744 | |
| 7745 | if (DBG) log("No locale found - returning null"); |
| 7746 | return null; |
| 7747 | } finally { |
| 7748 | Binder.restoreCallingIdentity(identity); |
| 7749 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7753 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7754 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7755 | } |
| 7756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | /** |
| 7758 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7759 | */ |
| 7760 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7761 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7762 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7763 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7764 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7765 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7766 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7767 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7768 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7769 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7770 | * representing the state of the modem. |
| 7771 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7772 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7773 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7774 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7775 | */ |
| 7776 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7777 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7778 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7779 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7780 | |
| 7781 | final long identity = Binder.clearCallingIdentity(); |
| 7782 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7783 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | } finally { |
| 7785 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7786 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7787 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7788 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7789 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7790 | // less than total activity duration. |
| 7791 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7792 | if (info == null) { |
| 7793 | return false; |
| 7794 | } |
| 7795 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7796 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7797 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7798 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7799 | return (info.isValid() |
| 7800 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7801 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7802 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7803 | && (totalTxTimeMs <= activityDurationMs)); |
| 7804 | } |
| 7805 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7806 | /** |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7807 | * Returns the service state information on specified subscription. |
| 7808 | */ |
| 7809 | @Override |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7810 | public ServiceState getServiceStateForSubscriber(int subId, |
| 7811 | boolean renounceFineLocationAccess, boolean renounceCoarseLocationAccess, |
| 7812 | String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7813 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7814 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7815 | return null; |
| 7816 | } |
| 7817 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7818 | boolean hasFinePermission = false; |
| 7819 | boolean hasCoarsePermission = false; |
| 7820 | if (!renounceFineLocationAccess) { |
| 7821 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7822 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7823 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7824 | .setCallingPackage(callingPackage) |
| 7825 | .setCallingFeatureId(callingFeatureId) |
| 7826 | .setCallingPid(Binder.getCallingPid()) |
| 7827 | .setCallingUid(Binder.getCallingUid()) |
| 7828 | .setMethod("getServiceStateForSubscriber") |
| 7829 | .setLogAsInfo(true) |
| 7830 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7831 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7832 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7833 | .build()); |
| 7834 | hasFinePermission = |
| 7835 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7836 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7837 | |
Sooraj Sasindran | 37bb1a7 | 2021-11-10 16:42:01 -0800 | [diff] [blame] | 7838 | if (!renounceCoarseLocationAccess) { |
| 7839 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7840 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7841 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7842 | .setCallingPackage(callingPackage) |
| 7843 | .setCallingFeatureId(callingFeatureId) |
| 7844 | .setCallingPid(Binder.getCallingPid()) |
| 7845 | .setCallingUid(Binder.getCallingUid()) |
| 7846 | .setMethod("getServiceStateForSubscriber") |
| 7847 | .setLogAsInfo(true) |
| 7848 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7849 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7850 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 7851 | .build()); |
| 7852 | hasCoarsePermission = |
| 7853 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7854 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7855 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7856 | final Phone phone = getPhone(subId); |
| 7857 | if (phone == null) { |
| 7858 | return null; |
| 7859 | } |
| 7860 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7863 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7864 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7866 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7867 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7868 | Rlog.d(LOG_TAG, |
| 7869 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7870 | return null; |
| 7871 | } |
| 7872 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7873 | ServiceState ss = phone.getServiceState(); |
| 7874 | |
| 7875 | // Scrub out the location info in ServiceState depending on what level of access |
| 7876 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7877 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7878 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7879 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7880 | } finally { |
| 7881 | Binder.restoreCallingIdentity(identity); |
| 7882 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7883 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7884 | |
| 7885 | /** |
| 7886 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7887 | * |
| 7888 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7889 | * voicemail ringtone. |
| 7890 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7891 | * PhoneAccount. |
| 7892 | */ |
| 7893 | @Override |
| 7894 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7895 | final long identity = Binder.clearCallingIdentity(); |
| 7896 | try { |
| 7897 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7898 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7899 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7900 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7901 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7902 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7903 | } finally { |
| 7904 | Binder.restoreCallingIdentity(identity); |
| 7905 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7906 | } |
| 7907 | |
| 7908 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7909 | * Sets the per-account voicemail ringtone. |
| 7910 | * |
| 7911 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7912 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7913 | * |
| 7914 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7915 | * voicemail ringtone. |
| 7916 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7917 | * PhoneAccount. |
| 7918 | */ |
| 7919 | @Override |
| 7920 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7921 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7922 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7923 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7924 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7925 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7927 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7928 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7929 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7930 | |
| 7931 | final long identity = Binder.clearCallingIdentity(); |
| 7932 | try { |
| 7933 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7934 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7935 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7936 | } |
| 7937 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7938 | } finally { |
| 7939 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7940 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7944 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7945 | * |
| 7946 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7947 | * voicemail vibration setting. |
| 7948 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7949 | */ |
| 7950 | @Override |
| 7951 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | try { |
| 7954 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7955 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7956 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7957 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7960 | } finally { |
| 7961 | Binder.restoreCallingIdentity(identity); |
| 7962 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7963 | } |
| 7964 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7965 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7966 | * Sets the per-account voicemail vibration. |
| 7967 | * |
| 7968 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7969 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7970 | * |
| 7971 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7972 | * voicemail vibration setting. |
| 7973 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7974 | * specific PhoneAccount. |
| 7975 | */ |
| 7976 | @Override |
| 7977 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7978 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7979 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7980 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7981 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7982 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7984 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7985 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7986 | } |
| 7987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7988 | final long identity = Binder.clearCallingIdentity(); |
| 7989 | try { |
| 7990 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7991 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7992 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | } |
| 7994 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7995 | } finally { |
| 7996 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7997 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7998 | } |
| 7999 | |
| 8000 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8001 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 8002 | * |
| 8003 | * @throws SecurityException if the caller does not have the required permission |
| 8004 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8005 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8006 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8007 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8008 | } |
| 8009 | |
| 8010 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8011 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 8012 | * permission. |
| 8013 | * |
| 8014 | * @throws SecurityException if the caller does not have the required permission |
| 8015 | */ |
| 8016 | private void enforceSendSmsPermission() { |
| 8017 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 8018 | } |
| 8019 | |
| 8020 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8021 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8022 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8023 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8024 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 8025 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8026 | final long identity = Binder.clearCallingIdentity(); |
| 8027 | try { |
| 8028 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8029 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8030 | if (componentName == null) { |
| 8031 | throw new SecurityException( |
| 8032 | "Caller not current active visual voicemail package[null]"); |
| 8033 | } |
| 8034 | String vvmPackage = componentName.getPackageName(); |
| 8035 | if (!callingPackage.equals(vvmPackage)) { |
| 8036 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 8037 | + vvmPackage + "]"); |
| 8038 | } |
| 8039 | } finally { |
| 8040 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 8041 | } |
| 8042 | } |
| 8043 | |
| 8044 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8045 | * Return the application ID for the app type. |
| 8046 | * |
| 8047 | * @param subId the subscription ID that this request applies to. |
| 8048 | * @param appType the uicc app type. |
| 8049 | * @return Application ID for specificied app type, or null if no uicc. |
| 8050 | */ |
| 8051 | @Override |
| 8052 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8053 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8054 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | |
| 8056 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8057 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8058 | if (phone == null) { |
| 8059 | return null; |
| 8060 | } |
| 8061 | String aid = null; |
| 8062 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8063 | aid = UiccController.getInstance().getUiccPort(phone.getPhoneId()) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8064 | .getApplicationByType(appType).getAid(); |
| 8065 | } catch (Exception e) { |
| 8066 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 8067 | } |
| 8068 | return aid; |
| 8069 | } finally { |
| 8070 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8071 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 8072 | } |
| 8073 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8074 | /** |
| 8075 | * Return the Electronic Serial Number. |
| 8076 | * |
| 8077 | * @param subId the subscription ID that this request applies to. |
| 8078 | * @return ESN or null if error. |
| 8079 | */ |
| 8080 | @Override |
| 8081 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8082 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8083 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8084 | |
| 8085 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8086 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | if (phone == null) { |
| 8088 | return null; |
| 8089 | } |
| 8090 | String esn = null; |
| 8091 | try { |
| 8092 | esn = phone.getEsn(); |
| 8093 | } catch (Exception e) { |
| 8094 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 8095 | } |
| 8096 | return esn; |
| 8097 | } finally { |
| 8098 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8099 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 8100 | } |
| 8101 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8102 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8103 | * Return the Preferred Roaming List Version. |
| 8104 | * |
| 8105 | * @param subId the subscription ID that this request applies to. |
| 8106 | * @return PRLVersion or null if error. |
| 8107 | */ |
| 8108 | @Override |
| 8109 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8110 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8111 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8112 | |
| 8113 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8114 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8115 | if (phone == null) { |
| 8116 | return null; |
| 8117 | } |
| 8118 | String cdmaPrlVersion = null; |
| 8119 | try { |
| 8120 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 8121 | } catch (Exception e) { |
| 8122 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 8123 | } |
| 8124 | return cdmaPrlVersion; |
| 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8127 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8131 | * Get snapshot of Telephony histograms |
| 8132 | * @return List of Telephony histograms |
| 8133 | * @hide |
| 8134 | */ |
| 8135 | @Override |
| 8136 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8137 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8138 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8139 | |
| 8140 | final long identity = Binder.clearCallingIdentity(); |
| 8141 | try { |
| 8142 | return RIL.getTelephonyRILTimingHistograms(); |
| 8143 | } finally { |
| 8144 | Binder.restoreCallingIdentity(identity); |
| 8145 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 8146 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8147 | |
| 8148 | /** |
| 8149 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8150 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 8151 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8152 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8153 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8154 | * @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] | 8155 | */ |
| 8156 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8157 | @TelephonyManager.SetCarrierRestrictionResult |
| 8158 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8159 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8160 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8161 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8162 | if (carrierRestrictionRules == null) { |
| 8163 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 8164 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8165 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8166 | final long identity = Binder.clearCallingIdentity(); |
| 8167 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8168 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8169 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8170 | } finally { |
| 8171 | Binder.restoreCallingIdentity(identity); |
| 8172 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8173 | } |
| 8174 | |
| 8175 | /** |
| 8176 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8177 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 8178 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8179 | * Require system privileges. In the future we may add this to carrier APIs. |
| 8180 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8181 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8182 | */ |
| 8183 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8184 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8185 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8186 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8187 | |
| 8188 | final long identity = Binder.clearCallingIdentity(); |
| 8189 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 8190 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 8191 | if (response instanceof CarrierRestrictionRules) { |
| 8192 | return (CarrierRestrictionRules) response; |
| 8193 | } |
| 8194 | // Response is an Exception of some kind, |
| 8195 | // which is signalled to the user as a NULL retval |
| 8196 | return null; |
| 8197 | } catch (Exception e) { |
| 8198 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 8199 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 8203 | } |
| 8204 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8205 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8206 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 8207 | * @param subId the subscription ID that this action applies to. |
| 8208 | * @param enabled control enable or disable radio. |
| 8209 | * {@hide} |
| 8210 | */ |
| 8211 | @Override |
| 8212 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 8213 | enforceModifyPermission(); |
| 8214 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8215 | |
| 8216 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8217 | if (phone == null) { |
| 8218 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 8219 | return; |
| 8220 | } |
| 8221 | try { |
| 8222 | phone.carrierActionSetRadioEnabled(enabled); |
| 8223 | } catch (Exception e) { |
| 8224 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8225 | } finally { |
| 8226 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 8227 | } |
| 8228 | } |
| 8229 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8230 | /** |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8231 | * Enable or disable Voice over NR (VoNR) |
| 8232 | * @param subId the subscription ID that this action applies to. |
| 8233 | * @param enabled enable or disable VoNR. |
| 8234 | * @return operation result. |
| 8235 | */ |
| 8236 | @Override |
| 8237 | public int setVoNrEnabled(int subId, boolean enabled) { |
| 8238 | enforceModifyPermission(); |
| 8239 | final Phone phone = getPhone(subId); |
| 8240 | |
| 8241 | final long identity = Binder.clearCallingIdentity(); |
| 8242 | if (phone == null) { |
| 8243 | loge("setVoNrEnabled fails with no phone object for subId: " + subId); |
| 8244 | return TelephonyManager.ENABLE_VONR_RADIO_NOT_AVAILABLE; |
| 8245 | } |
| 8246 | |
| 8247 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8248 | try { |
| 8249 | int result = (int) sendRequest(CMD_ENABLE_VONR, enabled, subId, |
| 8250 | workSource); |
| 8251 | if (DBG) log("setVoNrEnabled result: " + result); |
Gary Jian | 8dd305f | 2021-10-14 16:31:35 +0800 | [diff] [blame] | 8252 | |
| 8253 | if (result == TelephonyManager.ENABLE_VONR_SUCCESS) { |
| 8254 | if (DBG) { |
| 8255 | log("Set VoNR settings in siminfo db; subId=" + subId + ", value:" + enabled); |
| 8256 | } |
| 8257 | SubscriptionManager.setSubscriptionProperty( |
| 8258 | subId, SubscriptionManager.NR_ADVANCED_CALLING_ENABLED, |
| 8259 | (enabled ? "1" : "0")); |
| 8260 | } |
| 8261 | |
Sooraj Sasindran | bf5c79c | 2021-06-15 14:52:55 -0700 | [diff] [blame] | 8262 | return result; |
| 8263 | } finally { |
| 8264 | Binder.restoreCallingIdentity(identity); |
| 8265 | } |
| 8266 | } |
| 8267 | |
| 8268 | /** |
| 8269 | * Is voice over NR enabled |
| 8270 | * @return true if VoNR is enabled else false |
| 8271 | */ |
| 8272 | @Override |
| 8273 | public boolean isVoNrEnabled(int subId) { |
| 8274 | enforceReadPrivilegedPermission("isVoNrEnabled"); |
| 8275 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8276 | final long identity = Binder.clearCallingIdentity(); |
| 8277 | try { |
| 8278 | boolean isEnabled = (boolean) sendRequest(CMD_IS_VONR_ENABLED, |
| 8279 | null, subId, workSource); |
| 8280 | if (DBG) log("isVoNrEnabled: " + isEnabled); |
| 8281 | return isEnabled; |
| 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
| 8284 | } |
| 8285 | } |
| 8286 | |
| 8287 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8288 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 8289 | * network status based on which carrier apps could apply actions accordingly, |
| 8290 | * enable/disable default url handler for example. |
| 8291 | * |
| 8292 | * @param subId the subscription ID that this action applies to. |
| 8293 | * @param report control start/stop reporting the default network status. |
| 8294 | * {@hide} |
| 8295 | */ |
| 8296 | @Override |
| 8297 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 8298 | enforceModifyPermission(); |
| 8299 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8300 | |
| 8301 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8302 | if (phone == null) { |
| 8303 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 8304 | return; |
| 8305 | } |
| 8306 | try { |
| 8307 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 8308 | } catch (Exception e) { |
| 8309 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8310 | } finally { |
| 8311 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 8312 | } |
| 8313 | } |
| 8314 | |
| 8315 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 8316 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 8317 | * @param subId the subscription ID that this action applies to. |
| 8318 | * {@hide} |
| 8319 | */ |
| 8320 | @Override |
| 8321 | public void carrierActionResetAll(int subId) { |
| 8322 | enforceModifyPermission(); |
| 8323 | final Phone phone = getPhone(subId); |
| 8324 | if (phone == null) { |
| 8325 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 8326 | return; |
| 8327 | } |
| 8328 | try { |
| 8329 | phone.carrierActionResetAll(); |
| 8330 | } catch (Exception e) { |
| 8331 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 8332 | } |
| 8333 | } |
| 8334 | |
| 8335 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8336 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 8337 | * bug report is being generated. |
| 8338 | */ |
| 8339 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 8340 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8341 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 8342 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 8343 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 8344 | + Binder.getCallingPid() |
| 8345 | + ", uid=" + Binder.getCallingUid() |
| 8346 | + "without permission " |
| 8347 | + android.Manifest.permission.DUMP); |
| 8348 | return; |
| 8349 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8350 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 8351 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8352 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8353 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 8354 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 8355 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 8356 | @NonNull String[] args) { |
| 8357 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8358 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8359 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8360 | } |
| 8361 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8362 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8363 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8364 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8365 | * @param reason the reason the data enable change is taking place |
| 8366 | * @param enabled True if enabling the data, otherwise disabling. |
| 8367 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8368 | */ |
| 8369 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8370 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8371 | boolean enabled) { |
| 8372 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8373 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8374 | try { |
| 8375 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8376 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8377 | } catch (SecurityException se) { |
| 8378 | enforceModifyPermission(); |
| 8379 | } |
| 8380 | } else { |
| 8381 | enforceModifyPermission(); |
| 8382 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8383 | |
| 8384 | final long identity = Binder.clearCallingIdentity(); |
| 8385 | try { |
| 8386 | Phone phone = getPhone(subId); |
| 8387 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8388 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8389 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8390 | } else { |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 8391 | if (phone.isUsingNewDataStack()) { |
| 8392 | phone.getDataSettingsManager().setDataEnabled(reason, enabled); |
| 8393 | } else { |
| 8394 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8395 | } |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8396 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8397 | } |
| 8398 | } finally { |
| 8399 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8400 | } |
| 8401 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8402 | |
| 8403 | /** |
| 8404 | * Get Client request stats |
| 8405 | * @return List of Client Request Stats |
| 8406 | * @hide |
| 8407 | */ |
| 8408 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8409 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8410 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8411 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8412 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8413 | return null; |
| 8414 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8415 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8417 | final long identity = Binder.clearCallingIdentity(); |
| 8418 | try { |
| 8419 | if (phone != null) { |
| 8420 | return phone.getClientRequestStats(); |
| 8421 | } |
| 8422 | |
| 8423 | return null; |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
| 8426 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8427 | } |
| 8428 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8429 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8430 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Hunter Knepshield | d03383b | 2022-03-29 22:47:54 +0000 | [diff] [blame^] | 8431 | if (uid == Process.ROOT_UID && packageName == null) { |
| 8432 | // Downstream WorkSource attribution inside the RIL requires both a UID and package name |
| 8433 | // to be set for wakelock tracking, otherwise RIL requests fail with a runtime |
| 8434 | // exception. ROOT_UID seems not to have a valid package name returned by |
| 8435 | // PackageManager, so just fake it here to avoid issues when running telephony shell |
| 8436 | // commands that plumb through the RIL as root, like so: |
| 8437 | // $ adb root |
| 8438 | // $ adb shell cmd phone ... |
| 8439 | packageName = "root"; |
| 8440 | } |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8441 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8442 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8443 | |
| 8444 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8445 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8446 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8447 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8448 | * @param state State of SIM (power down, power up, pass through) |
| 8449 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8450 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8451 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8452 | * |
| 8453 | **/ |
| 8454 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8455 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8456 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8457 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8458 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8459 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8464 | phone.setSimPowerState(state, null, workSource); |
| 8465 | } |
| 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
| 8468 | } |
| 8469 | } |
| 8470 | |
| 8471 | /** |
| 8472 | * Set SIM card power state. |
| 8473 | * |
| 8474 | * @param slotIndex SIM slot id. |
| 8475 | * @param state State of SIM (power down, power up, pass through) |
| 8476 | * @param callback callback to trigger after success or failure |
| 8477 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8478 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8479 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8480 | * |
| 8481 | **/ |
| 8482 | @Override |
| 8483 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8484 | IIntegerConsumer callback) { |
| 8485 | enforceModifyPermission(); |
| 8486 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8487 | |
| 8488 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8489 | |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
| 8492 | if (phone != null) { |
| 8493 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8494 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8495 | } |
| 8496 | } finally { |
| 8497 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8498 | } |
| 8499 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8500 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8501 | private boolean isUssdApiAllowed(int subId) { |
| 8502 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8503 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8504 | if (configManager == null) { |
| 8505 | return false; |
| 8506 | } |
| 8507 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8508 | if (pb == null) { |
| 8509 | return false; |
| 8510 | } |
| 8511 | return pb.getBoolean( |
| 8512 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8513 | } |
| 8514 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8515 | /** |
| 8516 | * Check if phone is in emergency callback mode |
| 8517 | * @return true if phone is in emergency callback mode |
| 8518 | * @param subId sub id |
| 8519 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8520 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8521 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8522 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8523 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8524 | |
| 8525 | final long identity = Binder.clearCallingIdentity(); |
| 8526 | try { |
| 8527 | if (phone != null) { |
| 8528 | return phone.isInEcm(); |
| 8529 | } else { |
| 8530 | return false; |
| 8531 | } |
| 8532 | } finally { |
| 8533 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8534 | } |
| 8535 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8536 | |
| 8537 | /** |
| 8538 | * Get the current signal strength information for the given subscription. |
| 8539 | * Because this information is not updated when the device is in a low power state |
| 8540 | * it should not be relied-upon to be current. |
| 8541 | * @param subId Subscription index |
| 8542 | * @return the most recent cached signal strength info from the modem |
| 8543 | */ |
| 8544 | @Override |
| 8545 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8546 | final long identity = Binder.clearCallingIdentity(); |
| 8547 | try { |
| 8548 | Phone p = getPhone(subId); |
| 8549 | if (p == null) { |
| 8550 | return null; |
| 8551 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8552 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8553 | return p.getSignalStrength(); |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8557 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8558 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8559 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8560 | * Get the current modem radio state for the given slot. |
| 8561 | * @param slotIndex slot index. |
| 8562 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8563 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8564 | * @return the current radio power state from the modem |
| 8565 | */ |
| 8566 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8567 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8568 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8569 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8570 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8571 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8572 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8573 | } |
| 8574 | |
| 8575 | final long identity = Binder.clearCallingIdentity(); |
| 8576 | try { |
| 8577 | return phone.getRadioPowerState(); |
| 8578 | } finally { |
| 8579 | Binder.restoreCallingIdentity(identity); |
| 8580 | } |
| 8581 | } |
| 8582 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8583 | } |
| 8584 | |
| 8585 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8586 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8587 | * |
| 8588 | * <p>Requires one of the following permissions: |
| 8589 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8590 | * {@link android.Manifest.permission#READ_BASIC_PHONE_STATE}, |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8591 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8592 | * privileges. |
| 8593 | * |
| 8594 | * @param subId subscription id |
| 8595 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8596 | * {@code false}. |
| 8597 | */ |
| 8598 | @Override |
| 8599 | public boolean isDataRoamingEnabled(int subId) { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8600 | String functionName = "isDataRoamingEnabled"; |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8601 | try { |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8602 | try { |
| 8603 | mApp.enforceCallingOrSelfPermission( |
| 8604 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8605 | functionName); |
| 8606 | } catch (Exception e) { |
| 8607 | mApp.enforceCallingOrSelfPermission( |
| 8608 | permission.READ_BASIC_PHONE_STATE, functionName); |
| 8609 | } |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8610 | } catch (Exception e) { |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8611 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | 5d051bf | 2021-11-05 13:14:15 -0700 | [diff] [blame] | 8612 | mApp, subId, functionName); |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8613 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8614 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8615 | boolean isEnabled = false; |
| 8616 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8617 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8618 | Phone phone = getPhone(subId); |
| 8619 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8620 | } finally { |
| 8621 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8622 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8623 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8624 | } |
| 8625 | |
| 8626 | |
| 8627 | /** |
| 8628 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8629 | * |
| 8630 | * <p> Requires permission: |
| 8631 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8632 | * privileges. |
| 8633 | * |
| 8634 | * @param subId subscription id |
| 8635 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8636 | */ |
| 8637 | @Override |
| 8638 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8640 | mApp, subId, "setDataRoamingEnabled"); |
| 8641 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8644 | Phone phone = getPhone(subId); |
| 8645 | if (phone != null) { |
| 8646 | phone.setDataRoamingEnabled(isEnabled); |
| 8647 | } |
| 8648 | } finally { |
| 8649 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8650 | } |
| 8651 | } |
| 8652 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8653 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8654 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8655 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8656 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8657 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8658 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8659 | boolean isAllowed = true; |
| 8660 | final long identity = Binder.clearCallingIdentity(); |
| 8661 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8662 | Phone phone = getPhone(subId); |
| 8663 | if (phone != null) { |
| 8664 | isAllowed = phone.isCspPlmnEnabled(); |
| 8665 | } |
| 8666 | } finally { |
| 8667 | Binder.restoreCallingIdentity(identity); |
| 8668 | } |
| 8669 | return isAllowed; |
| 8670 | } |
| 8671 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8672 | private boolean haveCarrierPrivilegeAccess(UiccPort port, String callingPackage) { |
| 8673 | UiccProfile profile = port.getUiccProfile(); |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8674 | if (profile == null) { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8675 | return false; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8676 | } |
Hunter Knepshield | 25ee6fc | 2021-12-13 15:08:35 -0800 | [diff] [blame] | 8677 | Phone phone = PhoneFactory.getPhone(profile.getPhoneId()); |
| 8678 | if (phone == null) { |
| 8679 | return false; |
| 8680 | } |
| 8681 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 8682 | return cpt != null && cpt.getCarrierPrivilegeStatusForPackage(callingPackage) |
| 8683 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8684 | } |
| 8685 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8686 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8687 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8688 | // Verify that the callingPackage belongs to the calling UID |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8689 | mApp.getSystemService(AppOpsManager.class) |
| 8690 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8691 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8692 | boolean hasReadPermission = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8693 | boolean isIccIdAccessRestricted = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8694 | try { |
| 8695 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8696 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8697 | } catch (SecurityException e) { |
| 8698 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8699 | // has carrier privileges on an active UICC |
Rambo Wang | 04d1ace | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8700 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8701 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8702 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8703 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8704 | } |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8705 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8706 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8707 | Binder.getCallingUid())) { |
| 8708 | isIccIdAccessRestricted = true; |
| 8709 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8710 | final long identity = Binder.clearCallingIdentity(); |
| 8711 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8712 | UiccController uiccController = UiccController.getInstance(); |
| 8713 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8714 | if (hasReadPermission) { |
| 8715 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8716 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8717 | |
| 8718 | // Remove private info if the caller doesn't have access |
| 8719 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8720 | for (UiccCardInfo cardInfo : cardInfos) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8721 | //setting the value after compatibility check |
| 8722 | cardInfo.setIccIdAccessRestricted(isIccIdAccessRestricted); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8723 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8724 | // is available |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8725 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getPhysicalSlotIndex()); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8726 | if (card == null) { |
| 8727 | // assume no access if the card is unavailable |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8728 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8729 | continue; |
| 8730 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8731 | Collection<UiccPortInfo> portInfos = cardInfo.getPorts(); |
| 8732 | if (portInfos.isEmpty()) { |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8733 | filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo)); |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8734 | continue; |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8735 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8736 | List<UiccPortInfo> uiccPortInfos = new ArrayList<>(); |
| 8737 | for (UiccPortInfo portInfo : portInfos) { |
| 8738 | UiccPort port = uiccController.getUiccPortForSlot( |
| 8739 | cardInfo.getPhysicalSlotIndex(), portInfo.getPortIndex()); |
| 8740 | if (port == null) { |
| 8741 | // assume no access if port is null |
| 8742 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8743 | continue; |
| 8744 | } |
| 8745 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8746 | uiccPortInfos.add(portInfo); |
| 8747 | } else { |
| 8748 | uiccPortInfos.add(getUiccPortInfoUnPrivileged(portInfo)); |
| 8749 | } |
| 8750 | } |
| 8751 | filteredInfos.add(new UiccCardInfo( |
| 8752 | cardInfo.isEuicc(), |
| 8753 | cardInfo.getCardId(), |
| 8754 | null, |
| 8755 | cardInfo.getPhysicalSlotIndex(), |
| 8756 | cardInfo.isRemovable(), |
| 8757 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8758 | uiccPortInfos)); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8759 | } |
| 8760 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8761 | } finally { |
| 8762 | Binder.restoreCallingIdentity(identity); |
| 8763 | } |
| 8764 | } |
| 8765 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8766 | /** |
| 8767 | * Returns a copy of the UiccCardinfo with the EID and ICCID set to null. These values are |
| 8768 | * generally private and require carrier privileges to view. |
| 8769 | * |
| 8770 | * @hide |
| 8771 | */ |
| 8772 | @NonNull |
| 8773 | public UiccCardInfo getUiccCardInfoUnPrivileged(UiccCardInfo cardInfo) { |
| 8774 | List<UiccPortInfo> portinfo = new ArrayList<>(); |
| 8775 | for (UiccPortInfo portinfos : cardInfo.getPorts()) { |
| 8776 | portinfo.add(getUiccPortInfoUnPrivileged(portinfos)); |
| 8777 | } |
| 8778 | return new UiccCardInfo( |
| 8779 | cardInfo.isEuicc(), |
| 8780 | cardInfo.getCardId(), |
| 8781 | null, |
| 8782 | cardInfo.getPhysicalSlotIndex(), |
| 8783 | cardInfo.isRemovable(), |
| 8784 | cardInfo.isMultipleEnabledProfilesSupported(), |
| 8785 | portinfo |
| 8786 | ); |
| 8787 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8788 | |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8789 | /** |
| 8790 | * @hide |
| 8791 | * @return a copy of the UiccPortInfo with ICCID set to {@link UiccPortInfo#ICCID_REDACTED}. |
| 8792 | * These values are generally private and require carrier privileges to view. |
| 8793 | */ |
| 8794 | @NonNull |
| 8795 | public UiccPortInfo getUiccPortInfoUnPrivileged(UiccPortInfo portInfo) { |
| 8796 | return new UiccPortInfo( |
| 8797 | UiccPortInfo.ICCID_REDACTED, |
| 8798 | portInfo.getPortIndex(), |
| 8799 | portInfo.getLogicalSlotIndex(), |
| 8800 | portInfo.isActive() |
| 8801 | ); |
| 8802 | } |
| 8803 | @Override |
| 8804 | public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 8805 | // Verify that the callingPackage belongs to the calling UID |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8806 | mApp.getSystemService(AppOpsManager.class) |
| 8807 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8808 | |
| 8809 | boolean hasReadPermission = false; |
| 8810 | boolean isLogicalSlotAccessRestricted = false; |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8811 | |
| 8812 | try { |
| 8813 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
| 8814 | hasReadPermission = true; |
| 8815 | } catch (SecurityException e) { |
| 8816 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8817 | // has carrier privileges on an active UICC |
Rambo Wang | 04d1ace | 2022-02-23 13:41:02 -0800 | [diff] [blame] | 8818 | if (checkCarrierPrivilegesForPackageAnyPhoneWithPermission(callingPackage) |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8819 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8820 | hasReadPermission = true; |
| 8821 | } |
| 8822 | } |
| 8823 | |
| 8824 | // checking compatibility, if calling app's target SDK is T and beyond. |
| 8825 | if (CompatChanges.isChangeEnabled(GET_API_SIGNATURES_FROM_UICC_PORT_INFO, |
| 8826 | Binder.getCallingUid())) { |
| 8827 | isLogicalSlotAccessRestricted = true; |
| 8828 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8829 | final long identity = Binder.clearCallingIdentity(); |
| 8830 | try { |
| 8831 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8832 | if (slots == null) { |
| 8833 | Rlog.i(LOG_TAG, "slots is null."); |
| 8834 | return null; |
| 8835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8836 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8837 | for (int i = 0; i < slots.length; i++) { |
| 8838 | UiccSlot slot = slots[i]; |
| 8839 | if (slot == null) { |
| 8840 | continue; |
| 8841 | } |
| 8842 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8843 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8844 | UiccCard card = slot.getUiccCard(); |
| 8845 | if (card != null) { |
| 8846 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8847 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8848 | cardId = slot.getEid(); |
| 8849 | if (TextUtils.isEmpty(cardId)) { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8850 | // If cardId is null, use iccId of default port as cardId. Check if has |
| 8851 | // read permission otherwise set to null.(card is null which means no |
| 8852 | // carrier permission) |
| 8853 | cardId = hasReadPermission ? slot.getIccId( |
| 8854 | TelephonyManager.DEFAULT_PORT_INDEX) : null; |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8855 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8856 | } |
| 8857 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8858 | if (cardId != null) { |
| 8859 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8860 | // if cardId is an EID, it's all digits so this is fine |
| 8861 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8862 | } |
| 8863 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8864 | int cardState = 0; |
| 8865 | switch (slot.getCardState()) { |
| 8866 | case CARDSTATE_ABSENT: |
| 8867 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8868 | break; |
| 8869 | case CARDSTATE_PRESENT: |
| 8870 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8871 | break; |
| 8872 | case CARDSTATE_ERROR: |
| 8873 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8874 | break; |
| 8875 | case CARDSTATE_RESTRICTED: |
| 8876 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8877 | break; |
| 8878 | default: |
| 8879 | break; |
| 8880 | |
| 8881 | } |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8882 | List<UiccPortInfo> portInfos = new ArrayList<>(); |
| 8883 | int[] portIndexes = slot.getPortList(); |
| 8884 | for (int portIdx : portIndexes) { |
| 8885 | String iccId = IccUtils.stripTrailingFs(getIccId(slot, portIdx, |
| 8886 | callingPackage, hasReadPermission)); |
| 8887 | if (slot.isPortActive(portIdx)) { |
| 8888 | UiccPort port = slot.getUiccCard().getUiccPort(portIdx); |
| 8889 | portInfos.add(new UiccPortInfo(iccId, port.getPortIdx(), |
| 8890 | port.getPhoneId(), true)); |
| 8891 | } else { |
| 8892 | portInfos.add(new UiccPortInfo(iccId, portIdx, -1, false)); |
| 8893 | } |
| 8894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8895 | infos[i] = new UiccSlotInfo( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8896 | slot.isEuicc(), |
| 8897 | cardId, |
| 8898 | cardState, |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8899 | slot.isExtendedApduSupported(), |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8900 | slot.isRemovable(), portInfos); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8901 | //setting the value after compatibility check |
| 8902 | infos[i].setLogicalSlotAccessRestricted(isLogicalSlotAccessRestricted); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8903 | } |
| 8904 | return infos; |
| 8905 | } finally { |
| 8906 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8907 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8908 | } |
| 8909 | |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8910 | /* Returns null if doesn't have read permission or carrier privilege access. */ |
| 8911 | private String getIccId(UiccSlot slot, int portIndex, String callingPackage, |
| 8912 | boolean hasReadPermission) { |
| 8913 | String iccId = slot.getIccId(portIndex); |
| 8914 | if (hasReadPermission) { // if has read permission |
| 8915 | return iccId; |
| 8916 | } else { |
| 8917 | if (slot.getUiccCard() != null && slot.getUiccCard().getUiccPort(portIndex) != null) { |
| 8918 | UiccPort port = slot.getUiccCard().getUiccPort(portIndex); |
| 8919 | // if no read permission, checking carrier privilege access |
| 8920 | if (haveCarrierPrivilegeAccess(port, callingPackage)) { |
| 8921 | return iccId; |
| 8922 | } |
| 8923 | } |
| 8924 | } |
| 8925 | // No read permission or carrier privilege access. |
| 8926 | return UiccPortInfo.ICCID_REDACTED; |
| 8927 | } |
| 8928 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8929 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8930 | @Deprecated |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8931 | public boolean switchSlots(int[] physicalSlots) { |
| 8932 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8933 | |
| 8934 | final long identity = Binder.clearCallingIdentity(); |
| 8935 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8936 | List<UiccSlotMapping> slotMappings = new ArrayList<>(); |
| 8937 | for (int i = 0; i < physicalSlots.length; i++) { |
| 8938 | // Deprecated API, hence MEP is not supported. Adding default portIndex 0. |
| 8939 | slotMappings.add(new UiccSlotMapping(TelephonyManager.DEFAULT_PORT_INDEX, |
| 8940 | physicalSlots[i], i)); |
| 8941 | } |
| 8942 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMappings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8943 | } finally { |
| 8944 | Binder.restoreCallingIdentity(identity); |
| 8945 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8946 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8947 | |
| 8948 | @Override |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8949 | @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 8950 | public boolean setSimSlotMapping(@NonNull List<UiccSlotMapping> slotMapping) { |
| 8951 | enforceModifyPermission(); |
| 8952 | |
| 8953 | final long identity = Binder.clearCallingIdentity(); |
| 8954 | try { |
Muralidhar Reddy | 70bf65a | 2021-11-19 03:07:54 +0000 | [diff] [blame] | 8955 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, slotMapping); |
sandeepjs | 0a502c4 | 2021-09-27 15:34:44 +0000 | [diff] [blame] | 8956 | } finally { |
| 8957 | Binder.restoreCallingIdentity(identity); |
| 8958 | } |
| 8959 | } |
| 8960 | |
| 8961 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8962 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8963 | final long identity = Binder.clearCallingIdentity(); |
| 8964 | try { |
| 8965 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8966 | } finally { |
| 8967 | Binder.restoreCallingIdentity(identity); |
| 8968 | } |
| 8969 | } |
| 8970 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8971 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8972 | * A test API to reload the UICC profile. |
| 8973 | * |
| 8974 | * <p>Requires that the calling app has permission |
| 8975 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8976 | * @hide |
| 8977 | */ |
| 8978 | @Override |
| 8979 | public void refreshUiccProfile(int subId) { |
| 8980 | enforceModifyPermission(); |
| 8981 | |
| 8982 | final long identity = Binder.clearCallingIdentity(); |
| 8983 | try { |
| 8984 | Phone phone = getPhone(subId); |
| 8985 | if (phone == null) { |
| 8986 | return; |
| 8987 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8988 | UiccPort uiccPort = phone.getUiccPort(); |
| 8989 | if (uiccPort == null) { |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8990 | return; |
| 8991 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 8992 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8993 | if (uiccProfile == null) { |
| 8994 | return; |
| 8995 | } |
| 8996 | uiccProfile.refresh(); |
| 8997 | } finally { |
| 8998 | Binder.restoreCallingIdentity(identity); |
| 8999 | } |
| 9000 | } |
| 9001 | |
| 9002 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9003 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 9004 | */ |
| 9005 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9006 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9007 | } |
| 9008 | |
| 9009 | /** |
| 9010 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 9011 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 9012 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 9013 | */ |
| 9014 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 9015 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9016 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 9017 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9018 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 9019 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 9020 | return isDataRoamingEnabled; |
| 9021 | } |
| 9022 | |
| 9023 | /** |
| 9024 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 9025 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 9026 | */ |
| 9027 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 9028 | List<Integer> list = TelephonyProperties.default_network(); |
| 9029 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 9030 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 9031 | return list.get(phoneId); |
| 9032 | } |
| 9033 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 9034 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9035 | |
| 9036 | @Override |
| 9037 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 9038 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9039 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9040 | |
| 9041 | final long identity = Binder.clearCallingIdentity(); |
| 9042 | try { |
| 9043 | final Phone phone = getPhone(subId); |
| 9044 | if (phone == null) { |
| 9045 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 9046 | return; |
| 9047 | } |
Rambo Wang | a743688 | 2022-01-13 21:51:44 -0800 | [diff] [blame] | 9048 | CarrierPrivilegesTracker cpt = phone.getCarrierPrivilegesTracker(); |
| 9049 | if (cpt != null) { |
| 9050 | cpt.setTestOverrideCarrierPrivilegeRules(carrierPrivilegeRules); |
| 9051 | } |
| 9052 | // 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] | 9053 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 9054 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 9055 | if (carrierPrivilegeRules == null) { |
| 9056 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 9057 | } else { |
| 9058 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 9059 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9060 | } finally { |
| 9061 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9062 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9063 | } |
| 9064 | |
| 9065 | @Override |
| 9066 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 9067 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 9068 | |
| 9069 | final long identity = Binder.clearCallingIdentity(); |
| 9070 | try { |
| 9071 | final Phone phone = getPhone(subId); |
| 9072 | if (phone == null) { |
| 9073 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 9074 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 9075 | } |
| 9076 | return phone.getCarrierIdListVersion(); |
| 9077 | } finally { |
| 9078 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9079 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 9080 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9081 | |
| 9082 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9083 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 9084 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9085 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9086 | mApp, subId, callingPackage, callingFeatureId, |
| 9087 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 9088 | return -1; |
| 9089 | } |
| 9090 | |
| 9091 | final long identity = Binder.clearCallingIdentity(); |
| 9092 | try { |
| 9093 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 9094 | } finally { |
| 9095 | Binder.restoreCallingIdentity(identity); |
| 9096 | } |
| 9097 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9098 | |
| 9099 | @Override |
| 9100 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 9101 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9102 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9103 | mApp, subId, "getCdmaRoamingMode"); |
| 9104 | |
| 9105 | final long identity = Binder.clearCallingIdentity(); |
| 9106 | try { |
| 9107 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 9108 | } finally { |
| 9109 | Binder.restoreCallingIdentity(identity); |
| 9110 | } |
| 9111 | } |
| 9112 | |
| 9113 | @Override |
| 9114 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 9115 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9116 | mApp, subId, "setCdmaRoamingMode"); |
| 9117 | |
| 9118 | final long identity = Binder.clearCallingIdentity(); |
| 9119 | try { |
| 9120 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 9121 | } finally { |
| 9122 | Binder.restoreCallingIdentity(identity); |
| 9123 | } |
| 9124 | } |
| 9125 | |
| 9126 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9127 | public int getCdmaSubscriptionMode(int subId) { |
| 9128 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9129 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 9130 | mApp, subId, "getCdmaSubscriptionMode"); |
| 9131 | |
| 9132 | final long identity = Binder.clearCallingIdentity(); |
| 9133 | try { |
| 9134 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 9135 | } finally { |
| 9136 | Binder.restoreCallingIdentity(identity); |
| 9137 | } |
| 9138 | } |
| 9139 | |
| 9140 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 9141 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 9142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9143 | mApp, subId, "setCdmaSubscriptionMode"); |
| 9144 | |
| 9145 | final long identity = Binder.clearCallingIdentity(); |
| 9146 | try { |
| 9147 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 9148 | } finally { |
| 9149 | Binder.restoreCallingIdentity(identity); |
| 9150 | } |
| 9151 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 9152 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9153 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9154 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9155 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9157 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 9158 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9159 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9160 | } |
| 9161 | final long identity = Binder.clearCallingIdentity(); |
| 9162 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9163 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 9164 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9165 | if (phone.getEmergencyNumberTracker() != null |
| 9166 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 9167 | emergencyNumberListInternal.put( |
| 9168 | phone.getSubId(), |
| 9169 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 9170 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9171 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9172 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9173 | } finally { |
| 9174 | Binder.restoreCallingIdentity(identity); |
| 9175 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 9176 | } |
| 9177 | |
| 9178 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9179 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 9180 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9181 | if (!exactMatch) { |
| 9182 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9183 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 9184 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9185 | } |
| 9186 | final long identity = Binder.clearCallingIdentity(); |
| 9187 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 9188 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9189 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 9190 | && phone.getEmergencyNumberTracker() |
| 9191 | .isEmergencyNumber(number, exactMatch)) { |
| 9192 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9193 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 9194 | } |
| 9195 | return false; |
| 9196 | } finally { |
| 9197 | Binder.restoreCallingIdentity(identity); |
| 9198 | } |
| 9199 | } |
| 9200 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9201 | /** |
Shuo Qian | ccbaf74 | 2021-02-22 18:32:21 -0800 | [diff] [blame] | 9202 | * Start emergency callback mode for GsmCdmaPhone for testing. |
| 9203 | */ |
| 9204 | @Override |
| 9205 | public void startEmergencyCallbackMode() { |
| 9206 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9207 | "startEmergencyCallbackMode"); |
| 9208 | enforceModifyPermission(); |
| 9209 | final long identity = Binder.clearCallingIdentity(); |
| 9210 | try { |
| 9211 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9212 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType()); |
| 9213 | if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM) |
| 9214 | || (phone.getPhoneType() == PHONE_TYPE_CDMA))) { |
| 9215 | GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone; |
| 9216 | gsmCdmaPhone.obtainMessage( |
| 9217 | GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget(); |
| 9218 | Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered"); |
| 9219 | } |
| 9220 | } |
| 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
| 9224 | } |
| 9225 | |
| 9226 | /** |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 9227 | * Update emergency number list for test mode. |
| 9228 | */ |
| 9229 | @Override |
| 9230 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 9231 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9232 | "updateEmergencyNumberListTestMode"); |
| 9233 | |
| 9234 | final long identity = Binder.clearCallingIdentity(); |
| 9235 | try { |
| 9236 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9237 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9238 | if (tracker != null) { |
| 9239 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 9240 | } |
| 9241 | } |
| 9242 | } finally { |
| 9243 | Binder.restoreCallingIdentity(identity); |
| 9244 | } |
| 9245 | } |
| 9246 | |
| 9247 | /** |
| 9248 | * Get the full emergency number list for test mode. |
| 9249 | */ |
| 9250 | @Override |
| 9251 | public List<String> getEmergencyNumberListTestMode() { |
| 9252 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9253 | "getEmergencyNumberListTestMode"); |
| 9254 | |
| 9255 | final long identity = Binder.clearCallingIdentity(); |
| 9256 | try { |
| 9257 | Set<String> emergencyNumbers = new HashSet<>(); |
| 9258 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9259 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9260 | if (tracker != null) { |
| 9261 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 9262 | emergencyNumbers.add(num.getNumber()); |
| 9263 | } |
| 9264 | } |
| 9265 | } |
| 9266 | return new ArrayList<>(emergencyNumbers); |
| 9267 | } finally { |
| 9268 | Binder.restoreCallingIdentity(identity); |
| 9269 | } |
| 9270 | } |
| 9271 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9272 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9273 | public int getEmergencyNumberDbVersion(int subId) { |
| 9274 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 9275 | |
| 9276 | final long identity = Binder.clearCallingIdentity(); |
| 9277 | try { |
| 9278 | final Phone phone = getPhone(subId); |
| 9279 | if (phone == null) { |
| 9280 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 9281 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 9282 | } |
| 9283 | return phone.getEmergencyNumberDbVersion(); |
| 9284 | } finally { |
| 9285 | Binder.restoreCallingIdentity(identity); |
| 9286 | } |
| 9287 | } |
| 9288 | |
| 9289 | @Override |
| 9290 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 9291 | enforceModifyPermission(); |
| 9292 | |
| 9293 | final long identity = Binder.clearCallingIdentity(); |
| 9294 | try { |
| 9295 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9296 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9297 | if (tracker != null) { |
| 9298 | tracker.updateOtaEmergencyNumberDatabase(); |
| 9299 | } |
| 9300 | } |
| 9301 | } finally { |
| 9302 | Binder.restoreCallingIdentity(identity); |
| 9303 | } |
| 9304 | } |
| 9305 | |
| 9306 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9307 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9308 | enforceActiveEmergencySessionPermission(); |
| 9309 | |
| 9310 | final long identity = Binder.clearCallingIdentity(); |
| 9311 | try { |
| 9312 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9313 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9314 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 9315 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 9316 | } |
| 9317 | } |
| 9318 | } finally { |
| 9319 | Binder.restoreCallingIdentity(identity); |
| 9320 | } |
| 9321 | } |
| 9322 | |
| 9323 | @Override |
| 9324 | public void resetOtaEmergencyNumberDbFilePath() { |
| 9325 | enforceActiveEmergencySessionPermission(); |
| 9326 | |
| 9327 | final long identity = Binder.clearCallingIdentity(); |
| 9328 | try { |
| 9329 | for (Phone phone: PhoneFactory.getPhones()) { |
| 9330 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 9331 | if (tracker != null) { |
| 9332 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 9333 | } |
| 9334 | } |
| 9335 | } finally { |
| 9336 | Binder.restoreCallingIdentity(identity); |
| 9337 | } |
| 9338 | } |
| 9339 | |
| 9340 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 9341 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 9342 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 9343 | Phone phone = getPhone(subId); |
| 9344 | if (phone == null) { |
| 9345 | return null; |
| 9346 | } |
| 9347 | final long identity = Binder.clearCallingIdentity(); |
| 9348 | try { |
| 9349 | UiccProfile profile = UiccController.getInstance() |
| 9350 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 9351 | if (profile != null) { |
| 9352 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 9353 | } |
| 9354 | } finally { |
| 9355 | Binder.restoreCallingIdentity(identity); |
| 9356 | } |
| 9357 | return null; |
| 9358 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 9359 | |
| 9360 | /** |
| 9361 | * Enable or disable a modem stack. |
| 9362 | */ |
| 9363 | @Override |
| 9364 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 9365 | enforceModifyPermission(); |
| 9366 | |
| 9367 | final long identity = Binder.clearCallingIdentity(); |
| 9368 | try { |
| 9369 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9370 | if (phone == null) { |
| 9371 | return false; |
| 9372 | } else { |
| 9373 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 9374 | } |
| 9375 | } finally { |
| 9376 | Binder.restoreCallingIdentity(identity); |
| 9377 | } |
| 9378 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9379 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9380 | /** |
| 9381 | * Whether a modem stack is enabled or not. |
| 9382 | */ |
| 9383 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9384 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 9385 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9386 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 9387 | if (phone == null) return false; |
| 9388 | |
| 9389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9390 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 9391 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9392 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9393 | } |
| 9394 | |
| 9395 | final long identity = Binder.clearCallingIdentity(); |
| 9396 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 9397 | try { |
| 9398 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 9399 | } catch (NoSuchElementException ex) { |
| 9400 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 9401 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 9402 | } finally { |
| 9403 | Binder.restoreCallingIdentity(identity); |
| 9404 | } |
| 9405 | } |
| 9406 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9407 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9408 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9409 | enforceModifyPermission(); |
| 9410 | |
| 9411 | final long identity = Binder.clearCallingIdentity(); |
| 9412 | try { |
| 9413 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9414 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9415 | .commit(); |
| 9416 | } finally { |
| 9417 | Binder.restoreCallingIdentity(identity); |
| 9418 | } |
| 9419 | } |
| 9420 | |
| 9421 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9422 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9423 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9424 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9425 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 9426 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9427 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 9428 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9429 | |
| 9430 | final long identity = Binder.clearCallingIdentity(); |
| 9431 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9432 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 9433 | } finally { |
| 9434 | Binder.restoreCallingIdentity(identity); |
| 9435 | } |
| 9436 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9437 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9438 | @TelephonyManager.IsMultiSimSupportedResult |
| 9439 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9440 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 9441 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 9442 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9443 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 9444 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9445 | } |
| 9446 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 9447 | // supported by the modem, indicate that it is restricted. |
| 9448 | PhoneCapability staticCapability = |
| 9449 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 9450 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9451 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 9452 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9453 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 9454 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9455 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 9456 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9457 | } |
| 9458 | // Check if support of multiple SIMs is restricted by carrier |
| 9459 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9460 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9461 | } |
| 9462 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9463 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9464 | } |
| 9465 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9466 | /** |
| 9467 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9468 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 9469 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 9470 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9471 | * @param numOfSims number of active sims we want to switch to |
| 9472 | */ |
| 9473 | @Override |
| 9474 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 9475 | if (numOfSims == 1) { |
| 9476 | enforceModifyPermission(); |
| 9477 | } else { |
| 9478 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9479 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 9480 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9481 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9482 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9483 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9484 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 9485 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 9486 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 9487 | return; |
| 9488 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9489 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 9490 | } finally { |
| 9491 | Binder.restoreCallingIdentity(identity); |
| 9492 | } |
| 9493 | } |
| 9494 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9495 | @Override |
| 9496 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 9497 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 9498 | Phone phone = getPhone(subId); |
| 9499 | if (phone == null) { |
| 9500 | return false; |
| 9501 | } |
| 9502 | final long identity = Binder.clearCallingIdentity(); |
| 9503 | try { |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9504 | UiccPort uiccPort = phone.getUiccPort(); |
| 9505 | if (uiccPort == null) { |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9506 | return false; |
| 9507 | } |
Muralidhar Reddy | 864fe98 | 2021-09-29 19:38:40 +0000 | [diff] [blame] | 9508 | UiccProfile uiccProfile = uiccPort.getUiccProfile(); |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 9509 | if (uiccProfile == null) { |
| 9510 | return false; |
| 9511 | } |
| 9512 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 9513 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 9514 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 9515 | } |
| 9516 | return false; |
| 9517 | } finally { |
| 9518 | Binder.restoreCallingIdentity(identity); |
| 9519 | } |
| 9520 | } |
| 9521 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 9522 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9523 | * Get whether making changes to modem configurations will trigger reboot. |
| 9524 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9525 | */ |
| 9526 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9527 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 9528 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 9530 | mApp, subId, callingPackage, callingFeatureId, |
| 9531 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 9532 | return false; |
| 9533 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 9534 | final long identity = Binder.clearCallingIdentity(); |
| 9535 | try { |
| 9536 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 9537 | } finally { |
| 9538 | Binder.restoreCallingIdentity(identity); |
| 9539 | } |
| 9540 | } |
| 9541 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 9542 | private void updateModemStateMetrics() { |
| 9543 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 9544 | // TODO: check the state for each modem if the api is ready. |
| 9545 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 9546 | } |
| 9547 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9548 | @Override |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9549 | public List<UiccSlotMapping> getSlotsMapping(String callingPackage) { |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9550 | enforceReadPrivilegedPermission("getSlotsMapping"); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9551 | // Verify that the callingPackage belongs to the calling UID |
| 9552 | mApp.getSystemService(AppOpsManager.class) |
| 9553 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9554 | final long identity = Binder.clearCallingIdentity(); |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9555 | List<UiccSlotMapping> slotMap = new ArrayList<>(); |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9556 | try { |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9557 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName()); |
| 9558 | if (slotInfos != null) { |
| 9559 | for (int i = 0; i < slotInfos.length; i++) { |
| 9560 | for (UiccPortInfo portInfo : slotInfos[i].getPorts()) { |
| 9561 | if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) { |
| 9562 | slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i, |
| 9563 | portInfo.getLogicalSlotIndex())); |
| 9564 | } |
| 9565 | } |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9566 | } |
| 9567 | } |
sandeepjs | 29b7e8e | 2021-11-17 04:05:58 +0000 | [diff] [blame] | 9568 | return slotMap; |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 9569 | } finally { |
| 9570 | Binder.restoreCallingIdentity(identity); |
| 9571 | } |
| 9572 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9573 | |
| 9574 | /** |
| 9575 | * Get the IRadio HAL Version |
| 9576 | */ |
| 9577 | @Override |
| 9578 | public int getRadioHalVersion() { |
| 9579 | Phone phone = getDefaultPhone(); |
| 9580 | if (phone == null) return -1; |
| 9581 | HalVersion hv = phone.getHalVersion(); |
| 9582 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9583 | return hv.major * 100 + hv.minor; |
| 9584 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9585 | |
| 9586 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9587 | * Get the current calling package name. |
| 9588 | * @return the current calling package name |
| 9589 | */ |
| 9590 | @Override |
| 9591 | public String getCurrentPackageName() { |
| 9592 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9593 | } |
| 9594 | |
| 9595 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9596 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9597 | * corresponding network requests on a subId. |
| 9598 | * |
| 9599 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9600 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9601 | * 2) APN is un-metered for this subscription, or |
| 9602 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9603 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9604 | * |
| 9605 | * @return whether data is allowed for a apn type. |
| 9606 | * |
| 9607 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9608 | */ |
| 9609 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9610 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9611 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9612 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9613 | |
| 9614 | // Now that all security checks passes, perform the operation as ourselves. |
| 9615 | final long identity = Binder.clearCallingIdentity(); |
| 9616 | try { |
| 9617 | Phone phone = getPhone(subId); |
| 9618 | if (phone == null) return false; |
| 9619 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9620 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9621 | boolean isDataEnabled; |
| 9622 | if (phone.isUsingNewDataStack()) { |
| 9623 | isDataEnabled = phone.getDataSettingsManager().isDataEnabled(apnType); |
| 9624 | } else { |
| 9625 | isDataEnabled = phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9626 | } |
| 9627 | return !isMetered || isDataEnabled; |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9628 | } finally { |
| 9629 | Binder.restoreCallingIdentity(identity); |
| 9630 | } |
| 9631 | } |
| 9632 | |
| 9633 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9634 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9635 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9636 | |
| 9637 | // Now that all security checks passes, perform the operation as ourselves. |
| 9638 | final long identity = Binder.clearCallingIdentity(); |
| 9639 | try { |
| 9640 | Phone phone = getPhone(subId); |
| 9641 | if (phone == null) return true; // By default return true. |
| 9642 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9643 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9644 | } finally { |
| 9645 | Binder.restoreCallingIdentity(identity); |
| 9646 | } |
| 9647 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9648 | |
| 9649 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9650 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9651 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9652 | enforceModifyPermission(); |
| 9653 | long token = Binder.clearCallingIdentity(); |
| 9654 | try { |
| 9655 | Phone phone = getPhone(subscriptionId); |
| 9656 | if (phone == null) { |
| 9657 | try { |
| 9658 | if (resultCallback != null) { |
| 9659 | resultCallback.accept(false); |
| 9660 | } |
| 9661 | } catch (RemoteException e) { |
| 9662 | // ignore |
| 9663 | } |
| 9664 | return; |
| 9665 | } |
| 9666 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9667 | Pair.create(specifiers, (x) -> { |
| 9668 | try { |
| 9669 | if (resultCallback != null) { |
| 9670 | resultCallback.accept(x); |
| 9671 | } |
| 9672 | } catch (RemoteException e) { |
| 9673 | // ignore |
| 9674 | } |
| 9675 | }); |
| 9676 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9677 | } finally { |
| 9678 | Binder.restoreCallingIdentity(token); |
| 9679 | } |
| 9680 | } |
| 9681 | |
| 9682 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9683 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9684 | TelephonyPermissions |
Nathan Harold | 62c6851 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9685 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9686 | mApp, subId, "getSystemSelectionChannels"); |
| 9687 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9688 | final long identity = Binder.clearCallingIdentity(); |
| 9689 | try { |
Sarah Chin | 428d1d6 | 2021-03-13 03:17:40 -0800 | [diff] [blame] | 9690 | Object result = sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, null, subId, workSource); |
| 9691 | if (result instanceof IllegalStateException) { |
| 9692 | throw (IllegalStateException) result; |
| 9693 | } |
| 9694 | List<RadioAccessSpecifier> specifiers = (List<RadioAccessSpecifier>) result; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9695 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9696 | return specifiers; |
| 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | } |
| 9701 | |
| 9702 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9703 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9704 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9705 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9706 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9707 | if (iccRecords == null) { |
| 9708 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9709 | return false; |
| 9710 | } |
| 9711 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9712 | } |
| 9713 | |
| 9714 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9715 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9716 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9717 | if (callingPackage == null) { |
| 9718 | callingPackage = getCurrentPackageName(); |
| 9719 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9720 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9721 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9722 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9723 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9724 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9725 | } |
| 9726 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9727 | Intent intent = new Intent(); |
| 9728 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9729 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9730 | // Bring up choose default SMS subscription dialog right now |
| 9731 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9732 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9733 | mApp.startActivity(intent); |
| 9734 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9735 | |
| 9736 | @Override |
| 9737 | public String getMmsUAProfUrl(int subId) { |
| 9738 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9739 | final long identity = Binder.clearCallingIdentity(); |
| 9740 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9741 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9742 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9743 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9744 | return carrierUAProfUrl; |
| 9745 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9746 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9747 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | @Override |
| 9754 | public String getMmsUserAgent(int subId) { |
| 9755 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9756 | final long identity = Binder.clearCallingIdentity(); |
| 9757 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9758 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9759 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9760 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9761 | return carrierUserAgent; |
| 9762 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9763 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9764 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9765 | } finally { |
| 9766 | Binder.restoreCallingIdentity(identity); |
| 9767 | } |
| 9768 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9769 | |
| 9770 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9771 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9772 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9773 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9774 | final long identity = Binder.clearCallingIdentity(); |
| 9775 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9776 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9777 | if (phone == null) return false; |
| 9778 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9779 | switch (policy) { |
| 9780 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9781 | if (phone.isUsingNewDataStack()) { |
| 9782 | return phone.getDataSettingsManager().isDataAllowedInVoiceCall(); |
| 9783 | } else { |
| 9784 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9785 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9786 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9787 | if (phone.isUsingNewDataStack()) { |
| 9788 | return phone.getDataSettingsManager().isMmsAlwaysAllowed(); |
| 9789 | } else { |
| 9790 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9791 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9792 | default: |
| 9793 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9794 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9795 | } finally { |
| 9796 | Binder.restoreCallingIdentity(identity); |
| 9797 | } |
| 9798 | } |
| 9799 | |
| 9800 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9801 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9802 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9803 | enforceModifyPermission(); |
| 9804 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9805 | final long identity = Binder.clearCallingIdentity(); |
| 9806 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9807 | Phone phone = getPhone(subscriptionId); |
| 9808 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9809 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9810 | switch (policy) { |
| 9811 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9812 | if (phone.isUsingNewDataStack()) { |
| 9813 | phone.getDataSettingsManager().setAllowDataDuringVoiceCall(enabled); |
| 9814 | } else { |
| 9815 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9816 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9817 | break; |
| 9818 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
Jack Yu | 6bc9c8b | 2021-12-17 23:14:15 -0800 | [diff] [blame] | 9819 | if (phone.isUsingNewDataStack()) { |
| 9820 | phone.getDataSettingsManager().setAlwaysAllowMmsData(enabled); |
| 9821 | } else { |
| 9822 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9823 | } |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9824 | break; |
| 9825 | default: |
| 9826 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9827 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9828 | } finally { |
| 9829 | Binder.restoreCallingIdentity(identity); |
| 9830 | } |
| 9831 | } |
| 9832 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9833 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9834 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9835 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9836 | * otherwise. |
| 9837 | */ |
| 9838 | @Override |
| 9839 | public void setCepEnabled(boolean isCepEnabled) { |
| 9840 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9841 | |
| 9842 | final long identity = Binder.clearCallingIdentity(); |
| 9843 | try { |
| 9844 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9845 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9846 | Phone defaultPhone = phone.getImsPhone(); |
| 9847 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9848 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9849 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9850 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9851 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9852 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9853 | + imsPhone.getMsisdn()); |
| 9854 | } |
| 9855 | } |
| 9856 | } finally { |
| 9857 | Binder.restoreCallingIdentity(identity); |
| 9858 | } |
| 9859 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9860 | |
| 9861 | /** |
| 9862 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9863 | * |
| 9864 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9865 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9866 | * before being read. |
| 9867 | */ |
| 9868 | @Override |
| 9869 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9870 | isCompressed) { |
| 9871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9872 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9873 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9874 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9875 | } |
| 9876 | if (!isImsAvailableOnDevice()) { |
| 9877 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9878 | "IMS not available on device."); |
| 9879 | } |
| 9880 | |
| 9881 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9882 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9883 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9884 | } finally { |
| 9885 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9886 | } |
| 9887 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9888 | |
| 9889 | @Override |
| 9890 | public boolean isIccLockEnabled(int subId) { |
| 9891 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9892 | |
| 9893 | // Now that all security checks passes, perform the operation as ourselves. |
| 9894 | final long identity = Binder.clearCallingIdentity(); |
| 9895 | try { |
| 9896 | Phone phone = getPhone(subId); |
| 9897 | if (phone != null && phone.getIccCard() != null) { |
| 9898 | return phone.getIccCard().getIccLockEnabled(); |
| 9899 | } else { |
| 9900 | return false; |
| 9901 | } |
| 9902 | } finally { |
| 9903 | Binder.restoreCallingIdentity(identity); |
| 9904 | } |
| 9905 | } |
| 9906 | |
| 9907 | /** |
| 9908 | * Set the ICC pin lock enabled or disabled. |
| 9909 | * |
| 9910 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9911 | * three cases: |
| 9912 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9913 | * successfully. |
| 9914 | * - Positive number and zero for remaining password attempts. |
| 9915 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9916 | * |
| 9917 | */ |
| 9918 | @Override |
| 9919 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9920 | enforceModifyPermission(); |
| 9921 | |
| 9922 | Phone phone = getPhone(subId); |
| 9923 | if (phone == null) { |
| 9924 | return 0; |
| 9925 | } |
| 9926 | // Now that all security checks passes, perform the operation as ourselves. |
| 9927 | final long identity = Binder.clearCallingIdentity(); |
| 9928 | try { |
| 9929 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9930 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9931 | return attemptsRemaining; |
| 9932 | |
| 9933 | } catch (Exception e) { |
| 9934 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9935 | } finally { |
| 9936 | Binder.restoreCallingIdentity(identity); |
| 9937 | } |
| 9938 | return 0; |
| 9939 | } |
| 9940 | |
| 9941 | /** |
| 9942 | * Change the ICC password used in ICC pin lock. |
| 9943 | * |
| 9944 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9945 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9946 | * - Positive number and zero for remaining password attempts. |
| 9947 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9948 | * |
| 9949 | */ |
| 9950 | @Override |
| 9951 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9952 | enforceModifyPermission(); |
| 9953 | |
| 9954 | Phone phone = getPhone(subId); |
| 9955 | if (phone == null) { |
| 9956 | return 0; |
| 9957 | } |
| 9958 | // Now that all security checks passes, perform the operation as ourselves. |
| 9959 | final long identity = Binder.clearCallingIdentity(); |
| 9960 | try { |
| 9961 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9962 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9963 | return attemptsRemaining; |
| 9964 | |
| 9965 | } catch (Exception e) { |
| 9966 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9967 | } finally { |
| 9968 | Binder.restoreCallingIdentity(identity); |
| 9969 | } |
| 9970 | return 0; |
| 9971 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9972 | |
| 9973 | /** |
| 9974 | * Request for receiving user activity notification |
| 9975 | */ |
| 9976 | @Override |
| 9977 | public void requestUserActivityNotification() { |
| 9978 | if (!mNotifyUserActivity.get() |
| 9979 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9980 | mNotifyUserActivity.set(true); |
| 9981 | } |
| 9982 | } |
| 9983 | |
| 9984 | /** |
| 9985 | * Called when userActivity is signalled in the power manager. |
| 9986 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9987 | */ |
| 9988 | @Override |
| 9989 | public void userActivity() { |
| 9990 | // *************************************** |
| 9991 | // * Inherited from PhoneWindowManager * |
| 9992 | // *************************************** |
| 9993 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9994 | // WITH ITS LOCKS HELD. |
| 9995 | // |
| 9996 | // This code must be VERY careful about the locks |
| 9997 | // it acquires. |
| 9998 | // In fact, the current code acquires way too many, |
| 9999 | // and probably has lurking deadlocks. |
| 10000 | |
| 10001 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 10002 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 10003 | } |
| 10004 | |
| 10005 | if (mNotifyUserActivity.getAndSet(false)) { |
| 10006 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 10007 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 10008 | } |
| 10009 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 10010 | |
| 10011 | @Override |
| 10012 | public boolean canConnectTo5GInDsdsMode() { |
| 10013 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 10014 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 10015 | |
| 10016 | @Override |
| 10017 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 10018 | String callingFeatureId) { |
| 10019 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 10020 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 10021 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 10022 | } |
| 10023 | |
| 10024 | Phone phone = getPhone(subId); |
| 10025 | if (phone == null) { |
| 10026 | throw new RuntimeException("phone is not available"); |
| 10027 | } |
| 10028 | // Now that all security checks passes, perform the operation as ourselves. |
| 10029 | final long identity = Binder.clearCallingIdentity(); |
| 10030 | try { |
| 10031 | return phone.getEquivalentHomePlmns(); |
| 10032 | } finally { |
| 10033 | Binder.restoreCallingIdentity(identity); |
| 10034 | } |
| 10035 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10036 | |
| 10037 | @Override |
| 10038 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10039 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 10040 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 94f4366 | 2021-03-01 14:43:40 -0800 | [diff] [blame] | 10041 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10042 | if (radioInterfaceCapabilities == null) { |
| 10043 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10044 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame] | 10045 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 10046 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10047 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10048 | @Override |
| 10049 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 10050 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10051 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 10052 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10053 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 10054 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10055 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10056 | if (DBG) { |
| 10057 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 10058 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 10059 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 10060 | } |
| 10061 | |
| 10062 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 10063 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 10064 | || appType > TelephonyManager.APPTYPE_ISIM |
| 10065 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 10066 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 10067 | if (callback != null) { |
| 10068 | try { |
| 10069 | callback.onAuthenticationFailure( |
| 10070 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 10071 | } catch (RemoteException exception) { |
| 10072 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 10073 | } |
| 10074 | return; |
| 10075 | } |
| 10076 | } |
| 10077 | |
| 10078 | final long token = Binder.clearCallingIdentity(); |
| 10079 | try { |
| 10080 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 10081 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 10082 | forceBootStrapping, callback)); |
| 10083 | } finally { |
| 10084 | Binder.restoreCallingIdentity(token); |
| 10085 | } |
| 10086 | } |
| 10087 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10088 | /** |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10089 | * Attempts to set the radio power state for all phones for thermal reason. |
| 10090 | * This does not guarantee that the |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10091 | * requested radio power state will actually be set. See {@link |
| 10092 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 10093 | * |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10094 | * @param enable {@code true} if trying to turn radio on. |
| 10095 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 10096 | * false}. |
| 10097 | */ |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10098 | private boolean setRadioPowerForThermal(boolean enable) { |
| 10099 | boolean isPhoneAvailable = false; |
| 10100 | for (int i = 0; i < TelephonyManager.getDefault().getActiveModemCount(); i++) { |
| 10101 | Phone phone = PhoneFactory.getPhone(i); |
| 10102 | if (phone != null) { |
| 10103 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 10104 | isPhoneAvailable = true; |
| 10105 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10106 | } |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10107 | |
| 10108 | // return true if successfully informed the phone object about the thermal radio power |
| 10109 | // request. |
| 10110 | return isPhoneAvailable; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10111 | } |
| 10112 | |
| 10113 | private int handleDataThrottlingRequest(int subId, |
| 10114 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10115 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 10116 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 10117 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 10118 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 10119 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 10120 | } |
| 10121 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10122 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 10123 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10124 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10125 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10126 | } |
| 10127 | |
| 10128 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 10129 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10130 | if (isDataThrottlingSupported) { |
| 10131 | int thermalMitigationResult = |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10132 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10133 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 10134 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 10135 | } else if (thermalMitigationResult |
| 10136 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
Jack Nudelman | 760d096 | 2021-05-20 13:57:30 -0700 | [diff] [blame] | 10137 | log("Modem likely does not support data throttling on secondary carrier. Data " + |
| 10138 | "throttling action = " + dataThrottlingRequest.getDataThrottlingAction()); |
| 10139 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10140 | } |
| 10141 | return thermalMitigationResult; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10142 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 10143 | |
| 10144 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10145 | } |
| 10146 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10147 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 10148 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 10149 | for (String pckg : context.getResources() |
| 10150 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 10151 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 10152 | } |
| 10153 | } |
| 10154 | |
| 10155 | return sThermalMitigationAllowlistedPackages; |
| 10156 | } |
| 10157 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10158 | private boolean isAnyPhoneInEmergencyState() { |
| 10159 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 10160 | if (tm.isInEmergencyCall()) { |
| 10161 | Log.e(LOG_TAG , "Phone state is not valid. One of the phones is in an emergency call"); |
| 10162 | return true; |
| 10163 | } |
| 10164 | for (Phone phone : PhoneFactory.getPhones()) { |
| 10165 | if (phone.isInEmergencySmsMode() || phone.isInEcm()) { |
| 10166 | Log.e(LOG_TAG, "Phone state is not valid. isInEmergencySmsMode = " |
| 10167 | + phone.isInEmergencySmsMode() + " isInEmergencyCallbackMode = " |
| 10168 | + phone.isInEcm()); |
| 10169 | return true; |
| 10170 | } |
| 10171 | } |
| 10172 | |
| 10173 | return false; |
| 10174 | } |
| 10175 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10176 | /** |
| 10177 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 10178 | * @param packageName name of package to be allowlisted |
| 10179 | * @param context |
| 10180 | */ |
| 10181 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 10182 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10183 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 10184 | } |
| 10185 | |
| 10186 | /** |
| 10187 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 10188 | * @param packageName name of package to remove from allowlist |
| 10189 | * @param context |
| 10190 | */ |
| 10191 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 10192 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 10193 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 10194 | } |
| 10195 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10196 | /** |
| 10197 | * Thermal mitigation request to control functionalities at modem. |
| 10198 | * |
| 10199 | * @param subId the id of the subscription. |
| 10200 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10201 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10202 | * |
| 10203 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 10204 | */ |
| 10205 | @Override |
| 10206 | @ThermalMitigationResult |
| 10207 | public int sendThermalMitigationRequest( |
| 10208 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10209 | ThermalMitigationRequest thermalMitigationRequest, |
| 10210 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10211 | enforceModifyPermission(); |
| 10212 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 10213 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 10214 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 10215 | .contains(callingPackage)) { |
| 10216 | throw new SecurityException("Calling package must be configured in the device config. " |
| 10217 | + "calling package: " + callingPackage); |
| 10218 | } |
| 10219 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10220 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 10221 | final long identity = Binder.clearCallingIdentity(); |
| 10222 | |
| 10223 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 10224 | try { |
| 10225 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 10226 | switch (thermalMitigationAction) { |
| 10227 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 10228 | thermalMitigationResult = |
| 10229 | handleDataThrottlingRequest(subId, |
| 10230 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 10231 | break; |
| 10232 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 10233 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10234 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 10235 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 10236 | } |
| 10237 | |
| 10238 | // Ensure that radio is on. If not able to power on due to phone being |
| 10239 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10240 | if (!setRadioPowerForThermal(true)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10241 | thermalMitigationResult = |
| 10242 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10243 | break; |
| 10244 | } |
| 10245 | |
| 10246 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 10247 | false); |
| 10248 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10249 | break; |
| 10250 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 10251 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 10252 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 10253 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 10254 | } |
| 10255 | |
| 10256 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 10257 | if (registry != null) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10258 | Phone phone = getPhone(subId); |
| 10259 | if (phone == null) { |
| 10260 | thermalMitigationResult = |
| 10261 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10262 | break; |
| 10263 | } |
| 10264 | |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10265 | TelephonyConnectionService service = |
| 10266 | registry.getTelephonyConnectionService(); |
Jack Nudelman | b30ac30 | 2021-06-17 15:39:58 -0700 | [diff] [blame] | 10267 | if (service != null && service.isEmergencyCallPending()) { |
Jack Nudelman | e69bbc8 | 2021-05-13 10:00:15 -0700 | [diff] [blame] | 10268 | Log.e(LOG_TAG, "An emergency call is pending"); |
| 10269 | thermalMitigationResult = |
| 10270 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10271 | break; |
| 10272 | } else if (isAnyPhoneInEmergencyState()) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10273 | thermalMitigationResult = |
| 10274 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 10275 | break; |
| 10276 | } |
| 10277 | } else { |
| 10278 | thermalMitigationResult = |
| 10279 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10280 | break; |
| 10281 | } |
| 10282 | |
| 10283 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 10284 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
Sooraj Sasindran | 72cff49 | 2021-07-29 09:42:42 -0700 | [diff] [blame] | 10285 | if (!setRadioPowerForThermal(false)) { |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 10286 | thermalMitigationResult = |
| 10287 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 10288 | break; |
| 10289 | } |
| 10290 | thermalMitigationResult = |
| 10291 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 10292 | break; |
| 10293 | default: |
| 10294 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 10295 | + "not exist. Requested action: " + thermalMitigationAction); |
| 10296 | } |
| 10297 | } catch (IllegalArgumentException e) { |
| 10298 | throw e; |
| 10299 | } catch (Exception e) { |
| 10300 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 10301 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 10302 | } finally { |
| 10303 | Binder.restoreCallingIdentity(identity); |
| 10304 | } |
| 10305 | |
| 10306 | if (DBG) { |
| 10307 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 10308 | + thermalMitigationResult); |
| 10309 | } |
| 10310 | |
| 10311 | return thermalMitigationResult; |
| 10312 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 10313 | |
| 10314 | /** |
| 10315 | * Set the GbaService Package Name that Telephony will bind to. |
| 10316 | * |
| 10317 | * @param subId The sim that the GbaService is associated with. |
| 10318 | * @param packageName The name of the package to be replaced with. |
| 10319 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10320 | */ |
| 10321 | @Override |
| 10322 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 10323 | enforceModifyPermission(); |
| 10324 | |
| 10325 | final long identity = Binder.clearCallingIdentity(); |
| 10326 | try { |
| 10327 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 10328 | } finally { |
| 10329 | Binder.restoreCallingIdentity(identity); |
| 10330 | } |
| 10331 | } |
| 10332 | |
| 10333 | /** |
| 10334 | * Return the package name of the currently bound GbaService. |
| 10335 | * |
| 10336 | * @param subId The sim that the GbaService is associated with. |
| 10337 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 10338 | */ |
| 10339 | @Override |
| 10340 | public String getBoundGbaService(int subId) { |
| 10341 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 10342 | |
| 10343 | final long identity = Binder.clearCallingIdentity(); |
| 10344 | try { |
| 10345 | return getGbaManager(subId).getServicePackage(); |
| 10346 | } finally { |
| 10347 | Binder.restoreCallingIdentity(identity); |
| 10348 | } |
| 10349 | } |
| 10350 | |
| 10351 | /** |
| 10352 | * Set the release time for telephony to unbind GbaService. |
| 10353 | * |
| 10354 | * @param subId The sim that the GbaService is associated with. |
| 10355 | * @param interval The release time to unbind GbaService by millisecond. |
| 10356 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 10357 | */ |
| 10358 | @Override |
| 10359 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 10360 | enforceModifyPermission(); |
| 10361 | |
| 10362 | final long identity = Binder.clearCallingIdentity(); |
| 10363 | try { |
| 10364 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 10365 | } finally { |
| 10366 | Binder.restoreCallingIdentity(identity); |
| 10367 | } |
| 10368 | } |
| 10369 | |
| 10370 | /** |
| 10371 | * Return the release time for telephony to unbind GbaService. |
| 10372 | * |
| 10373 | * @param subId The sim that the GbaService is associated with. |
| 10374 | * @return The release time to unbind GbaService by millisecond. |
| 10375 | */ |
| 10376 | @Override |
| 10377 | public int getGbaReleaseTime(int subId) { |
| 10378 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 10379 | |
| 10380 | final long identity = Binder.clearCallingIdentity(); |
| 10381 | try { |
| 10382 | return getGbaManager(subId).getReleaseTime(); |
| 10383 | } finally { |
| 10384 | Binder.restoreCallingIdentity(identity); |
| 10385 | } |
| 10386 | } |
| 10387 | |
| 10388 | private GbaManager getGbaManager(int subId) { |
| 10389 | GbaManager instance = GbaManager.getInstance(subId); |
| 10390 | if (instance == null) { |
| 10391 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 10392 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 10393 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 10394 | } |
| 10395 | return instance; |
| 10396 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10397 | |
| 10398 | /** |
| 10399 | * indicate whether the device and the carrier can support |
| 10400 | * RCS VoLTE single registration. |
| 10401 | */ |
| 10402 | @Override |
| 10403 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10404 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 10405 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 10406 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10407 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10408 | |
| 10409 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10410 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10411 | } |
| 10412 | |
| 10413 | final long identity = Binder.clearCallingIdentity(); |
| 10414 | try { |
| 10415 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 10416 | if (rpm != null) { |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10417 | Boolean isCapable = rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 10418 | if (isCapable != null) { |
| 10419 | return isCapable; |
| 10420 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10421 | } |
Hui Wang | 67af90e | 2021-06-04 16:57:15 -0700 | [diff] [blame] | 10422 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10423 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10424 | } finally { |
| 10425 | Binder.restoreCallingIdentity(identity); |
| 10426 | } |
| 10427 | } |
| 10428 | |
| 10429 | /** |
| 10430 | * Register RCS provisioning callback. |
| 10431 | */ |
| 10432 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10433 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10434 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10435 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10436 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10437 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10438 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10439 | |
| 10440 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10441 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10442 | } |
| 10443 | if (!isImsAvailableOnDevice()) { |
| 10444 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10445 | "IMS not available on device."); |
| 10446 | } |
| 10447 | |
| 10448 | final long identity = Binder.clearCallingIdentity(); |
| 10449 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10450 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10451 | .registerRcsProvisioningCallback(subId, callback)) { |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10452 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10453 | "Active subscription not found."); |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10454 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10455 | } finally { |
| 10456 | Binder.restoreCallingIdentity(identity); |
| 10457 | } |
| 10458 | } |
| 10459 | |
| 10460 | /** |
| 10461 | * Unregister RCS provisioning callback. |
| 10462 | */ |
| 10463 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10464 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10465 | IRcsConfigCallback callback) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10466 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10467 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10468 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 10469 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10470 | |
| 10471 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10472 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10473 | } |
| 10474 | if (!isImsAvailableOnDevice()) { |
| 10475 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10476 | "IMS not available on device."); |
| 10477 | } |
| 10478 | |
| 10479 | final long identity = Binder.clearCallingIdentity(); |
| 10480 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 10481 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 10482 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10483 | } finally { |
| 10484 | Binder.restoreCallingIdentity(identity); |
| 10485 | } |
| 10486 | } |
| 10487 | |
| 10488 | /** |
| 10489 | * trigger RCS reconfiguration. |
| 10490 | */ |
| 10491 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10492 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10493 | "triggerRcsReconfiguration", |
| 10494 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10495 | |
| 10496 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10497 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10498 | } |
| 10499 | if (!isImsAvailableOnDevice()) { |
| 10500 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10501 | "IMS not available on device."); |
| 10502 | } |
| 10503 | |
| 10504 | final long identity = Binder.clearCallingIdentity(); |
| 10505 | try { |
| 10506 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 10507 | } finally { |
| 10508 | Binder.restoreCallingIdentity(identity); |
| 10509 | } |
| 10510 | } |
| 10511 | |
| 10512 | /** |
| 10513 | * Provide the client configuration parameters of the RCS application. |
| 10514 | */ |
| 10515 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 34c09a5 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 10516 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 10517 | "setRcsClientConfiguration", |
| 10518 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10519 | |
| 10520 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 10521 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 10522 | } |
| 10523 | if (!isImsAvailableOnDevice()) { |
| 10524 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 10525 | "IMS not available on device."); |
| 10526 | } |
| 10527 | |
| 10528 | final long identity = Binder.clearCallingIdentity(); |
| 10529 | |
| 10530 | try { |
| 10531 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 10532 | if (configBinder == null) { |
| 10533 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10534 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION, |
| 10535 | "could not find the requested subscription"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10536 | } else { |
| 10537 | configBinder.setRcsClientConfiguration(rcc); |
| 10538 | } |
joonhunshin | fa31464 | 2021-09-17 06:33:39 +0000 | [diff] [blame] | 10539 | |
| 10540 | RcsStats.getInstance().onRcsClientProvisioningStats(subId, |
| 10541 | RCS_CLIENT_PROVISIONING_STATS__EVENT__CLIENT_PARAMS_SENT); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10542 | } catch (RemoteException e) { |
| 10543 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
Brad Ebinger | 919631e | 2021-06-02 17:46:35 -0700 | [diff] [blame] | 10544 | throw new ServiceSpecificException(ImsException.CODE_ERROR_SERVICE_UNAVAILABLE, |
| 10545 | "service is temporarily unavailable."); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10546 | } finally { |
| 10547 | Binder.restoreCallingIdentity(identity); |
| 10548 | } |
| 10549 | } |
| 10550 | |
| 10551 | /** |
Hui Wang | baaee6a | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 10552 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 10553 | */ |
| 10554 | @Override |
| 10555 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 10556 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10557 | "setRcsSingleRegistrationTestModeEnabled"); |
| 10558 | |
| 10559 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 10560 | } |
| 10561 | |
| 10562 | /** |
| 10563 | * Gets the test mode for RCS VoLTE single registration. |
| 10564 | */ |
| 10565 | @Override |
| 10566 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 10567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10568 | "getRcsSingleRegistrationTestModeEnabled"); |
| 10569 | |
| 10570 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 10571 | } |
| 10572 | |
| 10573 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10574 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 10575 | */ |
| 10576 | @Override |
| 10577 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 10578 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10579 | "setDeviceSingleRegistrationEnabledOverride"); |
| 10580 | enforceModifyPermission(); |
| 10581 | |
| 10582 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10583 | : Boolean.parseBoolean(enabledStr); |
| 10584 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 10585 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10586 | } |
| 10587 | |
| 10588 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10589 | * Sends a device to device communication message. Only usable via shell. |
| 10590 | * @param message message to send. |
| 10591 | * @param value message value. |
| 10592 | */ |
| 10593 | @Override |
| 10594 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 10595 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10596 | "sendDeviceToDeviceMessage"); |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10597 | enforceModifyPermission(); |
| 10598 | |
| 10599 | final long identity = Binder.clearCallingIdentity(); |
| 10600 | try { |
| 10601 | TelephonyConnectionService service = |
| 10602 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10603 | if (service == null) { |
| 10604 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 10605 | return; |
| 10606 | } |
| 10607 | service.sendTestDeviceToDeviceMessage(message, value); |
| 10608 | } finally { |
| 10609 | Binder.restoreCallingIdentity(identity); |
| 10610 | } |
| 10611 | } |
| 10612 | |
Tyler Gunn | babbda0 | 2021-02-10 11:05:02 -0800 | [diff] [blame] | 10613 | /** |
| 10614 | * Sets the specified device to device transport active. |
| 10615 | * @param transport The transport to set active. |
| 10616 | */ |
| 10617 | @Override |
| 10618 | public void setActiveDeviceToDeviceTransport(@NonNull String transport) { |
| 10619 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10620 | "setActiveDeviceToDeviceTransport"); |
| 10621 | enforceModifyPermission(); |
| 10622 | |
| 10623 | final long identity = Binder.clearCallingIdentity(); |
| 10624 | try { |
| 10625 | TelephonyConnectionService service = |
| 10626 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 10627 | if (service == null) { |
| 10628 | Rlog.e(LOG_TAG, "setActiveDeviceToDeviceTransport: not in a call."); |
| 10629 | return; |
| 10630 | } |
| 10631 | service.setActiveDeviceToDeviceTransport(transport); |
| 10632 | } finally { |
| 10633 | Binder.restoreCallingIdentity(identity); |
| 10634 | } |
| 10635 | } |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10636 | |
Tyler Gunn | d457521 | 2021-05-03 14:46:49 -0700 | [diff] [blame] | 10637 | @Override |
| 10638 | public void setDeviceToDeviceForceEnabled(boolean isForceEnabled) { |
| 10639 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10640 | "setDeviceToDeviceForceEnabled"); |
| 10641 | |
| 10642 | final long identity = Binder.clearCallingIdentity(); |
| 10643 | try { |
| 10644 | Arrays.stream(PhoneFactory.getPhones()).forEach( |
| 10645 | p -> { |
| 10646 | Phone thePhone = p.getImsPhone(); |
| 10647 | if (thePhone != null && thePhone instanceof ImsPhone) { |
| 10648 | ImsPhone imsPhone = (ImsPhone) thePhone; |
| 10649 | CallTracker tracker = imsPhone.getCallTracker(); |
| 10650 | if (tracker != null && tracker instanceof ImsPhoneCallTracker) { |
| 10651 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 10652 | (ImsPhoneCallTracker) tracker; |
| 10653 | imsPhoneCallTracker.setDeviceToDeviceForceEnabled(isForceEnabled); |
| 10654 | } |
| 10655 | } |
| 10656 | } |
| 10657 | ); |
| 10658 | } finally { |
| 10659 | Binder.restoreCallingIdentity(identity); |
| 10660 | } |
| 10661 | } |
| 10662 | |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 10663 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 10664 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 10665 | */ |
| 10666 | @Override |
| 10667 | public boolean getDeviceSingleRegistrationEnabled() { |
| 10668 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 10669 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 10670 | } |
| 10671 | |
| 10672 | /** |
| 10673 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10674 | */ |
| 10675 | @Override |
| 10676 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 10677 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10678 | "setCarrierSingleRegistrationEnabledOverride"); |
| 10679 | enforceModifyPermission(); |
| 10680 | |
| 10681 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10682 | : Boolean.parseBoolean(enabledStr); |
| 10683 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 10684 | subId, enabled); |
| 10685 | } |
| 10686 | |
| 10687 | /** |
| 10688 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 10689 | */ |
| 10690 | @Override |
| 10691 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 10692 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 10693 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 10694 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10695 | |
| 10696 | /** |
Hui Wang | b647abe | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 10697 | * Overrides the ims feature validation result |
| 10698 | */ |
| 10699 | @Override |
| 10700 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 10701 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10702 | "setImsFeatureValidationOverride"); |
| 10703 | |
| 10704 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 10705 | : Boolean.parseBoolean(enabledStr); |
| 10706 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 10707 | subId, enabled); |
| 10708 | } |
| 10709 | |
| 10710 | /** |
| 10711 | * Gets the ims feature validation override value |
| 10712 | */ |
| 10713 | @Override |
| 10714 | public boolean getImsFeatureValidationOverride(int subId) { |
| 10715 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10716 | "getImsFeatureValidationOverride"); |
| 10717 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 10718 | } |
| 10719 | |
| 10720 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 10721 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 10722 | * their mobile plan. |
| 10723 | */ |
| 10724 | @Override |
| 10725 | public String getMobileProvisioningUrl() { |
| 10726 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 10727 | final long identity = Binder.clearCallingIdentity(); |
| 10728 | try { |
| 10729 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 10730 | } finally { |
| 10731 | Binder.restoreCallingIdentity(identity); |
| 10732 | } |
| 10733 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10734 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10735 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 10736 | * Get the EAB contact from the EAB database. |
| 10737 | */ |
| 10738 | @Override |
| 10739 | public String getContactFromEab(String contact) { |
| 10740 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 10741 | enforceModifyPermission(); |
| 10742 | final long identity = Binder.clearCallingIdentity(); |
| 10743 | try { |
| 10744 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 10745 | } finally { |
| 10746 | Binder.restoreCallingIdentity(identity); |
| 10747 | } |
| 10748 | } |
| 10749 | |
| 10750 | /** |
Calvin Pan | a143432 | 2021-07-01 19:27:01 +0800 | [diff] [blame] | 10751 | * Get the EAB capability from the EAB database. |
| 10752 | */ |
| 10753 | @Override |
| 10754 | public String getCapabilityFromEab(String contact) { |
| 10755 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getCapabilityFromEab"); |
| 10756 | enforceModifyPermission(); |
| 10757 | final long identity = Binder.clearCallingIdentity(); |
| 10758 | try { |
| 10759 | return EabUtil.getCapabilityFromEab(getDefaultPhone().getContext(), contact); |
| 10760 | } finally { |
| 10761 | Binder.restoreCallingIdentity(identity); |
| 10762 | } |
| 10763 | } |
| 10764 | |
| 10765 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 10766 | * Remove the EAB contacts from the EAB database. |
| 10767 | */ |
| 10768 | @Override |
| 10769 | public int removeContactFromEab(int subId, String contacts) { |
| 10770 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 10771 | enforceModifyPermission(); |
| 10772 | final long identity = Binder.clearCallingIdentity(); |
| 10773 | try { |
| 10774 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10775 | } finally { |
| 10776 | Binder.restoreCallingIdentity(identity); |
| 10777 | } |
| 10778 | } |
| 10779 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10780 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10781 | public boolean getDeviceUceEnabled() { |
| 10782 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10783 | final long identity = Binder.clearCallingIdentity(); |
| 10784 | try { |
| 10785 | return mApp.getDeviceUceEnabled(); |
| 10786 | } finally { |
| 10787 | Binder.restoreCallingIdentity(identity); |
| 10788 | } |
| 10789 | } |
| 10790 | |
| 10791 | @Override |
| 10792 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10793 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10794 | final long identity = Binder.clearCallingIdentity(); |
| 10795 | try { |
| 10796 | mApp.setDeviceUceEnabled(isEnabled); |
| 10797 | } finally { |
| 10798 | Binder.restoreCallingIdentity(identity); |
| 10799 | } |
| 10800 | } |
| 10801 | |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10802 | /** |
| 10803 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10804 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10805 | */ |
| 10806 | // Used for SHELL command only right now. |
| 10807 | @Override |
| 10808 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10809 | List<String> featureTags) { |
| 10810 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10811 | "addUceRegistrationOverrideShell"); |
| 10812 | final long identity = Binder.clearCallingIdentity(); |
| 10813 | try { |
| 10814 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10815 | new ArraySet<>(featureTags)); |
| 10816 | } catch (ImsException e) { |
| 10817 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10818 | } finally { |
| 10819 | Binder.restoreCallingIdentity(identity); |
| 10820 | } |
| 10821 | } |
| 10822 | |
| 10823 | /** |
| 10824 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10825 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10826 | */ |
| 10827 | // Used for SHELL command only right now. |
| 10828 | @Override |
| 10829 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10830 | List<String> featureTags) { |
| 10831 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10832 | "removeUceRegistrationOverrideShell"); |
| 10833 | final long identity = Binder.clearCallingIdentity(); |
| 10834 | try { |
| 10835 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10836 | new ArraySet<>(featureTags)); |
| 10837 | } catch (ImsException e) { |
| 10838 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10839 | } finally { |
| 10840 | Binder.restoreCallingIdentity(identity); |
| 10841 | } |
| 10842 | } |
| 10843 | |
| 10844 | /** |
| 10845 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10846 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10847 | */ |
| 10848 | // Used for SHELL command only right now. |
| 10849 | @Override |
| 10850 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10851 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10852 | "clearUceRegistrationOverrideShell"); |
| 10853 | final long identity = Binder.clearCallingIdentity(); |
| 10854 | try { |
| 10855 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10856 | } catch (ImsException e) { |
| 10857 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10858 | } finally { |
| 10859 | Binder.restoreCallingIdentity(identity); |
| 10860 | } |
| 10861 | } |
| 10862 | |
| 10863 | /** |
| 10864 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10865 | */ |
| 10866 | // Used for SHELL command only right now. |
| 10867 | @Override |
| 10868 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10869 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10870 | "getLatestRcsContactUceCapabilityShell"); |
| 10871 | final long identity = Binder.clearCallingIdentity(); |
| 10872 | try { |
| 10873 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10874 | } catch (ImsException e) { |
| 10875 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10876 | } finally { |
| 10877 | Binder.restoreCallingIdentity(identity); |
| 10878 | } |
| 10879 | } |
| 10880 | |
| 10881 | /** |
| 10882 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10883 | * device does not have an active PUBLISH. |
| 10884 | */ |
| 10885 | // Used for SHELL command only right now. |
| 10886 | @Override |
| 10887 | public String getLastUcePidfXmlShell(int subId) { |
| 10888 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10889 | final long identity = Binder.clearCallingIdentity(); |
| 10890 | try { |
| 10891 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10892 | } catch (ImsException e) { |
| 10893 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10894 | } finally { |
| 10895 | Binder.restoreCallingIdentity(identity); |
| 10896 | } |
| 10897 | } |
| 10898 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame] | 10899 | /** |
| 10900 | * Remove UCE requests cannot be sent to the network status. |
| 10901 | */ |
| 10902 | // Used for SHELL command only right now. |
| 10903 | @Override |
| 10904 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10905 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10906 | final long identity = Binder.clearCallingIdentity(); |
| 10907 | try { |
| 10908 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10909 | } catch (ImsException e) { |
| 10910 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10911 | } finally { |
| 10912 | Binder.restoreCallingIdentity(identity); |
| 10913 | } |
| 10914 | } |
| 10915 | |
James.cf Lin | 0fc71b0 | 2021-05-25 01:37:38 +0800 | [diff] [blame] | 10916 | /** |
| 10917 | * Remove UCE requests cannot be sent to the network status. |
| 10918 | */ |
| 10919 | // Used for SHELL command only. |
| 10920 | @Override |
| 10921 | public boolean setCapabilitiesRequestTimeout(int subId, long timeoutAfterMs) { |
| 10922 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCapRequestTimeout"); |
| 10923 | final long identity = Binder.clearCallingIdentity(); |
| 10924 | try { |
| 10925 | return mApp.imsRcsController.setCapabilitiesRequestTimeout(subId, timeoutAfterMs); |
| 10926 | } catch (ImsException e) { |
| 10927 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10928 | } finally { |
| 10929 | Binder.restoreCallingIdentity(identity); |
| 10930 | } |
| 10931 | } |
Brad Ebinger | 14d467f | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10932 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10933 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10934 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10935 | String callingPackage) { |
| 10936 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10937 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10938 | |
| 10939 | final int callingUid = Binder.getCallingUid(); |
| 10940 | // Verify that tha callingPackage belongs to the calling UID |
| 10941 | mApp.getSystemService(AppOpsManager.class) |
| 10942 | .checkPackage(callingUid, callingPackage); |
| 10943 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10944 | validateSignalStrengthUpdateRequest(mApp, request, callingUid); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10945 | |
| 10946 | final long identity = Binder.clearCallingIdentity(); |
| 10947 | try { |
| 10948 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10949 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10950 | |
| 10951 | if (result instanceof IllegalStateException) { |
| 10952 | throw (IllegalStateException) result; |
| 10953 | } |
| 10954 | } finally { |
| 10955 | Binder.restoreCallingIdentity(identity); |
| 10956 | } |
| 10957 | } |
| 10958 | |
| 10959 | @Override |
| 10960 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10961 | String callingPackage) { |
| 10962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10963 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10964 | |
| 10965 | final int callingUid = Binder.getCallingUid(); |
| 10966 | // Verify that tha callingPackage belongs to the calling UID |
| 10967 | mApp.getSystemService(AppOpsManager.class) |
| 10968 | .checkPackage(callingUid, callingPackage); |
| 10969 | |
| 10970 | final long identity = Binder.clearCallingIdentity(); |
| 10971 | try { |
| 10972 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10973 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10974 | |
| 10975 | if (result instanceof IllegalStateException) { |
| 10976 | throw (IllegalStateException) result; |
| 10977 | } |
| 10978 | } finally { |
| 10979 | Binder.restoreCallingIdentity(identity); |
| 10980 | } |
| 10981 | } |
| 10982 | |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10983 | private static void validateSignalStrengthUpdateRequest(Context context, |
| 10984 | SignalStrengthUpdateRequest request, int callingUid) { |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10985 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10986 | // phone/system process do not have further restriction on request |
| 10987 | return; |
| 10988 | } |
| 10989 | |
| 10990 | // Applications has restrictions on how to use the request: |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10991 | // Non-system callers need permission to set mIsSystemThresholdReportingRequestedWhileIdle |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10992 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
Rambo Wang | 3607f50 | 2021-02-01 21:51:40 -0800 | [diff] [blame] | 10993 | context.enforceCallingOrSelfPermission( |
| 10994 | android.Manifest.permission.LISTEN_ALWAYS_REPORTED_SIGNAL_STRENGTH, |
| 10995 | "validateSignalStrengthUpdateRequest"); |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10996 | } |
| 10997 | |
| 10998 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10999 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 11000 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 11001 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 11002 | || info.isEnabled()) { |
| 11003 | throw new IllegalArgumentException( |
| 11004 | "Only system can set hide fields in SignalThresholdInfo"); |
| 11005 | } |
| 11006 | |
| 11007 | // Thresholds length for each RAN need in range. This has been validated in |
| 11008 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 11009 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 11010 | final int[] thresholds = info.getThresholds(); |
| 11011 | Objects.requireNonNull(thresholds); |
| 11012 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 11013 | || thresholds.length |
| 11014 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 11015 | throw new IllegalArgumentException( |
| 11016 | "thresholds length is out of range: " + thresholds.length); |
| 11017 | } |
| 11018 | } |
| 11019 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 11020 | |
| 11021 | /** |
| 11022 | * Gets the current phone capability. |
| 11023 | * |
| 11024 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 11025 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 11026 | * It's used to evaluate possible phone config change, for example from single |
| 11027 | * SIM device to multi-SIM device. |
| 11028 | */ |
| 11029 | @Override |
| 11030 | public PhoneCapability getPhoneCapability() { |
| 11031 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 11032 | final long identity = Binder.clearCallingIdentity(); |
| 11033 | try { |
| 11034 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 11035 | } finally { |
| 11036 | Binder.restoreCallingIdentity(identity); |
| 11037 | } |
| 11038 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 11039 | |
| 11040 | /** |
| 11041 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 11042 | * required to be done shortly after the API is invoked. |
| 11043 | */ |
| 11044 | @Override |
| 11045 | @TelephonyManager.PrepareUnattendedRebootResult |
| 11046 | public int prepareForUnattendedReboot() { |
| 11047 | enforceRebootPermission(); |
| 11048 | |
| 11049 | final long identity = Binder.clearCallingIdentity(); |
| 11050 | try { |
| 11051 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 11052 | } finally { |
| 11053 | Binder.restoreCallingIdentity(identity); |
| 11054 | } |
| 11055 | } |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11056 | |
| 11057 | /** |
| 11058 | * Request to get the current slicing configuration including URSP rules and |
| 11059 | * NSSAIs (configured, allowed and rejected). |
| 11060 | * |
| 11061 | * Requires carrier privileges or READ_PRIVILEGED_PHONE_STATE permission. |
| 11062 | */ |
| 11063 | @Override |
| 11064 | public void getSlicingConfig(ResultReceiver callback) { |
Hongbo Zeng | 1b2063d | 2022-02-21 01:33:03 +0000 | [diff] [blame] | 11065 | TelephonyPermissions |
| 11066 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11067 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, "getSlicingConfig"); |
Hongbo Zeng | 156aa4a | 2021-02-08 21:50:28 +0800 | [diff] [blame] | 11068 | |
| 11069 | final long identity = Binder.clearCallingIdentity(); |
| 11070 | try { |
| 11071 | Phone phone = getDefaultPhone(); |
| 11072 | sendRequestAsync(CMD_GET_SLICING_CONFIG, callback, phone, null); |
| 11073 | } finally { |
| 11074 | Binder.restoreCallingIdentity(identity); |
| 11075 | } |
| 11076 | } |
Hunsuk Choi | c7ebc0f | 2021-11-15 23:46:41 +0000 | [diff] [blame] | 11077 | |
| 11078 | /** |
| 11079 | * Register an IMS connection state callback |
| 11080 | */ |
| 11081 | @Override |
| 11082 | public void registerImsStateCallback(int subId, int feature, IImsStateCallback cb, |
| 11083 | String callingPackage) { |
| 11084 | if (feature == ImsFeature.FEATURE_MMTEL) { |
| 11085 | // ImsMmTelManager |
| 11086 | // The following also checks READ_PRIVILEGED_PHONE_STATE. |
| 11087 | TelephonyPermissions |
| 11088 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 11089 | mApp, subId, "registerImsStateCallback"); |
| 11090 | } else if (feature == ImsFeature.FEATURE_RCS) { |
| 11091 | // ImsRcsManager or SipDelegateManager |
| 11092 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 11093 | Binder.getCallingUid(), "registerImsStateCallback", |
| 11094 | Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
| 11095 | Manifest.permission.READ_PRECISE_PHONE_STATE, |
| 11096 | Manifest.permission.ACCESS_RCS_USER_CAPABILITY_EXCHANGE, |
| 11097 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
| 11098 | } |
| 11099 | |
| 11100 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 11101 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11102 | "IMS not available on device."); |
| 11103 | } |
| 11104 | |
| 11105 | if (subId == SubscriptionManager.DEFAULT_SUBSCRIPTION_ID) { |
| 11106 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 11107 | } |
| 11108 | |
| 11109 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11110 | if (controller == null) { |
| 11111 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 11112 | "IMS not available on device."); |
| 11113 | } |
| 11114 | |
| 11115 | if (callingPackage == null) { |
| 11116 | callingPackage = getCurrentPackageName(); |
| 11117 | } |
| 11118 | |
| 11119 | final long token = Binder.clearCallingIdentity(); |
| 11120 | try { |
| 11121 | int slotId = getSlotIndexOrException(subId); |
| 11122 | controller.registerImsStateCallback(subId, feature, cb, callingPackage); |
| 11123 | } catch (ImsException e) { |
| 11124 | throw new ServiceSpecificException(e.getCode()); |
| 11125 | } finally { |
| 11126 | Binder.restoreCallingIdentity(token); |
| 11127 | } |
| 11128 | } |
| 11129 | |
| 11130 | /** |
| 11131 | * Unregister an IMS connection state callback |
| 11132 | */ |
| 11133 | @Override |
| 11134 | public void unregisterImsStateCallback(IImsStateCallback cb) { |
| 11135 | final long token = Binder.clearCallingIdentity(); |
| 11136 | ImsStateCallbackController controller = ImsStateCallbackController.getInstance(); |
| 11137 | if (controller == null) { |
| 11138 | return; |
| 11139 | } |
| 11140 | try { |
| 11141 | controller.unregisterImsStateCallback(cb); |
| 11142 | } finally { |
| 11143 | Binder.restoreCallingIdentity(token); |
| 11144 | } |
| 11145 | } |
Sooraj Sasindran | fae41b3 | 2021-10-26 02:10:05 -0700 | [diff] [blame] | 11146 | |
| 11147 | /** |
| 11148 | * @return {@CellIdentity} last known cell identity {@CellIdentity}. |
| 11149 | * |
| 11150 | * Require {@link android.Manifest.permission#ACCESS_FINE_LOCATION} and |
| 11151 | * com.android.phone.permission.ACCESS_LAST_KNOWN_CELL_ID, otherwise throws |
| 11152 | * SecurityException. |
| 11153 | * If there is current registered network this value will be same as the registered cell |
| 11154 | * identity. If the device goes out of service the previous cell identity is cached and |
| 11155 | * will be returned. If the cache age of the Cell identity is more than 24 hours |
| 11156 | * it will be cleared and null will be returned. |
| 11157 | * |
| 11158 | */ |
| 11159 | @Override |
| 11160 | public @Nullable CellIdentity getLastKnownCellIdentity(int subId, String callingPackage, |
| 11161 | String callingFeatureId) { |
| 11162 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 11163 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 11164 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 11165 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 11166 | .setCallingPackage(callingPackage) |
| 11167 | .setCallingFeatureId(callingFeatureId) |
| 11168 | .setCallingPid(Binder.getCallingPid()) |
| 11169 | .setCallingUid(Binder.getCallingUid()) |
| 11170 | .setMethod("getLastKnownCellIdentity") |
| 11171 | .setLogAsInfo(true) |
| 11172 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 11173 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 11174 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
| 11175 | .build()); |
| 11176 | |
| 11177 | boolean hasFinePermission = |
| 11178 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 11179 | if (!hasFinePermission |
| 11180 | || !TelephonyPermissions.checkLastKnownCellIdAccessPermission(mApp)) { |
| 11181 | throw new SecurityException("getLastKnownCellIdentity need ACCESS_FINE_LOCATION " |
| 11182 | + "and BIND_CONNECTION_SERVICE permission."); |
| 11183 | } |
| 11184 | |
| 11185 | final long identity = Binder.clearCallingIdentity(); |
| 11186 | try { |
| 11187 | Phone phone = getPhone(subId); |
| 11188 | if (phone == null) return null; |
| 11189 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 11190 | if (sst == null) return null; |
| 11191 | return sst.getLastKnownCellIdentity(); |
| 11192 | } finally { |
| 11193 | Binder.restoreCallingIdentity(identity); |
| 11194 | } |
| 11195 | } |
jimsun | 38340bf | 2021-10-26 15:01:23 +0800 | [diff] [blame] | 11196 | |
| 11197 | /** |
| 11198 | * Sets the modem service class Name that Telephony will bind to. |
| 11199 | * |
| 11200 | * @param serviceName The class name of the modem service. |
| 11201 | * @return true if the operation is succeed, otherwise false. |
| 11202 | */ |
| 11203 | public boolean setModemService(String serviceName) { |
| 11204 | Log.d(LOG_TAG, "setModemService - " + serviceName); |
| 11205 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setModemService"); |
| 11206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 11207 | SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11208 | "setModemService"); |
| 11209 | return mPhoneConfigurationManager.setModemService(serviceName); |
| 11210 | } |
| 11211 | |
| 11212 | /** |
| 11213 | * Return the class name of the currently bounded modem service. |
| 11214 | * |
| 11215 | * @return the class name of the modem service. |
| 11216 | */ |
| 11217 | public String getModemService() { |
| 11218 | String result; |
| 11219 | Log.d(LOG_TAG, "getModemService"); |
| 11220 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getModemService"); |
| 11221 | TelephonyPermissions |
| 11222 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 11223 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
| 11224 | "getModemService"); |
| 11225 | result = mPhoneConfigurationManager.getModemService(); |
| 11226 | Log.d(LOG_TAG, "result = " + result); |
| 11227 | return result; |
| 11228 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 11229 | } |